Skip to content

Commit

Permalink
Codechange: rename SettingGuiFlag to SettingFlag
Browse files Browse the repository at this point in the history
It is a lovely organicly grown enum, where it started off with
GUI-only flags, and after that a few flags got added that can be
considered GUI-only (the GUI disables/enables based on them), to
only have flags added that has nothing to do with the GUI.

So be less confusing, and rename them to what they do.

Additionally, I took this opportunity to rename 0ISDISABLED to
reflect what it really does.
  • Loading branch information
TrueBrain committed Jun 3, 2021
1 parent 28e9076 commit 193423f
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 220 deletions.
32 changes: 16 additions & 16 deletions src/settings.cpp
Expand Up @@ -386,9 +386,9 @@ void IntSettingDesc::MakeValueValidAndWrite(const void *object, int32 val) const
* Make the value valid given the limitations of this setting.
*
* In the case of int settings this is ensuring the value is between the minimum and
* maximum value, with a special case for 0 if SGF_0ISDISABLED is set.
* maximum value, with a special case for 0 if SF_GUI_0_IS_SPECIAL is set.
* This is generally done by clamping the value so it is within the allowed value range.
* However, for SGF_MULTISTRING the default is used when the value is not valid.
* However, for SF_GUI_DROPDOWN the default is used when the value is not valid.
* @param val The value to make valid.
*/
void IntSettingDesc::MakeValueValid(int32 &val) const
Expand All @@ -407,8 +407,8 @@ void IntSettingDesc::MakeValueValid(int32 &val) const
case SLE_VAR_U16:
case SLE_VAR_I32: {
/* Override the minimum value. No value below this->min, except special value 0 */
if (!(this->flags & SGF_0ISDISABLED) || val != 0) {
if (!(this->flags & SGF_MULTISTRING)) {
if (!(this->flags & SF_GUI_0_IS_SPECIAL) || val != 0) {
if (!(this->flags & SF_GUI_DROPDOWN)) {
/* Clamp value-type setting to its valid range */
val = Clamp(val, this->min, this->max);
} else if (val < this->min || val > (int32)this->max) {
Expand All @@ -421,8 +421,8 @@ void IntSettingDesc::MakeValueValid(int32 &val) const
case SLE_VAR_U32: {
/* Override the minimum value. No value below this->min, except special value 0 */
uint32 uval = (uint32)val;
if (!(this->flags & SGF_0ISDISABLED) || uval != 0) {
if (!(this->flags & SGF_MULTISTRING)) {
if (!(this->flags & SF_GUI_0_IS_SPECIAL) || uval != 0) {
if (!(this->flags & SF_GUI_DROPDOWN)) {
/* Clamp value-type setting to its valid range */
uval = ClampU(uval, this->min, this->max);
} else if (uval < (uint)this->min || uval > this->max) {
Expand Down Expand Up @@ -743,13 +743,13 @@ void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
*/
bool SettingDesc::IsEditable(bool do_command) const
{
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) &&
if (!do_command && !(this->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(this->flags & SF_PER_COMPANY)) return false;
if ((this->flags & SF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
if ((this->flags & SF_NO_NETWORK) && _networking) return false;
if ((this->flags & SF_NEWGAME_ONLY) &&
(_game_mode == GM_NORMAL ||
(_game_mode == GM_EDITOR && !(this->flags & SGF_SCENEDIT_TOO)))) return false;
if ((this->flags & SGF_SCENEDIT_ONLY) && _game_mode != GM_EDITOR) return false;
(_game_mode == GM_EDITOR && !(this->flags & SF_SCENEDIT_TOO)))) return false;
if ((this->flags & SF_SCENEDIT_ONLY) && _game_mode != GM_EDITOR) return false;
return true;
}

Expand All @@ -759,7 +759,7 @@ bool SettingDesc::IsEditable(bool do_command) const
*/
SettingType SettingDesc::GetType() const
{
if (this->flags & SGF_PER_COMPANY) return ST_COMPANY;
if (this->flags & SF_PER_COMPANY) return ST_COMPANY;
return (this->save.conv & SLF_NOT_IN_SAVE) ? ST_CLIENT : ST_GAME;
}

Expand Down Expand Up @@ -1689,7 +1689,7 @@ void IntSettingDesc::ChangeValue(const void *object, int32 newval) const
this->Write(object, newval);
if (this->post_callback != nullptr) this->post_callback(newval);

if (this->flags & SGF_NO_NETWORK) {
if (this->flags & SF_NO_NETWORK) {
GamelogStartAction(GLAT_SETTING);
GamelogSetting(this->name, oldval, newval);
GamelogStopAction();
Expand Down Expand Up @@ -1833,7 +1833,7 @@ CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32
bool SetSettingValue(const IntSettingDesc *sd, int32 value, bool force_newgame)
{
const IntSettingDesc *setting = sd->AsIntSetting();
if ((setting->flags & SGF_PER_COMPANY) != 0) {
if ((setting->flags & SF_PER_COMPANY) != 0) {
if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
return DoCommandP(0, 0, value, CMD_CHANGE_COMPANY_SETTING, nullptr, setting->name);
}
Expand Down Expand Up @@ -1992,7 +1992,7 @@ void IConsoleGetSetting(const char *name, bool force_newgame)
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)",
name, value, (sd->flags & SGF_0ISDISABLED) ? "(0) " : "", int_setting->min, int_setting->max);
name, value, (sd->flags & SF_GUI_0_IS_SPECIAL) ? "(0) " : "", int_setting->min, int_setting->max);
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/settings_gui.cpp
Expand Up @@ -1147,7 +1147,7 @@ bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)

static const void *ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd)
{
if ((sd->flags & SGF_PER_COMPANY) != 0) {
if ((sd->flags & SF_PER_COMPANY) != 0) {
if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
return &Company::Get(_local_company)->settings;
}
Expand All @@ -1166,13 +1166,13 @@ void SettingEntry::SetValueDParams(uint first_param, int32 value) const
if (this->setting->IsBoolSetting()) {
SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
} else {
if ((this->setting->flags & SGF_MULTISTRING) != 0) {
if ((this->setting->flags & SF_GUI_DROPDOWN) != 0) {
SetDParam(first_param++, this->setting->str_val - this->setting->min + value);
} else if ((this->setting->flags & SGF_DISPLAY_ABS) != 0) {
} else if ((this->setting->flags & SF_GUI_NEGATIVE_IS_SPECIAL) != 0) {
SetDParam(first_param++, this->setting->str_val + ((value >= 0) ? 1 : 0));
value = abs(value);
} else {
SetDParam(first_param++, this->setting->str_val + ((value == 0 && (this->setting->flags & SGF_0ISDISABLED) != 0) ? 1 : 0));
SetDParam(first_param++, this->setting->str_val + ((value == 0 && (this->setting->flags & SF_GUI_0_IS_SPECIAL) != 0) ? 1 : 0));
}
SetDParam(first_param++, value);
}
Expand Down Expand Up @@ -1205,13 +1205,13 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
if (sd->IsBoolSetting()) {
/* Draw checkbox for boolean-value either on/off */
DrawBoolButton(buttons_left, button_y, value != 0, editable);
} else if ((sd->flags & SGF_MULTISTRING) != 0) {
} else if ((sd->flags & SF_GUI_DROPDOWN) != 0) {
/* Draw [v] button for settings of an enum-type */
DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
} else {
/* Draw [<][>] boxes for settings of an integer-type */
DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
editable && value != (sd->flags & SGF_0ISDISABLED ? 0 : sd->min), editable && (uint32)value != sd->max);
editable && value != (sd->flags & SF_GUI_0_IS_SPECIAL ? 0 : sd->min), editable && (uint32)value != sd->max);
}
this->SetValueDParams(1, value);
DrawString(text_left, text_right, y + (SETTING_HEIGHT - FONT_HEIGHT_NORMAL) / 2, sd->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
Expand Down Expand Up @@ -2182,7 +2182,7 @@ struct GameSettingsWindow : Window {
int32 value = sd->Read(ResolveObject(settings_ptr, sd));

/* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
if (x < SETTING_BUTTON_WIDTH && (sd->flags & SGF_MULTISTRING)) {
if (x < SETTING_BUTTON_WIDTH && (sd->flags & SF_GUI_DROPDOWN)) {
this->SetDisplayedHelpText(pe);

if (this->valuedropdown_entry == pe) {
Expand Down Expand Up @@ -2250,7 +2250,7 @@ struct GameSettingsWindow : Window {
if (value < sd->min) value = sd->min; // skip between "disabled" and minimum
} else {
value -= step;
if (value < sd->min) value = (sd->flags & SGF_0ISDISABLED) ? 0 : sd->min;
if (value < sd->min) value = (sd->flags & SF_GUI_0_IS_SPECIAL) ? 0 : sd->min;
}

/* Set up scroller timeout for numeric values */
Expand All @@ -2271,10 +2271,10 @@ struct GameSettingsWindow : Window {
}
} 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->IsBoolSetting() && !(sd->flags & SGF_MULTISTRING)) {
if (this->last_clicked == pe && !sd->IsBoolSetting() && !(sd->flags & SF_GUI_DROPDOWN)) {
int64 value64 = value;
/* Show the correct currency-translated value */
if (sd->flags & SGF_CURRENCY) value64 *= _currency->rate;
if (sd->flags & SF_GUI_CURRENCY) value64 *= _currency->rate;

this->valuewindow_entry = pe;
SetDParam(0, value64);
Expand Down Expand Up @@ -2307,7 +2307,7 @@ struct GameSettingsWindow : Window {
long long llvalue = atoll(str);

/* Save the correct currency-translated value */
if (sd->flags & SGF_CURRENCY) llvalue /= _currency->rate;
if (sd->flags & SF_GUI_CURRENCY) llvalue /= _currency->rate;

value = (int32)ClampToI32(llvalue);
} else {
Expand Down Expand Up @@ -2348,7 +2348,7 @@ struct GameSettingsWindow : Window {
/* Deal with drop down boxes on the panel. */
assert(this->valuedropdown_entry != nullptr);
const IntSettingDesc *sd = this->valuedropdown_entry->setting;
assert(sd->flags & SGF_MULTISTRING);
assert(sd->flags & SF_GUI_DROPDOWN);

SetSettingValue(sd, index);
this->SetDirty();
Expand Down
51 changes: 25 additions & 26 deletions src/settings_internal.h
Expand Up @@ -12,21 +12,20 @@

#include "saveload/saveload.h"

enum SettingGuiFlag : uint16 {
/* 2 bytes allocated for a maximum of 16 flags. */
SGF_NONE = 0,
SGF_0ISDISABLED = 1 << 0, ///< a value of zero means the feature is disabled
SGF_DISPLAY_ABS = 1 << 1, ///< display absolute value of the setting
SGF_MULTISTRING = 1 << 2, ///< the value represents a limited number of string-options (internally integer)
SGF_NETWORK_ONLY = 1 << 3, ///< this setting only applies to network games
SGF_CURRENCY = 1 << 4, ///< the number represents money, so when reading value multiply by exchange rate
SGF_NO_NETWORK = 1 << 5, ///< this setting does not apply to network games; it may not be changed during the game
SGF_NEWGAME_ONLY = 1 << 6, ///< this setting cannot be changed in a game
SGF_SCENEDIT_TOO = 1 << 7, ///< this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set)
SGF_PER_COMPANY = 1 << 8, ///< this setting can be different for each company (saved in company struct)
SGF_SCENEDIT_ONLY = 1 << 9, ///< this setting can only be changed in the scenario editor
enum SettingFlag : uint16 {
SF_NONE = 0,
SF_GUI_0_IS_SPECIAL = 1 << 0, ///< a value of zero is possible and has a custom string (the one after "strval".
SF_GUI_NEGATIVE_IS_SPECIAL = 1 << 1, ///< a negative value has another string (the one after "strval").
SF_GUI_DROPDOWN = 1 << 2, ///< the value represents a limited number of string-options (internally integer) presented as dropdown.
SF_GUI_CURRENCY = 1 << 3, ///< the number represents money, so when reading value multiply by exchange rate.
SF_NETWORK_ONLY = 1 << 4, ///< this setting only applies to network games.
SF_NO_NETWORK = 1 << 5, ///< this setting does not apply to network games; it may not be changed during the game.
SF_NEWGAME_ONLY = 1 << 6, ///< this setting cannot be changed in a game.
SF_SCENEDIT_TOO = 1 << 7, ///< this setting can be changed in the scenario editor (only makes sense when SF_NEWGAME_ONLY is set).
SF_SCENEDIT_ONLY = 1 << 8, ///< this setting can only be changed in the scenario editor.
SF_PER_COMPANY = 1 << 9, ///< this setting can be different for each company (saved in company struct).
};
DECLARE_ENUM_AS_BIT_SET(SettingGuiFlag)
DECLARE_ENUM_AS_BIT_SET(SettingFlag)

/**
* A SettingCategory defines a grouping of the settings.
Expand Down Expand Up @@ -67,14 +66,14 @@ struct IniItem;

/** Properties of config file settings. */
struct SettingDesc {
SettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup) :
SettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup) :
name(name), flags(flags), startup(startup), save(save) {}
virtual ~SettingDesc() {}

const char *name; ///< name of the setting. Used in configuration file and for console
SettingGuiFlag flags; ///< handles how a setting would show up in the GUI (text/currency, etc.)
bool startup; ///< setting has to be loaded directly at startup?
SaveLoad save; ///< Internal structure (going to savegame, parts to config)
const char *name; ///< Name of the setting. Used in configuration file and for console.
SettingFlag flags; ///< Handles how a setting would show up in the GUI (text/currency, etc.).
bool startup; ///< Setting has to be loaded directly at startup?.
SaveLoad save; ///< Internal structure (going to savegame, parts to config).

bool IsEditable(bool do_command = false) const;
SettingType GetType() const;
Expand Down Expand Up @@ -138,7 +137,7 @@ struct IntSettingDesc : SettingDesc {
*/
typedef void PostChangeCallback(int32 value);

IntSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup, int32 def,
IntSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def,
int32 min, uint32 max, int32 interval, StringID str, StringID str_help, StringID str_val,
SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback) :
SettingDesc(save, name, flags, startup), def(def), min(min), max(max), interval(interval),
Expand Down Expand Up @@ -180,7 +179,7 @@ struct IntSettingDesc : SettingDesc {

/** Boolean setting. */
struct BoolSettingDesc : IntSettingDesc {
BoolSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup, bool def,
BoolSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, bool def,
StringID str, StringID str_help, StringID str_val, SettingCategory cat,
PreChangeCheck pre_check, PostChangeCallback post_callback) :
IntSettingDesc(save, name, flags, startup, def, 0, 1, 0, str, str_help, str_val, cat,
Expand All @@ -196,7 +195,7 @@ struct BoolSettingDesc : IntSettingDesc {
struct OneOfManySettingDesc : IntSettingDesc {
typedef size_t OnConvert(const char *value); ///< callback prototype for conversion error

OneOfManySettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup, int32 def,
OneOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def,
int32 max, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
PreChangeCheck pre_check, PostChangeCallback post_callback,
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
Expand All @@ -220,7 +219,7 @@ struct OneOfManySettingDesc : IntSettingDesc {

/** Many of many setting. */
struct ManyOfManySettingDesc : OneOfManySettingDesc {
ManyOfManySettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup,
ManyOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup,
int32 def, StringID str, StringID str_help, StringID str_val, SettingCategory cat,
PreChangeCheck pre_check, PostChangeCallback post_callback,
std::initializer_list<const char *> many, OnConvert *many_cnvt) :
Expand Down Expand Up @@ -249,7 +248,7 @@ struct StringSettingDesc : SettingDesc {
*/
typedef void PostChangeCallback(const std::string &value);

StringSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup, const char *def,
StringSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def,
uint32 max_length, PreChangeCheck pre_check, PostChangeCallback post_callback) :
SettingDesc(save, name, flags, startup), def(def == nullptr ? "" : def), max_length(max_length),
pre_check(pre_check), post_callback(post_callback) {}
Expand All @@ -275,7 +274,7 @@ struct StringSettingDesc : SettingDesc {

/** List/array settings. */
struct ListSettingDesc : SettingDesc {
ListSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, bool startup, const char *def) :
ListSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def) :
SettingDesc(save, name, flags, startup), def(def) {}
virtual ~ListSettingDesc() {}

Expand All @@ -289,7 +288,7 @@ struct ListSettingDesc : SettingDesc {
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
struct NullSettingDesc : SettingDesc {
NullSettingDesc(SaveLoad save) :
SettingDesc(save, "", SGF_NONE, false) {}
SettingDesc(save, "", SF_NONE, false) {}
virtual ~NullSettingDesc() {}

void FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); }
Expand Down
14 changes: 7 additions & 7 deletions src/table/settings/company_settings.ini
Expand Up @@ -24,7 +24,7 @@ SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for CompanySettings.$v

[defaults]
flags = 0
guiflags = SGF_PER_COMPANY
guiflags = SF_PER_COMPANY
interval = 0
str = STR_NULL
strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT
Expand All @@ -50,7 +50,7 @@ cat = SC_BASIC
[SDT_VAR]
var = engine_renew_months
type = SLE_INT16
guiflags = SGF_PER_COMPANY | SGF_DISPLAY_ABS
guiflags = SF_PER_COMPANY | SF_GUI_NEGATIVE_IS_SPECIAL
def = 6
min = -12
max = 12
Expand All @@ -61,7 +61,7 @@ strval = STR_CONFIG_SETTING_AUTORENEW_MONTHS_VALUE_BEFORE
[SDT_VAR]
var = engine_renew_money
type = SLE_UINT
guiflags = SGF_PER_COMPANY | SGF_CURRENCY
guiflags = SF_PER_COMPANY | SF_GUI_CURRENCY
def = 100000
min = 0
max = 2000000
Expand All @@ -83,7 +83,7 @@ post_cb = UpdateServiceInterval
[SDT_VAR]
var = vehicle.servint_trains
type = SLE_UINT16
guiflags = SGF_PER_COMPANY | SGF_0ISDISABLED
guiflags = SF_PER_COMPANY | SF_GUI_0_IS_SPECIAL
def = 150
min = 5
max = 800
Expand All @@ -96,7 +96,7 @@ post_cb = [](auto new_value) { UpdateServiceInterval(VEH_TRAIN, new_value); }
[SDT_VAR]
var = vehicle.servint_roadveh
type = SLE_UINT16
guiflags = SGF_PER_COMPANY | SGF_0ISDISABLED
guiflags = SF_PER_COMPANY | SF_GUI_0_IS_SPECIAL
def = 150
min = 5
max = 800
Expand All @@ -109,7 +109,7 @@ post_cb = [](auto new_value) { UpdateServiceInterval(VEH_ROAD, new_value); }
[SDT_VAR]
var = vehicle.servint_ships
type = SLE_UINT16
guiflags = SGF_PER_COMPANY | SGF_0ISDISABLED
guiflags = SF_PER_COMPANY | SF_GUI_0_IS_SPECIAL
def = 360
min = 5
max = 800
Expand All @@ -122,7 +122,7 @@ post_cb = [](auto new_value) { UpdateServiceInterval(VEH_SHIP, new_value); }
[SDT_VAR]
var = vehicle.servint_aircraft
type = SLE_UINT16
guiflags = SGF_PER_COMPANY | SGF_0ISDISABLED
guiflags = SF_PER_COMPANY | SF_GUI_0_IS_SPECIAL
def = 100
min = 5
max = 800
Expand Down
2 changes: 1 addition & 1 deletion src/table/settings/currency_settings.ini
Expand Up @@ -19,7 +19,7 @@ SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for CurrencySpec.$var

[defaults]
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
guiflags = SGF_NONE
guiflags = SF_NONE
interval = 0
str = STR_NULL
strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT
Expand Down
2 changes: 1 addition & 1 deletion src/table/settings/gameopt_settings.ini
Expand Up @@ -63,7 +63,7 @@ SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for GameSettings.$var

[defaults]
flags = 0
guiflags = SGF_NONE
guiflags = SF_NONE
interval = 0
str = STR_NULL
strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT
Expand Down
2 changes: 1 addition & 1 deletion src/table/settings/misc_settings.ini
Expand Up @@ -37,7 +37,7 @@ SDTG_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds st

[defaults]
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
guiflags = SGF_NONE
guiflags = SF_NONE
interval = 0
str = STR_NULL
strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT
Expand Down

0 comments on commit 193423f

Please sign in to comment.