diff --git a/src/base_media_base.h b/src/base_media_base.h index f85c9c40f8..0875996103 100644 --- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -254,6 +254,7 @@ public: bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename); GRFConfig *GetExtraConfig() const { return this->extra_cfg.get(); } GRFConfig &GetOrCreateExtraConfig() const; + bool IsConfigurable() const; void CopyCompatibleConfig(const GraphicsSet &src); static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir); diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index aa4d1c66fc..943c5bb102 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -389,6 +389,14 @@ GRFConfig &GraphicsSet::GetOrCreateExtraConfig() const return *this->extra_cfg; } +bool GraphicsSet::IsConfigurable() const +{ + const GRFConfig &cfg = this->GetOrCreateExtraConfig(); + /* This check is more strict than the one for NewGRF Settings. + * There are no legacy basesets with parameters, but without Action14 */ + return !cfg.param_info.empty(); +} + void GraphicsSet::CopyCompatibleConfig(const GraphicsSet &src) { const GRFConfig *src_cfg = src.GetExtraConfig(); diff --git a/src/lang/english.txt b/src/lang/english.txt index 69e4f3c989..1ff9eaf612 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3384,6 +3384,7 @@ STR_SAVE_PRESET_SAVE :{BLACK}Save STR_SAVE_PRESET_SAVE_TOOLTIP :{BLACK}Save the preset to the current selected name # NewGRF parameters window +STR_BASEGRF_PARAMETERS_CAPTION :{WHITE}Change base graphics parameters STR_NEWGRF_PARAMETERS_CAPTION :{WHITE}Change NewGRF parameters STR_NEWGRF_PARAMETERS_CLOSE :{BLACK}Close STR_NEWGRF_PARAMETERS_RESET :{BLACK}Reset diff --git a/src/newgrf_config.h b/src/newgrf_config.h index 8596eab563..c9f6d51d71 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -226,6 +226,7 @@ std::string GRFBuildParamList(const GRFConfig *c); /* In newgrf_gui.cpp */ void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config); +void OpenGRFParameterWindow(bool is_baseset, GRFConfig *c, bool editable); void UpdateNewGRFScanStatus(uint num, const char *name); void UpdateNewGRFConfigPalette(int32_t new_value = 0); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index f9e8e100d8..036914cfe1 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -155,7 +155,7 @@ struct NewGRFParametersWindow : public Window { bool action14present; ///< True if action14 information is present. bool editable; ///< Allow editing parameters. - NewGRFParametersWindow(WindowDesc *desc, GRFConfig *c, bool editable) : Window(desc), + NewGRFParametersWindow(WindowDesc *desc, bool is_baseset, GRFConfig *c, bool editable) : Window(desc), grf_config(c), clicked_button(UINT_MAX), clicked_dropdown(false), @@ -166,6 +166,7 @@ struct NewGRFParametersWindow : public Window { this->action14present = (c->num_valid_params != c->param.size() || !c->param_info.empty()); this->CreateNestedTree(); + this->GetWidget(WID_NP_CAPTION)->SetDataTip(is_baseset ? STR_BASEGRF_PARAMETERS_CAPTION : STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS); this->vscroll = this->GetScrollbar(WID_NP_SCROLLBAR); this->GetWidget(WID_NP_SHOW_NUMPAR)->SetDisplayedPlane(this->action14present ? SZSP_HORIZONTAL : 0); this->GetWidget(WID_NP_SHOW_DESCRIPTION)->SetDisplayedPlane(this->action14present ? 0 : SZSP_HORIZONTAL); @@ -509,7 +510,7 @@ GRFParameterInfo NewGRFParametersWindow::dummy_parameter_info(0); static const NWidgetPart _nested_newgrf_parameter_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_MAUVE), - NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), + NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_NP_CAPTION), NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE), EndContainer(), NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NP_SHOW_NUMPAR), @@ -546,10 +547,10 @@ static WindowDesc _newgrf_parameters_desc( std::begin(_nested_newgrf_parameter_widgets), std::end(_nested_newgrf_parameter_widgets) ); -static void OpenGRFParameterWindow(GRFConfig *c, bool editable) +void OpenGRFParameterWindow(bool is_baseset, GRFConfig *c, bool editable) { CloseWindowByClass(WC_GRF_PARAMETERS); - new NewGRFParametersWindow(&_newgrf_parameters_desc, c, editable); + new NewGRFParametersWindow(&_newgrf_parameters_desc, is_baseset, c, editable); } /** Window for displaying the textfile of a NewGRF. */ @@ -1133,7 +1134,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { case WID_NS_SET_PARAMETERS: { // Edit parameters if (this->active_sel == nullptr || !this->show_params || this->active_sel->num_valid_params == 0) break; - OpenGRFParameterWindow(this->active_sel, this->editable); + OpenGRFParameterWindow(false, this->active_sel, this->editable); this->InvalidateData(GOID_NEWGRF_CHANGES_MADE); break; } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 1749a6633c..dc56f92812 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -41,6 +41,7 @@ #include "music/music_driver.hpp" #include "gui.h" #include "mixer.h" +#include "newgrf_config.h" #include "network/core/config.h" #include "network/network_gui.h" #include "network/network_survey.h" @@ -601,6 +602,16 @@ struct GameOptionsWindow : Window { break; } + case WID_GO_BASE_GRF_PARAMETERS: { + auto *used_set = BaseGraphics::GetUsedSet(); + if (used_set == nullptr || !used_set->IsConfigurable()) break; + GRFConfig &extra_cfg = used_set->GetOrCreateExtraConfig(); + if (extra_cfg.num_params == 0) extra_cfg.SetParameterDefaults(); + OpenGRFParameterWindow(true, &extra_cfg, _game_mode == GM_MENU); + if (_game_mode == GM_MENU) this->reload = true; + break; + } + case WID_GO_BASE_SFX_VOLUME: case WID_GO_BASE_MUSIC_VOLUME: { byte &vol = (widget == WID_GO_BASE_MUSIC_VOLUME) ? _settings_client.music.music_vol : _settings_client.music.effect_vol; @@ -692,6 +703,7 @@ struct GameOptionsWindow : Window { case WID_GO_BASE_GRF_DROPDOWN: if (_game_mode == GM_MENU) { + CloseWindowByClass(WC_GRF_PARAMETERS); auto* set = BaseGraphics::GetSet(index); BaseGraphics::SetSet(set); this->reload = true; @@ -742,6 +754,8 @@ struct GameOptionsWindow : Window { bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0; this->GetWidget(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL); + this->SetWidgetDisabledState(WID_GO_BASE_GRF_PARAMETERS, BaseGraphics::GetUsedSet() == nullptr || !BaseGraphics::GetUsedSet()->IsConfigurable()); + for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) { this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == nullptr || !BaseGraphics::GetUsedSet()->GetTextfile(tft).has_value()); this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == nullptr || !BaseSounds::GetUsedSet()->GetTextfile(tft).has_value()); @@ -853,6 +867,7 @@ static const NWidgetPart _nested_game_options_widgets[] = { NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0), NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP), NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(100, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_PARAMETERS), SetDataTip(STR_NEWGRF_SETTINGS_SET_PARAMETERS, STR_NULL), EndContainer(), NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(200, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7), diff --git a/src/widgets/newgrf_widget.h b/src/widgets/newgrf_widget.h index 2d39665447..da4e4d584d 100644 --- a/src/widgets/newgrf_widget.h +++ b/src/widgets/newgrf_widget.h @@ -15,6 +15,7 @@ /** Widgets of the #NewGRFParametersWindow class. */ enum NewGRFParametersWidgets { + WID_NP_CAPTION, ///< Caption of the window. WID_NP_SHOW_NUMPAR, ///< #NWID_SELECTION to optionally display #WID_NP_NUMPAR. WID_NP_NUMPAR_DEC, ///< Button to decrease number of parameters. WID_NP_NUMPAR_INC, ///< Button to increase number of parameters. diff --git a/src/widgets/settings_widget.h b/src/widgets/settings_widget.h index f358e6ccda..58541546d5 100644 --- a/src/widgets/settings_widget.h +++ b/src/widgets/settings_widget.h @@ -26,6 +26,7 @@ enum GameOptionsWidgets { WID_GO_GUI_SCALE_AUTO, ///< Autodetect GUI scale button. WID_GO_GUI_SCALE_BEVEL_BUTTON, ///< Toggle for chunky bevels. WID_GO_BASE_GRF_DROPDOWN, ///< Use to select a base GRF. + WID_GO_BASE_GRF_PARAMETERS, ///< Base GRF parameters. WID_GO_BASE_GRF_STATUS, ///< Info about missing files etc. WID_GO_BASE_GRF_TEXTFILE, ///< Open base GRF readme, changelog (+1) or license (+2). WID_GO_BASE_GRF_DESCRIPTION = WID_GO_BASE_GRF_TEXTFILE + TFT_CONTENT_END, ///< Description of selected base GRF.