From fa2f3ed1049f1f171ecc2f40b5d27c9d481bf0d5 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 21 Mar 2021 12:52:01 +0000 Subject: [PATCH] Cheats window: Allow clicking money text to enter quantity --- src/cheat_gui.cpp | 11 +++++++++++ src/lang/english.txt | 1 + src/string.cpp | 1 + src/string_type.h | 1 + 4 files changed, 14 insertions(+) diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 427547c5f6..037428df87 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -29,6 +29,7 @@ #include "error.h" #include "network/network.h" #include "order_base.h" +#include "currency.h" #include "widgets/cheat_widget.h" @@ -391,6 +392,11 @@ struct CheatWindow : Window { SetDParam(0, value); ShowQueryString(STR_JUST_INT, STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED); return; + } else if (btn == CHT_MONEY && x >= 20 + this->box_width + SETTING_BUTTON_WIDTH) { + clicked_widget = CHT_MONEY; + SetDParam(0, value); + ShowQueryString(STR_JUST_INT, STR_CHEAT_EDIT_MONEY_QUERY_CAPT, 20, this, CS_NUMERAL_SIGNED, QSF_ACCEPT_UNCHANGED); + return; } else if (ce->type == SLF_NOT_IN_SAVE && x >= 20 + this->box_width + SETTING_BUTTON_WIDTH) { clicked_widget = btn; uint64 val = (uint64)ReadValue(ce->variable, SLE_UINT64); @@ -465,6 +471,11 @@ struct CheatWindow : Window { DoCommandP(0, (uint32)clicked_widget, (uint32)Clamp(atof(tmp_buffer) * 65536.0, 1 << 16, MAX_INFLATION), CMD_CHEAT_SETTING); return; } + if (ce->mode == CNM_MONEY) { + if (!_networking) *ce->been_used = true; + DoCommandP(0, (strtoll(str, nullptr, 10) / _currency->rate), 0, _network_server || _network_settings_access ? CMD_MONEY_CHEAT_ADMIN : CMD_MONEY_CHEAT); + return; + } if (_networking) return; int oldvalue = (int32)ReadValue(ce->variable, ce->type); diff --git a/src/lang/english.txt b/src/lang/english.txt index ab991bf39a..56526fabf5 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2177,6 +2177,7 @@ STR_CHEAT_CROSSINGTUNNELS :{LTBLUE}Tunnels STR_CHEAT_NO_JETCRASH :{LTBLUE}Jetplanes will not crash (frequently) on small airports: {ORANGE}{STRING} STR_CHEAT_EDIT_MAX_HL :{LTBLUE}Edit the maximum map height: {ORANGE}{NUM} STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT :{WHITE}Edit the maximum height of mountains on the map +STR_CHEAT_EDIT_MONEY_QUERY_CAPT :{WHITE}Increase or decrease money STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE :Temperate landscape STR_CHEAT_SWITCH_CLIMATE_SUB_ARCTIC_LANDSCAPE :Sub-arctic landscape STR_CHEAT_SWITCH_CLIMATE_SUB_TROPICAL_LANDSCAPE :Sub-tropical landscape diff --git a/src/string.cpp b/src/string.cpp index 0e04e8f98b..f5315f30d6 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -490,6 +490,7 @@ bool IsValidChar(WChar key, CharSetFilter afilter) switch (afilter) { case CS_ALPHANUMERAL: return IsPrintable(key); 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(); #else diff --git a/src/string_type.h b/src/string_type.h index cb28417d4f..698dabe22f 100644 --- a/src/string_type.h +++ b/src/string_type.h @@ -26,6 +26,7 @@ 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_SPACE, ///< Only numbers and spaces CS_ALPHA, ///< Only alphabetic values