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

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

Loading…
Cancel
Save