Fix text input of velocity setting values

See: #357
pull/362/head
Jonathan G Rennison 2 years ago
parent eab98e4808
commit a64a6aeeb8

@ -2718,11 +2718,12 @@ struct GameSettingsWindow : Window {
/* 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 & (SF_GUI_DROPDOWN | SF_ENUM))) {
int64 value64 = value;
/* Show the correct currency-translated value */
/* Show the correct currency or velocity translated value */
if (sd->flags & SF_GUI_CURRENCY) value64 *= _currency->rate;
if (sd->flags & SF_GUI_VELOCITY) value64 = ConvertKmhishSpeedToDisplaySpeed((uint)value64);
this->valuewindow_entry = pe;
if (sd->flags & SF_DECIMAL1) {
if (sd->flags & SF_DECIMAL1 || (sd->flags & SF_GUI_VELOCITY && _settings_game.locale.units_velocity == 3)) {
SetDParam(0, value64);
ShowQueryString(STR_JUST_DECIMAL1, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL_DECIMAL, QSF_ENABLE_DEFAULT);
} else {
@ -2755,7 +2756,7 @@ struct GameSettingsWindow : Window {
int32 value;
if (!StrEmpty(str)) {
long long llvalue;
if (sd->flags & SF_DECIMAL1) {
if (sd->flags & SF_DECIMAL1 || (sd->flags & SF_GUI_VELOCITY && _settings_game.locale.units_velocity == 3)) {
llvalue = atof(str) * 10;
} else {
llvalue = atoll(str);
@ -2765,6 +2766,9 @@ struct GameSettingsWindow : Window {
if (sd->flags & SF_GUI_CURRENCY) llvalue /= _currency->rate;
value = (int32)ClampToI32(llvalue);
/* Save the correct velocity-translated value */
if (sd->flags & SF_GUI_VELOCITY) value = ConvertDisplaySpeedToKmhishSpeed(value);
} else {
value = sd->def;
}

@ -32,6 +32,7 @@ enum SettingFlag : uint32 {
SF_NO_NEWGAME = 1 << 15, ///< the setting does not apply and is not shown in a new game context
SF_DEC1SCALE = 1 << 16, ///< also display a float representation of the scale of a decimal1 scale parameter
SF_RUN_CALLBACKS_ON_PARSE = 1 << 17, ///< run callbacks when parsing from config file
SF_GUI_VELOCITY = 1 << 18, ///< setting value is a velocity
};
DECLARE_ENUM_AS_BIT_SET(SettingFlag)

@ -1358,6 +1358,7 @@ cat = SC_EXPERT
[SDT_VAR]
var = vehicle.through_load_speed_limit
type = SLE_UINT16
flags = SF_GUI_VELOCITY
def = 15
min = 5
max = 500

Loading…
Cancel
Save