From ceb0053dd9a4ace2d68a22734d1aeac2b551f468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cheng?= Date: Sat, 13 Apr 2024 17:33:27 +0100 Subject: [PATCH] Codechange: Correct return type of GetDefaultValueCallback --- src/settings_gui.cpp | 6 +++--- src/settings_internal.h | 2 +- src/settings_table.cpp | 13 ++++++++++++- src/table/settings/company_settings.ini | 10 +++++----- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index be9244c150..0ef8fb330e 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2498,8 +2498,7 @@ struct GameSettingsWindow : Window { DrawString(tr, STR_CONFIG_SETTING_TYPE); tr.top += GetCharacterHeight(FS_NORMAL); - int32_t def_val = sd->def; - if (sd->get_def_cb != nullptr) sd->get_def_cb(def_val); + int32_t def_val = sd->get_def_cb != nullptr ? sd->get_def_cb() : sd->def; sd->SetValueDParams(0, def_val); DrawString(tr, STR_CONFIG_SETTING_DEFAULT_VALUE); 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; value = ClampTo(llvalue); + } else if (sd->get_def_cb != nullptr) { + value = sd->get_def_cb(); } else { value = sd->def; - if (sd->get_def_cb != nullptr) sd->get_def_cb(value); } SetSettingValue(this->valuewindow_entry->setting, value); diff --git a/src/settings_internal.h b/src/settings_internal.h index e473b47334..32bfa258e4 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -169,7 +169,7 @@ struct IntSettingDesc : SettingDesc { * units or expressed as a percentage. * @param value The prospective new value for the setting. */ - typedef void GetDefaultValueCallback(int32_t &value); + typedef int32_t GetDefaultValueCallback(); template < typename Tdef, diff --git a/src/settings_table.cpp b/src/settings_table.cpp index 4f0f724e0b..dcf19c8254 100644 --- a/src/settings_table.cpp +++ b/src/settings_table.cpp @@ -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. * @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; 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; } + int32_t new_value; if (vds->servint_ispercent) { new_value = DEF_SERVINT_PERCENT; } 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; 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) diff --git a/src/table/settings/company_settings.ini b/src/table/settings/company_settings.ini index 10a637ce71..68416b2838 100644 --- a/src/table/settings/company_settings.ini +++ b/src/table/settings/company_settings.ini @@ -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 void GetDefaultServiceInterval(VehicleType type, int32_t &new_value); +static int32_t GetDefaultServiceInterval(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 = [](auto &new_value) { GetDefaultServiceInterval(VEH_TRAIN, new_value); } +def_cb = []() { return GetDefaultServiceInterval(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 = [](auto &new_value) { GetDefaultServiceInterval(VEH_ROAD, new_value); } +def_cb = []() { return GetDefaultServiceInterval(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 = [](auto &new_value) { GetDefaultServiceInterval(VEH_SHIP, new_value); } +def_cb = []() { return GetDefaultServiceInterval(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 = [](auto &new_value) { GetDefaultServiceInterval(VEH_AIRCRAFT, new_value); } +def_cb = []() { return GetDefaultServiceInterval(VEH_AIRCRAFT); } val_cb = ServiceIntervalSettingsValueText