Codechange: let SettingDesc extend SettingDescBase

This commit is contained in:
rubidium42 2021-05-23 09:51:33 +02:00 committed by rubidium42
parent ac99a38175
commit 425d50372f
5 changed files with 62 additions and 63 deletions

View File

@ -75,7 +75,7 @@ const SaveLoad *GetLinkGraphJobDesc()
int setting = 0; int setting = 0;
const SettingDesc *desc = GetSettingDescription(setting); const SettingDesc *desc = GetSettingDescription(setting);
while (desc->save.cmd != SL_END) { while (desc->save.cmd != SL_END) {
if (desc->desc.name != nullptr && strncmp(desc->desc.name, prefix, prefixlen) == 0) { if (desc->name != nullptr && strncmp(desc->name, prefix, prefixlen) == 0) {
SaveLoad sl = desc->save; SaveLoad sl = desc->save;
sl.address_proc = proc; sl.address_proc = proc;
saveloads.push_back(sl); saveloads.push_back(sl);

View File

@ -18,7 +18,7 @@
/* static */ bool ScriptGameSettings::IsValid(const char *setting) /* static */ bool ScriptGameSettings::IsValid(const char *setting)
{ {
const SettingDesc *sd = GetSettingFromName(setting); const SettingDesc *sd = GetSettingFromName(setting);
return sd != nullptr && sd->desc.cmd != SDT_STDSTRING; return sd != nullptr && sd->cmd != SDT_STDSTRING;
} }
/* static */ int32 ScriptGameSettings::GetValue(const char *setting) /* static */ int32 ScriptGameSettings::GetValue(const char *setting)
@ -28,7 +28,7 @@
const SettingDesc *sd = GetSettingFromName(setting); const SettingDesc *sd = GetSettingFromName(setting);
void *ptr = GetVariableAddress(&_settings_game, &sd->save); void *ptr = GetVariableAddress(&_settings_game, &sd->save);
if (sd->desc.cmd == SDT_BOOLX) return *(bool*)ptr; if (sd->cmd == SDT_BOOLX) return *(bool*)ptr;
return (int32)ReadValue(ptr, sd->save.conv); return (int32)ReadValue(ptr, sd->save.conv);
} }
@ -40,7 +40,7 @@
const SettingDesc *sd = GetSettingFromName(setting); const SettingDesc *sd = GetSettingFromName(setting);
if ((sd->save.conv & SLF_NO_NETWORK_SYNC) != 0) return false; if ((sd->save.conv & SLF_NO_NETWORK_SYNC) != 0) return false;
if (sd->desc.cmd != SDT_BOOLX && sd->desc.cmd != SDT_NUMX) return false; if (sd->cmd != SDT_BOOLX && sd->cmd != SDT_NUMX) return false;
return ScriptObject::DoCommand(0, GetSettingIndex(sd), value, CMD_CHANGE_SETTING); return ScriptObject::DoCommand(0, GetSettingIndex(sd), value, CMD_CHANGE_SETTING);
} }

View File

@ -434,7 +434,7 @@ static const void *StringToVal(const SettingDescBase *desc, const char *orig_str
*/ */
static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val) static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
{ {
const SettingDescBase *sdb = &sd->desc; const SettingDescBase *sdb = sd;
if (sdb->cmd != SDT_BOOLX && if (sdb->cmd != SDT_BOOLX &&
sdb->cmd != SDT_NUMX && sdb->cmd != SDT_NUMX &&
@ -508,11 +508,11 @@ static void Write_ValidateStdString(void *ptr, const SettingDesc *sd, const char
case SLE_VAR_STR: case SLE_VAR_STR:
case SLE_VAR_STRQ: case SLE_VAR_STRQ:
if (p != nullptr) { if (p != nullptr) {
if (sd->desc.max != 0 && strlen(p) >= sd->desc.max) { if (sd->max != 0 && strlen(p) >= sd->max) {
/* In case a maximum length is imposed by the setting, the length /* In case a maximum length is imposed by the setting, the length
* includes the '\0' termination for network transfer purposes. * includes the '\0' termination for network transfer purposes.
* Also ensure the string is valid after chopping of some bytes. */ * Also ensure the string is valid after chopping of some bytes. */
std::string str(p, sd->desc.max - 1); std::string str(p, sd->max - 1);
dst->assign(str_validate(str, SVS_NONE)); dst->assign(str_validate(str, SVS_NONE));
} else { } else {
dst->assign(p); dst->assign(p);
@ -541,11 +541,11 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
IniGroup *group_def = ini->GetGroup(grpname); IniGroup *group_def = ini->GetGroup(grpname);
for (; sd->save.cmd != SL_END; sd++) { for (; sd->save.cmd != SL_END; sd++) {
const SettingDescBase *sdb = &sd->desc; const SettingDescBase *sdb = sd;
const SaveLoad *sld = &sd->save; const SaveLoad *sld = &sd->save;
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue; if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
if (sd->desc.startup != only_startup) continue; if (sd->startup != only_startup) continue;
/* For settings.xx.yy load the settings from [xx] yy = ? */ /* For settings.xx.yy load the settings from [xx] yy = ? */
std::string s{ sdb->name }; std::string s{ sdb->name };
@ -593,8 +593,8 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
/* Use default */ /* Use default */
LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv)); LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
} else if (sd->desc.proc_cnvt != nullptr) { } else if (sd->proc_cnvt != nullptr) {
sd->desc.proc_cnvt((const char*)p); sd->proc_cnvt((const char*)p);
} }
break; break;
} }
@ -623,7 +623,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
void *ptr; void *ptr;
for (; sd->save.cmd != SL_END; sd++) { for (; sd->save.cmd != SL_END; sd++) {
const SettingDescBase *sdb = &sd->desc; const SettingDescBase *sdb = sd;
const SaveLoad *sld = &sd->save; const SaveLoad *sld = &sd->save;
/* If the setting is not saved to the configuration /* If the setting is not saved to the configuration
@ -802,13 +802,13 @@ void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
*/ */
bool SettingDesc::IsEditable(bool do_command) const bool SettingDesc::IsEditable(bool do_command) const
{ {
if (!do_command && !(this->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->desc.flags & SGF_PER_COMPANY)) return false; if (!do_command && !(this->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->flags & SGF_PER_COMPANY)) return false;
if ((this->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false; if ((this->flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
if ((this->desc.flags & SGF_NO_NETWORK) && _networking) return false; if ((this->flags & SGF_NO_NETWORK) && _networking) return false;
if ((this->desc.flags & SGF_NEWGAME_ONLY) && if ((this->flags & SGF_NEWGAME_ONLY) &&
(_game_mode == GM_NORMAL || (_game_mode == GM_NORMAL ||
(_game_mode == GM_EDITOR && !(this->desc.flags & SGF_SCENEDIT_TOO)))) return false; (_game_mode == GM_EDITOR && !(this->flags & SGF_SCENEDIT_TOO)))) return false;
if ((this->desc.flags & SGF_SCENEDIT_ONLY) && _game_mode != GM_EDITOR) return false; if ((this->flags & SGF_SCENEDIT_ONLY) && _game_mode != GM_EDITOR) return false;
return true; return true;
} }
@ -818,7 +818,7 @@ bool SettingDesc::IsEditable(bool do_command) const
*/ */
SettingType SettingDesc::GetType() const SettingType SettingDesc::GetType() const
{ {
if (this->desc.flags & SGF_PER_COMPANY) return ST_COMPANY; if (this->flags & SGF_PER_COMPANY) return ST_COMPANY;
return (this->save.conv & SLF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME; return (this->save.conv & SLF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME;
} }
@ -1892,14 +1892,14 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (oldval == newval) return CommandCost(); if (oldval == newval) return CommandCost();
if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) { if (sd->proc != nullptr && !sd->proc(newval)) {
WriteValue(var, sd->save.conv, (int64)oldval); WriteValue(var, sd->save.conv, (int64)oldval);
return CommandCost(); return CommandCost();
} }
if (sd->desc.flags & SGF_NO_NETWORK) { if (sd->flags & SGF_NO_NETWORK) {
GamelogStartAction(GLAT_SETTING); GamelogStartAction(GLAT_SETTING);
GamelogSetting(sd->desc.name, oldval, newval); GamelogSetting(sd->name, oldval, newval);
GamelogStopAction(); GamelogStopAction();
} }
@ -1937,7 +1937,7 @@ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32
if (oldval == newval) return CommandCost(); if (oldval == newval) return CommandCost();
if (sd->desc.proc != nullptr && !sd->desc.proc(newval)) { if (sd->proc != nullptr && !sd->proc(newval)) {
WriteValue(var, sd->save.conv, (int64)oldval); WriteValue(var, sd->save.conv, (int64)oldval);
return CommandCost(); return CommandCost();
} }
@ -1955,7 +1955,7 @@ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32
*/ */
uint GetSettingIndex(const SettingDesc *sd) uint GetSettingIndex(const SettingDesc *sd)
{ {
assert((sd->desc.flags & SGF_PER_COMPANY) == 0); assert((sd->flags & SGF_PER_COMPANY) == 0);
return sd - _settings; return sd - _settings;
} }
@ -1968,14 +1968,14 @@ uint GetSettingIndex(const SettingDesc *sd)
*/ */
bool SetSettingValue(const SettingDesc *sd, int32 value, bool force_newgame) bool SetSettingValue(const SettingDesc *sd, int32 value, bool force_newgame)
{ {
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) { if ((sd->flags & SGF_PER_COMPANY) != 0) {
if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) { if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
return DoCommandP(0, sd - _company_settings, value, CMD_CHANGE_COMPANY_SETTING); return DoCommandP(0, sd - _company_settings, value, CMD_CHANGE_COMPANY_SETTING);
} }
void *var = GetVariableAddress(&_settings_client.company, &sd->save); void *var = GetVariableAddress(&_settings_client.company, &sd->save);
Write_ValidateSetting(var, sd, value); Write_ValidateSetting(var, sd, value);
if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv)); if (sd->proc != nullptr) sd->proc((int32)ReadValue(var, sd->save.conv));
return true; return true;
} }
@ -1991,7 +1991,7 @@ bool SetSettingValue(const SettingDesc *sd, int32 value, bool force_newgame)
void *var2 = GetVariableAddress(&_settings_newgame, &sd->save); void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
Write_ValidateSetting(var2, sd, value); Write_ValidateSetting(var2, sd, value);
} }
if (sd->desc.proc != nullptr) sd->desc.proc((int32)ReadValue(var, sd->save.conv)); if (sd->proc != nullptr) sd->proc((int32)ReadValue(var, sd->save.conv));
SetWindowClassesDirty(WC_GAME_OPTIONS); SetWindowClassesDirty(WC_GAME_OPTIONS);
@ -2023,7 +2023,7 @@ void SetDefaultCompanySettings(CompanyID cid)
const SettingDesc *sd; const SettingDesc *sd;
for (sd = _company_settings; sd->save.cmd != SL_END; sd++) { for (sd = _company_settings; sd->save.cmd != SL_END; sd++) {
void *var = GetVariableAddress(&c->settings, &sd->save); void *var = GetVariableAddress(&c->settings, &sd->save);
Write_ValidateSetting(var, sd, (int32)(size_t)sd->desc.def); Write_ValidateSetting(var, sd, (int32)(size_t)sd->def);
} }
} }
@ -2051,7 +2051,7 @@ void SyncCompanySettings()
uint GetCompanySettingIndex(const char *name) uint GetCompanySettingIndex(const char *name)
{ {
const SettingDesc *sd = GetSettingFromName(name); const SettingDesc *sd = GetSettingFromName(name);
assert(sd != nullptr && (sd->desc.flags & SGF_PER_COMPANY) != 0); assert(sd != nullptr && (sd->flags & SGF_PER_COMPANY) != 0);
return sd - _company_settings; return sd - _company_settings;
} }
@ -2072,7 +2072,7 @@ bool SetSettingValue(const SettingDesc *sd, const char *value, bool force_newgam
void *ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save); void *ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
Write_ValidateStdString(ptr, sd, value); Write_ValidateStdString(ptr, sd, value);
if (sd->desc.proc != nullptr) sd->desc.proc(0); if (sd->proc != nullptr) sd->proc(0);
if (_save_config) SaveToConfig(); if (_save_config) SaveToConfig();
return true; return true;
@ -2090,13 +2090,13 @@ const SettingDesc *GetSettingFromName(const char *name)
/* First check all full names */ /* First check all full names */
for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) { for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (strcmp(sd->desc.name, name) == 0) return sd; if (strcmp(sd->name, name) == 0) return sd;
} }
/* Then check the shortcut variant of the name. */ /* Then check the shortcut variant of the name. */
for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) { for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
const char *short_name = strchr(sd->desc.name, '.'); const char *short_name = strchr(sd->name, '.');
if (short_name != nullptr) { if (short_name != nullptr) {
short_name++; short_name++;
if (strcmp(short_name, name) == 0) return sd; if (strcmp(short_name, name) == 0) return sd;
@ -2107,7 +2107,7 @@ const SettingDesc *GetSettingFromName(const char *name)
/* And finally the company-based settings */ /* And finally the company-based settings */
for (const SettingDesc *sd = _company_settings; sd->save.cmd != SL_END; sd++) { for (const SettingDesc *sd = _company_settings; sd->save.cmd != SL_END; sd++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (strcmp(sd->desc.name, name) == 0) return sd; if (strcmp(sd->name, name) == 0) return sd;
} }
return nullptr; return nullptr;
@ -2125,7 +2125,7 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
} }
bool success; bool success;
if (sd->desc.cmd == SDT_STDSTRING) { if (sd->cmd == SDT_STDSTRING) {
success = SetSettingValue(sd, value, force_newgame); success = SetSettingValue(sd, value, force_newgame);
} else { } else {
uint32 val; uint32 val;
@ -2173,17 +2173,17 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save); ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
if (sd->desc.cmd == SDT_STDSTRING) { if (sd->cmd == SDT_STDSTRING) {
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, reinterpret_cast<const std::string *>(ptr)->c_str()); IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, reinterpret_cast<const std::string *>(ptr)->c_str());
} else { } else {
if (sd->desc.cmd == SDT_BOOLX) { if (sd->cmd == SDT_BOOLX) {
seprintf(value, lastof(value), (*(const bool*)ptr != 0) ? "on" : "off"); seprintf(value, lastof(value), (*(const bool*)ptr != 0) ? "on" : "off");
} else { } else {
seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv)); seprintf(value, lastof(value), sd->min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
} }
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)", IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)",
name, value, (sd->desc.flags & SGF_0ISDISABLED) ? "(0) " : "", sd->desc.min, sd->desc.max); name, value, (sd->flags & SGF_0ISDISABLED) ? "(0) " : "", sd->min, sd->max);
} }
} }
@ -2198,18 +2198,18 @@ void IConsoleListSettings(const char *prefilter)
for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) { for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
if (prefilter != nullptr && strstr(sd->desc.name, prefilter) == nullptr) continue; if (prefilter != nullptr && strstr(sd->name, prefilter) == nullptr) continue;
char value[80]; char value[80];
const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save); const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
if (sd->desc.cmd == SDT_BOOLX) { if (sd->cmd == SDT_BOOLX) {
seprintf(value, lastof(value), (*(const bool *)ptr != 0) ? "on" : "off"); seprintf(value, lastof(value), (*(const bool *)ptr != 0) ? "on" : "off");
} else if (sd->desc.cmd == SDT_STDSTRING) { } else if (sd->cmd == SDT_STDSTRING) {
seprintf(value, lastof(value), "%s", reinterpret_cast<const std::string *>(ptr)->c_str()); seprintf(value, lastof(value), "%s", reinterpret_cast<const std::string *>(ptr)->c_str());
} else { } else {
seprintf(value, lastof(value), sd->desc.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv)); seprintf(value, lastof(value), sd->min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
} }
IConsolePrintF(CC_DEFAULT, "%s = %s", sd->desc.name, value); IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name, value);
} }
IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value"); IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");

View File

@ -843,7 +843,7 @@ struct SettingEntry : BaseSettingEntry {
*/ */
inline StringID GetHelpText() const inline StringID GetHelpText() const
{ {
return this->setting->desc.str_help; return this->setting->str_help;
} }
void SetValueDParams(uint first_param, int32 value) const; void SetValueDParams(uint first_param, int32 value) const;
@ -1036,7 +1036,7 @@ void SettingEntry::Init(byte level)
/* Sets the given setting entry to its default value */ /* Sets the given setting entry to its default value */
void SettingEntry::ResetAll() void SettingEntry::ResetAll()
{ {
int32 default_value = ReadValue(&this->setting->desc.def, this->setting->save.conv); int32 default_value = ReadValue(&this->setting->def, this->setting->save.conv);
SetSettingValue(this->setting, default_value); SetSettingValue(this->setting, default_value);
} }
@ -1080,8 +1080,8 @@ bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
GameSettings *settings_ptr = &GetGameSettings(); GameSettings *settings_ptr = &GetGameSettings();
const SettingDesc *sd = this->setting; const SettingDesc *sd = this->setting;
if (mode == RM_BASIC) return (this->setting->desc.cat & SC_BASIC_LIST) != 0; if (mode == RM_BASIC) return (this->setting->cat & SC_BASIC_LIST) != 0;
if (mode == RM_ADVANCED) return (this->setting->desc.cat & SC_ADVANCED_LIST) != 0; if (mode == RM_ADVANCED) return (this->setting->cat & SC_ADVANCED_LIST) != 0;
/* Read the current value. */ /* Read the current value. */
const void *var = ResolveVariableAddress(settings_ptr, sd); const void *var = ResolveVariableAddress(settings_ptr, sd);
@ -1093,7 +1093,7 @@ bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
/* This entry shall only be visible, if the value deviates from its default value. */ /* This entry shall only be visible, if the value deviates from its default value. */
/* Read the default value. */ /* Read the default value. */
filter_value = ReadValue(&sd->desc.def, sd->save.conv); filter_value = ReadValue(&sd->def, sd->save.conv);
} else { } else {
assert(mode == RM_CHANGED_AGAINST_NEW); assert(mode == RM_CHANGED_AGAINST_NEW);
/* This entry shall only be visible, if the value deviates from /* This entry shall only be visible, if the value deviates from
@ -1127,7 +1127,7 @@ bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
/* Process the search text filter for this item. */ /* Process the search text filter for this item. */
filter.string.ResetState(); filter.string.ResetState();
const SettingDescBase *sdb = &sd->desc; const SettingDescBase *sdb = sd;
SetDParam(0, STR_EMPTY); SetDParam(0, STR_EMPTY);
filter.string.AddLine(sdb->str); filter.string.AddLine(sdb->str);
@ -1153,7 +1153,7 @@ bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd) static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
{ {
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) { if ((sd->flags & SGF_PER_COMPANY) != 0) {
if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) { if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save); return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
} else { } else {
@ -1171,7 +1171,7 @@ static const void *ResolveVariableAddress(const GameSettings *settings_ptr, cons
*/ */
void SettingEntry::SetValueDParams(uint first_param, int32 value) const void SettingEntry::SetValueDParams(uint first_param, int32 value) const
{ {
const SettingDescBase *sdb = &this->setting->desc; const SettingDescBase *sdb = this->setting;
if (sdb->cmd == SDT_BOOLX) { if (sdb->cmd == SDT_BOOLX) {
SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF); SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
} else { } else {
@ -1198,7 +1198,7 @@ void SettingEntry::SetValueDParams(uint first_param, int32 value) const
void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const
{ {
const SettingDesc *sd = this->setting; const SettingDesc *sd = this->setting;
const SettingDescBase *sdb = &sd->desc; const SettingDescBase *sdb = sd;
const void *var = ResolveVariableAddress(settings_ptr, sd); const void *var = ResolveVariableAddress(settings_ptr, sd);
int state = this->flags & SEF_BUTTONS_MASK; int state = this->flags & SEF_BUTTONS_MASK;
@ -2091,7 +2091,7 @@ struct GameSettingsWindow : Window {
DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE); DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE);
y += FONT_HEIGHT_NORMAL; y += FONT_HEIGHT_NORMAL;
int32 default_value = ReadValue(&sd->desc.def, sd->save.conv); int32 default_value = ReadValue(&sd->def, sd->save.conv);
this->last_clicked->SetValueDParams(0, default_value); this->last_clicked->SetValueDParams(0, default_value);
DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE); DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE);
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL; y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
@ -2195,8 +2195,8 @@ struct GameSettingsWindow : Window {
int32 value = (int32)ReadValue(var, sd->save.conv); int32 value = (int32)ReadValue(var, sd->save.conv);
/* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */ /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
if (x < SETTING_BUTTON_WIDTH && (sd->desc.flags & SGF_MULTISTRING)) { if (x < SETTING_BUTTON_WIDTH && (sd->flags & SGF_MULTISTRING)) {
const SettingDescBase *sdb = &sd->desc; const SettingDescBase *sdb = sd;
this->SetDisplayedHelpText(pe); this->SetDisplayedHelpText(pe);
if (this->valuedropdown_entry == pe) { if (this->valuedropdown_entry == pe) {
@ -2234,7 +2234,7 @@ struct GameSettingsWindow : Window {
this->SetDirty(); this->SetDirty();
} else if (x < SETTING_BUTTON_WIDTH) { } else if (x < SETTING_BUTTON_WIDTH) {
this->SetDisplayedHelpText(pe); this->SetDisplayedHelpText(pe);
const SettingDescBase *sdb = &sd->desc; const SettingDescBase *sdb = sd;
int32 oldvalue = value; int32 oldvalue = value;
switch (sdb->cmd) { switch (sdb->cmd) {
@ -2291,10 +2291,10 @@ struct GameSettingsWindow : Window {
} }
} else { } else {
/* Only open editbox if clicked for the second time, and only for types where it is sensible for. */ /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
if (this->last_clicked == pe && sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) { if (this->last_clicked == pe && sd->cmd != SDT_BOOLX && !(sd->flags & SGF_MULTISTRING)) {
int64 value64 = value; int64 value64 = value;
/* Show the correct currency-translated value */ /* Show the correct currency-translated value */
if (sd->desc.flags & SGF_CURRENCY) value64 *= _currency->rate; if (sd->flags & SGF_CURRENCY) value64 *= _currency->rate;
this->valuewindow_entry = pe; this->valuewindow_entry = pe;
SetDParam(0, value64); SetDParam(0, value64);
@ -2327,11 +2327,11 @@ struct GameSettingsWindow : Window {
long long llvalue = atoll(str); long long llvalue = atoll(str);
/* Save the correct currency-translated value */ /* Save the correct currency-translated value */
if (sd->desc.flags & SGF_CURRENCY) llvalue /= _currency->rate; if (sd->flags & SGF_CURRENCY) llvalue /= _currency->rate;
value = (int32)ClampToI32(llvalue); value = (int32)ClampToI32(llvalue);
} else { } else {
value = (int32)(size_t)sd->desc.def; value = (int32)(size_t)sd->def;
} }
SetSettingValue(this->valuewindow_entry->setting, value); SetSettingValue(this->valuewindow_entry->setting, value);
@ -2368,7 +2368,7 @@ struct GameSettingsWindow : Window {
/* Deal with drop down boxes on the panel. */ /* Deal with drop down boxes on the panel. */
assert(this->valuedropdown_entry != nullptr); assert(this->valuedropdown_entry != nullptr);
const SettingDesc *sd = this->valuedropdown_entry->setting; const SettingDesc *sd = this->valuedropdown_entry->setting;
assert(sd->desc.flags & SGF_MULTISTRING); assert(sd->flags & SGF_MULTISTRING);
SetSettingValue(sd, index); SetSettingValue(sd, index);
this->SetDirty(); this->SetDirty();

View File

@ -100,8 +100,7 @@ struct SettingDescBase {
bool startup; ///< setting has to be loaded directly at startup? bool startup; ///< setting has to be loaded directly at startup?
}; };
struct SettingDesc { struct SettingDesc : SettingDescBase {
SettingDescBase desc; ///< Settings structure (going to configuration file)
SaveLoad save; ///< Internal structure (going to savegame, parts to config) SaveLoad save; ///< Internal structure (going to savegame, parts to config)
bool IsEditable(bool do_command = false) const; bool IsEditable(bool do_command = false) const;