diff --git a/src/lang/english.txt b/src/lang/english.txt index 1ab7354042..0a8eb3665c 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3396,6 +3396,8 @@ STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND :{BLACK}Generate STR_TERRAFORM_SE_NEW_WORLD :{BLACK}Create new scenario STR_TERRAFORM_RESET_LANDSCAPE :{BLACK}Reset landscape STR_TERRAFORM_RESET_LANDSCAPE_TOOLTIP :{BLACK}Remove all company-owned property from the map +STR_TERRAFORM_PUBLIC_ROADS :{BLACK}Build public roads +STR_TERRAFORM_PUBLIC_ROADS_TOOLTIP :{BLACK}Build public roads between the towns on the map STR_QUERY_RESET_LANDSCAPE_CAPTION :{WHITE}Reset Landscape STR_RESET_LANDSCAPE_CONFIRMATION_TEXT :{WHITE}Are you sure you want to remove all company-owned property? diff --git a/src/settings.cpp b/src/settings.cpp index 6ec480aecc..1b42726e7d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1536,6 +1536,11 @@ static bool ChangeTrackTypeSortMode(int32 p1) { return true; } +static bool PublicRoadsSettingChange(int32 p1) { + InvalidateWindowClassesData(WC_SCEN_LAND_GEN); + return true; +} + /** Checks if any settings are set to incorrect values, and sets them to correct values in that case. */ static void ValidateSettings() { diff --git a/src/table/settings.ini b/src/table/settings.ini index 14de0db585..befe6cfe2b 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -63,6 +63,7 @@ static bool UpdateLinkgraphColours(int32 p1); static bool ClimateThresholdModeChanged(int32 p1); static bool VelocityUnitsChanged(int32 p1); static bool ChangeTrackTypeSortMode(int32 p1); +static bool PublicRoadsSettingChange(int32 p1); static bool UpdateClientName(int32 p1); static bool UpdateServerPassword(int32 p1); @@ -4080,13 +4081,14 @@ xref = ""game_creation.build_public_roads"" base = GameSettings var = game_creation.build_public_roads type = SLE_UINT8 -guiflags = SGF_MULTISTRING | SGF_NEWGAME_ONLY +guiflags = SGF_MULTISTRING | SGF_NEWGAME_ONLY | SGF_SCENEDIT_TOO def = 0 min = 0 max = 2 str = STR_CONFIG_SETTING_BUILD_PUBLIC_ROADS strhelp = STR_CONFIG_SETTING_BUILD_PUBLIC_ROADS_HELPTEXT strval = STR_CONFIG_SETTING_BUILD_PUBLIC_ROADS_NONE +proc = PublicRoadsSettingChange patxname = ""public_roads.game_creation.build_public_roads"" ; locale diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 41a71b7096..4b2f646a87 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -572,7 +572,12 @@ static const NWidgetPart _nested_scen_edit_land_gen_widgets[] = { NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_ETT_NEW_SCENARIO), SetMinimalSize(160, 12), SetFill(1, 0), SetDataTip(STR_TERRAFORM_SE_NEW_WORLD, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetPadding(0, 2, 0, 2), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_ETT_RESET_LANDSCAPE), SetMinimalSize(160, 12), - SetFill(1, 0), SetDataTip(STR_TERRAFORM_RESET_LANDSCAPE, STR_TERRAFORM_RESET_LANDSCAPE_TOOLTIP), SetPadding(1, 2, 2, 2), + SetFill(1, 0), SetDataTip(STR_TERRAFORM_RESET_LANDSCAPE, STR_TERRAFORM_RESET_LANDSCAPE_TOOLTIP), SetPadding(1, 2, 0, 2), + NWidget(NWID_SELECTION, INVALID_COLOUR, WID_ETT_SHOW_PUBLIC_ROADS), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_ETT_PUBLIC_ROADS), SetMinimalSize(160, 12), + SetFill(1, 0), SetDataTip(STR_TERRAFORM_PUBLIC_ROADS, STR_TERRAFORM_PUBLIC_ROADS_TOOLTIP), SetPadding(1, 2, 0, 2), + EndContainer(), + NWidget(NWID_SPACER), SetMinimalSize(0, 2), EndContainer(), }; @@ -617,8 +622,7 @@ struct ScenarioEditorLandscapeGenerationWindow : Window { ScenarioEditorLandscapeGenerationWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc) { this->CreateNestedTree(); - NWidgetStacked *show_desert = this->GetWidget(WID_ETT_SHOW_PLACE_DESERT); - show_desert->SetDisplayedPlane(_settings_game.game_creation.landscape == LT_TROPIC ? 0 : SZSP_NONE); + this->SetButtonStates(); this->FinishInitNested(window_number); this->last_user_action = WIDGET_LIST_END; } @@ -723,6 +727,12 @@ struct ScenarioEditorLandscapeGenerationWindow : Window { ShowQuery(STR_QUERY_RESET_LANDSCAPE_CAPTION, STR_RESET_LANDSCAPE_CONFIRMATION_TEXT, nullptr, ResetLandscapeConfirmationCallback); break; + case WID_ETT_PUBLIC_ROADS: { // Build public roads + extern void GeneratePublicRoads(); + GeneratePublicRoads(); + break; + } + default: NOT_REACHED(); } } @@ -798,6 +808,27 @@ struct ScenarioEditorLandscapeGenerationWindow : Window { this->SetDirty(); } + /** + * 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; + + this->SetButtonStates(); + this->ReInit(); + } + + void SetButtonStates() + { + NWidgetStacked *show_desert = this->GetWidget(WID_ETT_SHOW_PLACE_DESERT); + show_desert->SetDisplayedPlane(_settings_game.game_creation.landscape == LT_TROPIC ? 0 : SZSP_NONE); + NWidgetStacked *show_public_roads = this->GetWidget(WID_ETT_SHOW_PUBLIC_ROADS); + show_public_roads->SetDisplayedPlane(_settings_game.game_creation.build_public_roads != 0 ? 0 : SZSP_NONE); + } + static HotkeyList hotkeys; }; diff --git a/src/widgets/terraform_widget.h b/src/widgets/terraform_widget.h index 009d312458..b715e84b31 100644 --- a/src/widgets/terraform_widget.h +++ b/src/widgets/terraform_widget.h @@ -28,6 +28,7 @@ enum TerraformToolbarWidgets { /** Widgets of the #ScenarioEditorLandscapeGenerationWindow class. */ enum EditorTerraformToolbarWidgets { WID_ETT_SHOW_PLACE_DESERT, ///< Should the place desert button be shown? + WID_ETT_SHOW_PUBLIC_ROADS, ///< Should the public roads button be shown? WID_ETT_START, ///< Used for iterations. WID_ETT_DOTS = WID_ETT_START, ///< Invisible widget for rendering the terraform size on. WID_ETT_BUTTONS_START, ///< Start of pushable buttons. @@ -44,6 +45,7 @@ enum EditorTerraformToolbarWidgets { WID_ETT_DECREASE_SIZE, ///< Downwards arrow button to decrease terraforming size. WID_ETT_NEW_SCENARIO, ///< Button for generating a new scenario. WID_ETT_RESET_LANDSCAPE, ///< Button for removing all company-owned property. + WID_ETT_PUBLIC_ROADS, ///< Button for creating public roads. }; #endif /* WIDGETS_TERRAFORM_WIDGET_H */