2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-01-07 00:19:09 +00:00
|
|
|
/** @file settings_internal.h Functions and types used internally for the settings configurations. */
|
2007-04-04 01:35:16 +00:00
|
|
|
|
2008-01-07 00:19:09 +00:00
|
|
|
#ifndef SETTINGS_INTERNAL_H
|
|
|
|
#define SETTINGS_INTERNAL_H
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2009-01-04 15:32:25 +00:00
|
|
|
#include "saveload/saveload.h"
|
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
2006-03-01 23:53:20 +00:00
|
|
|
|
2021-06-03 19:18:29 +00:00
|
|
|
enum SettingFlag : uint16 {
|
|
|
|
SF_NONE = 0,
|
2021-06-03 18:55:03 +00:00
|
|
|
SF_GUI_0_IS_SPECIAL = 1 << 0, ///< A value of zero is possible and has a custom string (the one after "strval").
|
|
|
|
SF_GUI_NEGATIVE_IS_SPECIAL = 1 << 1, ///< A negative value has another string (the one after "strval").
|
|
|
|
SF_GUI_DROPDOWN = 1 << 2, ///< The value represents a limited number of string-options (internally integer) presented as dropdown.
|
|
|
|
SF_GUI_CURRENCY = 1 << 3, ///< The number represents money, so when reading value multiply by exchange rate.
|
|
|
|
SF_NETWORK_ONLY = 1 << 4, ///< This setting only applies to network games.
|
|
|
|
SF_NO_NETWORK = 1 << 5, ///< This setting does not apply to network games; it may not be changed during the game.
|
|
|
|
SF_NEWGAME_ONLY = 1 << 6, ///< This setting cannot be changed in a game.
|
|
|
|
SF_SCENEDIT_TOO = 1 << 7, ///< This setting can be changed in the scenario editor (only makes sense when SF_NEWGAME_ONLY is set).
|
|
|
|
SF_SCENEDIT_ONLY = 1 << 8, ///< This setting can only be changed in the scenario editor.
|
|
|
|
SF_PER_COMPANY = 1 << 9, ///< This setting can be different for each company (saved in company struct).
|
|
|
|
SF_NOT_IN_SAVE = 1 << 10, ///< Do not save with savegame, basically client-based.
|
|
|
|
SF_NOT_IN_CONFIG = 1 << 11, ///< Do not save to config file.
|
|
|
|
SF_NO_NETWORK_SYNC = 1 << 12, ///< Do not synchronize over network (but it is saved if SF_NOT_IN_SAVE is not set).
|
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
2006-03-01 23:53:20 +00:00
|
|
|
};
|
2021-06-03 19:18:29 +00:00
|
|
|
DECLARE_ENUM_AS_BIT_SET(SettingFlag)
|
2007-01-10 18:56:51 +00:00
|
|
|
|
2012-11-08 10:04:00 +00:00
|
|
|
/**
|
|
|
|
* A SettingCategory defines a grouping of the settings.
|
|
|
|
* The group #SC_BASIC is intended for settings which also a novice player would like to change and is able to understand.
|
|
|
|
* The group #SC_ADVANCED is intended for settings which an experienced player would like to use. This is the case for most settings.
|
|
|
|
* Finally #SC_EXPERT settings only few people want to see in rare cases.
|
|
|
|
* The grouping is meant to be inclusive, i.e. all settings in #SC_BASIC also will be included
|
|
|
|
* in the set of settings in #SC_ADVANCED. The group #SC_EXPERT contains all settings.
|
|
|
|
*/
|
|
|
|
enum SettingCategory {
|
|
|
|
SC_NONE = 0,
|
|
|
|
|
|
|
|
/* Filters for the list */
|
|
|
|
SC_BASIC_LIST = 1 << 0, ///< Settings displayed in the list of basic settings.
|
|
|
|
SC_ADVANCED_LIST = 1 << 1, ///< Settings displayed in the list of advanced settings.
|
|
|
|
SC_EXPERT_LIST = 1 << 2, ///< Settings displayed in the list of expert settings.
|
|
|
|
|
|
|
|
/* Setting classification */
|
|
|
|
SC_BASIC = SC_BASIC_LIST | SC_ADVANCED_LIST | SC_EXPERT_LIST, ///< Basic settings are part of all lists.
|
|
|
|
SC_ADVANCED = SC_ADVANCED_LIST | SC_EXPERT_LIST, ///< Advanced settings are part of advanced and expert list.
|
|
|
|
SC_EXPERT = SC_EXPERT_LIST, ///< Expert settings can only be seen in the expert list.
|
|
|
|
|
|
|
|
SC_END,
|
|
|
|
};
|
|
|
|
|
2012-12-26 17:43:35 +00:00
|
|
|
/**
|
|
|
|
* Type of settings for filtering.
|
|
|
|
*/
|
|
|
|
enum SettingType {
|
|
|
|
ST_GAME, ///< Game setting.
|
|
|
|
ST_COMPANY, ///< Company setting.
|
|
|
|
ST_CLIENT, ///< Client setting.
|
2012-12-26 17:47:02 +00:00
|
|
|
|
|
|
|
ST_ALL, ///< Used in setting filter to match all types.
|
2012-12-26 17:43:35 +00:00
|
|
|
};
|
2007-01-10 18:56:51 +00:00
|
|
|
|
2021-05-22 18:57:41 +00:00
|
|
|
struct IniItem;
|
2006-02-04 22:48:57 +00:00
|
|
|
|
2010-12-11 15:14:28 +00:00
|
|
|
/** Properties of config file settings. */
|
2021-05-23 08:47:12 +00:00
|
|
|
struct SettingDesc {
|
2021-06-03 19:18:29 +00:00
|
|
|
SettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup) :
|
2021-05-23 17:27:46 +00:00
|
|
|
name(name), flags(flags), startup(startup), save(save) {}
|
2021-05-22 17:00:43 +00:00
|
|
|
virtual ~SettingDesc() {}
|
|
|
|
|
2021-06-03 19:18:29 +00:00
|
|
|
const char *name; ///< Name of the setting. Used in configuration file and for console.
|
|
|
|
SettingFlag flags; ///< Handles how a setting would show up in the GUI (text/currency, etc.).
|
|
|
|
bool startup; ///< Setting has to be loaded directly at startup?.
|
|
|
|
SaveLoad save; ///< Internal structure (going to savegame, parts to config).
|
2012-12-05 19:35:09 +00:00
|
|
|
|
|
|
|
bool IsEditable(bool do_command = false) const;
|
2012-12-26 17:43:35 +00:00
|
|
|
SettingType GetType() const;
|
2021-05-23 17:27:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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; }
|
|
|
|
|
2021-05-22 18:44:09 +00:00
|
|
|
const struct IntSettingDesc *AsIntSetting() const;
|
2021-05-22 18:52:24 +00:00
|
|
|
const struct StringSettingDesc *AsStringSetting() const;
|
2021-05-22 11:39:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Format the value of the setting associated with this object.
|
|
|
|
* @param buf The before of the buffer to format into.
|
|
|
|
* @param last The end of the buffer to format into.
|
|
|
|
* @param object The object the setting is in.
|
|
|
|
*/
|
|
|
|
virtual void FormatValue(char *buf, const char *last, const void *object) const = 0;
|
2021-05-22 18:57:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse/read the value from the Ini item into the setting associated with this object.
|
|
|
|
* @param item The Ini item with the content of this setting.
|
|
|
|
* @param object The object the setting is in.
|
|
|
|
*/
|
|
|
|
virtual void ParseValue(const IniItem *item, void *object) const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the value in the Ini item is the same as is saved in this setting in the object.
|
|
|
|
* It might be that determining whether the value is the same is way more expensive than just
|
|
|
|
* writing the value. In those cases this function may unconditionally return false even though
|
|
|
|
* the value might be the same as in the Ini item.
|
|
|
|
* @param item The Ini item with the content of this setting.
|
|
|
|
* @param object The object the setting is in.
|
|
|
|
* @return True if the value is definitely the same (might be false when the same).
|
|
|
|
*/
|
|
|
|
virtual bool IsSameValue(const IniItem *item, void *object) const = 0;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
(svn r3719) - [1/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. This first part rewrites the configuration section to use the SaveLoad VarType in general.
- This unified structure consists of a SaveLoad type which stores all data relevant about the variable internals such as type, mem/filesize, address, version-control. The SettingDesc type is concerned more about the representation. Things like default value, string-name, minimum/maximum values, gui-behaviour etc.
- The SaveLoad type has received a few flags controlling saving/loading. These are:
SLF_SAVE_NO: the setting is not saved with the savegame, effectively making this setting player-based. Eg. it will NOT be overwritten when joining a network-game
SLF_CONFIG_NO: the setting is not saved to the configuration file so you cannot overwrite it ingame.
SLF_NETWORK_NO: the setting is not synchronised with the local settings when the game is loaded during network-play. Note that when SLF_SAVE_NO is set, SLF_NETWORK_NO is also set (which is logical), at least if the proper macros are used (in [2/4]).
- NOTE! The game is not compilable after this commit.
2006-03-01 23:53:20 +00:00
|
|
|
|
2021-05-23 16:20:49 +00:00
|
|
|
/** Base integer type, including boolean, settings. Only these are shown in the settings UI. */
|
2021-05-22 17:00:43 +00:00
|
|
|
struct IntSettingDesc : SettingDesc {
|
2021-05-24 09:47:37 +00:00
|
|
|
/**
|
|
|
|
* A check to be performed before the setting gets changed. The passed integer may be
|
|
|
|
* changed by the check if that is important, for example to remove some unwanted bit.
|
|
|
|
* The return value denotes whether the value, potentially after the changes,
|
|
|
|
* is allowed to be used/set in the configuration.
|
|
|
|
* @param value The prospective new value for the setting.
|
|
|
|
* @return True when the setting is accepted.
|
|
|
|
*/
|
|
|
|
typedef bool PreChangeCheck(int32 &value);
|
|
|
|
/**
|
|
|
|
* A callback to denote that a setting has been changed.
|
|
|
|
* @param The new value for the setting.
|
|
|
|
*/
|
|
|
|
typedef void PostChangeCallback(int32 value);
|
|
|
|
|
2021-06-03 19:18:29 +00:00
|
|
|
IntSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def,
|
2021-05-24 09:47:37 +00:00
|
|
|
int32 min, uint32 max, int32 interval, StringID str, StringID str_help, StringID str_val,
|
|
|
|
SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback) :
|
2021-05-23 17:27:46 +00:00
|
|
|
SettingDesc(save, name, flags, startup), def(def), min(min), max(max), interval(interval),
|
2021-05-24 09:47:37 +00:00
|
|
|
str(str), str_help(str_help), str_val(str_val), cat(cat), pre_check(pre_check),
|
|
|
|
post_callback(post_callback) {}
|
2021-05-22 17:00:43 +00:00
|
|
|
virtual ~IntSettingDesc() {}
|
2021-05-22 11:39:41 +00:00
|
|
|
|
2021-05-22 19:09:30 +00:00
|
|
|
int32 def; ///< default value given when none is present
|
|
|
|
int32 min; ///< minimum values
|
|
|
|
uint32 max; ///< maximum values
|
|
|
|
int32 interval; ///< the interval to use between settings in the 'settings' window. If interval is '0' the interval is dynamically determined
|
|
|
|
StringID str; ///< (translated) string with descriptive text; gui and console
|
|
|
|
StringID str_help; ///< (Translated) string with help text; gui only.
|
|
|
|
StringID str_val; ///< (Translated) first string describing the value.
|
|
|
|
SettingCategory cat; ///< assigned categories of the setting
|
2021-05-24 09:47:37 +00:00
|
|
|
PreChangeCheck *pre_check; ///< Callback to check for the validity of the setting.
|
|
|
|
PostChangeCallback *post_callback; ///< Callback when the setting has been changed.
|
2021-05-22 19:09:30 +00:00
|
|
|
|
2021-05-23 17:27:46 +00:00
|
|
|
/**
|
|
|
|
* 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; }
|
|
|
|
|
2021-05-22 18:44:09 +00:00
|
|
|
void ChangeValue(const void *object, int32 newvalue) const;
|
2021-05-24 08:42:02 +00:00
|
|
|
void MakeValueValidAndWrite(const void *object, int32 value) const;
|
2021-05-22 18:44:09 +00:00
|
|
|
|
2021-05-23 16:20:49 +00:00
|
|
|
virtual size_t ParseValue(const char *str) const;
|
2021-05-22 11:39:41 +00:00
|
|
|
void FormatValue(char *buf, const char *last, const void *object) const override;
|
2021-05-22 18:57:41 +00:00
|
|
|
void ParseValue(const IniItem *item, void *object) const override;
|
|
|
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
2021-05-24 08:42:02 +00:00
|
|
|
int32 Read(const void *object) const;
|
2021-05-24 08:42:02 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void MakeValueValid(int32 &value) const;
|
|
|
|
void Write(const void *object, int32 value) const;
|
2021-05-22 17:00:43 +00:00
|
|
|
};
|
|
|
|
|
2021-05-23 16:20:49 +00:00
|
|
|
/** Boolean setting. */
|
|
|
|
struct BoolSettingDesc : IntSettingDesc {
|
2021-06-03 19:18:29 +00:00
|
|
|
BoolSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, bool def,
|
2021-05-24 09:47:37 +00:00
|
|
|
StringID str, StringID str_help, StringID str_val, SettingCategory cat,
|
|
|
|
PreChangeCheck pre_check, PostChangeCallback post_callback) :
|
|
|
|
IntSettingDesc(save, name, flags, startup, def, 0, 1, 0, str, str_help, str_val, cat,
|
|
|
|
pre_check, post_callback) {}
|
2021-05-23 16:20:49 +00:00
|
|
|
virtual ~BoolSettingDesc() {}
|
|
|
|
|
2021-05-23 17:27:46 +00:00
|
|
|
bool IsBoolSetting() const override { return true; }
|
2021-05-23 16:20:49 +00:00
|
|
|
size_t ParseValue(const char *str) const override;
|
|
|
|
void FormatValue(char *buf, const char *last, const void *object) const override;
|
|
|
|
};
|
|
|
|
|
2021-05-23 17:16:56 +00:00
|
|
|
/** One of many setting. */
|
|
|
|
struct OneOfManySettingDesc : IntSettingDesc {
|
2021-05-24 09:47:37 +00:00
|
|
|
typedef size_t OnConvert(const char *value); ///< callback prototype for conversion error
|
|
|
|
|
2021-06-03 19:18:29 +00:00
|
|
|
OneOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def,
|
2021-05-24 09:47:37 +00:00
|
|
|
int32 max, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
|
|
|
|
PreChangeCheck pre_check, PostChangeCallback post_callback,
|
|
|
|
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
|
|
|
|
IntSettingDesc(save, name, flags, startup, def, 0, max, 0, str, str_help, str_val, cat,
|
|
|
|
pre_check, post_callback), many_cnvt(many_cnvt)
|
2021-05-23 17:16:56 +00:00
|
|
|
{
|
|
|
|
for (auto one : many) this->many.push_back(one);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~OneOfManySettingDesc() {}
|
|
|
|
|
|
|
|
std::vector<std::string> many; ///< possible values for this type
|
|
|
|
OnConvert *many_cnvt; ///< callback procedure when loading value mechanism fails
|
|
|
|
|
|
|
|
static size_t ParseSingleValue(const char *str, size_t len, const std::vector<std::string> &many);
|
|
|
|
char *FormatSingleValue(char *buf, const char *last, uint id) const;
|
|
|
|
|
|
|
|
size_t ParseValue(const char *str) const override;
|
|
|
|
void FormatValue(char *buf, const char *last, const void *object) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Many of many setting. */
|
|
|
|
struct ManyOfManySettingDesc : OneOfManySettingDesc {
|
2021-06-03 19:18:29 +00:00
|
|
|
ManyOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup,
|
2021-05-24 09:47:37 +00:00
|
|
|
int32 def, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
|
|
|
|
PreChangeCheck pre_check, PostChangeCallback post_callback,
|
2021-05-23 17:16:56 +00:00
|
|
|
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
|
2021-05-23 17:27:46 +00:00
|
|
|
OneOfManySettingDesc(save, name, flags, startup, def, (1 << many.size()) - 1, str, str_help,
|
2021-05-24 09:47:37 +00:00
|
|
|
str_val, cat, pre_check, post_callback, many, many_cnvt) {}
|
2021-05-23 17:16:56 +00:00
|
|
|
virtual ~ManyOfManySettingDesc() {}
|
|
|
|
|
|
|
|
size_t ParseValue(const char *str) const override;
|
|
|
|
void FormatValue(char *buf, const char *last, const void *object) const override;
|
|
|
|
};
|
|
|
|
|
2021-05-22 17:00:43 +00:00
|
|
|
/** String settings. */
|
|
|
|
struct StringSettingDesc : SettingDesc {
|
2021-05-24 07:44:20 +00:00
|
|
|
/**
|
|
|
|
* A check to be performed before the setting gets changed. The passed string may be
|
|
|
|
* changed by the check if that is important, for example to remove unwanted white
|
|
|
|
* space. The return value denotes whether the value, potentially after the changes,
|
|
|
|
* is allowed to be used/set in the configuration.
|
|
|
|
* @param value The prospective new value for the setting.
|
|
|
|
* @return True when the setting is accepted.
|
|
|
|
*/
|
|
|
|
typedef bool PreChangeCheck(std::string &value);
|
|
|
|
/**
|
|
|
|
* A callback to denote that a setting has been changed.
|
|
|
|
* @param The new value for the setting.
|
|
|
|
*/
|
|
|
|
typedef void PostChangeCallback(const std::string &value);
|
|
|
|
|
2021-06-03 19:18:29 +00:00
|
|
|
StringSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def,
|
2021-05-24 07:44:20 +00:00
|
|
|
uint32 max_length, PreChangeCheck pre_check, PostChangeCallback post_callback) :
|
2021-05-24 07:44:20 +00:00
|
|
|
SettingDesc(save, name, flags, startup), def(def == nullptr ? "" : def), max_length(max_length),
|
2021-05-24 07:44:20 +00:00
|
|
|
pre_check(pre_check), post_callback(post_callback) {}
|
2021-05-22 17:00:43 +00:00
|
|
|
virtual ~StringSettingDesc() {}
|
2021-05-22 11:39:41 +00:00
|
|
|
|
2021-05-24 07:44:20 +00:00
|
|
|
std::string def; ///< Default value given when none is present
|
|
|
|
uint32 max_length; ///< Maximum length of the string, 0 means no maximum length
|
|
|
|
PreChangeCheck *pre_check; ///< Callback to check for the validity of the setting.
|
|
|
|
PostChangeCallback *post_callback; ///< Callback when the setting has been changed.
|
2021-05-22 19:09:30 +00:00
|
|
|
|
2021-05-23 17:27:46 +00:00
|
|
|
bool IsStringSetting() const override { return true; }
|
2021-05-24 07:44:20 +00:00
|
|
|
void ChangeValue(const void *object, std::string &newval) const;
|
2021-05-22 18:52:24 +00:00
|
|
|
|
2021-05-22 11:39:41 +00:00
|
|
|
void FormatValue(char *buf, const char *last, const void *object) const override;
|
2021-05-22 18:57:41 +00:00
|
|
|
void ParseValue(const IniItem *item, void *object) const override;
|
|
|
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
2021-05-22 11:39:41 +00:00
|
|
|
const std::string &Read(const void *object) const;
|
2021-05-24 07:44:20 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void MakeValueValid(std::string &str) const;
|
|
|
|
void Write(const void *object, const std::string &str) const;
|
2021-05-22 17:00:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** List/array settings. */
|
|
|
|
struct ListSettingDesc : SettingDesc {
|
2021-06-03 19:18:29 +00:00
|
|
|
ListSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def) :
|
2021-05-23 17:27:46 +00:00
|
|
|
SettingDesc(save, name, flags, startup), def(def) {}
|
2021-05-22 17:00:43 +00:00
|
|
|
virtual ~ListSettingDesc() {}
|
2021-05-22 11:39:41 +00:00
|
|
|
|
2021-05-22 19:09:30 +00:00
|
|
|
const char *def; ///< default value given when none is present
|
|
|
|
|
2021-05-22 11:39:41 +00:00
|
|
|
void FormatValue(char *buf, const char *last, const void *object) const override;
|
2021-05-22 18:57:41 +00:00
|
|
|
void ParseValue(const IniItem *item, void *object) const override;
|
|
|
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
2021-05-22 17:00:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
|
|
|
|
struct NullSettingDesc : SettingDesc {
|
|
|
|
NullSettingDesc(SaveLoad save) :
|
2021-06-03 18:55:03 +00:00
|
|
|
SettingDesc(save, "", SF_NOT_IN_CONFIG, false) {}
|
2021-05-22 17:00:43 +00:00
|
|
|
virtual ~NullSettingDesc() {}
|
2021-05-22 11:39:41 +00:00
|
|
|
|
|
|
|
void FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); }
|
2021-05-22 18:57:41 +00:00
|
|
|
void ParseValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
|
|
|
bool IsSameValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
2021-05-22 17:00:43 +00:00
|
|
|
};
|
|
|
|
|
2021-05-23 08:47:12 +00:00
|
|
|
typedef std::initializer_list<std::unique_ptr<const SettingDesc>> SettingTable;
|
2021-05-18 19:01:42 +00:00
|
|
|
|
2021-05-30 09:30:03 +00:00
|
|
|
const SettingDesc *GetSettingFromName(const std::string_view name);
|
|
|
|
void GetSettingSaveLoadByPrefix(const std::string_view prefix, std::vector<SaveLoad> &saveloads);
|
2021-05-23 09:55:22 +00:00
|
|
|
bool SetSettingValue(const IntSettingDesc *sd, int32 value, bool force_newgame = false);
|
2021-05-24 07:44:20 +00:00
|
|
|
bool SetSettingValue(const StringSettingDesc *sd, const std::string value, bool force_newgame = false);
|
2005-05-02 15:52:19 +00:00
|
|
|
|
2010-12-22 10:50:32 +00:00
|
|
|
#endif /* SETTINGS_INTERNAL_H */
|