mirror of https://github.com/OpenTTD/OpenTTD
Codechange: remove SettingDescType in lieu of the actual classes
parent
e666a962b1
commit
86c9ef8134
|
@ -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->cmd != SDT_STDSTRING;
|
return sd != nullptr && sd->IsIntSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ int32 ScriptGameSettings::GetValue(const char *setting)
|
/* static */ int32 ScriptGameSettings::GetValue(const char *setting)
|
||||||
|
@ -28,8 +28,6 @@
|
||||||
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->cmd == SDT_BOOLX) return *(bool*)ptr;
|
|
||||||
|
|
||||||
return (int32)ReadValue(ptr, sd->save.conv);
|
return (int32)ReadValue(ptr, sd->save.conv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +38,6 @@
|
||||||
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->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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -400,13 +400,11 @@ void IntSettingDesc::Write_ValidateSetting(const void *object, int32 val) const
|
||||||
{
|
{
|
||||||
void *ptr = GetVariableAddress(object, &this->save);
|
void *ptr = GetVariableAddress(object, &this->save);
|
||||||
|
|
||||||
/* We cannot know the maximum value of a bitset variable, so just have faith */
|
|
||||||
if (this->cmd != SDT_MANYOFMANY) {
|
|
||||||
/* We need to take special care of the uint32 type as we receive from the function
|
/* We need to take special care of the uint32 type as we receive from the function
|
||||||
* a signed integer. While here also bail out on 64-bit settings as those are not
|
* a signed integer. While here also bail out on 64-bit settings as those are not
|
||||||
* supported. Unsigned 8 and 16-bit variables are safe since they fit into a signed
|
* supported. Unsigned 8 and 16-bit variables are safe since they fit into a signed
|
||||||
* 32-bit variable
|
* 32-bit variable
|
||||||
* TODO: Support 64-bit settings/variables */
|
* TODO: Support 64-bit settings/variables; requires 64 bit over command protocol! */
|
||||||
switch (GetVarMemType(this->save.conv)) {
|
switch (GetVarMemType(this->save.conv)) {
|
||||||
case SLE_VAR_NULL: return;
|
case SLE_VAR_NULL: return;
|
||||||
case SLE_VAR_BL:
|
case SLE_VAR_BL:
|
||||||
|
@ -415,7 +413,7 @@ void IntSettingDesc::Write_ValidateSetting(const void *object, int32 val) const
|
||||||
case SLE_VAR_I16:
|
case SLE_VAR_I16:
|
||||||
case SLE_VAR_U16:
|
case SLE_VAR_U16:
|
||||||
case SLE_VAR_I32: {
|
case SLE_VAR_I32: {
|
||||||
/* Override the minimum value. No value below sdb->min, except special value 0 */
|
/* Override the minimum value. No value below this->min, except special value 0 */
|
||||||
if (!(this->flags & SGF_0ISDISABLED) || val != 0) {
|
if (!(this->flags & SGF_0ISDISABLED) || val != 0) {
|
||||||
if (!(this->flags & SGF_MULTISTRING)) {
|
if (!(this->flags & SGF_MULTISTRING)) {
|
||||||
/* Clamp value-type setting to its valid range */
|
/* Clamp value-type setting to its valid range */
|
||||||
|
@ -428,7 +426,7 @@ void IntSettingDesc::Write_ValidateSetting(const void *object, int32 val) const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SLE_VAR_U32: {
|
case SLE_VAR_U32: {
|
||||||
/* Override the minimum value. No value below sdb->min, except special value 0 */
|
/* Override the minimum value. No value below this->min, except special value 0 */
|
||||||
uint32 uval = (uint32)val;
|
uint32 uval = (uint32)val;
|
||||||
if (!(this->flags & SGF_0ISDISABLED) || uval != 0) {
|
if (!(this->flags & SGF_0ISDISABLED) || uval != 0) {
|
||||||
if (!(this->flags & SGF_MULTISTRING)) {
|
if (!(this->flags & SGF_MULTISTRING)) {
|
||||||
|
@ -446,7 +444,6 @@ void IntSettingDesc::Write_ValidateSetting(const void *object, int32 val) const
|
||||||
case SLE_VAR_U64:
|
case SLE_VAR_U64:
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
WriteValue(ptr, this->save.conv, (int64)val);
|
WriteValue(ptr, this->save.conv, (int64)val);
|
||||||
}
|
}
|
||||||
|
@ -755,22 +752,6 @@ SettingType SettingDesc::GetType() const
|
||||||
return (this->save.conv & SLF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME;
|
return (this->save.conv & SLF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether this setting is an integer type setting.
|
|
||||||
* @return True when the underlying type is an integer.
|
|
||||||
*/
|
|
||||||
bool SettingDesc::IsIntSetting() const {
|
|
||||||
return this->cmd == SDT_BOOLX || this->cmd == SDT_NUMX || this->cmd == SDT_ONEOFMANY || this->cmd == SDT_MANYOFMANY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether this setting is an string type setting.
|
|
||||||
* @return True when the underlying type is a string.
|
|
||||||
*/
|
|
||||||
bool SettingDesc::IsStringSetting() const {
|
|
||||||
return this->cmd == SDT_STDSTRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the setting description of this setting as an integer setting.
|
* Get the setting description of this setting as an integer setting.
|
||||||
* @return The integer setting description.
|
* @return The integer setting description.
|
||||||
|
@ -2109,10 +2090,10 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success;
|
bool success = true;
|
||||||
if (sd->cmd == SDT_STDSTRING) {
|
if (sd->IsStringSetting()) {
|
||||||
success = SetSettingValue(sd->AsStringSetting(), value, force_newgame);
|
success = SetSettingValue(sd->AsStringSetting(), value, force_newgame);
|
||||||
} else {
|
} else if (sd->IsIntSetting()) {
|
||||||
uint32 val;
|
uint32 val;
|
||||||
extern bool GetArgumentInteger(uint32 *value, const char *arg);
|
extern bool GetArgumentInteger(uint32 *value, const char *arg);
|
||||||
success = GetArgumentInteger(&val, value);
|
success = GetArgumentInteger(&val, value);
|
||||||
|
@ -2155,9 +2136,8 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
|
||||||
|
|
||||||
const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
|
const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
|
||||||
|
|
||||||
if (sd->cmd == SDT_STDSTRING) {
|
if (sd->IsStringSetting()) {
|
||||||
const void *ptr = GetVariableAddress(object, &sd->save);
|
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, sd->AsStringSetting()->Read(object).c_str());
|
||||||
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", name, reinterpret_cast<const std::string *>(ptr)->c_str());
|
|
||||||
} else if (sd->IsIntSetting()) {
|
} else if (sd->IsIntSetting()) {
|
||||||
char value[20];
|
char value[20];
|
||||||
sd->FormatValue(value, lastof(value), object);
|
sd->FormatValue(value, lastof(value), object);
|
||||||
|
|
|
@ -1167,7 +1167,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
|
||||||
{
|
{
|
||||||
if (this->setting->cmd == SDT_BOOLX) {
|
if (this->setting->IsBoolSetting()) {
|
||||||
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 {
|
||||||
if ((this->setting->flags & SGF_MULTISTRING) != 0) {
|
if ((this->setting->flags & SGF_MULTISTRING) != 0) {
|
||||||
|
@ -1207,7 +1207,7 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
|
||||||
|
|
||||||
SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
|
SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
|
||||||
int32 value = (int32)ReadValue(var, sd->save.conv);
|
int32 value = (int32)ReadValue(var, sd->save.conv);
|
||||||
if (sd->cmd == SDT_BOOLX) {
|
if (sd->IsBoolSetting()) {
|
||||||
/* Draw checkbox for boolean-value either on/off */
|
/* Draw checkbox for boolean-value either on/off */
|
||||||
DrawBoolButton(buttons_left, button_y, value != 0, editable);
|
DrawBoolButton(buttons_left, button_y, value != 0, editable);
|
||||||
} else if ((sd->flags & SGF_MULTISTRING) != 0) {
|
} else if ((sd->flags & SGF_MULTISTRING) != 0) {
|
||||||
|
@ -2228,10 +2228,9 @@ struct GameSettingsWindow : Window {
|
||||||
this->SetDisplayedHelpText(pe);
|
this->SetDisplayedHelpText(pe);
|
||||||
int32 oldvalue = value;
|
int32 oldvalue = value;
|
||||||
|
|
||||||
switch (sd->cmd) {
|
if (sd->IsBoolSetting()) {
|
||||||
case SDT_BOOLX: value ^= 1; break;
|
value ^= 1;
|
||||||
case SDT_ONEOFMANY:
|
} else {
|
||||||
case SDT_NUMX: {
|
|
||||||
/* Add a dynamic step-size to the scroller. In a maximum of
|
/* Add a dynamic step-size to the scroller. In a maximum of
|
||||||
* 50-steps you should be able to get from min to max,
|
* 50-steps you should be able to get from min to max,
|
||||||
* unless specified otherwise in the 'interval' variable
|
* unless specified otherwise in the 'interval' variable
|
||||||
|
@ -2270,10 +2269,6 @@ struct GameSettingsWindow : Window {
|
||||||
this->SetTimeout();
|
this->SetTimeout();
|
||||||
_left_button_clicked = false;
|
_left_button_clicked = false;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: NOT_REACHED();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value != oldvalue) {
|
if (value != oldvalue) {
|
||||||
|
@ -2282,7 +2277,7 @@ 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->cmd != SDT_BOOLX && !(sd->flags & SGF_MULTISTRING)) {
|
if (this->last_clicked == pe && !sd->IsBoolSetting() && !(sd->flags & SGF_MULTISTRING)) {
|
||||||
int64 value64 = value;
|
int64 value64 = value;
|
||||||
/* Show the correct currency-translated value */
|
/* Show the correct currency-translated value */
|
||||||
if (sd->flags & SGF_CURRENCY) value64 *= _currency->rate;
|
if (sd->flags & SGF_CURRENCY) value64 *= _currency->rate;
|
||||||
|
|
|
@ -12,22 +12,6 @@
|
||||||
|
|
||||||
#include "saveload/saveload.h"
|
#include "saveload/saveload.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* Convention/Type of settings. This is then further specified if necessary
|
|
||||||
* with the SLE_ (SLE_VAR/SLE_FILE) enums in saveload.h
|
|
||||||
* @see VarTypes
|
|
||||||
* @see SettingDesc
|
|
||||||
*/
|
|
||||||
enum SettingDescType : byte {
|
|
||||||
SDT_NUMX = 0, ///< any number-type
|
|
||||||
SDT_BOOLX = 1, ///< a boolean number
|
|
||||||
SDT_ONEOFMANY = 2, ///< bitmasked number where only ONE bit may be set
|
|
||||||
SDT_MANYOFMANY = 3, ///< bitmasked number where MULTIPLE bits may be set
|
|
||||||
SDT_INTLIST = 4, ///< list of integers separated by a comma ','
|
|
||||||
SDT_STDSTRING = 6, ///< \c std::string
|
|
||||||
SDT_NULL = 7, ///< an old setting that has been removed but could still be in savegames
|
|
||||||
};
|
|
||||||
|
|
||||||
enum SettingGuiFlag : uint16 {
|
enum SettingGuiFlag : uint16 {
|
||||||
/* 2 bytes allocated for a maximum of 16 flags. */
|
/* 2 bytes allocated for a maximum of 16 flags. */
|
||||||
SGF_NONE = 0,
|
SGF_NONE = 0,
|
||||||
|
@ -85,20 +69,30 @@ typedef size_t OnConvert(const char *value); ///< callback prototype for convers
|
||||||
|
|
||||||
/** Properties of config file settings. */
|
/** Properties of config file settings. */
|
||||||
struct SettingDesc {
|
struct SettingDesc {
|
||||||
SettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, SettingDescType cmd, bool startup) :
|
SettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup) :
|
||||||
name(name), flags(flags), cmd(cmd), startup(startup), save(save) {}
|
name(name), flags(flags), startup(startup), save(save) {}
|
||||||
virtual ~SettingDesc() {}
|
virtual ~SettingDesc() {}
|
||||||
|
|
||||||
const char *name; ///< name of the setting. Used in configuration file and for console
|
const char *name; ///< name of the setting. Used in configuration file and for console
|
||||||
SettingGuiFlag flags; ///< handles how a setting would show up in the GUI (text/currency, etc.)
|
SettingGuiFlag flags; ///< handles how a setting would show up in the GUI (text/currency, etc.)
|
||||||
SettingDescType cmd; ///< various flags for the variable
|
|
||||||
bool startup; ///< setting has to be loaded directly at startup?
|
bool startup; ///< setting has to be loaded directly at startup?
|
||||||
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;
|
||||||
SettingType GetType() const;
|
SettingType GetType() const;
|
||||||
bool IsIntSetting() const;
|
|
||||||
bool IsStringSetting() const;
|
/**
|
||||||
|
* Check whether this setting is an integer type setting.
|
||||||
|
* @return True when the underlying type is an integer.
|
||||||
|
*/
|
||||||
|
virtual bool IsIntSetting() const { return false; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this setting is an string type setting.
|
||||||
|
* @return True when the underlying type is a string.
|
||||||
|
*/
|
||||||
|
virtual bool IsStringSetting() const { return false; }
|
||||||
|
|
||||||
const struct IntSettingDesc *AsIntSetting() const;
|
const struct IntSettingDesc *AsIntSetting() const;
|
||||||
const struct StringSettingDesc *AsStringSetting() const;
|
const struct StringSettingDesc *AsStringSetting() const;
|
||||||
|
|
||||||
|
@ -131,10 +125,10 @@ struct SettingDesc {
|
||||||
|
|
||||||
/** Base integer type, including boolean, settings. Only these are shown in the settings UI. */
|
/** Base integer type, including boolean, settings. Only these are shown in the settings UI. */
|
||||||
struct IntSettingDesc : SettingDesc {
|
struct IntSettingDesc : SettingDesc {
|
||||||
IntSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, SettingDescType cmd, bool startup, int32 def,
|
IntSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup, int32 def,
|
||||||
int32 min, uint32 max, int32 interval, StringID str, StringID str_help, StringID str_val,
|
int32 min, uint32 max, int32 interval, StringID str, StringID str_help, StringID str_val,
|
||||||
SettingCategory cat, OnChange *proc) :
|
SettingCategory cat, OnChange *proc) :
|
||||||
SettingDesc(save, name, flags, cmd, startup), def(def), min(min), max(max), interval(interval),
|
SettingDesc(save, name, flags, startup), def(def), min(min), max(max), interval(interval),
|
||||||
str(str), str_help(str_help), str_val(str_val), cat(cat), proc(proc) {}
|
str(str), str_help(str_help), str_val(str_val), cat(cat), proc(proc) {}
|
||||||
virtual ~IntSettingDesc() {}
|
virtual ~IntSettingDesc() {}
|
||||||
|
|
||||||
|
@ -148,6 +142,13 @@ struct IntSettingDesc : SettingDesc {
|
||||||
SettingCategory cat; ///< assigned categories of the setting
|
SettingCategory cat; ///< assigned categories of the setting
|
||||||
OnChange *proc; ///< callback procedure for when the value is changed
|
OnChange *proc; ///< callback procedure for when the value is changed
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this setting is a boolean type setting.
|
||||||
|
* @return True when the underlying type is an integer.
|
||||||
|
*/
|
||||||
|
virtual bool IsBoolSetting() const { return false; }
|
||||||
|
bool IsIntSetting() const override { return true; }
|
||||||
|
|
||||||
void ChangeValue(const void *object, int32 newvalue) const;
|
void ChangeValue(const void *object, int32 newvalue) const;
|
||||||
void Write_ValidateSetting(const void *object, int32 value) const;
|
void Write_ValidateSetting(const void *object, int32 value) const;
|
||||||
|
|
||||||
|
@ -159,21 +160,22 @@ struct IntSettingDesc : SettingDesc {
|
||||||
|
|
||||||
/** Boolean setting. */
|
/** Boolean setting. */
|
||||||
struct BoolSettingDesc : IntSettingDesc {
|
struct BoolSettingDesc : IntSettingDesc {
|
||||||
BoolSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, SettingDescType cmd, bool startup, bool def,
|
BoolSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup, bool def,
|
||||||
StringID str, StringID str_help, StringID str_val, SettingCategory cat, OnChange *proc) :
|
StringID str, StringID str_help, StringID str_val, SettingCategory cat, OnChange *proc) :
|
||||||
IntSettingDesc(save, name, flags, cmd, startup, def, 0, 1, 0, str, str_help, str_val, cat, proc) {}
|
IntSettingDesc(save, name, flags, startup, def, 0, 1, 0, str, str_help, str_val, cat, proc) {}
|
||||||
virtual ~BoolSettingDesc() {}
|
virtual ~BoolSettingDesc() {}
|
||||||
|
|
||||||
|
bool IsBoolSetting() const override { return true; }
|
||||||
size_t ParseValue(const char *str) const override;
|
size_t ParseValue(const char *str) const override;
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override;
|
void FormatValue(char *buf, const char *last, const void *object) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** One of many setting. */
|
/** One of many setting. */
|
||||||
struct OneOfManySettingDesc : IntSettingDesc {
|
struct OneOfManySettingDesc : IntSettingDesc {
|
||||||
OneOfManySettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, SettingDescType cmd, bool startup,
|
OneOfManySettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup,
|
||||||
int32 def, int32 max, StringID str, StringID str_help, StringID str_val, SettingCategory cat, OnChange *proc,
|
int32 def, int32 max, StringID str, StringID str_help, StringID str_val, SettingCategory cat, OnChange *proc,
|
||||||
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
|
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
|
||||||
IntSettingDesc(save, name, flags, cmd, startup, def, 0, max, 0, str, str_help, str_val, cat, proc), many_cnvt(many_cnvt)
|
IntSettingDesc(save, name, flags, startup, def, 0, max, 0, str, str_help, str_val, cat, proc), many_cnvt(many_cnvt)
|
||||||
{
|
{
|
||||||
for (auto one : many) this->many.push_back(one);
|
for (auto one : many) this->many.push_back(one);
|
||||||
}
|
}
|
||||||
|
@ -192,10 +194,10 @@ struct OneOfManySettingDesc : IntSettingDesc {
|
||||||
|
|
||||||
/** Many of many setting. */
|
/** Many of many setting. */
|
||||||
struct ManyOfManySettingDesc : OneOfManySettingDesc {
|
struct ManyOfManySettingDesc : OneOfManySettingDesc {
|
||||||
ManyOfManySettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, SettingDescType cmd, bool startup,
|
ManyOfManySettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup,
|
||||||
int32 def, StringID str, StringID str_help, StringID str_val, SettingCategory cat, OnChange *proc,
|
int32 def, StringID str, StringID str_help, StringID str_val, SettingCategory cat, OnChange *proc,
|
||||||
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
|
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
|
||||||
OneOfManySettingDesc(save, name, flags, cmd, startup, def, (1 << many.size()) - 1, str, str_help,
|
OneOfManySettingDesc(save, name, flags, startup, def, (1 << many.size()) - 1, str, str_help,
|
||||||
str_val, cat, proc, many, many_cnvt) {}
|
str_val, cat, proc, many, many_cnvt) {}
|
||||||
virtual ~ManyOfManySettingDesc() {}
|
virtual ~ManyOfManySettingDesc() {}
|
||||||
|
|
||||||
|
@ -205,15 +207,16 @@ struct ManyOfManySettingDesc : OneOfManySettingDesc {
|
||||||
|
|
||||||
/** String settings. */
|
/** String settings. */
|
||||||
struct StringSettingDesc : SettingDesc {
|
struct StringSettingDesc : SettingDesc {
|
||||||
StringSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, SettingDescType cmd, bool startup, const char *def,
|
StringSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup, const char *def,
|
||||||
uint32 max_length, OnChange proc) :
|
uint32 max_length, OnChange proc) :
|
||||||
SettingDesc(save, name, flags, cmd, startup), def(def), max_length(max_length), proc(proc) {}
|
SettingDesc(save, name, flags, startup), def(def), max_length(max_length), proc(proc) {}
|
||||||
virtual ~StringSettingDesc() {}
|
virtual ~StringSettingDesc() {}
|
||||||
|
|
||||||
const char *def; ///< default value given when none is present
|
const char *def; ///< default value given when none is present
|
||||||
uint32 max_length; ///< maximum length of the string, 0 means no maximum length
|
uint32 max_length; ///< maximum length of the string, 0 means no maximum length
|
||||||
OnChange *proc; ///< callback procedure for when the value is changed
|
OnChange *proc; ///< callback procedure for when the value is changed
|
||||||
|
|
||||||
|
bool IsStringSetting() const override { return true; }
|
||||||
void ChangeValue(const void *object, const char *newval) const;
|
void ChangeValue(const void *object, const char *newval) const;
|
||||||
void Write_ValidateSetting(const void *object, const char *str) const;
|
void Write_ValidateSetting(const void *object, const char *str) const;
|
||||||
|
|
||||||
|
@ -225,8 +228,8 @@ struct StringSettingDesc : SettingDesc {
|
||||||
|
|
||||||
/** List/array settings. */
|
/** List/array settings. */
|
||||||
struct ListSettingDesc : SettingDesc {
|
struct ListSettingDesc : SettingDesc {
|
||||||
ListSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, SettingDescType cmd, bool startup, const char *def) :
|
ListSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup, const char *def) :
|
||||||
SettingDesc(save, name, flags, cmd, startup), def(def) {}
|
SettingDesc(save, name, flags, startup), def(def) {}
|
||||||
virtual ~ListSettingDesc() {}
|
virtual ~ListSettingDesc() {}
|
||||||
|
|
||||||
const char *def; ///< default value given when none is present
|
const char *def; ///< default value given when none is present
|
||||||
|
@ -239,7 +242,7 @@ struct ListSettingDesc : SettingDesc {
|
||||||
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
|
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
|
||||||
struct NullSettingDesc : SettingDesc {
|
struct NullSettingDesc : SettingDesc {
|
||||||
NullSettingDesc(SaveLoad save) :
|
NullSettingDesc(SaveLoad save) :
|
||||||
SettingDesc(save, "", SGF_NONE, SDT_NULL, false) {}
|
SettingDesc(save, "", SGF_NONE, false) {}
|
||||||
virtual ~NullSettingDesc() {}
|
virtual ~NullSettingDesc() {}
|
||||||
|
|
||||||
void FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); }
|
void FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); }
|
||||||
|
|
|
@ -59,22 +59,22 @@ static size_t ConvertLandscape(const char *value);
|
||||||
/* Macros for various objects to go in the configuration file.
|
/* Macros for various objects to go in the configuration file.
|
||||||
* This section is for global variables */
|
* This section is for global variables */
|
||||||
#define SDTG_VAR(name, type, flags, guiflags, var, def, min, max, interval, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
#define SDTG_VAR(name, type, flags, guiflags, var, def, min, max, interval, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
||||||
NSD(Int, SLEG_GENERAL(SL_VAR, var, type | flags, 1, from, to, extra), name, guiflags, SDT_NUMX, startup, def, min, max, interval, str, strhelp, strval, cat, proc)
|
NSD(Int, SLEG_GENERAL(SL_VAR, var, type | flags, 1, from, to, extra), name, guiflags, startup, def, min, max, interval, str, strhelp, strval, cat, proc)
|
||||||
|
|
||||||
#define SDTG_BOOL(name, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
#define SDTG_BOOL(name, flags, guiflags, var, def, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
||||||
NSD(Bool, SLEG_GENERAL(SL_VAR, var, SLE_BOOL | flags, 1, from, to, extra), name, guiflags, SDT_BOOLX, startup, def, str, strhelp, strval, cat, proc)
|
NSD(Bool, SLEG_GENERAL(SL_VAR, var, SLE_BOOL | flags, 1, from, to, extra), name, guiflags, startup, def, str, strhelp, strval, cat, proc)
|
||||||
|
|
||||||
#define SDTG_LIST(name, type, flags, guiflags, var, def, length, from, to, cat, extra, startup)\
|
#define SDTG_LIST(name, type, flags, guiflags, var, def, length, from, to, cat, extra, startup)\
|
||||||
NSD(List, SLEG_GENERAL(SL_ARR, var, type | flags, length, from, to, extra), name, guiflags, SDT_INTLIST, startup, def)
|
NSD(List, SLEG_GENERAL(SL_ARR, var, type | flags, length, from, to, extra), name, guiflags, startup, def)
|
||||||
|
|
||||||
#define SDTG_SSTR(name, type, flags, guiflags, var, def, max_length, proc, from, to, cat, extra, startup)\
|
#define SDTG_SSTR(name, type, flags, guiflags, var, def, max_length, proc, from, to, cat, extra, startup)\
|
||||||
NSD(String, SLEG_GENERAL(SL_STDSTR, var, type | flags, sizeof(var), from, to, extra), name, guiflags, SDT_STDSTRING, startup, def, max_length, proc)
|
NSD(String, SLEG_GENERAL(SL_STDSTR, var, type | flags, sizeof(var), from, to, extra), name, guiflags, startup, def, max_length, proc)
|
||||||
|
|
||||||
#define SDTG_OMANY(name, type, flags, guiflags, var, def, max, full, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
#define SDTG_OMANY(name, type, flags, guiflags, var, def, max, full, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
||||||
NSD(OneOfMany, SLEG_GENERAL(SL_VAR, var, type | flags, 1, from, to, extra), name, guiflags, SDT_ONEOFMANY, startup, def, max, str, strhelp, strval, cat, proc, full, nullptr)
|
NSD(OneOfMany, SLEG_GENERAL(SL_VAR, var, type | flags, 1, from, to, extra), name, guiflags, startup, def, max, str, strhelp, strval, cat, proc, full, nullptr)
|
||||||
|
|
||||||
#define SDTG_MMANY(name, type, flags, guiflags, var, def, full, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
#define SDTG_MMANY(name, type, flags, guiflags, var, def, full, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
||||||
NSD(ManyOfMany, SLEG_GENERAL(SL_VAR, var, type | flags, 1, from, to, extra), name, guiflags, SDT_MANYOFMANY, startup, def, str, strhelp, strval, cat, proc, full, nullptr)
|
NSD(ManyOfMany, SLEG_GENERAL(SL_VAR, var, type | flags, 1, from, to, extra), name, guiflags, startup, def, str, strhelp, strval, cat, proc, full, nullptr)
|
||||||
|
|
||||||
#define SDTG_NULL(length, from, to)\
|
#define SDTG_NULL(length, from, to)\
|
||||||
NSD(Null, SLEG_NULL(length, from, to))
|
NSD(Null, SLEG_NULL(length, from, to))
|
||||||
|
@ -82,22 +82,22 @@ static size_t ConvertLandscape(const char *value);
|
||||||
/* Macros for various objects to go in the configuration file.
|
/* Macros for various objects to go in the configuration file.
|
||||||
* This section is for structures where their various members are saved */
|
* This section is for structures where their various members are saved */
|
||||||
#define SDT_VAR(base, var, type, flags, guiflags, def, min, max, interval, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
#define SDT_VAR(base, var, type, flags, guiflags, def, min, max, interval, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
||||||
NSD(Int, SLE_GENERAL(SL_VAR, base, var, type | flags, 1, from, to, extra), #var, guiflags, SDT_NUMX, startup, def, min, max, interval, str, strhelp, strval, cat, proc)
|
NSD(Int, SLE_GENERAL(SL_VAR, base, var, type | flags, 1, from, to, extra), #var, guiflags, startup, def, min, max, interval, str, strhelp, strval, cat, proc)
|
||||||
|
|
||||||
#define SDT_BOOL(base, var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
#define SDT_BOOL(base, var, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extra, startup)\
|
||||||
NSD(Bool, SLE_GENERAL(SL_VAR, base, var, SLE_BOOL | flags, 1, from, to, extra), #var, guiflags, SDT_BOOLX, startup, def, str, strhelp, strval, cat, proc)
|
NSD(Bool, SLE_GENERAL(SL_VAR, base, var, SLE_BOOL | flags, 1, from, to, extra), #var, guiflags, startup, def, str, strhelp, strval, cat, proc)
|
||||||
|
|
||||||
#define SDT_LIST(base, var, type, flags, guiflags, def, from, to, cat, extra, startup)\
|
#define SDT_LIST(base, var, type, flags, guiflags, def, from, to, cat, extra, startup)\
|
||||||
NSD(List, SLE_GENERAL(SL_ARR, base, var, type | flags, lengthof(((base*)8)->var), from, to, extra), #var, guiflags, SDT_INTLIST, startup, def)
|
NSD(List, SLE_GENERAL(SL_ARR, base, var, type | flags, lengthof(((base*)8)->var), from, to, extra), #var, guiflags, startup, def)
|
||||||
|
|
||||||
#define SDT_SSTR(base, var, type, flags, guiflags, def, proc, from, to, cat, extra, startup)\
|
#define SDT_SSTR(base, var, type, flags, guiflags, def, proc, from, to, cat, extra, startup)\
|
||||||
NSD(String, SLE_GENERAL(SL_STDSTR, base, var, type | flags, sizeof(((base*)8)->var), from, to, extra), #var, guiflags, SDT_STDSTRING, startup, def, 0, proc)
|
NSD(String, SLE_GENERAL(SL_STDSTR, base, var, type | flags, sizeof(((base*)8)->var), from, to, extra), #var, guiflags, startup, def, 0, proc)
|
||||||
|
|
||||||
#define SDT_OMANY(base, var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, load, cat, extra, startup)\
|
#define SDT_OMANY(base, var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, load, cat, extra, startup)\
|
||||||
NSD(OneOfMany, SLE_GENERAL(SL_VAR, base, var, type | flags, 1, from, to, extra), #var, guiflags, SDT_ONEOFMANY, startup, def, max, str, strhelp, strval, cat, proc, full, load)
|
NSD(OneOfMany, SLE_GENERAL(SL_VAR, base, var, type | flags, 1, from, to, extra), #var, guiflags, startup, def, max, str, strhelp, strval, cat, proc, full, load)
|
||||||
|
|
||||||
#define SDT_MMANY(base, var, type, flags, guiflags, def, full, str, proc, strhelp, strval, from, to, cat, extra, startup)\
|
#define SDT_MMANY(base, var, type, flags, guiflags, def, full, str, proc, strhelp, strval, from, to, cat, extra, startup)\
|
||||||
NSD(ManyOfMany, SLE_GENERAL(SL_VAR, base, var, type | flags, 1, from, to, extra), #var, guiflags, SDT_MANYOFMANY, startup, def, str, strhelp, strval, cat, proc, full, nullptr)
|
NSD(ManyOfMany, SLE_GENERAL(SL_VAR, base, var, type | flags, 1, from, to, extra), #var, guiflags, startup, def, str, strhelp, strval, cat, proc, full, nullptr)
|
||||||
|
|
||||||
#define SDT_NULL(length, from, to)\
|
#define SDT_NULL(length, from, to)\
|
||||||
NSD(Null, SLE_CONDNULL(length, from, to))
|
NSD(Null, SLE_CONDNULL(length, from, to))
|
||||||
|
|
Loading…
Reference in New Issue