Feature: Base graphics can offer parameters for additional settings.

This commit is contained in:
frosch 2023-10-02 14:43:10 +02:00 committed by frosch
parent de3f29d7b2
commit e81313e93e
8 changed files with 34 additions and 5 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -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<NWidgetCore>(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<NWidgetStacked>(WID_NP_SHOW_NUMPAR)->SetDisplayedPlane(this->action14present ? SZSP_HORIZONTAL : 0);
this->GetWidget<NWidgetStacked>(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;
}

View File

@ -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<NWidgetCore>(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),

View File

@ -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.

View File

@ -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.