mirror of https://github.com/OpenTTD/OpenTTD.git
Fix #11345: Use correct default button value for vehicle service interval setting
This commit is contained in:
parent
a4071b78d7
commit
fd80a1ec66
|
@ -2734,6 +2734,7 @@ struct GameSettingsWindow : Window {
|
||||||
value = ClampTo<int32_t>(llvalue);
|
value = ClampTo<int32_t>(llvalue);
|
||||||
} 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);
|
||||||
|
|
|
@ -240,6 +240,32 @@ static void UpdateServiceInterval(VehicleType type, int32_t new_value)
|
||||||
SetWindowClassesDirty(WC_VEHICLE_DETAILS);
|
SetWindowClassesDirty(WC_VEHICLE_DETAILS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
VehicleDefaultSettings *vds;
|
||||||
|
if (_game_mode == GM_MENU || !Company::IsValidID(_current_company)) {
|
||||||
|
vds = &_settings_client.company.vehicle;
|
||||||
|
} else {
|
||||||
|
vds = &Company::Get(_current_company)->settings.vehicle;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vds->servint_ispercent) {
|
||||||
|
new_value = DEF_SERVINT_PERCENT;
|
||||||
|
} else 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void TrainAccelerationModelChanged(int32_t)
|
static void TrainAccelerationModelChanged(int32_t)
|
||||||
{
|
{
|
||||||
for (Train *t : Train::Iterate()) {
|
for (Train *t : Train::Iterate()) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ static void UpdateAllServiceInterval(int32_t new_value);
|
||||||
static bool CanUpdateServiceInterval(VehicleType type, int32_t &new_value);
|
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 GetDefaultServiceInterval(VehicleType type, int32_t &new_value);
|
||||||
|
|
||||||
static const SettingVariant _company_settings_table[] = {
|
static const SettingVariant _company_settings_table[] = {
|
||||||
[post-amble]
|
[post-amble]
|
||||||
|
@ -98,6 +99,7 @@ strhelp = STR_CONFIG_SETTING_SERVINT_TRAINS_HELPTEXT
|
||||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE
|
strval = STR_CONFIG_SETTING_SERVINT_VALUE
|
||||||
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); }
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
var = vehicle.servint_roadveh
|
var = vehicle.servint_roadveh
|
||||||
|
@ -112,6 +114,7 @@ strhelp = STR_CONFIG_SETTING_SERVINT_ROAD_VEHICLES_HELPTEXT
|
||||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE
|
strval = STR_CONFIG_SETTING_SERVINT_VALUE
|
||||||
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); }
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
var = vehicle.servint_ships
|
var = vehicle.servint_ships
|
||||||
|
@ -126,6 +129,7 @@ strhelp = STR_CONFIG_SETTING_SERVINT_SHIPS_HELPTEXT
|
||||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE
|
strval = STR_CONFIG_SETTING_SERVINT_VALUE
|
||||||
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); }
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
var = vehicle.servint_aircraft
|
var = vehicle.servint_aircraft
|
||||||
|
@ -140,3 +144,4 @@ strhelp = STR_CONFIG_SETTING_SERVINT_AIRCRAFT_HELPTEXT
|
||||||
strval = STR_CONFIG_SETTING_SERVINT_VALUE
|
strval = STR_CONFIG_SETTING_SERVINT_VALUE
|
||||||
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); }
|
||||||
|
|
Loading…
Reference in New Issue