summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-12-04 21:51:02 +0000
committeralberth <alberth@openttd.org>2010-12-04 21:51:02 +0000
commitfd2f1399d4d1f319cc313045e06dabb530cbe007 (patch)
tree91eafe824daa1c10ba024c6080d08a201c40f5db /src
parent4a35dafcd2ecae40424510aedc1d0e59f9569902 (diff)
downloadopenttd-fd2f1399d4d1f319cc313045e06dabb530cbe007.tar.xz
(svn r21388) -Feature [FS#4289]: Allow entering of the new year in a text box when cheating the year.
Diffstat (limited to 'src')
-rw-r--r--src/cheat_gui.cpp30
-rw-r--r--src/lang/english.txt1
2 files changed, 29 insertions, 2 deletions
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
index 490380668..7c39175a7 100644
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -18,7 +18,9 @@
#include "date_func.h"
#include "saveload/saveload.h"
#include "window_gui.h"
+#include "querystring_gui.h"
#include "newgrf.h"
+#include "string_func.h"
#include "strings_func.h"
#include "window_func.h"
#include "rail_gui.h"
@@ -325,13 +327,22 @@ struct CheatWindow : Window {
bool rtl = _current_text_dir == TD_RTL;
if (rtl) x = wid->current_x - x;
- /* Not clicking a button? */
- if (!IsInsideMM(x, 20, 40) || btn >= lengthof(_cheats_ui)) return;
+ if (btn >= lengthof(_cheats_ui)) return;
const CheatEntry *ce = &_cheats_ui[btn];
int value = (int32)ReadValue(ce->variable, ce->type);
int oldvalue = value;
+ if (btn == CHT_CHANGE_DATE && x >= 40) {
+ /* Click at the date text directly. */
+ SetDParam(0, value);
+ ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, 100, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
+ return;
+ }
+
+ /* Not clicking a button? */
+ if (!IsInsideMM(x, 20, 40)) return;
+
*ce->been_used = true;
switch (ce->type) {
@@ -361,6 +372,21 @@ struct CheatWindow : Window {
this->clicked = 0;
this->SetDirty();
}
+
+ virtual void OnQueryTextFinished(char *str)
+ {
+ /* Was 'cancel' pressed or nothing entered? */
+ if (str == NULL || StrEmpty(str)) return;
+
+ const CheatEntry *ce = &_cheats_ui[CHT_CHANGE_DATE];
+ int oldvalue = (int32)ReadValue(ce->variable, ce->type);
+ int value = atoi(str);
+ *ce->been_used = true;
+ value = ce->proc(value, value - oldvalue);
+
+ if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value);
+ this->SetDirty();
+ }
};
/** Window description of the cheats GUI. */
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 3af722a26..a0e48b899 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1430,6 +1430,7 @@ STR_CHEAT_SWITCH_CLIMATE_SUB_ARCTIC_LANDSCAPE :Sub-arctic land
STR_CHEAT_SWITCH_CLIMATE_SUB_TROPICAL_LANDSCAPE :Sub-tropical landscape
STR_CHEAT_SWITCH_CLIMATE_TOYLAND_LANDSCAPE :Toyland landscape
STR_CHEAT_CHANGE_DATE :{LTBLUE}Change date: {ORANGE}{DATE_SHORT}
+STR_CHEAT_CHANGE_DATE_QUERY_CAPT :{WHITE}Change current year
STR_CHEAT_SETUP_PROD :{LTBLUE}Enable modifying production values: {ORANGE}{STRING1}
# Livery window