Setting: Add setting flag: no new game (in game use only)

pull/88/head
Jonathan G Rennison 5 years ago
parent 8b1ee39ace
commit 79e49cf4a9

@ -526,28 +526,31 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
const SaveLoad *sld = &sd->save;
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to, sld->ext_feature_test)) continue;
/* For settings.xx.yy load the settings from [xx] yy = ? */
s = strchr(sdb->name, '.');
if (s != nullptr) {
group = ini->GetGroup(sdb->name, s - sdb->name);
s++;
if (sdb->flags & SGF_NO_NEWGAME) {
item = nullptr;
} else {
s = sdb->name;
group = group_def;
}
/* For settings.xx.yy load the settings from [xx] yy = ? */
s = strchr(sdb->name, '.');
if (s != nullptr) {
group = ini->GetGroup(sdb->name, s - sdb->name);
s++;
} else {
s = sdb->name;
group = group_def;
}
item = group->GetItem(s, false);
if (item == nullptr && group != group_def) {
/* For settings.xx.yy load the settings from [settingss] yy = ? in case the previous
* did not exist (e.g. loading old config files with a [settings] section */
item = group_def->GetItem(s, false);
}
if (item == nullptr) {
/* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
* did not exist (e.g. loading old config files with a [yapf] section */
const char *sc = strchr(s, '.');
if (sc != nullptr) item = ini->GetGroup(s, sc - s)->GetItem(sc + 1, false);
item = group->GetItem(s, false);
if (item == nullptr && group != group_def) {
/* For settings.xx.yy load the settings from [settingss] yy = ? in case the previous
* did not exist (e.g. loading old config files with a [settings] section */
item = group_def->GetItem(s, false);
}
if (item == nullptr) {
/* For settings.xx.zz.yy load the settings from [zz] yy = ? in case the previous
* did not exist (e.g. loading old config files with a [yapf] section */
const char *sc = strchr(s, '.');
if (sc != nullptr) item = ini->GetGroup(s, sc - s)->GetItem(sc + 1, false);
}
}
p = (item == nullptr) ? sdb->def : StringToVal(sdb, item->value);
@ -626,6 +629,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
* file, just continue with the next setting */
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to, sld->ext_feature_test)) continue;
if (sld->conv & SLF_NOT_IN_CONFIG) continue;
if (sdb->flags & SGF_NO_NEWGAME) continue;
/* XXX - wtf is this?? (group override?) */
s = strchr(sdb->name, '.');
@ -2084,11 +2088,13 @@ bool SetSettingValue(uint index, int32 value, bool force_newgame)
* (if any) to change. Also *hack*hack* we update the _newgame version
* of settings because changing a company-based setting in a game also
* changes its defaults. At least that is the convention we have chosen */
bool no_newgame = sd->desc.flags & SGF_NO_NEWGAME;
if (no_newgame && _game_mode == GM_MENU) return false;
if (sd->save.conv & SLF_NO_NETWORK_SYNC) {
void *var = GetVariableAddress(&GetGameSettings(), &sd->save);
Write_ValidateSetting(var, sd, value);
if (_game_mode != GM_MENU) {
if (_game_mode != GM_MENU && !no_newgame) {
void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
Write_ValidateSetting(var2, sd, value);
}
@ -2099,7 +2105,7 @@ bool SetSettingValue(uint index, int32 value, bool force_newgame)
return true;
}
if (force_newgame) {
if (force_newgame && !no_newgame) {
void *var2 = GetVariableAddress(&_settings_newgame, &sd->save);
Write_ValidateSetting(var2, sd, value);
return true;
@ -2123,7 +2129,7 @@ void SetCompanySetting(uint index, int32 value)
const SettingDesc *sd = &_company_settings[index];
if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
DoCommandP(0, index, value, CMD_CHANGE_COMPANY_SETTING);
} else {
} else if (!(sd->desc.flags & SGF_NO_NEWGAME)) {
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));
@ -2245,7 +2251,7 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
uint index;
const SettingDesc *sd = GetSettingFromName(name, &index);
if (sd == nullptr) {
if (sd == nullptr || ((sd->desc.flags & SGF_NO_NEWGAME) && (_game_mode == GM_MENU || force_newgame))) {
IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
return;
}
@ -2294,7 +2300,7 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
const SettingDesc *sd = GetSettingFromName(name, &index);
const void *ptr;
if (sd == nullptr) {
if (sd == nullptr || ((sd->desc.flags & SGF_NO_NEWGAME) && (_game_mode == GM_MENU || force_newgame))) {
IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
return;
}
@ -2327,6 +2333,7 @@ void IConsoleListSettings(const char *prefilter)
for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to, sd->save.ext_feature_test)) continue;
if (prefilter != nullptr && strstr(sd->desc.name, prefilter) == nullptr) continue;
if ((sd->desc.flags & SGF_NO_NEWGAME) && _game_mode == GM_MENU) continue;
char value[80];
const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);

@ -1053,6 +1053,10 @@ bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
*/
bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
{
if (this->setting->desc.flags & SGF_NO_NEWGAME && _game_mode == GM_MENU) {
SETBITS(this->flags, SEF_FILTERED);
return false;
}
CLRBITS(this->flags, SEF_FILTERED);
bool visible = true;

@ -50,6 +50,7 @@ enum SettingGuiFlagLong {
SGF_PER_COMPANY = 1 << 8, ///< this setting can be different for each company (saved in company struct)
SGF_DECIMAL1 = 1 << 9, ///< display a decimal representation of the setting value divided by 10
SGF_ENUM = 1 << 10,///< the setting can take one of the values given by an array of struct SettingDescEnumEntry
SGF_NO_NEWGAME = 1 << 11,///< the setting does not apply and is not shown in a new game context
};
DECLARE_ENUM_AS_BIT_SET(SettingGuiFlagLong)
typedef SimpleTinyEnumT<SettingGuiFlagLong, uint16> SettingGuiFlag;

Loading…
Cancel
Save