mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-18 13:14:34 +00:00
Codechange: Make GetDefaultValueCallback() more similar to other setting override callbacks (#13259)
This commit is contained in:
parent
d38ecd6525
commit
a52923b3b9
@ -479,7 +479,7 @@ void IntSettingDesc::SetValueDParams(uint first_param, int32_t value) const
|
||||
*/
|
||||
int32_t IntSettingDesc::GetDefaultValue() const
|
||||
{
|
||||
return this->get_def_cb != nullptr ? this->get_def_cb() : this->def;
|
||||
return this->get_def_cb != nullptr ? this->get_def_cb(*this) : this->def;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -150,6 +150,7 @@ struct IntSettingDesc : SettingDesc {
|
||||
typedef StringID GetTitleCallback(const IntSettingDesc &sd);
|
||||
typedef StringID GetHelpCallback(const IntSettingDesc &sd);
|
||||
typedef void SetValueDParamsCallback(const IntSettingDesc &sd, uint first_param, int32_t value);
|
||||
typedef int32_t GetDefaultValueCallback(const IntSettingDesc &sd);
|
||||
|
||||
/**
|
||||
* A check to be performed before the setting gets changed. The passed integer may be
|
||||
@ -165,12 +166,6 @@ struct IntSettingDesc : SettingDesc {
|
||||
* @param The new value for the setting.
|
||||
*/
|
||||
typedef void PostChangeCallback(int32_t value);
|
||||
/**
|
||||
* A callback to get the correct default value. For example a default that can be measured in time
|
||||
* units or expressed as a percentage.
|
||||
* @return The correct default value for the setting.
|
||||
*/
|
||||
typedef int32_t GetDefaultValueCallback();
|
||||
|
||||
template <
|
||||
typename Tdef,
|
||||
|
@ -265,9 +265,8 @@ static void UpdateServiceInterval(VehicleType type, int32_t new_value)
|
||||
|
||||
/**
|
||||
* Checks if the service intervals in the settings are specified as percentages and corrects the default value accordingly.
|
||||
* @param new_value Contains the service interval's default value in days, or 50 (default in percentage).
|
||||
*/
|
||||
static int32_t GetDefaultServiceInterval(VehicleType type)
|
||||
static int32_t GetDefaultServiceInterval(const IntSettingDesc &sd, VehicleType type)
|
||||
{
|
||||
VehicleDefaultSettings *vds;
|
||||
if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
|
||||
@ -276,28 +275,19 @@ static int32_t GetDefaultServiceInterval(VehicleType type)
|
||||
vds = &Company::Get(_current_company)->settings.vehicle;
|
||||
}
|
||||
|
||||
int32_t new_value;
|
||||
if (vds->servint_ispercent) {
|
||||
new_value = DEF_SERVINT_PERCENT;
|
||||
} else if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
|
||||
if (vds->servint_ispercent) return DEF_SERVINT_PERCENT;
|
||||
|
||||
if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
|
||||
switch (type) {
|
||||
case VEH_TRAIN: new_value = DEF_SERVINT_MINUTES_TRAINS; break;
|
||||
case VEH_ROAD: new_value = DEF_SERVINT_MINUTES_ROADVEH; break;
|
||||
case VEH_AIRCRAFT: new_value = DEF_SERVINT_MINUTES_AIRCRAFT; break;
|
||||
case VEH_SHIP: new_value = DEF_SERVINT_MINUTES_SHIPS; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
} else {
|
||||
switch (type) {
|
||||
case VEH_TRAIN: new_value = DEF_SERVINT_DAYS_TRAINS; break;
|
||||
case VEH_ROAD: new_value = DEF_SERVINT_DAYS_ROADVEH; break;
|
||||
case VEH_AIRCRAFT: new_value = DEF_SERVINT_DAYS_AIRCRAFT; break;
|
||||
case VEH_SHIP: new_value = DEF_SERVINT_DAYS_SHIPS; break;
|
||||
case VEH_TRAIN: return DEF_SERVINT_MINUTES_TRAINS;
|
||||
case VEH_ROAD: return DEF_SERVINT_MINUTES_ROADVEH;
|
||||
case VEH_AIRCRAFT: return DEF_SERVINT_MINUTES_AIRCRAFT;
|
||||
case VEH_SHIP: return DEF_SERVINT_MINUTES_SHIPS;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
return new_value;
|
||||
return sd.def;
|
||||
}
|
||||
|
||||
static void TrainAccelerationModelChanged(int32_t)
|
||||
|
@ -13,7 +13,7 @@ static bool CanUpdateServiceInterval(VehicleType type, int32_t &new_value);
|
||||
static void UpdateServiceInterval(VehicleType type, int32_t new_value);
|
||||
static void SettingsValueAbsolute(const IntSettingDesc &sd, uint first_param, int32_t value);
|
||||
static void ServiceIntervalSettingsValueText(const IntSettingDesc &sd, uint first_param, int32_t value);
|
||||
static int32_t GetDefaultServiceInterval(VehicleType type);
|
||||
static int32_t GetDefaultServiceInterval(const IntSettingDesc &sd, VehicleType type);
|
||||
|
||||
static const SettingVariant _company_settings_table[] = {
|
||||
[post-amble]
|
||||
@ -100,7 +100,7 @@ strhelp = STR_CONFIG_SETTING_SERVINT_TRAINS_HELPTEXT
|
||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
||||
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_TRAIN, new_value); }
|
||||
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_TRAIN, new_value); }
|
||||
def_cb = []() { return GetDefaultServiceInterval(VEH_TRAIN); }
|
||||
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_TRAIN); }
|
||||
val_cb = ServiceIntervalSettingsValueText
|
||||
|
||||
[SDT_VAR]
|
||||
@ -116,7 +116,7 @@ strhelp = STR_CONFIG_SETTING_SERVINT_ROAD_VEHICLES_HELPTEXT
|
||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
||||
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_ROAD, new_value); }
|
||||
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_ROAD, new_value); }
|
||||
def_cb = []() { return GetDefaultServiceInterval(VEH_ROAD); }
|
||||
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_ROAD); }
|
||||
val_cb = ServiceIntervalSettingsValueText
|
||||
|
||||
[SDT_VAR]
|
||||
@ -132,7 +132,7 @@ strhelp = STR_CONFIG_SETTING_SERVINT_SHIPS_HELPTEXT
|
||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
||||
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_SHIP, new_value); }
|
||||
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_SHIP, new_value); }
|
||||
def_cb = []() { return GetDefaultServiceInterval(VEH_SHIP); }
|
||||
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_SHIP); }
|
||||
val_cb = ServiceIntervalSettingsValueText
|
||||
|
||||
[SDT_VAR]
|
||||
@ -148,5 +148,5 @@ strhelp = STR_CONFIG_SETTING_SERVINT_AIRCRAFT_HELPTEXT
|
||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
||||
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_AIRCRAFT, new_value); }
|
||||
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_AIRCRAFT, new_value); }
|
||||
def_cb = []() { return GetDefaultServiceInterval(VEH_AIRCRAFT); }
|
||||
def_cb = [](auto &sd) { return GetDefaultServiceInterval(sd, VEH_AIRCRAFT); }
|
||||
val_cb = ServiceIntervalSettingsValueText
|
||||
|
Loading…
Reference in New Issue
Block a user