author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9770 | 8c260fb382f8 |
child 9858 | c8e0746a5945 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8965
diff
changeset
|
3 |
/** @file cheat_gui.cpp GUI related to cheating. */ |
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1879
diff
changeset
|
6 |
#include "openttd.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
7 |
#include "command_func.h" |
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
8 |
#include "cheat_func.h" |
8254
1496654ca5e7
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8224
diff
changeset
|
9 |
#include "player_base.h" |
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
10 |
#include "player_func.h" |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
11 |
#include "gfx_func.h" |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
12 |
#include "date_func.h" |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
13 |
#include "saveload.h" |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
14 |
#include "window_gui.h" |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
15 |
#include "newgrf.h" |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
16 |
#include "settings_type.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8108
diff
changeset
|
17 |
#include "strings_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8123
diff
changeset
|
18 |
#include "window_func.h" |
8809
e0d09d74e805
(svn r12550) -Change: the signal GUI is now persistent - has the same data when it is reopened
smatz
parents:
8787
diff
changeset
|
19 |
#include "rail_gui.h" |
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
20 |
#include "gui.h" |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
21 |
#include "player_gui.h" |
9457
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9413
diff
changeset
|
22 |
#include "gamelog.h" |
911
7ccc33888a33
(svn r1398) -Feature: CTRL+V (Paste) now works on all editboxes. This includes 'Add Server', chat, etc. Feature is Windows only.
darkvater
parents:
910
diff
changeset
|
23 |
|
8965
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
24 |
#include "table/strings.h" |
29a591456a2f
(svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents:
8916
diff
changeset
|
25 |
#include "table/sprites.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
26 |
|
0 | 27 |
|
8715
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
28 |
/** |
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
29 |
* The 'amount' to cheat with. |
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
30 |
* This variable is semantically a constant value, but because the cheat |
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
31 |
* code requires to be able to write to the variable it is not constified. |
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
32 |
*/ |
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
33 |
static int32 _money_cheat_amount = 10000000; |
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
34 |
|
410 | 35 |
static int32 ClickMoneyCheat(int32 p1, int32 p2) |
0 | 36 |
{ |
8715
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
37 |
DoCommandP(0, (uint32)(p2 * _money_cheat_amount), 0, NULL, CMD_MONEY_CHEAT); |
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
38 |
return _money_cheat_amount; |
0 | 39 |
} |
40 |
||
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
41 |
/** |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
42 |
* @param p1 player to set to |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
43 |
* @param p2 is -1 or +1 (down/up) |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
44 |
*/ |
410 | 45 |
static int32 ClickChangePlayerCheat(int32 p1, int32 p2) |
0 | 46 |
{ |
9659
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9652
diff
changeset
|
47 |
while ((uint)p1 < GetPlayerPoolSize()) { |
187142ff9b6c
(svn r13731) -Codechange: make a pool of the array of players.
rubidium
parents:
9652
diff
changeset
|
48 |
if (IsValidPlayerID((PlayerID)p1)) { |
5376
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5355
diff
changeset
|
49 |
SetLocalPlayer((PlayerID)p1); |
204acb84473f
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents:
5355
diff
changeset
|
50 |
|
138
6ab4d97d1034
(svn r139) Added MarkWholeScreenDirty() on switch player screen
dominik
parents:
108
diff
changeset
|
51 |
MarkWholeScreenDirty(); |
0 | 52 |
return _local_player; |
53 |
} |
|
54 |
p1 += p2; |
|
55 |
} |
|
155
81e9878f3678
(svn r156) -Codechange: remove obsolete callback arrays
darkvater
parents:
147
diff
changeset
|
56 |
|
81e9878f3678
(svn r156) -Codechange: remove obsolete callback arrays
darkvater
parents:
147
diff
changeset
|
57 |
return _local_player; |
0 | 58 |
} |
59 |
||
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
60 |
/** |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
61 |
* @param p1 -1 or +1 (down/up) |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
62 |
* @param p2 unused |
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
63 |
*/ |
1095 | 64 |
static int32 ClickChangeClimateCheat(int32 p1, int32 p2) |
100 | 65 |
{ |
2639 | 66 |
if (p1 == -1) p1 = 3; |
67 |
if (p1 == 4) p1 = 0; |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
68 |
_settings_game.game_creation.landscape = p1; |
9457
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9413
diff
changeset
|
69 |
|
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9413
diff
changeset
|
70 |
GamelogStartAction(GLAT_CHEAT); |
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9413
diff
changeset
|
71 |
GamelogTestMode(); |
5352
86fca6a41aa1
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5320
diff
changeset
|
72 |
ReloadNewGRFData(); |
9457
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9413
diff
changeset
|
73 |
GamelogStopAction(); |
75f11a6caef8
(svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents:
9413
diff
changeset
|
74 |
|
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
75 |
return _settings_game.game_creation.landscape; |
100 | 76 |
} |
77 |
||
6247 | 78 |
extern void EnginesMonthlyLoop(); |
108
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
79 |
|
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
80 |
/** |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
81 |
* @param p1 unused |
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
82 |
* @param p2 1 (increase) or -1 (decrease) |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
83 |
*/ |
1095 | 84 |
static int32 ClickChangeDateCheat(int32 p1, int32 p2) |
108
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
85 |
{ |
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
86 |
YearMonthDay ymd; |
4288
393de75451b1
(svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents:
4286
diff
changeset
|
87 |
ConvertDateToYMD(_date, &ymd); |
108
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
88 |
|
4293
4b7006c1b5eb
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4288
diff
changeset
|
89 |
if ((ymd.year == MIN_YEAR && p2 == -1) || (ymd.year == MAX_YEAR && p2 == 1)) return _cur_year; |
108
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
90 |
|
4288
393de75451b1
(svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents:
4286
diff
changeset
|
91 |
SetDate(ConvertYMDToDate(_cur_year + p2, ymd.month, ymd.day)); |
108
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
92 |
EnginesMonthlyLoop(); |
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
93 |
SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0)); |
8809
e0d09d74e805
(svn r12550) -Change: the signal GUI is now persistent - has the same data when it is reopened
smatz
parents:
8787
diff
changeset
|
94 |
ResetSignalVariant(); |
108
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
95 |
return _cur_year; |
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
96 |
} |
100 | 97 |
|
0 | 98 |
typedef int32 CheckButtonClick(int32, int32); |
99 |
||
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
100 |
struct CheatEntry { |
6201
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
101 |
VarType type; ///< type of selector |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
102 |
StringID str; ///< string with descriptive text |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
103 |
void *variable; ///< pointer to the variable |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
104 |
bool *been_used; ///< has this cheat been used before? |
bee01dc45e39
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6197
diff
changeset
|
105 |
CheckButtonClick *proc;///< procedure |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
106 |
}; |
0 | 107 |
|
108 |
static const CheatEntry _cheats_ui[] = { |
|
9358
2e1e4d2f71dd
(svn r13255) -Codechange: move _opt to _settings.
rubidium
parents:
9333
diff
changeset
|
109 |
{SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat }, |
2e1e4d2f71dd
(svn r13255) -Codechange: move _opt to _settings.
rubidium
parents:
9333
diff
changeset
|
110 |
{SLE_UINT8, STR_CHEAT_CHANGE_PLAYER, &_local_player, &_cheats.switch_player.been_used, &ClickChangePlayerCheat }, |
2e1e4d2f71dd
(svn r13255) -Codechange: move _opt to _settings.
rubidium
parents:
9333
diff
changeset
|
111 |
{SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL }, |
2e1e4d2f71dd
(svn r13255) -Codechange: move _opt to _settings.
rubidium
parents:
9333
diff
changeset
|
112 |
{SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, NULL }, |
2e1e4d2f71dd
(svn r13255) -Codechange: move _opt to _settings.
rubidium
parents:
9333
diff
changeset
|
113 |
{SLE_BOOL, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used, NULL }, |
2e1e4d2f71dd
(svn r13255) -Codechange: move _opt to _settings.
rubidium
parents:
9333
diff
changeset
|
114 |
{SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL }, |
2e1e4d2f71dd
(svn r13255) -Codechange: move _opt to _settings.
rubidium
parents:
9333
diff
changeset
|
115 |
{SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, NULL }, |
9413
7042a8ec3fa8
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents:
9358
diff
changeset
|
116 |
{SLE_UINT8, STR_CHEAT_SWITCH_CLIMATE, &_settings_game.game_creation.landscape, &_cheats.switch_climate.been_used, &ClickChangeClimateCheat}, |
9358
2e1e4d2f71dd
(svn r13255) -Codechange: move _opt to _settings.
rubidium
parents:
9333
diff
changeset
|
117 |
{SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat }, |
0 | 118 |
}; |
119 |
||
120 |
||
121 |
static const Widget _cheat_widgets[] = { |
|
9751
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9659
diff
changeset
|
122 |
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9659
diff
changeset
|
123 |
{ WWT_CAPTION, RESIZE_NONE, COLOUR_GREY, 11, 399, 0, 13, STR_CHEATS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9659
diff
changeset
|
124 |
{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 399, 14, 169, 0x0, STR_NULL}, |
9e9c726170cc
(svn r13887) -Codechange: Replace numbers with Colours enum on autoreplace, build_vehicle, cheat, depot and dock guis.
belugas
parents:
9659
diff
changeset
|
125 |
{ WWT_PANEL, RESIZE_NONE, COLOUR_GREY, 0, 399, 14, 169, 0x0, STR_CHEATS_TIP}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
126 |
{ WIDGETS_END}, |
0 | 127 |
}; |
128 |
||
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
129 |
struct CheatWindow : Window { |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
130 |
int clicked; |
8715
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
131 |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
132 |
CheatWindow(const WindowDesc *desc) : Window(desc) |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
133 |
{ |
9333
2da01b3b71d8
(svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents:
9317
diff
changeset
|
134 |
this->FindWindowPlacementAndResize(desc); |
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
135 |
} |
8715
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
136 |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
137 |
virtual void OnPaint() |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
138 |
{ |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9243
diff
changeset
|
139 |
this->DrawWidgets(); |
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
140 |
DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, width - 50); |
8715
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
141 |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
142 |
for (int i = 0, x = 0, y = 45; i != lengthof(_cheats_ui); i++) { |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
143 |
const CheatEntry *ce = &_cheats_ui[i]; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
144 |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
145 |
DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, x + 5, y + 2); |
8715
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
146 |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
147 |
switch (ce->type) { |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
148 |
case SLE_BOOL: { |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
149 |
bool on = (*(bool*)ce->variable); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
150 |
|
9770
8c260fb382f8
(svn r13907) -Codechange: Replace a number with Colours enum on DrawFrameRect usage
belugas
parents:
9751
diff
changeset
|
151 |
DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? COLOUR_GREEN : COLOUR_RED, on ? FR_LOWERED : FR_NONE); |
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
152 |
SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
153 |
} break; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
154 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
155 |
default: { |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
156 |
int32 val = (int32)ReadValue(ce->variable, ce->type); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
157 |
char buf[512]; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
158 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
159 |
/* Draw [<][>] boxes for settings of an integer-type */ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
160 |
DrawArrowButtons(x + 20, y, 3, clicked - (i * 2), true, true); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
161 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
162 |
switch (ce->str) { |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
163 |
/* Display date for change date cheat */ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
164 |
case STR_CHEAT_CHANGE_DATE: SetDParam(0, _date); break; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
165 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
166 |
/* Draw colored flag for change player cheat */ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
167 |
case STR_CHEAT_CHANGE_PLAYER: |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
168 |
SetDParam(0, val); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
169 |
GetString(buf, STR_CHEAT_CHANGE_PLAYER, lastof(buf)); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
170 |
DrawPlayerIcon(_current_player, 60 + GetStringBoundingBox(buf).width, y + 2); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
171 |
break; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
172 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
173 |
/* Set correct string for switch climate cheat */ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
174 |
case STR_CHEAT_SWITCH_CLIMATE: val += STR_TEMPERATE_LANDSCAPE; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
175 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
176 |
/* Fallthrough */ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
177 |
default: SetDParam(0, val); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
178 |
} |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
179 |
} break; |
0 | 180 |
} |
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
181 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
182 |
DrawString(50, y + 1, ce->str, TC_FROMSTRING); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
183 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
184 |
y += 12; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
185 |
} |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
186 |
} |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
187 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
188 |
virtual void OnClick(Point pt, int widget) |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
189 |
{ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
190 |
uint btn = (pt.y - 46) / 12; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
191 |
uint x = pt.x; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
192 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
193 |
/* Not clicking a button? */ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
194 |
if (!IsInsideMM(x, 20, 40) || btn >= lengthof(_cheats_ui)) return; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
195 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
196 |
const CheatEntry *ce = &_cheats_ui[btn]; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
197 |
int value = (int32)ReadValue(ce->variable, ce->type); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
198 |
int oldvalue = value; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
199 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
200 |
*ce->been_used = true; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
201 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
202 |
switch (ce->type) { |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
203 |
case SLE_BOOL: |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
204 |
value ^= 1; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
205 |
if (ce->proc != NULL) ce->proc(value, 0); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
206 |
break; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
207 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
208 |
default: |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
209 |
/* Take whatever the function returns */ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
210 |
value = ce->proc(value + ((x >= 30) ? 1 : -1), (x >= 30) ? 1 : -1); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
211 |
|
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
212 |
/* The first cheat (money), doesn't return a different value. */ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
213 |
if (value != oldvalue || btn == 0) this->clicked = btn * 2 + 1 + ((x >= 30) ? 1 : 0); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
214 |
break; |
0 | 215 |
} |
2639 | 216 |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
217 |
if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value); |
0 | 218 |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
219 |
flags4 |= 5 << WF_TIMEOUT_SHL; |
0 | 220 |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
221 |
SetDirty(); |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
222 |
} |
8715
26eb4dd8f515
(svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents:
8671
diff
changeset
|
223 |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
224 |
virtual void OnTimeout() |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
225 |
{ |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
226 |
this->clicked = 0; |
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
227 |
this->SetDirty(); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
228 |
} |
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
229 |
}; |
2639 | 230 |
|
0 | 231 |
static const WindowDesc _cheats_desc = { |
7341
02515d0d4ced
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7321
diff
changeset
|
232 |
240, 22, 400, 170, 400, 170, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
233 |
WC_CHEATS, WC_NONE, |
0 | 234 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
235 |
_cheat_widgets, |
|
236 |
}; |
|
237 |
||
238 |
||
6247 | 239 |
void ShowCheatWindow() |
0 | 240 |
{ |
241 |
DeleteWindowById(WC_CHEATS, 0); |
|
9243
8e5cea2fe464
(svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents:
9142
diff
changeset
|
242 |
new CheatWindow(&_cheats_desc); |
0 | 243 |
} |