From abc3a1048405aae601616242d0d6bbbc851301c1 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 22 Feb 2015 15:26:27 +0000 Subject: [PATCH] Invalidate toolbars when changing max vehicles settings (openttd r27163) -Fix [FS#6204]: Toolbars were not invalidated when changing max-vehicles settings. (adf88) --- src/airport_gui.cpp | 12 ++++++++++++ src/dock_gui.cpp | 8 +++++++- src/rail_gui.cpp | 12 ++++++++++++ src/road_gui.cpp | 9 ++++++++- src/settings.cpp | 7 +++++++ src/table/settings.ini | 9 +++++---- 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index e07269a90..0d3b231be 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -81,6 +81,18 @@ struct BuildAirToolbarWindow : Window { if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } + /** + * 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. + */ + virtual void OnInvalidateData(int data = 0, bool gui_scope = true) + { + if (!gui_scope) return; + + if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) delete this; + } + virtual void OnClick(Point pt, int widget, int click_count) { switch (widget) { diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 8bd11451f..f7ce812e9 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -120,11 +120,17 @@ struct BuildDocksToolbarWindow : Window { virtual void OnInvalidateData(int data = 0, bool gui_scope = true) { if (!gui_scope) return; - this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_SHIP), + + bool can_build = CanBuildVehicleInfrastructure(VEH_SHIP); + this->SetWidgetsDisabledState(!can_build, WID_DT_DEPOT, WID_DT_STATION, WID_DT_BUOY, WIDGET_LIST_END); + if (!can_build) { + DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER); + DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_WATER); + } } virtual void OnClick(Point pt, int widget, int click_count) diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index a223e8443..6b64fcb91 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -419,6 +419,18 @@ 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. + */ + virtual void OnInvalidateData(int data = 0, bool gui_scope = true) + { + if (!gui_scope) return; + + if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) delete this; + } + + /** * Configures the rail toolbar for railtype given * @param railtype the railtype to display */ diff --git a/src/road_gui.cpp b/src/road_gui.cpp index d45ac5c3a..fced81c2b 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -341,11 +341,18 @@ struct BuildRoadToolbarWindow : Window { virtual void OnInvalidateData(int data = 0, bool gui_scope = true) { if (!gui_scope) return; - this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD), + + bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD); + this->SetWidgetsDisabledState(!can_build, WID_ROT_DEPOT, WID_ROT_BUS_STATION, WID_ROT_TRUCK_STATION, WIDGET_LIST_END); + if (!can_build) { + DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_ROAD); + DeleteWindowById(WC_BUS_STATION, TRANSPORT_ROAD); + DeleteWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD); + } } /** diff --git a/src/settings.cpp b/src/settings.cpp index 69c25837a..3f6a1ed8e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1295,6 +1295,13 @@ static bool StationCatchmentChanged(int32 p1) return true; } +static bool MaxVehiclesChanged(int32 p1) +{ + InvalidateWindowClassesData(WC_BUILD_TOOLBAR); + MarkWholeScreenDirty(); + return true; +} + #ifdef ENABLE_NETWORK diff --git a/src/table/settings.ini b/src/table/settings.ini index 83f404064..d099e0b92 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -41,6 +41,7 @@ static bool RedrawTownAuthority(int32 p1); static bool InvalidateCompanyInfrastructureWindow(int32 p1); static bool InvalidateCompanyWindow(int32 p1); static bool ZoomMinMaxChanged(int32 p1); +static bool MaxVehiclesChanged(int32 p1); #ifdef ENABLE_NETWORK static bool UpdateClientName(int32 p1); @@ -955,7 +956,7 @@ max = 5000 str = STR_CONFIG_SETTING_MAX_TRAINS strhelp = STR_CONFIG_SETTING_MAX_TRAINS_HELPTEXT strval = STR_JUST_COMMA -proc = RedrawScreen +proc = MaxVehiclesChanged cat = SC_BASIC [SDT_VAR] @@ -968,7 +969,7 @@ max = 5000 str = STR_CONFIG_SETTING_MAX_ROAD_VEHICLES strhelp = STR_CONFIG_SETTING_MAX_ROAD_VEHICLES_HELPTEXT strval = STR_JUST_COMMA -proc = RedrawScreen +proc = MaxVehiclesChanged cat = SC_BASIC [SDT_VAR] @@ -981,7 +982,7 @@ max = 5000 str = STR_CONFIG_SETTING_MAX_AIRCRAFT strhelp = STR_CONFIG_SETTING_MAX_AIRCRAFT_HELPTEXT strval = STR_JUST_COMMA -proc = RedrawScreen +proc = MaxVehiclesChanged cat = SC_BASIC [SDT_VAR] @@ -994,7 +995,7 @@ max = 5000 str = STR_CONFIG_SETTING_MAX_SHIPS strhelp = STR_CONFIG_SETTING_MAX_SHIPS_HELPTEXT strval = STR_JUST_COMMA -proc = RedrawScreen +proc = MaxVehiclesChanged cat = SC_BASIC [SDTG_BOOL] -- 2.11.4.GIT