diff options
-rw-r--r-- | src/airport_gui.cpp | 10 | ||||
-rw-r--r-- | src/dock_gui.cpp | 3 | ||||
-rw-r--r-- | src/rail_gui.cpp | 13 | ||||
-rw-r--r-- | src/road_gui.cpp | 16 | ||||
-rw-r--r-- | src/toolbar_gui.cpp | 11 |
5 files changed, 22 insertions, 31 deletions
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 8760e1f2a..62eca78f9 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -71,6 +71,7 @@ struct BuildAirToolbarWindow : Window { BuildAirToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc) { this->InitNested(window_number); + this->OnInvalidateData(); if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this); this->last_user_action = WIDGET_LIST_END; } @@ -90,7 +91,13 @@ struct BuildAirToolbarWindow : Window { { if (!gui_scope) return; - if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) delete this; + bool can_build = CanBuildVehicleInfrastructure(VEH_AIRCRAFT); + this->SetWidgetsDisabledState(!can_build, + WID_AT_AIRPORT, + WIDGET_LIST_END); + if (!can_build) { + DeleteWindowById(WC_BUILD_STATION, TRANSPORT_AIR); + } } void OnClick(Point pt, int widget, int click_count) override @@ -160,7 +167,6 @@ struct BuildAirToolbarWindow : Window { */ static EventState AirportToolbarGlobalHotkeys(int hotkey) { - if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED; Window *w = ShowBuildAirToolbar(); if (w == nullptr) return ES_NOT_HANDLED; return w->OnHotkey(hotkey); diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 30a60e74f..7e2d61857 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -144,17 +144,14 @@ struct BuildDocksToolbarWindow : Window { break; case WID_DT_DEPOT: // Build depot button - if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return; if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this); break; case WID_DT_STATION: // Build station button - if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return; if (HandlePlacePushButton(this, WID_DT_STATION, SPR_CURSOR_DOCK, HT_SPECIAL)) ShowBuildDockStationPicker(this); break; case WID_DT_BUOY: // Build buoy button - if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return; HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT); break; diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 177f72acc..37c365881 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -437,18 +437,6 @@ struct BuildRailToolbarWindow : Window { } /** - * Some data on this window has become invalid. - * @param data Information about the changed data. - * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details. - */ - void OnInvalidateData(int data = 0, bool gui_scope = true) override - { - if (!gui_scope) return; - - if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) delete this; - } - - /** * Configures the rail toolbar for railtype given * @param railtype the railtype to display */ @@ -781,7 +769,6 @@ struct BuildRailToolbarWindow : Window { */ static EventState RailToolbarGlobalHotkeys(int hotkey) { - if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED; extern RailType _last_built_railtype; Window *w = ShowBuildRailToolbar(_last_built_railtype); if (w == nullptr) return ES_NOT_HANDLED; diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 1e1f3e807..dff4d2bc1 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -304,7 +304,17 @@ struct BuildRoadToolbarWindow : Window { { if (!gui_scope) return; - if (_game_mode != GM_EDITOR && !CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype))) delete this; + bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype)); + this->SetWidgetsDisabledState(!can_build, + WID_ROT_DEPOT, + WID_ROT_BUS_STATION, + WID_ROT_TRUCK_STATION, + WIDGET_LIST_END); + if (!can_build) { + DeleteWindowById(WC_BUS_STATION, TRANSPORT_ROAD); + DeleteWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD); + DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_ROAD); + } } void Initialize(RoadType roadtype) @@ -434,7 +444,6 @@ struct BuildRoadToolbarWindow : Window { break; case WID_ROT_DEPOT: - if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype))) return; if (HandlePlacePushButton(this, WID_ROT_DEPOT, this->rti->cursor.depot, HT_RECT)) { ShowRoadDepotPicker(this); this->last_started_action = widget; @@ -442,7 +451,6 @@ struct BuildRoadToolbarWindow : Window { break; case WID_ROT_BUS_STATION: - if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype))) return; if (HandlePlacePushButton(this, WID_ROT_BUS_STATION, SPR_CURSOR_BUS_STATION, HT_RECT)) { ShowRVStationPicker(this, ROADSTOP_BUS); this->last_started_action = widget; @@ -450,7 +458,6 @@ struct BuildRoadToolbarWindow : Window { break; case WID_ROT_TRUCK_STATION: - if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD, GetRoadTramType(this->roadtype))) return; if (HandlePlacePushButton(this, WID_ROT_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, HT_RECT)) { ShowRVStationPicker(this, ROADSTOP_TRUCK); this->last_started_action = widget; @@ -711,7 +718,6 @@ static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build, Window* w = nullptr; switch (_game_mode) { case GM_NORMAL: - if (!CanBuildVehicleInfrastructure(VEH_ROAD, rtt)) return ES_NOT_HANDLED; w = ShowBuildRoadToolbar(last_build); break; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 224c8ccdb..6a851d2b5 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -2033,11 +2033,6 @@ struct MainToolbarWindow : Window { this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0); this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0); - this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN)); - this->SetWidgetDisabledState(WID_TN_ROADS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_ROAD)); - this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM)); - this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)); - this->DrawWidgets(); } @@ -2078,11 +2073,11 @@ struct MainToolbarWindow : Window { case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break; case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break; case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break; - case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break; + case MTHK_BUILD_RAIL: ShowBuildRailToolbar(_last_built_railtype); break; case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break; - case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM)) ShowBuildRoadToolbar(_last_built_tramtype); break; + case MTHK_BUILD_TRAM: ShowBuildRoadToolbar(_last_built_tramtype); break; case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break; - case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break; + case MTHK_BUILD_AIRPORT: ShowBuildAirToolbar(); break; case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break; case MTHK_MUSIC: ShowMusicWindow(); break; case MTHK_AI_DEBUG: ShowAIDebugWindow(); break; |