mirror of https://github.com/OpenTTD/OpenTTD
(svn r24787) -Fix: Unify checks for editability of settings.
parent
a499435351
commit
22dc45738d
|
@ -732,6 +732,22 @@ static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList *li
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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. */
|
/* Begin - Callback Functions for the various settings. */
|
||||||
|
|
||||||
/** Reposition the main toolbar as the setting changed. */
|
/** Reposition the main toolbar as the setting changed. */
|
||||||
|
@ -1782,13 +1798,7 @@ CommandCost CmdChangeSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
||||||
if (sd == NULL) return CMD_ERROR;
|
if (sd == NULL) return CMD_ERROR;
|
||||||
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) 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->IsEditable(true)) 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 (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
|
void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
|
||||||
|
|
|
@ -859,10 +859,7 @@ public:
|
||||||
/* skip deprecated difficulty options */
|
/* skip deprecated difficulty options */
|
||||||
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
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);
|
int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
|
||||||
bool disable = (sd->desc.flags & SGF_NEWGAME_ONLY) &&
|
bool disable = !sd->IsEditable();
|
||||||
(_game_mode == GM_NORMAL ||
|
|
||||||
(_game_mode == GM_EDITOR && (sd->desc.flags & SGF_SCENEDIT_TOO) == 0));
|
|
||||||
|
|
||||||
this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 0, disable || sdb->min == value);
|
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);
|
this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 1, disable || sdb->max == (uint32)value);
|
||||||
}
|
}
|
||||||
|
@ -1517,7 +1514,6 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
|
||||||
const SettingDesc *sd = this->d.entry.setting;
|
const SettingDesc *sd = this->d.entry.setting;
|
||||||
const SettingDescBase *sdb = &sd->desc;
|
const SettingDescBase *sdb = &sd->desc;
|
||||||
const void *var = ResolveVariableAddress(settings_ptr, sd);
|
const void *var = ResolveVariableAddress(settings_ptr, sd);
|
||||||
bool editable = true;
|
|
||||||
|
|
||||||
bool rtl = _current_text_dir == TD_RTL;
|
bool rtl = _current_text_dir == TD_RTL;
|
||||||
uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
|
uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
|
||||||
|
@ -1526,9 +1522,7 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
|
||||||
uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
|
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 */
|
/* 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;
|
bool editable = sd->IsEditable();
|
||||||
if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false;
|
|
||||||
if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -2177,8 +2171,7 @@ struct GameSettingsWindow : Window {
|
||||||
const SettingDesc *sd = pe->d.entry.setting;
|
const SettingDesc *sd = pe->d.entry.setting;
|
||||||
|
|
||||||
/* return if action is only active in network, or only settable by server */
|
/* 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)) ||
|
if (!sd->IsEditable()) {
|
||||||
((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) || ((sd->desc.flags & SGF_NO_NETWORK) && _networking)) {
|
|
||||||
this->SetDisplayedHelpText(pe);
|
this->SetDisplayedHelpText(pe);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,8 @@ struct SettingDescBase {
|
||||||
struct SettingDesc {
|
struct SettingDesc {
|
||||||
SettingDescBase desc; ///< Settings structure (going to configuration file)
|
SettingDescBase desc; ///< Settings structure (going to configuration file)
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* NOTE: The only difference between SettingDesc and SettingDescGlob is
|
/* NOTE: The only difference between SettingDesc and SettingDescGlob is
|
||||||
|
|
Loading…
Reference in New Issue