From af22a4f2cda86a7667578281a51ea1ec08a49af6 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Thu, 7 Jan 2021 23:06:23 +0100 Subject: [PATCH] Add: show in the tooltip of disabled toolbar buttons why they are disabled --- src/airport_gui.cpp | 5 +++++ src/dock_gui.cpp | 9 +++++++++ src/lang/english.txt | 3 +++ src/road_gui.cpp | 12 +++++++++++- src/widget.cpp | 9 +++++++++ src/widget_type.h | 1 + 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 62eca78f9f..e12b8dccbd 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -97,6 +97,11 @@ struct BuildAirToolbarWindow : Window { WIDGET_LIST_END); if (!can_build) { DeleteWindowById(WC_BUILD_STATION, TRANSPORT_AIR); + + /* Show in the tooltip why this button is disabled. */ + this->GetWidget(WID_AT_AIRPORT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE); + } else { + this->GetWidget(WID_AT_AIRPORT)->SetToolTip(STR_TOOLBAR_AIRCRAFT_BUILD_AIRPORT_TOOLTIP); } } diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 7e2d618572..39237f5ca1 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -125,6 +125,15 @@ struct BuildDocksToolbarWindow : Window { if (!can_build) { DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER); DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER); + + /* Show in the tooltip why this button is disabled. */ + this->GetWidget(WID_DT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE); + this->GetWidget(WID_DT_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE); + this->GetWidget(WID_DT_BUOY)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE); + } else { + this->GetWidget(WID_DT_DEPOT)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUILD_DEPOT_TOOLTIP); + this->GetWidget(WID_DT_STATION)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUILD_DOCK_TOOLTIP); + this->GetWidget(WID_DT_BUOY)->SetToolTip(STR_WATERWAYS_TOOLBAR_BUOY_TOOLTIP); } } diff --git a/src/lang/english.txt b/src/lang/english.txt index 52b75f413f..a0cf2b9a0f 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2353,6 +2353,9 @@ STR_JOIN_STATION_CREATE_SPLITTED_STATION :{YELLOW}Build a STR_JOIN_WAYPOINT_CAPTION :{WHITE}Join waypoint STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT :{YELLOW}Build a separate waypoint +# Generic toolbar +STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE :{BLACK}Disabled as currently no vehicles are available for this infrastructure + # Rail construction toolbar STR_RAIL_TOOLBAR_RAILROAD_CONSTRUCTION_CAPTION :Railway Construction STR_RAIL_TOOLBAR_ELRAIL_CONSTRUCTION_CAPTION :Electrified Railway Construction diff --git a/src/road_gui.cpp b/src/road_gui.cpp index dff4d2bc10..b9f59333d4 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -303,8 +303,9 @@ struct BuildRoadToolbarWindow : Window { void OnInvalidateData(int data = 0, bool gui_scope = true) override { if (!gui_scope) return; + RoadTramType rtt = GetRoadTramType(this->roadtype); - bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype)); + bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD, rtt); this->SetWidgetsDisabledState(!can_build, WID_ROT_DEPOT, WID_ROT_BUS_STATION, @@ -314,6 +315,15 @@ struct BuildRoadToolbarWindow : Window { DeleteWindowById(WC_BUS_STATION, TRANSPORT_ROAD); DeleteWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD); DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_ROAD); + + /* Show in the tooltip why this button is disabled. */ + this->GetWidget(WID_ROT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE); + this->GetWidget(WID_ROT_BUS_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE); + this->GetWidget(WID_ROT_TRUCK_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE); + } else { + this->GetWidget(WID_ROT_DEPOT)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT); + this->GetWidget(WID_ROT_BUS_STATION)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION); + this->GetWidget(WID_ROT_TRUCK_STATION)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION); } } diff --git a/src/widget.cpp b/src/widget.cpp index 2be2f2b85d..d1ba44679b 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -895,6 +895,15 @@ void NWidgetCore::SetDataTip(uint32 widget_data, StringID tool_tip) this->tool_tip = tool_tip; } +/** + * Set the tool tip of the nested widget. + * @param tool_tip Tool tip string to use. + */ +void NWidgetCore::SetToolTip(StringID tool_tip) +{ + this->tool_tip = tool_tip; +} + void NWidgetCore::FillNestedArray(NWidgetBase **array, uint length) { if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this; diff --git a/src/widget_type.h b/src/widget_type.h index 1b16770391..d8841f9bd2 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -285,6 +285,7 @@ public: void SetIndex(int index); void SetDataTip(uint32 widget_data, StringID tool_tip); + void SetToolTip(StringID tool_tip); inline void SetLowered(bool lowered); inline bool IsLowered() const;