Changeset - r19832:28610f312539
[Not reviewed]
master
0 3 0
frosch - 12 years ago 2012-12-05 19:35:09
frosch@openttd.org
(svn r24787) -Fix: Unify checks for editability of settings.
3 files changed with 22 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/settings.cpp
Show inline comments
 
@@ -729,12 +729,28 @@ static void IniSaveSettingList(IniFile *
 

	
 
	for (char **iter = list->Begin(); iter != list->End(); iter++) {
 
		group->GetItem(*iter, true)->SetValue("");
 
	}
 
}
 

	
 
/**
 
 * 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) &&
 
			(_game_mode == GM_NORMAL ||
 
			(_game_mode == GM_EDITOR && !(this->desc.flags & SGF_SCENEDIT_TOO)))) return false;
 
	return true;
 
}
 

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

	
 
/** Reposition the main toolbar as the setting changed. */
 
static bool v_PositionMainToolbar(int32 p1)
 
{
 
	if (_game_mode != GM_MENU) PositionMainToolbar(NULL);
 
@@ -1779,19 +1795,13 @@ CommandCost CmdChangeSetting(TileIndex t
 
{
 
	const SettingDesc *sd = GetSettingDescription(p1);
 

	
 
	if (sd == NULL) return CMD_ERROR;
 
	if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) return CMD_ERROR;
 

	
 
	if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return CMD_ERROR;
 
	if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return CMD_ERROR;
 
	if ((sd->desc.flags & SGF_NEWGAME_ONLY) &&
 
			(_game_mode == GM_NORMAL ||
 
			(_game_mode == GM_EDITOR && (sd->desc.flags & SGF_SCENEDIT_TOO) == 0))) {
 
		return CMD_ERROR;
 
	}
 
	if (!sd->IsEditable(true)) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
 

	
 
		int32 oldval = (int32)ReadValue(var, sd->save.conv);
 
		int32 newval = (int32)p2;
src/settings_gui.cpp
Show inline comments
 
@@ -856,16 +856,13 @@ public:
 
		const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
 
		for (i = 0; i < GAME_DIFFICULTY_NUM; i++, sd++) {
 
			const SettingDescBase *sdb = &sd->desc;
 
			/* skip deprecated difficulty options */
 
			if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
 
			int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
 
			bool disable = (sd->desc.flags & SGF_NEWGAME_ONLY) &&
 
					(_game_mode == GM_NORMAL ||
 
					(_game_mode == GM_EDITOR && (sd->desc.flags & SGF_SCENEDIT_TOO) == 0));
 

	
 
			bool disable = !sd->IsEditable();
 
			this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 0, disable || sdb->min == value);
 
			this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 1, disable || sdb->max == (uint32)value);
 
		}
 
	}
 
};
 

	
 
@@ -1514,24 +1511,21 @@ void SettingEntry::SetValueDParams(uint 
 
 */
 
void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, int state, bool highlight)
 
{
 
	const SettingDesc *sd = this->d.entry.setting;
 
	const SettingDescBase *sdb = &sd->desc;
 
	const void *var = ResolveVariableAddress(settings_ptr, sd);
 
	bool editable = true;
 

	
 
	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);
 
	uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + 5 : 0);
 
	uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
 

	
 
	/* We do not allow changes of some items when we are a client in a networkgame */
 
	if (!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sdb->flags & SGF_PER_COMPANY)) editable = false;
 
	if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false;
 
	if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
 
	bool editable = sd->IsEditable();
 

	
 
	SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
 
	int32 value = (int32)ReadValue(var, sd->save.conv);
 
	if (sdb->cmd == SDT_BOOLX) {
 
		/* Draw checkbox for boolean-value either on/off */
 
		DrawBoolButton(buttons_left, button_y, value != 0, editable);
 
@@ -2174,14 +2168,13 @@ struct GameSettingsWindow : Window {
 
		}
 

	
 
		assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
 
		const SettingDesc *sd = pe->d.entry.setting;
 

	
 
		/* return if action is only active in network, or only settable by server */
 
		if ((!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sd->desc.flags & SGF_PER_COMPANY)) ||
 
				((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) || ((sd->desc.flags & SGF_NO_NETWORK) && _networking)) {
 
		if (!sd->IsEditable()) {
 
			this->SetDisplayedHelpText(pe);
 
			return;
 
		}
 

	
 
		const void *var = ResolveVariableAddress(settings_ptr, sd);
 
		int32 value = (int32)ReadValue(var, sd->save.conv);
src/settings_internal.h
Show inline comments
 
@@ -98,12 +98,14 @@ struct SettingDescBase {
 
	SettingCategory cat;    ///< assigned categories of the setting
 
};
 

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

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

	
 
/* NOTE: The only difference between SettingDesc and SettingDescGlob is
 
 * that one uses global variables as a source and the other offsets
 
 * in a struct which are bound to a certain variable during runtime.
 
 * The only way to differentiate between these two is to check if an object
0 comments (0 inline, 0 general)