Changeset - r25527:ad30d3893783
[Not reviewed]
master
0 5 0
rubidium42 - 3 years ago 2021-05-23 07:51:33
rubidium@openttd.org
Codechange: let SettingDesc extend SettingDescBase
5 files changed with 62 insertions and 63 deletions:
0 comments (0 inline, 0 general)
src/saveload/linkgraph_sl.cpp
Show inline comments
 
@@ -72,13 +72,13 @@ const SaveLoad *GetLinkGraphJobDesc()
 
	if (saveloads.size() == 0) {
 
		size_t prefixlen = strlen(prefix);
 

	
 
		int setting = 0;
 
		const SettingDesc *desc = GetSettingDescription(setting);
 
		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;
 
				sl.address_proc = proc;
 
				saveloads.push_back(sl);
 
			}
 
			desc = GetSettingDescription(++setting);
 
		}
src/script/api/script_gamesettings.cpp
Show inline comments
 
@@ -15,35 +15,35 @@
 

	
 
#include "../../safeguards.h"
 

	
 
/* static */ bool ScriptGameSettings::IsValid(const char *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)
 
{
 
	if (!IsValid(setting)) return -1;
 

	
 
	const SettingDesc *sd = GetSettingFromName(setting);
 

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

	
 
/* static */ bool ScriptGameSettings::SetValue(const char *setting, int value)
 
{
 
	if (!IsValid(setting)) return false;
 

	
 
	const SettingDesc *sd = GetSettingFromName(setting);
 

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

	
 
/* static */ bool ScriptGameSettings::IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type)
 
{
src/settings.cpp
Show inline comments
 
@@ -431,13 +431,13 @@ static const void *StringToVal(const Set
 
 * @param val signed long version of the new value
 
 * @pre SettingDesc is of type SDT_BOOLX, SDT_NUMX,
 
 * SDT_ONEOFMANY or SDT_MANYOFMANY. Other types are not supported as of now
 
 */
 
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 &&
 
			sdb->cmd != SDT_NUMX &&
 
			sdb->cmd != SDT_ONEOFMANY &&
 
			sdb->cmd != SDT_MANYOFMANY) {
 
		return;
 
@@ -505,17 +505,17 @@ static void Write_ValidateStdString(void
 
	std::string *dst = reinterpret_cast<std::string *>(ptr);
 

	
 
	switch (GetVarMemType(sd->save.conv)) {
 
		case SLE_VAR_STR:
 
		case SLE_VAR_STRQ:
 
			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
 
					 * includes the '\0' termination for network transfer purposes.
 
					 * 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));
 
				} else {
 
					dst->assign(p);
 
				}
 
			} else {
 
				dst->clear();
 
@@ -538,17 +538,17 @@ static void Write_ValidateStdString(void
 
static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool only_startup)
 
{
 
	IniGroup *group;
 
	IniGroup *group_def = ini->GetGroup(grpname);
 

	
 
	for (; sd->save.cmd != SL_END; sd++) {
 
		const SettingDescBase *sdb = &sd->desc;
 
		const SettingDescBase *sdb = sd;
 
		const SaveLoad        *sld = &sd->save;
 

	
 
		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 = ? */
 
		std::string s{ sdb->name };
 
		auto sc = s.find('.');
 
		if (sc != std::string::npos) {
 
			group = ini->GetGroup(s.substr(0, sc));
 
@@ -590,14 +590,14 @@ static void IniLoadSettings(IniFile *ini
 
					ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
 
					msg.SetDParamStr(0, sdb->name);
 
					_settings_error_list.push_back(msg);
 

	
 
					/* Use default */
 
					LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
 
				} else if (sd->desc.proc_cnvt != nullptr) {
 
					sd->desc.proc_cnvt((const char*)p);
 
				} else if (sd->proc_cnvt != nullptr) {
 
					sd->proc_cnvt((const char*)p);
 
				}
 
				break;
 
			}
 
			default: NOT_REACHED();
 
		}
 
	}
 
@@ -620,13 +620,13 @@ static void IniSaveSettings(IniFile *ini
 
	IniGroup *group_def = nullptr, *group;
 
	IniItem *item;
 
	char buf[512];
 
	void *ptr;
 

	
 
	for (; sd->save.cmd != SL_END; sd++) {
 
		const SettingDescBase *sdb = &sd->desc;
 
		const SettingDescBase *sdb = sd;
 
		const SaveLoad        *sld = &sd->save;
 

	
 
		/* If the setting is not saved to the configuration
 
		 * file, just continue with the next setting */
 
		if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
 
		if (sld->conv & SLF_NOT_IN_CONFIG) continue;
 
@@ -799,29 +799,29 @@ void IniSaveWindowSettings(IniFile *ini,
 
 * Check whether the setting is editable in the current gamemode.
 
 * @param do_command true if this is about checking a command from the server.
 
 * @return true if editable.
 
 */
 
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 ((this->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
 
	if ((this->desc.flags & SGF_NO_NETWORK) && _networking) return false;
 
	if ((this->desc.flags & SGF_NEWGAME_ONLY) &&
 
	if (!do_command && !(this->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->flags & SGF_PER_COMPANY)) return false;
 
	if ((this->flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
 
	if ((this->flags & SGF_NO_NETWORK) && _networking) return false;
 
	if ((this->flags & SGF_NEWGAME_ONLY) &&
 
			(_game_mode == GM_NORMAL ||
 
			(_game_mode == GM_EDITOR && !(this->desc.flags & SGF_SCENEDIT_TOO)))) return false;
 
	if ((this->desc.flags & SGF_SCENEDIT_ONLY) && _game_mode != GM_EDITOR) return false;
 
			(_game_mode == GM_EDITOR && !(this->flags & SGF_SCENEDIT_TOO)))) return false;
 
	if ((this->flags & SGF_SCENEDIT_ONLY) && _game_mode != GM_EDITOR) return false;
 
	return true;
 
}
 

	
 
/**
 
 * Return the type of the setting.
 
 * @return type of setting
 
 */
 
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;
 
}
 

	
 
/* Begin - Callback Functions for the various settings. */
 

	
 
/** Reposition the main toolbar as the setting changed. */
 
@@ -1889,20 +1889,20 @@ CommandCost CmdChangeSetting(TileIndex t
 

	
 
		Write_ValidateSetting(var, sd, newval);
 
		newval = (int32)ReadValue(var, sd->save.conv);
 

	
 
		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);
 
			return CommandCost();
 
		}
 

	
 
		if (sd->desc.flags & SGF_NO_NETWORK) {
 
		if (sd->flags & SGF_NO_NETWORK) {
 
			GamelogStartAction(GLAT_SETTING);
 
			GamelogSetting(sd->desc.name, oldval, newval);
 
			GamelogSetting(sd->name, oldval, newval);
 
			GamelogStopAction();
 
		}
 

	
 
		SetWindowClassesDirty(WC_GAME_OPTIONS);
 

	
 
		if (_save_config) SaveToConfig();
 
@@ -1934,13 +1934,13 @@ CommandCost CmdChangeCompanySetting(Tile
 

	
 
		Write_ValidateSetting(var, sd, newval);
 
		newval = (int32)ReadValue(var, sd->save.conv);
 

	
 
		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);
 
			return CommandCost();
 
		}
 

	
 
		SetWindowClassesDirty(WC_GAME_OPTIONS);
 
	}
 
@@ -1952,33 +1952,33 @@ CommandCost CmdChangeCompanySetting(Tile
 
 * Get the index of the setting with this description.
 
 * @param sd the setting to get the index for.
 
 * @return the index of the setting to be used for CMD_CHANGE_SETTING.
 
 */
 
uint GetSettingIndex(const SettingDesc *sd)
 
{
 
	assert((sd->desc.flags & SGF_PER_COMPANY) == 0);
 
	assert((sd->flags & SGF_PER_COMPANY) == 0);
 
	return sd - _settings;
 
}
 

	
 
/**
 
 * Top function to save the new value of an element of the Settings struct
 
 * @param index offset in the SettingDesc array of the Settings struct which
 
 * identifies the setting member we want to change
 
 * @param value new value of the setting
 
 * @param force_newgame force the newgame settings
 
 */
 
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) {
 
			return DoCommandP(0, sd - _company_settings, value, CMD_CHANGE_COMPANY_SETTING);
 
		}
 

	
 
		void *var = GetVariableAddress(&_settings_client.company, &sd->save);
 
		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;
 
	}
 

	
 
	/* If an item is company-based, we do not send it over the network
 
	 * (if any) to change. Also *hack*hack* we update the _newgame version
 
	 * of settings because changing a company-based setting in a game also
 
@@ -1988,13 +1988,13 @@ bool SetSettingValue(const SettingDesc *
 
		Write_ValidateSetting(var, sd, value);
 

	
 
		if (_game_mode != GM_MENU) {
 
			void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
 
			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);
 

	
 
		if (_save_config) SaveToConfig();
 
		return true;
 
	}
 
@@ -2020,13 +2020,13 @@ bool SetSettingValue(const SettingDesc *
 
void SetDefaultCompanySettings(CompanyID cid)
 
{
 
	Company *c = Company::Get(cid);
 
	const SettingDesc *sd;
 
	for (sd = _company_settings; sd->save.cmd != SL_END; sd++) {
 
		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);
 
	}
 
}
 

	
 
/**
 
 * Sync all company settings in a multiplayer game.
 
 */
 
@@ -2048,13 +2048,13 @@ void SyncCompanySettings()
 
 * @param name The name of the setting
 
 * @return The index in the _company_settings array
 
 */
 
uint GetCompanySettingIndex(const char *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;
 
}
 

	
 
/**
 
 * Set a setting value with a string.
 
 * @param sd the setting to change.
 
@@ -2069,13 +2069,13 @@ bool SetSettingValue(const SettingDesc *
 
	if (GetVarMemType(sd->save.conv) == SLE_VAR_STRQ && strcmp(value, "(null)") == 0) {
 
		value = nullptr;
 
	}
 

	
 
	void *ptr = GetVariableAddress((_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game, &sd->save);
 
	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();
 
	return true;
 
}
 

	
 
/**
 
@@ -2087,30 +2087,30 @@ bool SetSettingValue(const SettingDesc *
 
 */
 
const SettingDesc *GetSettingFromName(const char *name)
 
{
 
	/* First check all full names */
 
	for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
 
		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. */
 
	for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
 
		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) {
 
			short_name++;
 
			if (strcmp(short_name, name) == 0) return sd;
 
		}
 
	}
 

	
 
	if (strncmp(name, "company.", 8) == 0) name += 8;
 
	/* And finally the company-based settings */
 
	for (const SettingDesc *sd = _company_settings; sd->save.cmd != SL_END; sd++) {
 
		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;
 
}
 

	
 
/* Those 2 functions need to be here, else we have to make some stuff non-static
 
@@ -2122,13 +2122,13 @@ void IConsoleSetSetting(const char *name
 
	if (sd == nullptr) {
 
		IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
 
		return;
 
	}
 

	
 
	bool success;
 
	if (sd->desc.cmd == SDT_STDSTRING) {
 
	if (sd->cmd == SDT_STDSTRING) {
 
		success = SetSettingValue(sd, value, force_newgame);
 
	} else {
 
		uint32 val;
 
		extern bool GetArgumentInteger(uint32 *value, const char *arg);
 
		success = GetArgumentInteger(&val, value);
 
		if (!success) {
 
@@ -2170,23 +2170,23 @@ void IConsoleGetSetting(const char *name
 
		IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
 
		return;
 
	}
 

	
 
	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());
 
	} else {
 
		if (sd->desc.cmd == SDT_BOOLX) {
 
		if (sd->cmd == SDT_BOOLX) {
 
			seprintf(value, lastof(value), (*(const bool*)ptr != 0) ? "on" : "off");
 
		} 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)",
 
			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);
 
	}
 
}
 

	
 
/**
 
 * List all settings and their value to the console
 
 *
 
@@ -2195,24 +2195,24 @@ void IConsoleGetSetting(const char *name
 
void IConsoleListSettings(const char *prefilter)
 
{
 
	IConsolePrintF(CC_WARNING, "All settings with their current value:");
 

	
 
	for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
 
		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];
 
		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");
 
		} 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());
 
		} 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");
 
}
 

	
 
/**
src/settings_gui.cpp
Show inline comments
 
@@ -840,13 +840,13 @@ struct SettingEntry : BaseSettingEntry {
 
	/**
 
	 * Get the help text of a single setting.
 
	 * @return The requested help text.
 
	 */
 
	inline StringID GetHelpText() const
 
	{
 
		return this->setting->desc.str_help;
 
		return this->setting->str_help;
 
	}
 

	
 
	void SetValueDParams(uint first_param, int32 value) const;
 

	
 
protected:
 
	virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const;
 
@@ -1033,13 +1033,13 @@ void SettingEntry::Init(byte level)
 
	assert(this->setting != nullptr);
 
}
 

	
 
/* Sets the given setting entry to its default value */
 
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);
 
}
 

	
 
/**
 
 * Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
 
 * @param new_val New value for the button flags
 
@@ -1077,26 +1077,26 @@ bool SettingEntry::IsVisibleByRestrictio
 
	/* There shall not be any restriction, i.e. all settings shall be visible. */
 
	if (mode == RM_ALL) return true;
 

	
 
	GameSettings *settings_ptr = &GetGameSettings();
 
	const SettingDesc *sd = this->setting;
 

	
 
	if (mode == RM_BASIC) return (this->setting->desc.cat & SC_BASIC_LIST) != 0;
 
	if (mode == RM_ADVANCED) return (this->setting->desc.cat & SC_ADVANCED_LIST) != 0;
 
	if (mode == RM_BASIC) return (this->setting->cat & SC_BASIC_LIST) != 0;
 
	if (mode == RM_ADVANCED) return (this->setting->cat & SC_ADVANCED_LIST) != 0;
 

	
 
	/* Read the current value. */
 
	const void *var = ResolveVariableAddress(settings_ptr, sd);
 
	int64 current_value = ReadValue(var, sd->save.conv);
 

	
 
	int64 filter_value;
 

	
 
	if (mode == RM_CHANGED_AGAINST_DEFAULT) {
 
		/* This entry shall only be visible, if the value deviates from its default value. */
 

	
 
		/* Read the default value. */
 
		filter_value = ReadValue(&sd->desc.def, sd->save.conv);
 
		filter_value = ReadValue(&sd->def, sd->save.conv);
 
	} else {
 
		assert(mode == RM_CHANGED_AGAINST_NEW);
 
		/* This entry shall only be visible, if the value deviates from
 
		 * its value is used when starting a new game. */
 

	
 
		/* Make sure we're not comparing the new game settings against itself. */
 
@@ -1124,13 +1124,13 @@ bool SettingEntry::UpdateFilterState(Set
 

	
 
	const SettingDesc *sd = this->setting;
 
	if (!force_visible && !filter.string.IsEmpty()) {
 
		/* Process the search text filter for this item. */
 
		filter.string.ResetState();
 

	
 
		const SettingDescBase *sdb = &sd->desc;
 
		const SettingDescBase *sdb = sd;
 

	
 
		SetDParam(0, STR_EMPTY);
 
		filter.string.AddLine(sdb->str);
 
		filter.string.AddLine(this->GetHelpText());
 

	
 
		visible = filter.string.GetState();
 
@@ -1150,13 +1150,13 @@ bool SettingEntry::UpdateFilterState(Set
 
	if (!visible) SETBITS(this->flags, SEF_FILTERED);
 
	return visible;
 
}
 

	
 
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) {
 
			return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
 
		} else {
 
			return GetVariableAddress(&_settings_client.company, &sd->save);
 
		}
 
	} else {
 
@@ -1168,13 +1168,13 @@ static const void *ResolveVariableAddres
 
 * Set the DParams for drawing the value of a setting.
 
 * @param first_param First DParam to use
 
 * @param value Setting value to set params for.
 
 */
 
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) {
 
		SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
 
	} else {
 
		if ((sdb->flags & SGF_MULTISTRING) != 0) {
 
			SetDParam(first_param++, sdb->str_val - sdb->min + value);
 
		} else if ((sdb->flags & SGF_DISPLAY_ABS) != 0) {
 
@@ -1195,13 +1195,13 @@ void SettingEntry::SetValueDParams(uint 
 
 * @param y            Upper-most position in window/panel to start drawing
 
 * @param highlight    Highlight entry.
 
 */
 
void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const
 
{
 
	const SettingDesc *sd = this->setting;
 
	const SettingDescBase *sdb = &sd->desc;
 
	const SettingDescBase *sdb = sd;
 
	const void *var = ResolveVariableAddress(settings_ptr, sd);
 
	int state = this->flags & SEF_BUTTONS_MASK;
 

	
 
	bool rtl = _current_text_dir == TD_RTL;
 
	uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
 
	uint text_left  = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + 5);
 
@@ -2088,13 +2088,13 @@ struct GameSettingsWindow : Window {
 
						case ST_GAME:    SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
 
						default: NOT_REACHED();
 
					}
 
					DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE);
 
					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);
 
					DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE);
 
					y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
 

	
 
					DrawStringMultiLine(r.left, r.right, y, r.bottom, this->last_clicked->GetHelpText(), TC_WHITE);
 
				}
 
@@ -2192,14 +2192,14 @@ struct GameSettingsWindow : Window {
 
		}
 

	
 
		const void *var = ResolveVariableAddress(settings_ptr, sd);
 
		int32 value = (int32)ReadValue(var, sd->save.conv);
 

	
 
		/* 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)) {
 
			const SettingDescBase *sdb = &sd->desc;
 
		if (x < SETTING_BUTTON_WIDTH && (sd->flags & SGF_MULTISTRING)) {
 
			const SettingDescBase *sdb = sd;
 
			this->SetDisplayedHelpText(pe);
 

	
 
			if (this->valuedropdown_entry == pe) {
 
				/* unclick the dropdown */
 
				HideDropDownMenu(this);
 
				this->closing_dropdown = false;
 
@@ -2231,13 +2231,13 @@ struct GameSettingsWindow : Window {
 
					ShowDropDownListAt(this, std::move(list), value, -1, wi_rect, COLOUR_ORANGE, true);
 
				}
 
			}
 
			this->SetDirty();
 
		} else if (x < SETTING_BUTTON_WIDTH) {
 
			this->SetDisplayedHelpText(pe);
 
			const SettingDescBase *sdb = &sd->desc;
 
			const SettingDescBase *sdb = sd;
 
			int32 oldvalue = value;
 

	
 
			switch (sdb->cmd) {
 
				case SDT_BOOLX: value ^= 1; break;
 
				case SDT_ONEOFMANY:
 
				case SDT_NUMX: {
 
@@ -2288,16 +2288,16 @@ struct GameSettingsWindow : Window {
 
			if (value != oldvalue) {
 
				SetSettingValue(sd, value);
 
				this->SetDirty();
 
			}
 
		} else {
 
			/* 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;
 
				/* 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;
 
				SetDParam(0, value64);
 
				/* Limit string length to 14 so that MAX_INT32 * max currency rate doesn't exceed MAX_INT64. */
 
				ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
 
			}
 
@@ -2324,17 +2324,17 @@ struct GameSettingsWindow : Window {
 

	
 
		int32 value;
 
		if (!StrEmpty(str)) {
 
			long long llvalue = atoll(str);
 

	
 
			/* 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);
 
		} else {
 
			value = (int32)(size_t)sd->desc.def;
 
			value = (int32)(size_t)sd->def;
 
		}
 

	
 
		SetSettingValue(this->valuewindow_entry->setting, value);
 
		this->SetDirty();
 
	}
 

	
 
@@ -2365,13 +2365,13 @@ struct GameSettingsWindow : Window {
 

	
 
			default:
 
				if (widget < 0) {
 
					/* Deal with drop down boxes on the panel. */
 
					assert(this->valuedropdown_entry != nullptr);
 
					const SettingDesc *sd = this->valuedropdown_entry->setting;
 
					assert(sd->desc.flags & SGF_MULTISTRING);
 
					assert(sd->flags & SGF_MULTISTRING);
 

	
 
					SetSettingValue(sd, index);
 
					this->SetDirty();
 
				}
 
				break;
 
		}
src/settings_internal.h
Show inline comments
 
@@ -97,14 +97,13 @@ struct SettingDescBase {
 
	OnChange *proc;         ///< callback procedure for when the value is changed
 
	OnConvert *proc_cnvt;   ///< callback procedure when loading value mechanism fails
 
	SettingCategory cat;    ///< assigned categories of the setting
 
	bool startup;           ///< setting has to be loaded directly at startup?
 
};
 

	
 
struct SettingDesc {
 
	SettingDescBase desc;   ///< Settings structure (going to configuration file)
 
struct SettingDesc : SettingDescBase {
 
	SaveLoad save;          ///< Internal structure (going to savegame, parts to config)
 

	
 
	bool IsEditable(bool do_command = false) const;
 
	SettingType GetType() const;
 
};
 

	
0 comments (0 inline, 0 general)