|
@@ -1926,25 +1926,25 @@ void StringSettingDesc::ChangeValue(cons
|
|
|
/* Those 2 functions need to be here, else we have to make some stuff non-static
|
|
|
* and besides, it is also better to keep stuff like this at the same place */
|
|
|
void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
|
|
|
{
|
|
|
const SettingDesc *sd = GetSettingFromName(name);
|
|
|
if (sd == nullptr) {
|
|
|
IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
|
|
|
IConsolePrint(CC_ERROR, "'{}' is an unknown setting.", name);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
bool success = true;
|
|
|
if (sd->IsStringSetting()) {
|
|
|
success = SetSettingValue(sd->AsStringSetting(), value, force_newgame);
|
|
|
} else if (sd->IsIntSetting()) {
|
|
|
uint32 val;
|
|
|
extern bool GetArgumentInteger(uint32 *value, const char *arg);
|
|
|
success = GetArgumentInteger(&val, value);
|
|
|
if (!success) {
|
|
|
IConsolePrintF(CC_ERROR, "'%s' is not an integer.", value);
|
|
|
IConsolePrint(CC_ERROR, "'{}' is not an integer.", value);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
success = SetSettingValue(sd->AsIntSetting(), val, force_newgame);
|
|
|
}
|
|
|
|
|
@@ -1970,47 +1970,47 @@ void IConsoleSetSetting(const char *name
|
|
|
* @param force_newgame force the newgame settings
|
|
|
*/
|
|
|
void IConsoleGetSetting(const char *name, bool force_newgame)
|
|
|
{
|
|
|
const SettingDesc *sd = GetSettingFromName(name);
|
|
|
if (sd == nullptr) {
|
|
|
IConsolePrintF(CC_WARNING, "'%s' is an unknown setting.", name);
|
|
|
IConsolePrint(CC_ERROR, "'{}' is an unknown setting.", name);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const void *object = (_game_mode == GM_MENU || force_newgame) ? &_settings_newgame : &_settings_game;
|
|
|
|
|
|
if (sd->IsStringSetting()) {
|
|
|
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s'", sd->name.c_str(), sd->AsStringSetting()->Read(object).c_str());
|
|
|
IConsolePrint(CC_INFO, "Current value for '{}' is '{}'.", sd->name, sd->AsStringSetting()->Read(object));
|
|
|
} else if (sd->IsIntSetting()) {
|
|
|
char value[20];
|
|
|
sd->FormatValue(value, lastof(value), object);
|
|
|
const IntSettingDesc *int_setting = sd->AsIntSetting();
|
|
|
IConsolePrintF(CC_WARNING, "Current value for '%s' is: '%s' (min: %s%d, max: %u)",
|
|
|
IConsolePrint(CC_INFO, "Current value for '{}' is '{}' (min: {}{}, max: {}).",
|
|
|
sd->name.c_str(), value, (sd->flags & SF_GUI_0_IS_SPECIAL) ? "(0) " : "", int_setting->min, int_setting->max);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* List all settings and their value to the console
|
|
|
*
|
|
|
* @param prefilter If not \c nullptr, only list settings with names that begin with \a prefilter prefix
|
|
|
*/
|
|
|
void IConsoleListSettings(const char *prefilter)
|
|
|
{
|
|
|
IConsolePrintF(CC_WARNING, "All settings with their current value:");
|
|
|
IConsolePrint(CC_HELP, "All settings with their current value:");
|
|
|
|
|
|
for (auto &sd : _settings) {
|
|
|
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
|
|
if (prefilter != nullptr && sd->name.find(prefilter) == std::string::npos) continue;
|
|
|
char value[80];
|
|
|
sd->FormatValue(value, lastof(value), &GetGameSettings());
|
|
|
IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name.c_str(), value);
|
|
|
IConsolePrint(CC_DEFAULT, "{} = {}", sd->name, value);
|
|
|
}
|
|
|
|
|
|
IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");
|
|
|
IConsolePrint(CC_HELP, "Use 'setting' command to change a value.");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the SaveLoad description for the SettingTable.
|
|
|
* @param settings SettingDesc struct containing all information.
|
|
|
* @param is_loading True iff the SaveLoad table is for loading.
|