mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Correct return type of GetDefaultValueCallback
This commit is contained in:
parent
339b0ea0ff
commit
ceb0053dd9
|
@ -2498,8 +2498,7 @@ struct GameSettingsWindow : Window {
|
||||||
DrawString(tr, STR_CONFIG_SETTING_TYPE);
|
DrawString(tr, STR_CONFIG_SETTING_TYPE);
|
||||||
tr.top += GetCharacterHeight(FS_NORMAL);
|
tr.top += GetCharacterHeight(FS_NORMAL);
|
||||||
|
|
||||||
int32_t def_val = sd->def;
|
int32_t def_val = sd->get_def_cb != nullptr ? sd->get_def_cb() : sd->def;
|
||||||
if (sd->get_def_cb != nullptr) sd->get_def_cb(def_val);
|
|
||||||
sd->SetValueDParams(0, def_val);
|
sd->SetValueDParams(0, def_val);
|
||||||
DrawString(tr, STR_CONFIG_SETTING_DEFAULT_VALUE);
|
DrawString(tr, STR_CONFIG_SETTING_DEFAULT_VALUE);
|
||||||
tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
|
tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
|
||||||
|
@ -2734,9 +2733,10 @@ struct GameSettingsWindow : Window {
|
||||||
if (sd->flags & SF_GUI_CURRENCY) llvalue /= GetCurrency().rate;
|
if (sd->flags & SF_GUI_CURRENCY) llvalue /= GetCurrency().rate;
|
||||||
|
|
||||||
value = ClampTo<int32_t>(llvalue);
|
value = ClampTo<int32_t>(llvalue);
|
||||||
|
} else if (sd->get_def_cb != nullptr) {
|
||||||
|
value = sd->get_def_cb();
|
||||||
} else {
|
} else {
|
||||||
value = sd->def;
|
value = sd->def;
|
||||||
if (sd->get_def_cb != nullptr) sd->get_def_cb(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetSettingValue(this->valuewindow_entry->setting, value);
|
SetSettingValue(this->valuewindow_entry->setting, value);
|
||||||
|
|
|
@ -169,7 +169,7 @@ struct IntSettingDesc : SettingDesc {
|
||||||
* units or expressed as a percentage.
|
* units or expressed as a percentage.
|
||||||
* @param value The prospective new value for the setting.
|
* @param value The prospective new value for the setting.
|
||||||
*/
|
*/
|
||||||
typedef void GetDefaultValueCallback(int32_t &value);
|
typedef int32_t GetDefaultValueCallback();
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename Tdef,
|
typename Tdef,
|
||||||
|
|
|
@ -266,7 +266,7 @@ 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.
|
* 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).
|
* @param new_value Contains the service interval's default value in days, or 50 (default in percentage).
|
||||||
*/
|
*/
|
||||||
static void GetDefaultServiceInterval(VehicleType type, int32_t &new_value)
|
static int32_t GetDefaultServiceInterval(VehicleType type)
|
||||||
{
|
{
|
||||||
VehicleDefaultSettings *vds;
|
VehicleDefaultSettings *vds;
|
||||||
if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
|
if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
|
||||||
|
@ -275,6 +275,7 @@ static void GetDefaultServiceInterval(VehicleType type, int32_t &new_value)
|
||||||
vds = &Company::Get(_current_company)->settings.vehicle;
|
vds = &Company::Get(_current_company)->settings.vehicle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t new_value;
|
||||||
if (vds->servint_ispercent) {
|
if (vds->servint_ispercent) {
|
||||||
new_value = DEF_SERVINT_PERCENT;
|
new_value = DEF_SERVINT_PERCENT;
|
||||||
} else if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
|
} else if (TimerGameEconomy::UsingWallclockUnits(_game_mode == GM_MENU)) {
|
||||||
|
@ -285,7 +286,17 @@ static void GetDefaultServiceInterval(VehicleType type, int32_t &new_value)
|
||||||
case VEH_SHIP: new_value = DEF_SERVINT_MINUTES_SHIPS; break;
|
case VEH_SHIP: new_value = DEF_SERVINT_MINUTES_SHIPS; break;
|
||||||
default: NOT_REACHED();
|
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;
|
||||||
|
default: NOT_REACHED();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TrainAccelerationModelChanged(int32_t)
|
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 UpdateServiceInterval(VehicleType type, int32_t new_value);
|
||||||
static void SettingsValueAbsolute(const IntSettingDesc &sd, uint first_param, int32_t 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 void ServiceIntervalSettingsValueText(const IntSettingDesc &sd, uint first_param, int32_t value);
|
||||||
static void GetDefaultServiceInterval(VehicleType type, int32_t &new_value);
|
static int32_t GetDefaultServiceInterval(VehicleType type);
|
||||||
|
|
||||||
static const SettingVariant _company_settings_table[] = {
|
static const SettingVariant _company_settings_table[] = {
|
||||||
[post-amble]
|
[post-amble]
|
||||||
|
@ -100,7 +100,7 @@ strhelp = STR_CONFIG_SETTING_SERVINT_TRAINS_HELPTEXT
|
||||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
||||||
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_TRAIN, new_value); }
|
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_TRAIN, new_value); }
|
||||||
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_TRAIN, new_value); }
|
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_TRAIN, new_value); }
|
||||||
def_cb = [](auto &new_value) { GetDefaultServiceInterval(VEH_TRAIN, new_value); }
|
def_cb = []() { return GetDefaultServiceInterval(VEH_TRAIN); }
|
||||||
val_cb = ServiceIntervalSettingsValueText
|
val_cb = ServiceIntervalSettingsValueText
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
|
@ -116,7 +116,7 @@ strhelp = STR_CONFIG_SETTING_SERVINT_ROAD_VEHICLES_HELPTEXT
|
||||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
||||||
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_ROAD, new_value); }
|
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_ROAD, new_value); }
|
||||||
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_ROAD, new_value); }
|
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_ROAD, new_value); }
|
||||||
def_cb = [](auto &new_value) { GetDefaultServiceInterval(VEH_ROAD, new_value); }
|
def_cb = []() { return GetDefaultServiceInterval(VEH_ROAD); }
|
||||||
val_cb = ServiceIntervalSettingsValueText
|
val_cb = ServiceIntervalSettingsValueText
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
|
@ -132,7 +132,7 @@ strhelp = STR_CONFIG_SETTING_SERVINT_SHIPS_HELPTEXT
|
||||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
||||||
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_SHIP, new_value); }
|
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_SHIP, new_value); }
|
||||||
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_SHIP, new_value); }
|
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_SHIP, new_value); }
|
||||||
def_cb = [](auto &new_value) { GetDefaultServiceInterval(VEH_SHIP, new_value); }
|
def_cb = []() { return GetDefaultServiceInterval(VEH_SHIP); }
|
||||||
val_cb = ServiceIntervalSettingsValueText
|
val_cb = ServiceIntervalSettingsValueText
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
|
@ -148,5 +148,5 @@ strhelp = STR_CONFIG_SETTING_SERVINT_AIRCRAFT_HELPTEXT
|
||||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
strval = STR_CONFIG_SETTING_SERVINT_VALUE_DAYS
|
||||||
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_AIRCRAFT, new_value); }
|
pre_cb = [](auto &new_value) { return CanUpdateServiceInterval(VEH_AIRCRAFT, new_value); }
|
||||||
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_AIRCRAFT, new_value); }
|
post_cb = [](auto new_value) { UpdateServiceInterval(VEH_AIRCRAFT, new_value); }
|
||||||
def_cb = [](auto &new_value) { GetDefaultServiceInterval(VEH_AIRCRAFT, new_value); }
|
def_cb = []() { return GetDefaultServiceInterval(VEH_AIRCRAFT); }
|
||||||
val_cb = ServiceIntervalSettingsValueText
|
val_cb = ServiceIntervalSettingsValueText
|
||||||
|
|
Loading…
Reference in New Issue