1
0
Fork 0

Fix: Restore the behaviour when entering numbers in query windows: clamp integers out of range to the maximum valid value.

pull/14288/head
frosch 2025-05-16 12:22:00 +02:00 committed by frosch
parent c1389c77b2
commit 2926179d02
14 changed files with 20 additions and 20 deletions

View File

@ -608,7 +608,7 @@ struct CheatWindow : Window {
int32_t value;
if (!str->empty()) {
auto llvalue = ParseInteger<int64_t>(*str);
auto llvalue = ParseInteger<int64_t>(*str, 10, true);
if (!llvalue.has_value()) return;
/* Save the correct currency-translated value */
@ -623,7 +623,7 @@ struct CheatWindow : Window {
} else {
const CheatEntry *ce = &_cheats_ui[clicked_cheat];
int oldvalue = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
auto value = ParseInteger<int32_t>(*str);
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
*ce->been_used = true;
value = ce->proc(*value, *value - oldvalue);

View File

@ -1693,7 +1693,7 @@ public:
if (!str.has_value()) return;
/* Set a new company manager face number */
if (!str->empty()) {
auto val = ParseInteger(*str);
auto val = ParseInteger(*str, 10, true);
if (!val.has_value()) return;
this->face = *val;
ScaleAllCompanyManagerFaceBits(this->face);
@ -2458,7 +2458,7 @@ struct CompanyWindow : Window
default: NOT_REACHED();
case WID_C_GIVE_MONEY: {
auto value = ParseInteger<uint64_t>(*str);
auto value = ParseInteger<uint64_t>(*str, 10, true);
if (!value.has_value()) return;
Money money = *value / GetCurrency().rate;
Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, this->window_number);

View File

@ -348,7 +348,7 @@ struct GSConfigWindow : public Window {
void OnQueryTextFinished(std::optional<std::string> str) override
{
if (!str.has_value()) return;
auto value = ParseInteger<int32_t>(*str);
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
SetValue(*value);
}

View File

@ -914,7 +914,7 @@ struct GenerateLandscapeWindow : public Window {
int32_t value;
if (!str->empty()) {
auto val = ParseInteger<int32_t>(*str);
auto val = ParseInteger<int32_t>(*str, 10, true);
if (!val.has_value()) return;
value = *val;
} else {
@ -1203,7 +1203,7 @@ struct CreateScenarioWindow : public Window
{
if (!str.has_value()) return;
auto value = ParseInteger<int32_t>(*str);
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
switch (this->widget_id) {

View File

@ -1165,7 +1165,7 @@ public:
if (!str.has_value() || str->empty()) return;
Industry *i = Industry::Get(this->window_number);
auto value = ParseInteger(*str);
auto value = ParseInteger(*str, 10, true);
if (!value.has_value()) return;
switch (this->editbox_line) {
case IL_NONE: NOT_REACHED();

View File

@ -1116,7 +1116,7 @@ struct NetworkStartServerWindow : public Window {
if (this->widget_id == WID_NSS_SETPWD) {
_settings_client.network.server_password = std::move(*str);
} else {
auto value = ParseInteger<int32_t>(*str);
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
this->SetWidgetDirty(this->widget_id);
switch (this->widget_id) {

View File

@ -594,7 +594,7 @@ struct NewGRFInspectWindow : Window {
{
if (!str.has_value()) return;
auto val = ParseInteger<int32_t>(*str);
auto val = ParseInteger<int32_t>(*str, 10, true);
if (!val.has_value()) return;
NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = *val;
this->SetDirty();
@ -1066,7 +1066,7 @@ struct SpriteAlignerWindow : Window {
{
if (!str.has_value()) return;
auto value = ParseInteger(*str);
auto value = ParseInteger(*str, 10, true);
if (!value.has_value()) return;
this->current_sprite = *value;
if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0;

View File

@ -435,7 +435,7 @@ struct NewGRFParametersWindow : public Window {
void OnQueryTextFinished(std::optional<std::string> str) override
{
if (!str.has_value() || str->empty()) return;
auto value = ParseInteger<int32_t>(*str);
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
this->grf_config.SetValue(par_info, *value);

View File

@ -1363,7 +1363,7 @@ public:
if (!str.has_value() || str->empty()) return;
VehicleOrderID sel = this->OrderGetSel();
auto value = ParseInteger(*str);
auto value = ParseInteger(*str, 10, true);
if (!value.has_value()) return;
switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {

View File

@ -486,7 +486,7 @@ struct ScriptSettingsWindow : public Window {
void OnQueryTextFinished(std::optional<std::string> str) override
{
if (!str.has_value()) return;
auto value = ParseInteger<int32_t>(*str);
auto value = ParseInteger<int32_t>(*str, 10, true);
if (!value.has_value()) return;
SetValue(*value);
}

View File

@ -1371,7 +1371,7 @@ struct GameOptionsWindow : Window {
int32_t value;
if (!str->empty()) {
auto llvalue = ParseInteger<int64_t>(*str);
auto llvalue = ParseInteger<int64_t>(*str, 10, true);
if (!llvalue.has_value()) return;
/* Save the correct currency-translated value */
@ -2067,7 +2067,7 @@ struct CustomCurrencyWindow : Window {
switch (this->query_widget) {
case WID_CC_RATE: {
auto val = ParseInteger(*str);
auto val = ParseInteger(*str, 10, true);
if (!val.has_value()) return;
GetCustomCurrency().rate = Clamp(*val, 1, UINT16_MAX);
break;
@ -2088,7 +2088,7 @@ struct CustomCurrencyWindow : Window {
case WID_CC_YEAR: { // Year to switch to euro
TimerGameCalendar::Year year = CF_NOEURO;
if (!str->empty()) {
auto val = ParseInteger(*str);
auto val = ParseInteger(*str, 10, true);
if (!val.has_value()) return;
year = Clamp(static_cast<TimerGameCalendar::Year>(*val), MIN_EURO_YEAR, CalendarTime::MAX_YEAR);
}

View File

@ -748,7 +748,7 @@ struct TimetableWindow : Window {
if (!str.has_value()) return;
const Vehicle *v = this->vehicle;
uint64_t val = ParseInteger<uint64_t>(*str).value_or(0);
uint64_t val = ParseInteger<uint64_t>(*str, 10, true).value_or(0);
auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, query_widget == WID_VT_CHANGE_SPEED);
switch (query_widget) {

View File

@ -2501,7 +2501,7 @@ struct ScenarioEditorToolbarWindow : Window {
TimerGameCalendar::Year value;
if (!str->empty()) {
auto val = ParseInteger(*str);
auto val = ParseInteger(*str, 10, true);
if (!val.has_value()) return;
value = static_cast<TimerGameCalendar::Year>(*val);
} else {

View File

@ -1275,7 +1275,7 @@ public:
/* Was 'cancel' pressed? */
if (!str.has_value()) return;
auto value = ParseInteger(*str);
auto value = ParseInteger(*str, 10, true);
if (!value.has_value()) return;
Backup<bool> old_generating_world(_generating_world, true);