src/cheat_gui.cpp
author smatz
Sat, 13 Dec 2008 15:59:25 +0000
changeset 10416 b35c0a4c73c5
parent 10352 1d7538888215
permissions -rw-r--r--
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2167
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2167
diff changeset
     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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     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"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
     9
#include "company_base.h"
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    10
#include "company_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
    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"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    21
#include "company_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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    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
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 402
diff changeset
    35
static int32 ClickMoneyCheat(int32 p1, int32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    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
/**
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
    42
 * @param p1 company to set to
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
    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
 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
    45
static int32 ClickChangeCompanyCheat(int32 p1, int32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
    47
	while ((uint)p1 < GetCompanyPoolSize()) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
    48
		if (IsValidCompanyID((CompanyID)p1)) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
    49
			SetLocalCompany((CompanyID)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
    50
138
6ab4d97d1034 (svn r139) Added MarkWholeScreenDirty() on switch player screen
dominik
parents: 108
diff changeset
    51
			MarkWholeScreenDirty();
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
    52
			return _local_company;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
		p1 += p2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
	}
155
81e9878f3678 (svn r156) -Codechange: remove obsolete callback arrays
darkvater
parents: 147
diff changeset
    56
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
    57
	return _local_company;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    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
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
    64
static int32 ClickChangeClimateCheat(int32 p1, int32 p2)
100
8e87945f6bcb (svn r101) New cheat: switch climate
dominik
parents: 74
diff changeset
    65
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    66
	if (p1 == -1) p1 = 3;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    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
8e87945f6bcb (svn r101) New cheat: switch climate
dominik
parents: 74
diff changeset
    76
}
8e87945f6bcb (svn r101) New cheat: switch climate
dominik
parents: 74
diff changeset
    77
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6239
diff changeset
    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
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
    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
8e87945f6bcb (svn r101) New cheat: switch climate
dominik
parents: 74
diff changeset
    97
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
typedef int32 CheckButtonClick(int32, int32);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
static const CheatEntry _cheats_ui[] = {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   109
	{SLE_INT32, STR_CHEAT_MONEY,           &_money_cheat_amount,                    &_cheats.money.been_used,            &ClickMoneyCheat         },
10209
a1e7417bf1b7 (svn r14423) -Codechange: also do r14221 for the strings.
rubidium
parents: 10208
diff changeset
   110
	{SLE_UINT8, STR_CHEAT_CHANGE_COMPANY,  &_local_company,                         &_cheats.switch_company.been_used,   &ClickChangeCompanyCheat },
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   111
	{SLE_BOOL,  STR_CHEAT_EXTRA_DYNAMITE,  &_cheats.magic_bulldozer.value,          &_cheats.magic_bulldozer.been_used,  NULL                     },
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   112
	{SLE_BOOL,  STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value,         &_cheats.crossing_tunnels.been_used, NULL                     },
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   113
	{SLE_BOOL,  STR_CHEAT_BUILD_IN_PAUSE,  &_cheats.build_in_pause.value,           &_cheats.build_in_pause.been_used,   NULL                     },
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   114
	{SLE_BOOL,  STR_CHEAT_NO_JETCRASH,     &_cheats.no_jetcrash.value,              &_cheats.no_jetcrash.been_used,      NULL                     },
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   115
	{SLE_BOOL,  STR_CHEAT_SETUP_PROD,      &_cheats.setup_prod.value,               &_cheats.setup_prod.been_used,       NULL                     },
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   116
	{SLE_UINT8, STR_CHEAT_SWITCH_CLIMATE,  &_settings_game.game_creation.landscape, &_cheats.switch_climate.been_used,   &ClickChangeClimateCheat },
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   117
	{SLE_INT32, STR_CHEAT_CHANGE_DATE,     &_cur_year,                              &_cheats.change_date.been_used,      &ClickChangeDateCheat    },
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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 */
9858
c8e0746a5945 (svn r14003) -Codechange: Replace numbers with Colours enum opn some DrawArrowButtons calls
belugas
parents: 9770
diff changeset
   160
					DrawArrowButtons(x + 20, y, COLOUR_YELLOW, clicked - (i * 2), true, true);
9243
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
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   166
						/* Draw colored flag for change company cheat */
10209
a1e7417bf1b7 (svn r14423) -Codechange: also do r14221 for the strings.
rubidium
parents: 10208
diff changeset
   167
						case STR_CHEAT_CHANGE_COMPANY:
10352
1d7538888215 (svn r14603) -Fix [FS#2422]: the company ID is off-by-one w.r.t. to the rest of the GUI in the cheat window.
rubidium
parents: 10209
diff changeset
   168
							SetDParam(0, val + 1);
10209
a1e7417bf1b7 (svn r14423) -Codechange: also do r14221 for the strings.
rubidium
parents: 10208
diff changeset
   169
							GetString(buf, STR_CHEAT_CHANGE_COMPANY, lastof(buf));
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10180
diff changeset
   170
							DrawCompanyIcon(_current_company, 60 + GetStringBoundingBox(buf).width, y + 2);
9243
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		}
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
10180
a99cf854c6d0 (svn r14390) -Codechange: replace magic constants with symbolic constants.
rubidium
parents: 9858
diff changeset
   219
		this->flags4 |= WF_TIMEOUT_BEGIN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   230
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	_cheat_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6239
diff changeset
   239
void ShowCheatWindow()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
}