src/cheat_gui.cpp
author rubidium
Mon, 14 Jul 2008 20:18:06 +0000
changeset 11144 7eff560780d2
parent 10824 1a34ba6f338a
child 11161 7d0fac8f14cd
permissions -rw-r--r--
(svn r13702) -Fix: do not overflow the order/timetable window when 'long' orders are displayed.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2167
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2167
diff changeset
     2
10429
1b99254f9607 (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: 10225
diff changeset
     3
/** @file cheat_gui.cpp GUI related to cheating. */
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1879
diff changeset
     6
#include "openttd.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
     7
#include "command_func.h"
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
     8
#include "cheat_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8720
diff changeset
     9
#include "player_base.h"
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    10
#include "player_func.h"
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    11
#include "gfx_func.h"
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    12
#include "date_func.h"
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    13
#include "saveload.h"
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    14
#include "window_gui.h"
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    15
#include "newgrf.h"
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    16
#include "settings_type.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8604
diff changeset
    17
#include "strings_func.h"
8627
448ebf3a8291 (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: 8619
diff changeset
    18
#include "window_func.h"
9305
0c214cd8b39e (svn r12550) -Change: the signal GUI is now persistent - has the same data when it is reopened
smatz
parents: 9283
diff changeset
    19
#include "rail_gui.h"
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    20
#include "gui.h"
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    21
#include "player_gui.h"
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10775
diff changeset
    22
#include "gamelog.h"
911
bde79514283f (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
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    24
#include "table/strings.h"
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10155
diff changeset
    25
#include "table/sprites.h"
4300
687a17c9c557 (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
9211
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
    28
/**
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
    29
 * The 'amount' to cheat with.
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
    30
 * This variable is semantically a constant value, but because the cheat
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
    31
 * code requires to be able to write to the variable it is not constified.
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
    32
 */
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
    33
static int32 _money_cheat_amount = 10000000;
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
    34
410
8de2aaf20800 (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
{
9211
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
    37
	DoCommandP(0, (uint32)(p2 * _money_cheat_amount), 0, NULL, CMD_MONEY_CHEAT);
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
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
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    41
/**
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    42
 * @param p1 player to set to
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    43
 * @param p2 is -1 or +1 (down/up)
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    44
 */
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 402
diff changeset
    45
static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
{
4850
b4e9be22945f (svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents: 4834
diff changeset
    47
	while (IsValidPlayer((PlayerID)p1)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    48
		if (_players[p1].is_active) {
5564
6e1b3ea1ba7f (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);
6e1b3ea1ba7f (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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
			return _local_player;
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
81e9878f3678 (svn r156) -Codechange: remove obsolete callback arrays
darkvater
parents: 147
diff changeset
    57
	return _local_player;
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
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    60
/**
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    61
 * @param p1 -1 or +1 (down/up)
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6949
diff changeset
    62
 * @param p2 unused
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    63
 */
1095
90220990fd7c (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
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    66
	if (p1 == -1) p1 = 3;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
    67
	if (p1 ==  4) p1 = 0;
10775
7061477bfbcf (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: 10707
diff changeset
    68
	_settings_game.game_creation.landscape = p1;
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10775
diff changeset
    69
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10775
diff changeset
    70
	GamelogStartAction(GLAT_CHEAT);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10775
diff changeset
    71
	GamelogTestMode();
5352
82a50c80b0c4 (svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents: 5320
diff changeset
    72
	ReloadNewGRFData();
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10775
diff changeset
    73
	GamelogStopAction();
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10775
diff changeset
    74
10775
7061477bfbcf (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: 10707
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
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6565
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
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    80
/**
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6949
diff changeset
    81
 * @param p1 unused
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    82
 * @param p2 1 (increase) or -1 (decrease)
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
    83
 */
1095
90220990fd7c (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
60398d0e64ee (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
2c24234a7aec (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
60398d0e64ee (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));
9305
0c214cd8b39e (svn r12550) -Change: the signal GUI is now persistent - has the same data when it is reopened
smatz
parents: 9283
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
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
   100
struct CheatEntry {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
   101
	VarType type;          ///< type of selector
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
   102
	StringID str;          ///< string with descriptive text
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
   103
	void *variable;        ///< pointer to the variable
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
   104
	bool *been_used;       ///< has this cheat been used before?
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6523
diff changeset
   105
	CheckButtonClick *proc;///< procedure
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
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[] = {
10707
81a4013a7680 (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 10681
diff changeset
   109
	{SLE_INT32, STR_CHEAT_MONEY,           &_money_cheat_amount,               &_cheats.money.been_used,            &ClickMoneyCheat        },
81a4013a7680 (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 10681
diff changeset
   110
	{SLE_UINT8, STR_CHEAT_CHANGE_PLAYER,   &_local_player,                     &_cheats.switch_player.been_used,    &ClickChangePlayerCheat },
81a4013a7680 (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 10681
diff changeset
   111
	{SLE_BOOL,  STR_CHEAT_EXTRA_DYNAMITE,  &_cheats.magic_bulldozer.value,     &_cheats.magic_bulldozer.been_used,  NULL                    },
81a4013a7680 (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 10681
diff changeset
   112
	{SLE_BOOL,  STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value,    &_cheats.crossing_tunnels.been_used, NULL                    },
81a4013a7680 (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 10681
diff changeset
   113
	{SLE_BOOL,  STR_CHEAT_BUILD_IN_PAUSE,  &_cheats.build_in_pause.value,      &_cheats.build_in_pause.been_used,   NULL                    },
81a4013a7680 (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 10681
diff changeset
   114
	{SLE_BOOL,  STR_CHEAT_NO_JETCRASH,     &_cheats.no_jetcrash.value,         &_cheats.no_jetcrash.been_used,      NULL                    },
81a4013a7680 (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 10681
diff changeset
   115
	{SLE_BOOL,  STR_CHEAT_SETUP_PROD,      &_cheats.setup_prod.value,          &_cheats.setup_prod.been_used,       NULL                    },
10775
7061477bfbcf (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: 10707
diff changeset
   116
	{SLE_UINT8, STR_CHEAT_SWITCH_CLIMATE,  &_settings_game.game_creation.landscape, &_cheats.switch_climate.been_used,   &ClickChangeClimateCheat},
10707
81a4013a7680 (svn r13255) -Codechange: move _opt to _settings.
rubidium
parents: 10681
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[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   122
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,   STR_018B_CLOSE_WINDOW},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   123
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   399,     0,    13, STR_CHEATS, STR_018C_WINDOW_TITLE_DRAG_THIS},
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   124
{      WWT_PANEL,   RESIZE_NONE,    14,     0,   399,    14,   169, 0x0,        STR_NULL},
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4912
diff changeset
   125
{      WWT_PANEL,   RESIZE_NONE,    14,     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
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   129
struct CheatWindow : Window {
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   130
	int clicked;
9211
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
   131
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   132
	CheatWindow(const WindowDesc *desc) : Window(desc)
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   133
	{
10681
3aa3de4d448b (svn r13225) -Fix (r13041): Missing calls to FindWindowPlacementAndResize() from lots
peter1138
parents: 10641
diff changeset
   134
		this->FindWindowPlacementAndResize(desc);
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   135
	}
9211
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
   136
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   137
	virtual void OnPaint()
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   138
	{
10595
7957c71b0dfe (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 10565
diff changeset
   139
		this->DrawWidgets();
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   140
		DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, width - 50);
9211
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
   141
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   142
		for (int i = 0, x = 0, y = 45; i != lengthof(_cheats_ui); i++) {
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
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
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   145
			DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, x + 5, y + 2);
9211
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
   146
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   147
			switch (ce->type) {
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   148
				case SLE_BOOL: {
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   149
					bool on = (*(bool*)ce->variable);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   150
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   151
					DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? 6 : 4, on ? FR_LOWERED : FR_NONE);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   152
					SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   153
				} break;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   154
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   155
				default: {
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   156
					int32 val = (int32)ReadValue(ce->variable, ce->type);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   157
					char buf[512];
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   158
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   159
					/* Draw [<][>] boxes for settings of an integer-type */
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   160
					DrawArrowButtons(x + 20, y, 3, clicked - (i * 2), true, true);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   161
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   162
					switch (ce->str) {
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   163
						/* Display date for change date cheat */
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   164
						case STR_CHEAT_CHANGE_DATE: SetDParam(0, _date); break;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   165
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   166
						/* Draw colored flag for change player cheat */
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   167
						case STR_CHEAT_CHANGE_PLAYER:
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   168
							SetDParam(0, val);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   169
							GetString(buf, STR_CHEAT_CHANGE_PLAYER, lastof(buf));
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   170
							DrawPlayerIcon(_current_player, 60 + GetStringBoundingBox(buf).width, y + 2);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   171
							break;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   172
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   173
						/* Set correct string for switch climate cheat */
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   174
						case STR_CHEAT_SWITCH_CLIMATE: val += STR_TEMPERATE_LANDSCAPE;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   175
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   176
						/* Fallthrough */
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   177
						default: SetDParam(0, val);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   178
					}
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   179
				} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
			}
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   181
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   182
			DrawString(50, y + 1, ce->str, TC_FROMSTRING);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   183
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   184
			y += 12;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   185
		}
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   186
	}
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   187
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   188
	virtual void OnClick(Point pt, int widget)
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   189
	{
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   190
		uint btn = (pt.y - 46) / 12;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   191
		uint x = pt.x;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   192
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   193
		/* Not clicking a button? */
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   194
		if (!IsInsideMM(x, 20, 40) || btn >= lengthof(_cheats_ui)) return;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   195
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   196
		const CheatEntry *ce = &_cheats_ui[btn];
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   197
		int value = (int32)ReadValue(ce->variable, ce->type);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   198
		int oldvalue = value;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   199
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   200
		*ce->been_used = true;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   201
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   202
		switch (ce->type) {
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   203
			case SLE_BOOL:
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   204
				value ^= 1;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   205
				if (ce->proc != NULL) ce->proc(value, 0);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   206
				break;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   207
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   208
			default:
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   209
				/* Take whatever the function returns */
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   210
				value = ce->proc(value + ((x >= 30) ? 1 : -1), (x >= 30) ? 1 : -1);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   211
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   212
				/* The first cheat (money), doesn't return a different value. */
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   213
				if (value != oldvalue || btn == 0) this->clicked = btn * 2 + 1 + ((x >= 30) ? 1 : 0);
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   214
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		}
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   216
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
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
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   219
		flags4 |= 5 << WF_TIMEOUT_SHL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   221
		SetDirty();
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   222
	}
9211
6ee04ee57ab5 (svn r12389) -Codechange: remove unneeded code from the Cheat window handling and bring it in line with the coding guidelines.
rubidium
parents: 9167
diff changeset
   223
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   224
	virtual void OnTimeout()
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   225
	{
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   226
		this->clicked = 0;
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   227
		this->SetDirty();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
   228
	}
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   229
};
2639
8a7342eb3a78 (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 = {
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7817
diff changeset
   232
	240, 22, 400, 170, 400, 170,
6144
5a0ffbf27ced (svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents: 6001
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
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6565
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);
10565
0889f005903b (svn r13109) -Codechange: make a class out of the CheatWindow.
rubidium
parents: 10461
diff changeset
   242
	new CheatWindow(&_cheats_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
}