Changeset - r25791:c5c057e89e2a
[Not reviewed]
master
0 3 0
Rubidium - 3 years ago 2021-07-08 17:26:21
rubidium@openttd.org
Codechange: use the name string in SaveLoad for the name of the Setting as well
3 files changed with 29 insertions and 36 deletions:
0 comments (0 inline, 0 general)
src/saveload/settings_sl.cpp
Show inline comments
 
@@ -89,11 +89,7 @@ static std::vector<SaveLoad> GetSettings
 
			continue;
 
		}
 

	
 
		SaveLoad sv = sd->save;
 
		/* Replace the name with the actual name of the setting. */
 
		assert(!sd->GetName().empty());
 
		sv.name = sd->GetName();
 
		saveloads.push_back(sv);
 
		saveloads.push_back(sd->save);
 
	}
 

	
 
	return saveloads;
src/settings_internal.h
Show inline comments
 
@@ -70,13 +70,10 @@ struct IniItem;
 

	
 
/** Properties of config file settings. */
 
struct SettingDesc {
 
	SettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup) :
 
		name(name), flags(flags), startup(startup), save(save) {}
 
	SettingDesc(SaveLoad save, SettingFlag flags, bool startup) :
 
		flags(flags), startup(startup), save(save) {}
 
	virtual ~SettingDesc() {}
 

	
 
private:
 
	std::string name;   ///< Name of the setting. Used in configuration file and for console.
 
public:
 
	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).
 
@@ -90,7 +87,7 @@ public:
 
	 */
 
	constexpr const std::string &GetName() const
 
	{
 
		return this->name;
 
		return this->save.name;
 
	}
 

	
 
	/**
 
@@ -152,10 +149,10 @@ struct IntSettingDesc : SettingDesc {
 
	 */
 
	typedef void PostChangeCallback(int32 value);
 

	
 
	IntSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def,
 
	IntSettingDesc(SaveLoad save, SettingFlag flags, bool startup, int32 def,
 
			int32 min, uint32 max, int32 interval, StringID str, StringID str_help, StringID str_val,
 
			SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback) :
 
		SettingDesc(save, name, flags, startup), def(def), min(min), max(max), interval(interval),
 
		SettingDesc(save, flags, startup), def(def), min(min), max(max), interval(interval),
 
			str(str), str_help(str_help), str_val(str_val), cat(cat), pre_check(pre_check),
 
			post_callback(post_callback) {}
 
	virtual ~IntSettingDesc() {}
 
@@ -194,10 +191,10 @@ private:
 

	
 
/** Boolean setting. */
 
struct BoolSettingDesc : IntSettingDesc {
 
	BoolSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, bool def,
 
	BoolSettingDesc(SaveLoad save, SettingFlag flags, bool startup, bool def,
 
			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,
 
		IntSettingDesc(save, flags, startup, def, 0, 1, 0, str, str_help, str_val, cat,
 
			pre_check, post_callback) {}
 
	virtual ~BoolSettingDesc() {}
 

	
 
@@ -210,11 +207,11 @@ struct BoolSettingDesc : IntSettingDesc 
 
struct OneOfManySettingDesc : IntSettingDesc {
 
	typedef size_t OnConvert(const char *value); ///< callback prototype for conversion error
 

	
 
	OneOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def,
 
	OneOfManySettingDesc(SaveLoad save, SettingFlag flags, bool startup, int32 def,
 
			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,
 
		IntSettingDesc(save, flags, startup, def, 0, max, 0, str, str_help, str_val, cat,
 
			pre_check, post_callback), many_cnvt(many_cnvt)
 
	{
 
		for (auto one : many) this->many.push_back(one);
 
@@ -234,11 +231,11 @@ struct OneOfManySettingDesc : IntSetting
 

	
 
/** Many of many setting. */
 
struct ManyOfManySettingDesc : OneOfManySettingDesc {
 
	ManyOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup,
 
	ManyOfManySettingDesc(SaveLoad save, SettingFlag flags, bool startup,
 
		int32 def, 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) :
 
		OneOfManySettingDesc(save, name, flags, startup, def, (1 << many.size()) - 1, str, str_help,
 
		OneOfManySettingDesc(save, flags, startup, def, (1 << many.size()) - 1, str, str_help,
 
			str_val, cat, pre_check, post_callback, many, many_cnvt) {}
 
	virtual ~ManyOfManySettingDesc() {}
 

	
 
@@ -263,9 +260,9 @@ struct StringSettingDesc : SettingDesc {
 
	 */
 
	typedef void PostChangeCallback(const std::string &value);
 

	
 
	StringSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def,
 
	StringSettingDesc(SaveLoad save, SettingFlag flags, bool startup, const char *def,
 
			uint32 max_length, PreChangeCheck pre_check, PostChangeCallback post_callback) :
 
		SettingDesc(save, name, flags, startup), def(def == nullptr ? "" : def), max_length(max_length),
 
		SettingDesc(save, flags, startup), def(def == nullptr ? "" : def), max_length(max_length),
 
			pre_check(pre_check), post_callback(post_callback) {}
 
	virtual ~StringSettingDesc() {}
 

	
 
@@ -289,8 +286,8 @@ private:
 

	
 
/** List/array settings. */
 
struct ListSettingDesc : SettingDesc {
 
	ListSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def) :
 
		SettingDesc(save, name, flags, startup), def(def) {}
 
	ListSettingDesc(SaveLoad save, SettingFlag flags, bool startup, const char *def) :
 
		SettingDesc(save, flags, startup), def(def) {}
 
	virtual ~ListSettingDesc() {}
 

	
 
	const char *def;        ///< default value given when none is present
 
@@ -303,7 +300,7 @@ struct ListSettingDesc : SettingDesc {
 
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
 
struct NullSettingDesc : SettingDesc {
 
	NullSettingDesc(SaveLoad save) :
 
		SettingDesc(save, "", SF_NOT_IN_CONFIG, false) {}
 
		SettingDesc(save, SF_NOT_IN_CONFIG, false) {}
 
	virtual ~NullSettingDesc() {}
 

	
 
	void FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); }
src/table/settings.h.preamble
Show inline comments
 
@@ -57,42 +57,42 @@ static size_t ConvertLandscape(const cha
 
/* Macros for various objects to go in the configuration file.
 
 * This section is for global variables */
 
#define SDTG_VAR(name, type, flags, var, def, min, max, interval, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\
 
	NSD(Int, SLEG_GENERAL(#var, SL_VAR, var, type, 1, from, to, extra), name, flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback)
 
	NSD(Int, SLEG_GENERAL(name, SL_VAR, var, type, 1, from, to, extra), flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback)
 

	
 
#define SDTG_BOOL(name, flags, var, def, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\
 
	NSD(Bool, SLEG_GENERAL(#var, SL_VAR, var, SLE_BOOL, 1, from, to, extra), name, flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback)
 
	NSD(Bool, SLEG_GENERAL(name, SL_VAR, var, SLE_BOOL, 1, from, to, extra), flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback)
 

	
 
#define SDTG_LIST(name, type, flags, var, def, length, from, to, cat, extra, startup)\
 
	NSD(List, SLEG_GENERAL(#var, SL_ARR, var, type, length, from, to, extra), name, flags, startup, def)
 
	NSD(List, SLEG_GENERAL(name, SL_ARR, var, type, length, from, to, extra),flags, startup, def)
 

	
 
#define SDTG_SSTR(name, type, flags, var, def, max_length, pre_check, post_callback, from, to, cat, extra, startup)\
 
	NSD(String, SLEG_GENERAL(#var, SL_STDSTR, var, type, sizeof(var), from, to, extra), name, flags, startup, def, max_length, pre_check, post_callback)
 
	NSD(String, SLEG_GENERAL(name, SL_STDSTR, var, type, sizeof(var), from, to, extra), flags, startup, def, max_length, pre_check, post_callback)
 

	
 
#define SDTG_OMANY(name, type, flags, var, def, max, full, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\
 
	NSD(OneOfMany, SLEG_GENERAL(#var, SL_VAR, var, type, 1, from, to, extra), name, flags, startup, def, max, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr)
 
	NSD(OneOfMany, SLEG_GENERAL(name, SL_VAR, var, type, 1, from, to, extra), flags, startup, def, max, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr)
 

	
 
#define SDTG_MMANY(name, type, flags, var, def, full, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\
 
	NSD(ManyOfMany, SLEG_GENERAL(#var, SL_VAR, var, type, 1, from, to, extra), name, flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr)
 
	NSD(ManyOfMany, SLEG_GENERAL(name, SL_VAR, var, type, 1, from, to, extra), flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr)
 

	
 
/* Macros for various objects to go in the configuration file.
 
 * This section is for structures where their various members are saved */
 
#define SDT_VAR(base, var, type, flags, def, min, max, interval, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\
 
	NSD(Int, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), #var, flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback)
 
	NSD(Int, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback)
 

	
 
#define SDT_BOOL(base, var, flags, def, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\
 
	NSD(Bool, SLE_GENERAL(SL_VAR, base, var, SLE_BOOL, 1, from, to, extra), #var, flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback)
 
	NSD(Bool, SLE_GENERAL(SL_VAR, base, var, SLE_BOOL, 1, from, to, extra), flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback)
 

	
 
#define SDT_LIST(base, var, type, flags, def, from, to, cat, extra, startup)\
 
	NSD(List, SLE_GENERAL(SL_ARR, base, var, type, lengthof(((base*)8)->var), from, to, extra), #var, flags, startup, def)
 
	NSD(List, SLE_GENERAL(SL_ARR, base, var, type, lengthof(((base*)8)->var), from, to, extra), flags, startup, def)
 

	
 
#define SDT_SSTR(base, var, type, flags, def, pre_check, post_callback, from, to, cat, extra, startup)\
 
	NSD(String, SLE_GENERAL(SL_STDSTR, base, var, type, sizeof(((base*)8)->var), from, to, extra), #var, flags, startup, def, 0, pre_check, post_callback)
 
	NSD(String, SLE_GENERAL(SL_STDSTR, base, var, type, sizeof(((base*)8)->var), from, to, extra), flags, startup, def, 0, pre_check, post_callback)
 

	
 
#define SDT_OMANY(base, var, type, flags, def, max, full, str, strhelp, strval, pre_check, post_callback, from, to, load, cat, extra, startup)\
 
	NSD(OneOfMany, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), #var, flags, startup, def, max, str, strhelp, strval, cat, pre_check, post_callback, full, load)
 
	NSD(OneOfMany, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), flags, startup, def, max, str, strhelp, strval, cat, pre_check, post_callback, full, load)
 

	
 
#define SDT_MMANY(base, var, type, flags, def, full, str, pre_check, post_callback, strhelp, strval, from, to, cat, extra, startup)\
 
	NSD(ManyOfMany, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), #var, flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr)
 
	NSD(ManyOfMany, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr)
 

	
 

	
 
#define SDTC_VAR(var, type, flags, def, min, max, interval, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\
0 comments (0 inline, 0 general)