mirror of https://github.com/OpenTTD/OpenTTD
Fix: Restore the behaviour when entering numbers in query windows: clamp integers out of range to the maximum valid value.
parent
c1389c77b2
commit
2926179d02
|
@ -608,7 +608,7 @@ struct CheatWindow : Window {
|
||||||
|
|
||||||
int32_t value;
|
int32_t value;
|
||||||
if (!str->empty()) {
|
if (!str->empty()) {
|
||||||
auto llvalue = ParseInteger<int64_t>(*str);
|
auto llvalue = ParseInteger<int64_t>(*str, 10, true);
|
||||||
if (!llvalue.has_value()) return;
|
if (!llvalue.has_value()) return;
|
||||||
|
|
||||||
/* Save the correct currency-translated value */
|
/* Save the correct currency-translated value */
|
||||||
|
@ -623,7 +623,7 @@ struct CheatWindow : Window {
|
||||||
} else {
|
} else {
|
||||||
const CheatEntry *ce = &_cheats_ui[clicked_cheat];
|
const CheatEntry *ce = &_cheats_ui[clicked_cheat];
|
||||||
int oldvalue = static_cast<int32_t>(ReadValue(ce->variable, ce->type));
|
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;
|
if (!value.has_value()) return;
|
||||||
*ce->been_used = true;
|
*ce->been_used = true;
|
||||||
value = ce->proc(*value, *value - oldvalue);
|
value = ce->proc(*value, *value - oldvalue);
|
||||||
|
|
|
@ -1693,7 +1693,7 @@ public:
|
||||||
if (!str.has_value()) return;
|
if (!str.has_value()) return;
|
||||||
/* Set a new company manager face number */
|
/* Set a new company manager face number */
|
||||||
if (!str->empty()) {
|
if (!str->empty()) {
|
||||||
auto val = ParseInteger(*str);
|
auto val = ParseInteger(*str, 10, true);
|
||||||
if (!val.has_value()) return;
|
if (!val.has_value()) return;
|
||||||
this->face = *val;
|
this->face = *val;
|
||||||
ScaleAllCompanyManagerFaceBits(this->face);
|
ScaleAllCompanyManagerFaceBits(this->face);
|
||||||
|
@ -2458,7 +2458,7 @@ struct CompanyWindow : Window
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
|
|
||||||
case WID_C_GIVE_MONEY: {
|
case WID_C_GIVE_MONEY: {
|
||||||
auto value = ParseInteger<uint64_t>(*str);
|
auto value = ParseInteger<uint64_t>(*str, 10, true);
|
||||||
if (!value.has_value()) return;
|
if (!value.has_value()) return;
|
||||||
Money money = *value / GetCurrency().rate;
|
Money money = *value / GetCurrency().rate;
|
||||||
Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, this->window_number);
|
Command<CMD_GIVE_MONEY>::Post(STR_ERROR_CAN_T_GIVE_MONEY, money, this->window_number);
|
||||||
|
|
|
@ -348,7 +348,7 @@ struct GSConfigWindow : public Window {
|
||||||
void OnQueryTextFinished(std::optional<std::string> str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (!str.has_value()) return;
|
if (!str.has_value()) return;
|
||||||
auto value = ParseInteger<int32_t>(*str);
|
auto value = ParseInteger<int32_t>(*str, 10, true);
|
||||||
if (!value.has_value()) return;
|
if (!value.has_value()) return;
|
||||||
SetValue(*value);
|
SetValue(*value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -914,7 +914,7 @@ struct GenerateLandscapeWindow : public Window {
|
||||||
|
|
||||||
int32_t value;
|
int32_t value;
|
||||||
if (!str->empty()) {
|
if (!str->empty()) {
|
||||||
auto val = ParseInteger<int32_t>(*str);
|
auto val = ParseInteger<int32_t>(*str, 10, true);
|
||||||
if (!val.has_value()) return;
|
if (!val.has_value()) return;
|
||||||
value = *val;
|
value = *val;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1203,7 +1203,7 @@ struct CreateScenarioWindow : public Window
|
||||||
{
|
{
|
||||||
if (!str.has_value()) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
auto value = ParseInteger<int32_t>(*str);
|
auto value = ParseInteger<int32_t>(*str, 10, true);
|
||||||
if (!value.has_value()) return;
|
if (!value.has_value()) return;
|
||||||
|
|
||||||
switch (this->widget_id) {
|
switch (this->widget_id) {
|
||||||
|
|
|
@ -1165,7 +1165,7 @@ public:
|
||||||
if (!str.has_value() || str->empty()) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
|
|
||||||
Industry *i = Industry::Get(this->window_number);
|
Industry *i = Industry::Get(this->window_number);
|
||||||
auto value = ParseInteger(*str);
|
auto value = ParseInteger(*str, 10, true);
|
||||||
if (!value.has_value()) return;
|
if (!value.has_value()) return;
|
||||||
switch (this->editbox_line) {
|
switch (this->editbox_line) {
|
||||||
case IL_NONE: NOT_REACHED();
|
case IL_NONE: NOT_REACHED();
|
||||||
|
|
|
@ -1116,7 +1116,7 @@ struct NetworkStartServerWindow : public Window {
|
||||||
if (this->widget_id == WID_NSS_SETPWD) {
|
if (this->widget_id == WID_NSS_SETPWD) {
|
||||||
_settings_client.network.server_password = std::move(*str);
|
_settings_client.network.server_password = std::move(*str);
|
||||||
} else {
|
} else {
|
||||||
auto value = ParseInteger<int32_t>(*str);
|
auto value = ParseInteger<int32_t>(*str, 10, true);
|
||||||
if (!value.has_value()) return;
|
if (!value.has_value()) return;
|
||||||
this->SetWidgetDirty(this->widget_id);
|
this->SetWidgetDirty(this->widget_id);
|
||||||
switch (this->widget_id) {
|
switch (this->widget_id) {
|
||||||
|
|
|
@ -594,7 +594,7 @@ struct NewGRFInspectWindow : Window {
|
||||||
{
|
{
|
||||||
if (!str.has_value()) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
auto val = ParseInteger<int32_t>(*str);
|
auto val = ParseInteger<int32_t>(*str, 10, true);
|
||||||
if (!val.has_value()) return;
|
if (!val.has_value()) return;
|
||||||
NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = *val;
|
NewGRFInspectWindow::var60params[GetFeatureNum(this->window_number)][this->current_edit_param - 0x60] = *val;
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
|
@ -1066,7 +1066,7 @@ struct SpriteAlignerWindow : Window {
|
||||||
{
|
{
|
||||||
if (!str.has_value()) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
auto value = ParseInteger(*str);
|
auto value = ParseInteger(*str, 10, true);
|
||||||
if (!value.has_value()) return;
|
if (!value.has_value()) return;
|
||||||
this->current_sprite = *value;
|
this->current_sprite = *value;
|
||||||
if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0;
|
if (this->current_sprite >= GetMaxSpriteID()) this->current_sprite = 0;
|
||||||
|
|
|
@ -435,7 +435,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
void OnQueryTextFinished(std::optional<std::string> str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (!str.has_value() || str->empty()) return;
|
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;
|
if (!value.has_value()) return;
|
||||||
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
|
GRFParameterInfo &par_info = this->GetParameterInfo(this->clicked_row);
|
||||||
this->grf_config.SetValue(par_info, *value);
|
this->grf_config.SetValue(par_info, *value);
|
||||||
|
|
|
@ -1363,7 +1363,7 @@ public:
|
||||||
if (!str.has_value() || str->empty()) return;
|
if (!str.has_value() || str->empty()) return;
|
||||||
|
|
||||||
VehicleOrderID sel = this->OrderGetSel();
|
VehicleOrderID sel = this->OrderGetSel();
|
||||||
auto value = ParseInteger(*str);
|
auto value = ParseInteger(*str, 10, true);
|
||||||
if (!value.has_value()) return;
|
if (!value.has_value()) return;
|
||||||
|
|
||||||
switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
|
switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
|
||||||
|
|
|
@ -486,7 +486,7 @@ struct ScriptSettingsWindow : public Window {
|
||||||
void OnQueryTextFinished(std::optional<std::string> str) override
|
void OnQueryTextFinished(std::optional<std::string> str) override
|
||||||
{
|
{
|
||||||
if (!str.has_value()) return;
|
if (!str.has_value()) return;
|
||||||
auto value = ParseInteger<int32_t>(*str);
|
auto value = ParseInteger<int32_t>(*str, 10, true);
|
||||||
if (!value.has_value()) return;
|
if (!value.has_value()) return;
|
||||||
SetValue(*value);
|
SetValue(*value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1371,7 +1371,7 @@ struct GameOptionsWindow : Window {
|
||||||
|
|
||||||
int32_t value;
|
int32_t value;
|
||||||
if (!str->empty()) {
|
if (!str->empty()) {
|
||||||
auto llvalue = ParseInteger<int64_t>(*str);
|
auto llvalue = ParseInteger<int64_t>(*str, 10, true);
|
||||||
if (!llvalue.has_value()) return;
|
if (!llvalue.has_value()) return;
|
||||||
|
|
||||||
/* Save the correct currency-translated value */
|
/* Save the correct currency-translated value */
|
||||||
|
@ -2067,7 +2067,7 @@ struct CustomCurrencyWindow : Window {
|
||||||
|
|
||||||
switch (this->query_widget) {
|
switch (this->query_widget) {
|
||||||
case WID_CC_RATE: {
|
case WID_CC_RATE: {
|
||||||
auto val = ParseInteger(*str);
|
auto val = ParseInteger(*str, 10, true);
|
||||||
if (!val.has_value()) return;
|
if (!val.has_value()) return;
|
||||||
GetCustomCurrency().rate = Clamp(*val, 1, UINT16_MAX);
|
GetCustomCurrency().rate = Clamp(*val, 1, UINT16_MAX);
|
||||||
break;
|
break;
|
||||||
|
@ -2088,7 +2088,7 @@ struct CustomCurrencyWindow : Window {
|
||||||
case WID_CC_YEAR: { // Year to switch to euro
|
case WID_CC_YEAR: { // Year to switch to euro
|
||||||
TimerGameCalendar::Year year = CF_NOEURO;
|
TimerGameCalendar::Year year = CF_NOEURO;
|
||||||
if (!str->empty()) {
|
if (!str->empty()) {
|
||||||
auto val = ParseInteger(*str);
|
auto val = ParseInteger(*str, 10, true);
|
||||||
if (!val.has_value()) return;
|
if (!val.has_value()) return;
|
||||||
year = Clamp(static_cast<TimerGameCalendar::Year>(*val), MIN_EURO_YEAR, CalendarTime::MAX_YEAR);
|
year = Clamp(static_cast<TimerGameCalendar::Year>(*val), MIN_EURO_YEAR, CalendarTime::MAX_YEAR);
|
||||||
}
|
}
|
||||||
|
|
|
@ -748,7 +748,7 @@ struct TimetableWindow : Window {
|
||||||
if (!str.has_value()) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
const Vehicle *v = this->vehicle;
|
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);
|
auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, query_widget == WID_VT_CHANGE_SPEED);
|
||||||
|
|
||||||
switch (query_widget) {
|
switch (query_widget) {
|
||||||
|
|
|
@ -2501,7 +2501,7 @@ struct ScenarioEditorToolbarWindow : Window {
|
||||||
|
|
||||||
TimerGameCalendar::Year value;
|
TimerGameCalendar::Year value;
|
||||||
if (!str->empty()) {
|
if (!str->empty()) {
|
||||||
auto val = ParseInteger(*str);
|
auto val = ParseInteger(*str, 10, true);
|
||||||
if (!val.has_value()) return;
|
if (!val.has_value()) return;
|
||||||
value = static_cast<TimerGameCalendar::Year>(*val);
|
value = static_cast<TimerGameCalendar::Year>(*val);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1275,7 +1275,7 @@ public:
|
||||||
/* Was 'cancel' pressed? */
|
/* Was 'cancel' pressed? */
|
||||||
if (!str.has_value()) return;
|
if (!str.has_value()) return;
|
||||||
|
|
||||||
auto value = ParseInteger(*str);
|
auto value = ParseInteger(*str, 10, true);
|
||||||
if (!value.has_value()) return;
|
if (!value.has_value()) return;
|
||||||
|
|
||||||
Backup<bool> old_generating_world(_generating_world, true);
|
Backup<bool> old_generating_world(_generating_world, true);
|
||||||
|
|
Loading…
Reference in New Issue