diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 8287f3acc7..d46188e400 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2811,8 +2811,11 @@ struct GameSettingsWindow : Window { this->valuewindow_entry = pe; if (sd->flags & SF_DECIMAL1 || (sd->flags & SF_GUI_VELOCITY && _settings_game.locale.units_velocity == 3)) { + CharSetFilter charset_filter = CS_NUMERAL_DECIMAL; //default, only numeric input and decimal point allowed + if (sd->min < 0) charset_filter = CS_NUMERAL_DECIMAL_SIGNED; // special case, also allow '-' sign for negative input + 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, charset_filter, QSF_ENABLE_DEFAULT); } else { CharSetFilter charset_filter = CS_NUMERAL; //default, only numeric input allowed if (sd->min < 0) charset_filter = CS_NUMERAL_SIGNED; // special case, also allow '-' sign for negative input diff --git a/src/string.cpp b/src/string.cpp index ad09053d20..db564c28ab 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -602,9 +602,11 @@ bool IsValidChar(WChar key, CharSetFilter afilter) case CS_NUMERAL: return (key >= '0' && key <= '9'); case CS_NUMERAL_SIGNED: return (key >= '0' && key <= '9') || key == '-'; #if !defined(STRGEN) && !defined(SETTINGSGEN) - case CS_NUMERAL_DECIMAL: return (key >= '0' && key <= '9') || key == '.' || key == '-' || key == GetDecimalSeparatorChar(); + case CS_NUMERAL_DECIMAL: return (key >= '0' && key <= '9') || key == '.' || key == GetDecimalSeparatorChar(); + case CS_NUMERAL_DECIMAL_SIGNED: return (key >= '0' && key <= '9') || key == '.' || key == '-' || key == GetDecimalSeparatorChar(); #else - case CS_NUMERAL_DECIMAL: return (key >= '0' && key <= '9') || key == '.' || key == '-'; + case CS_NUMERAL_DECIMAL: return (key >= '0' && key <= '9') || key == '.'; + case CS_NUMERAL_DECIMAL_SIGNED: return (key >= '0' && key <= '9') || key == '.' || key == '-'; #endif case CS_NUMERAL_SPACE: return (key >= '0' && key <= '9') || key == ' '; case CS_ALPHA: return IsPrintable(key) && !(key >= '0' && key <= '9'); diff --git a/src/string_type.h b/src/string_type.h index ddd27a9d91..88660e14c9 100644 --- a/src/string_type.h +++ b/src/string_type.h @@ -27,7 +27,8 @@ enum CharSetFilter { CS_ALPHANUMERAL, ///< Both numeric and alphabetic and spaces and stuff CS_NUMERAL, ///< Only numeric ones CS_NUMERAL_SIGNED, ///< Only numeric ones, and minus/negative - CS_NUMERAL_DECIMAL, ///< Only numeric, decimal separaters, and minus/negative + CS_NUMERAL_DECIMAL, ///< Only numeric, decimal separaters + CS_NUMERAL_DECIMAL_SIGNED, ///< Only numeric, decimal separaters, and minus/negative CS_NUMERAL_SPACE, ///< Only numbers and spaces CS_ALPHA, ///< Only alphabetic values CS_HEXADECIMAL, ///< Only hexadecimal characters