author | KUDr |
Fri, 20 Apr 2007 19:43:06 +0000 | |
changeset 6513 | 454347ca3dfb |
parent 6492 | 286a52449b54 |
child 6626 | 207875b9069a |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
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
|
3 |
/** @file misc_gui.cpp */ |
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" |
4223
d4c9ef555f43
(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents:
4217
diff
changeset
|
7 |
#include "hal.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
8 |
#include "heightmap.h" |
1299
39c06aba09aa
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1274
diff
changeset
|
9 |
#include "debug.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2162
diff
changeset
|
10 |
#include "functions.h" |
6453
226bcddeba32
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents:
6350
diff
changeset
|
11 |
#include "landscape.h" |
5352
86fca6a41aa1
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5320
diff
changeset
|
12 |
#include "newgrf.h" |
2162
b98e430ffd10
(svn r2672) Move saving/loading related declarations to saveload.h
tron
parents:
2159
diff
changeset
|
13 |
#include "saveload.h" |
1309
4403a69da4f8
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1304
diff
changeset
|
14 |
#include "strings.h" |
1363
775a7ee52369
(svn r1867) Include tables/sprites.h only in files which need it
tron
parents:
1349
diff
changeset
|
15 |
#include "table/sprites.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
485
diff
changeset
|
16 |
#include "table/strings.h" |
1784
d0698aac0c2e
(svn r2288) - CodeChange: protected the next batch of commands (41 so far, out of 115).
Darkvater
parents:
1694
diff
changeset
|
17 |
#include "table/tree_land.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
674
diff
changeset
|
18 |
#include "map.h" |
0 | 19 |
#include "window.h" |
20 |
#include "gui.h" |
|
21 |
#include "viewport.h" |
|
22 |
#include "gfx.h" |
|
23 |
#include "station.h" |
|
24 |
#include "command.h" |
|
25 |
#include "player.h" |
|
26 |
#include "town.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
278
diff
changeset
|
27 |
#include "sound.h" |
5469
7edfc643abbc
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5447
diff
changeset
|
28 |
#include "network/network.h" |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
29 |
#include "string.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2134
diff
changeset
|
30 |
#include "variables.h" |
3890
e04bc34bc50c
(svn r4946) "Feature": Add a cheat that allows running electric engines on normal rail
celestar
parents:
3798
diff
changeset
|
31 |
#include "vehicle.h" |
e04bc34bc50c
(svn r4946) "Feature": Add a cheat that allows running electric engines on normal rail
celestar
parents:
3798
diff
changeset
|
32 |
#include "train.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
33 |
#include "tgp.h" |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
34 |
#include "settings.h" |
4261
28670f743746
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4223
diff
changeset
|
35 |
#include "date.h" |
6091
c8827d9ae04a
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
5893
diff
changeset
|
36 |
#include "cargotype.h" |
6190
01a2b579b668
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
6091
diff
changeset
|
37 |
#include "player_face.h" |
1341
f52b476be477
(svn r1845) - Revert r1835 since it totally screws network compiling
darkvater
parents:
1336
diff
changeset
|
38 |
|
4223
d4c9ef555f43
(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents:
4217
diff
changeset
|
39 |
#include "fios.h" |
d4c9ef555f43
(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents:
4217
diff
changeset
|
40 |
/* Variables to display file lists */ |
d4c9ef555f43
(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents:
4217
diff
changeset
|
41 |
FiosItem *_fios_list; |
d4c9ef555f43
(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents:
4217
diff
changeset
|
42 |
int _saveload_mode; |
0 | 43 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
44 |
|
1596
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
45 |
static bool _fios_path_changed; |
1594
00485cb74836
(svn r2098) Make a variable static, move a function declaration to a header and remove unnecessary preprocessor magic
tron
parents:
1578
diff
changeset
|
46 |
static bool _savegame_sort_dirty; |
00485cb74836
(svn r2098) Make a variable static, move a function declaration to a header and remove unnecessary preprocessor magic
tron
parents:
1578
diff
changeset
|
47 |
|
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
48 |
enum { |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
49 |
LAND_INFO_LINES = 7, |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
50 |
LAND_INFO_LINE_BUFF_SIZE = 512, |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
51 |
}; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
52 |
|
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
53 |
static char _landinfo_data[LAND_INFO_LINES][LAND_INFO_LINE_BUFF_SIZE]; |
0 | 54 |
|
55 |
static void LandInfoWndProc(Window *w, WindowEvent *e) |
|
56 |
{ |
|
57 |
if (e->event == WE_PAINT) { |
|
58 |
DrawWindowWidgets(w); |
|
59 |
||
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
60 |
DoDrawStringCentered(140, 16, _landinfo_data[0], 13); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
61 |
DoDrawStringCentered(140, 27, _landinfo_data[1], 0); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
62 |
DoDrawStringCentered(140, 38, _landinfo_data[2], 0); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
63 |
DoDrawStringCentered(140, 49, _landinfo_data[3], 0); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
64 |
DoDrawStringCentered(140, 60, _landinfo_data[4], 0); |
6197
558f3a9b5bd4
(svn r8977) -Codechange: Remove the hardcoded maximum width for some drawstrings and replace them with a portion of w->width. Only visible improvement is QueryWndProc which will not write exactly to the edge of the window anymore.
Darkvater
parents:
6190
diff
changeset
|
65 |
if (_landinfo_data[5][0] != '\0') DrawStringMultiCenter(140, 76, BindCString(_landinfo_data[5]), w->width - 4); |
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
66 |
if (_landinfo_data[6][0] != '\0') DoDrawStringCentered(140, 71, _landinfo_data[6], 0); |
0 | 67 |
} |
68 |
} |
|
69 |
||
70 |
static const Widget _land_info_widgets[] = { |
|
4344
7e123fec5b0b
(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
|
71 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
72 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 279, 0, 13, STR_01A3_LAND_AREA_INFORMATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4912
diff
changeset
|
73 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 279, 14, 92, 0x0, STR_NULL}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
74 |
{ WIDGETS_END}, |
0 | 75 |
}; |
76 |
||
77 |
static const WindowDesc _land_info_desc = { |
|
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
5039
diff
changeset
|
78 |
WDP_AUTO, WDP_AUTO, 280, 93, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
79 |
WC_LAND_INFO, WC_NONE, |
0 | 80 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
81 |
_land_info_widgets, |
|
82 |
LandInfoWndProc |
|
83 |
}; |
|
84 |
||
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
85 |
static void Place_LandInfo(TileIndex tile) |
0 | 86 |
{ |
87 |
Player *p; |
|
88 |
Window *w; |
|
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
89 |
Town *t; |
0 | 90 |
int64 old_money; |
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
91 |
int64 costclear; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
92 |
AcceptedCargo ac; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
93 |
TileDesc td; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
94 |
StringID str; |
0 | 95 |
|
96 |
DeleteWindowById(WC_LAND_INFO, 0); |
|
97 |
||
98 |
w = AllocateWindowDesc(&_land_info_desc); |
|
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
99 |
WP(w, void_d).data = &_landinfo_data; |
0 | 100 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
101 |
p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST); |
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
102 |
t = ClosestTownFromTile(tile, _patches.dist_local_authority); |
3
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
103 |
|
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
104 |
old_money = p->money64; |
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
105 |
p->money64 = p->player_money = 0x7fffffff; |
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
106 |
costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR); |
3
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
107 |
p->money64 = old_money; |
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
108 |
UpdatePlayerMoney32(p); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
109 |
|
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
110 |
/* Because build_date is not set yet in every TileDesc, we make sure it is empty */ |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
111 |
td.build_date = 0; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
112 |
GetAcceptedCargo(tile, ac); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
113 |
GetTileDesc(tile, &td); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
114 |
|
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
115 |
SetDParam(0, td.dparam[0]); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
116 |
GetString(_landinfo_data[0], td.str, lastof(_landinfo_data[0])); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
117 |
|
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
118 |
SetDParam(0, STR_01A6_N_A); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
119 |
if (td.owner != OWNER_NONE && td.owner != OWNER_WATER) GetNameOfOwner(td.owner, tile); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
120 |
GetString(_landinfo_data[1], STR_01A7_OWNER, lastof(_landinfo_data[1])); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
121 |
|
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
122 |
str = STR_01A4_COST_TO_CLEAR_N_A; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
123 |
if (!CmdFailed(costclear)) { |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
124 |
SetDParam(0, costclear); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
125 |
str = STR_01A5_COST_TO_CLEAR; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
126 |
} |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
127 |
GetString(_landinfo_data[2], str, lastof(_landinfo_data[2])); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
128 |
|
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
129 |
snprintf(_userstring, lengthof(_userstring), "0x%.4X", tile); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
130 |
SetDParam(0, TileX(tile)); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
131 |
SetDParam(1, TileY(tile)); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
132 |
SetDParam(2, STR_SPEC_USERSTRING); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
133 |
GetString(_landinfo_data[3], STR_LANDINFO_COORDS, lastof(_landinfo_data[3])); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
134 |
|
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
135 |
SetDParam(0, STR_01A9_NONE); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
136 |
if (t != NULL && IsValidTown(t)) { |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
137 |
SetDParam(0, STR_TOWN); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
138 |
SetDParam(1, t->index); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
139 |
} |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
140 |
GetString(_landinfo_data[4], STR_01A8_LOCAL_AUTHORITY, lastof(_landinfo_data[4])); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
141 |
|
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
142 |
{ |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
143 |
char *p = GetString(_landinfo_data[5], STR_01CE_CARGO_ACCEPTED, lastof(_landinfo_data[5])); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
144 |
bool found = false; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
145 |
|
6350
04b19f551aec
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6332
diff
changeset
|
146 |
for (CargoID i = 0; i < NUM_CARGO; ++i) { |
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
147 |
if (ac[i] > 0) { |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
148 |
/* Add a comma between each item. */ |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
149 |
if (found) { |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
150 |
*p++ = ','; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
151 |
*p++ = ' '; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
152 |
} |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
153 |
found = true; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
154 |
|
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
155 |
/* If the accepted value is less than 8, show it in 1/8:ths */ |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
156 |
if (ac[i] < 8) { |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
157 |
SetDParam(0, ac[i]); |
6091
c8827d9ae04a
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
5893
diff
changeset
|
158 |
SetDParam(1, GetCargo(i)->name); |
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
159 |
p = GetString(p, STR_01D1_8, lastof(_landinfo_data[5])); |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
160 |
} else { |
6091
c8827d9ae04a
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
5893
diff
changeset
|
161 |
p = GetString(p, GetCargo(i)->name, lastof(_landinfo_data[5])); |
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
162 |
} |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
163 |
} |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
164 |
} |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
165 |
|
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
166 |
if (!found) _landinfo_data[5][0] = '\0'; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
167 |
} |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
168 |
|
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
169 |
if (td.build_date != 0) { |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
170 |
SetDParam(0, td.build_date); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
171 |
GetString(_landinfo_data[6], STR_BUILD_DATE, lastof(_landinfo_data[6])); |
5583
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
172 |
} else { |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
173 |
_landinfo_data[6][0] = '\0'; |
136d8764c7e6
(svn r8030) -Fix: segmentation fault when removing a town in the scenario editor while having the query tool window open for one of the town's tiles.
rubidium
parents:
5475
diff
changeset
|
174 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
175 |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
176 |
#if defined(_DEBUG) |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
177 |
# define LANDINFOD_LEVEL 0 |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
178 |
#else |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
179 |
# define LANDINFOD_LEVEL 1 |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
180 |
#endif |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5376
diff
changeset
|
181 |
DEBUG(misc, LANDINFOD_LEVEL, "TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile)); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5376
diff
changeset
|
182 |
DEBUG(misc, LANDINFOD_LEVEL, "type_height = %#x", _m[tile].type_height); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5376
diff
changeset
|
183 |
DEBUG(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5376
diff
changeset
|
184 |
DEBUG(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5376
diff
changeset
|
185 |
DEBUG(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5376
diff
changeset
|
186 |
DEBUG(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4); |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5376
diff
changeset
|
187 |
DEBUG(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5); |
5596
5bf7128140a0
(svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents:
5587
diff
changeset
|
188 |
DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _m[tile].m6); |
6332
f3f436dcd7d0
(svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents:
6248
diff
changeset
|
189 |
DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7); |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
190 |
#undef LANDINFOD_LEVEL |
0 | 191 |
} |
192 |
||
6247 | 193 |
void PlaceLandBlockInfo() |
0 | 194 |
{ |
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
195 |
if (_cursor.sprite == SPR_CURSOR_QUERY) { |
0 | 196 |
ResetObjectToPlace(); |
197 |
} else { |
|
198 |
_place_proc = Place_LandInfo; |
|
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
199 |
SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, 1, WC_MAIN_TOOLBAR, 0); |
0 | 200 |
} |
201 |
} |
|
202 |
||
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
203 |
static const char *credits[] = { |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
204 |
/************************************************************************* |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
205 |
* maximum length of string which fits in window -^*/ |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
206 |
"Original design by Chris Sawyer", |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
207 |
"Original graphics by Simon Foster", |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
208 |
"", |
1124 | 209 |
"The OpenTTD team (in alphabetical order):", |
5355
195bce6def67
(svn r7527) -Update appropiate files with release information for 0.5.0-RC1
Darkvater
parents:
5352
diff
changeset
|
210 |
" Jean-Francois Claeys (Belugas) - In training, not yet specialized", |
2310
95d4a45a0ad4
(svn r2836) fixed the alphabetical order of the credits list like it says it is in
bjarni
parents:
2275
diff
changeset
|
211 |
" Bjarni Corfitzen (Bjarni) - MacOSX port, coder", |
5355
195bce6def67
(svn r7527) -Update appropiate files with release information for 0.5.0-RC1
Darkvater
parents:
5352
diff
changeset
|
212 |
" Matthijs Kooijman (blathijs) - Pathfinder-guru", |
1125 | 213 |
" Victor Fischer (Celestar) - Programming everywhere you need him to", |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
214 |
" Tamás Faragó (Darkvater) - Lead coder", |
5355
195bce6def67
(svn r7527) -Update appropiate files with release information for 0.5.0-RC1
Darkvater
parents:
5352
diff
changeset
|
215 |
" Loïc Guilloux (glx) - In training, not yet specialized", |
195bce6def67
(svn r7527) -Update appropiate files with release information for 0.5.0-RC1
Darkvater
parents:
5352
diff
changeset
|
216 |
" Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;)", |
6239 | 217 |
" Jonathan Coome (Maedhros) - High priest of the newGRF Temple", |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
218 |
" Attila Bán (MiHaMiX) - WebTranslator, Nightlies, Wiki and bugtracker host", |
2748
21bbb96a6467
(svn r3293) - Miscellaneous: add peter1138 as developer
Darkvater
parents:
2737
diff
changeset
|
219 |
" Peter Nelson (peter1138) - Spiritual descendant from newgrf gods", |
5726
a1592d73615b
(svn r8254) -Merge: Release changes from the 0.5 branch back to trunk. This ensures an updated changelog, readme, et.
Darkvater
parents:
5668
diff
changeset
|
220 |
" Remko Bijker (Rubidium) - THE desync hunter", |
1126 | 221 |
" Christoph Mallon (Tron) - Programmer, code correctness police", |
1124 | 222 |
" Patric Stout (TrueLight) - Coder, network guru, SVN- and website host", |
1125 | 223 |
"", |
224 |
"Retired Developers:", |
|
225 |
" Ludvig Strigeus (ludde) - OpenTTD author, main coder (0.1 - 0.3.3)", |
|
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
226 |
" Serge Paquet (vurlix) - Assistant project manager, coder (0.1 - 0.3.3)", |
1826
6000a1a8e448
(svn r2331) - Fix (regression): fix text overflows in about box.
Darkvater
parents:
1821
diff
changeset
|
227 |
" Dominik Scherer (dominik81) - Lead programmer, GUI expert (0.3.0 - 0.3.6)", |
5355
195bce6def67
(svn r7527) -Update appropiate files with release information for 0.5.0-RC1
Darkvater
parents:
5352
diff
changeset
|
228 |
" Owen Rudge (orudge) - Forum- and masterserver host, OS/2 port (0.1 - 0.4.8)", |
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
229 |
"", |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
230 |
"Special thanks go out to:", |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
231 |
" Josef Drexler - For his great work on TTDPatch", |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
232 |
" Marcin Grzegorczyk - For his documentation of TTD internals", |
1577 | 233 |
" Petr Baudis (pasky) - Many patches, newgrf support", |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
234 |
" Stefan Meißner (sign_de) - For his work on the console", |
1826
6000a1a8e448
(svn r2331) - Fix (regression): fix text overflows in about box.
Darkvater
parents:
1821
diff
changeset
|
235 |
" Simon Sasburg (HackyKid) - Many bugfixes he has blessed us with (and PBS)", |
1124 | 236 |
" Cian Duffy (MYOB) - BeOS port / manual writing", |
4133
f9878fb9a365
(svn r5489) -Fix: corrected tokai's name and morphos details (tokai)
truelight
parents:
4091
diff
changeset
|
237 |
" Christian Rosentreter (tokai) - MorphOS / AmigaOS port", |
5355
195bce6def67
(svn r7527) -Update appropiate files with release information for 0.5.0-RC1
Darkvater
parents:
5352
diff
changeset
|
238 |
" Richard Kempton (richK) - additional airports, initial TGP implementation", |
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
239 |
"", |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
240 |
" Michael Blunck - Pre-Signals and Semaphores © 2003", |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
241 |
" George - Canal/Lock graphics © 2003-2004", |
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
242 |
" Marcin Grzegorczyk - Foundations for Tracks on Slopes", |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
243 |
" All Translators - Who made OpenTTD a truly international game", |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
244 |
" Bug Reporters - Without whom OpenTTD would still be full of bugs!", |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
245 |
"", |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
246 |
"", |
1124 | 247 |
"And last but not least:", |
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
248 |
" Chris Sawyer - For an amazing game!" |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
249 |
}; |
0 | 250 |
|
251 |
static void AboutWindowProc(Window *w, WindowEvent *e) |
|
252 |
{ |
|
2639 | 253 |
switch (e->event) { |
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
|
254 |
case WE_CREATE: // Set up window counter and start position of scroller |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
980
diff
changeset
|
255 |
WP(w, scroller_d).counter = 0; |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
980
diff
changeset
|
256 |
WP(w, scroller_d).height = w->height - 40; |
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
257 |
break; |
0 | 258 |
case WE_PAINT: { |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
926
diff
changeset
|
259 |
uint i; |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
980
diff
changeset
|
260 |
int y = WP(w, scroller_d).height; |
0 | 261 |
DrawWindowWidgets(w); |
262 |
||
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
|
263 |
/* Show original copyright and revision version */ |
1125 | 264 |
DrawStringCentered(210, 17, STR_00B6_ORIGINAL_COPYRIGHT, 0); |
265 |
DrawStringCentered(210, 17 + 10, STR_00B7_VERSION, 0); |
|
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
266 |
|
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
|
267 |
/* Show all scrolling credits */ |
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
268 |
for (i = 0; i < lengthof(credits); i++) { |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
269 |
if (y >= 50 && y < (w->height - 40)) { |
1392
136eaaac002c
(svn r1896) - Fix: remove Translated by hack since it's not used
Darkvater
parents:
1390
diff
changeset
|
270 |
DoDrawString(credits[i], 10, y, 0x10); |
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
271 |
} |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
272 |
y += 10; |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
273 |
} |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
274 |
|
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
|
275 |
/* If the last text has scrolled start anew from the start */ |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
980
diff
changeset
|
276 |
if (y < 50) WP(w, scroller_d).height = w->height - 40; |
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
277 |
|
2134 | 278 |
DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", 16); |
279 |
DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, 0); |
|
6492
286a52449b54
(svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents:
6491
diff
changeset
|
280 |
} break; |
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
|
281 |
case WE_MOUSELOOP: // Timer to scroll the text and adjust the new top |
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
980
diff
changeset
|
282 |
if (WP(w, scroller_d).counter++ % 3 == 0) { |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
980
diff
changeset
|
283 |
WP(w, scroller_d).height--; |
859
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
284 |
SetWindowDirty(w); |
611a03925f9a
(svn r1340) -Feature: scrolling credits list...finally! Hope nobody gets offended if I forgot them.
darkvater
parents:
842
diff
changeset
|
285 |
} |
0 | 286 |
break; |
287 |
} |
|
288 |
} |
|
289 |
||
290 |
static const Widget _about_widgets[] = { |
|
4344
7e123fec5b0b
(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
|
291 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(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
|
292 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 419, 0, 13, STR_015B_OPENTTD, STR_NULL}, |
7e123fec5b0b
(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
|
293 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 419, 14, 271, 0x0, STR_NULL}, |
7e123fec5b0b
(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
|
294 |
{ WWT_FRAME, RESIZE_NONE, 14, 5, 414, 40, 245, STR_NULL, STR_NULL}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
295 |
{ WIDGETS_END}, |
0 | 296 |
}; |
297 |
||
298 |
static const WindowDesc _about_desc = { |
|
1125 | 299 |
WDP_CENTER, WDP_CENTER, 420, 272, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
300 |
WC_GAME_OPTIONS, WC_NONE, |
0 | 301 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
302 |
_about_widgets, |
|
303 |
AboutWindowProc |
|
304 |
}; |
|
305 |
||
306 |
||
6247 | 307 |
void ShowAboutWindow() |
0 | 308 |
{ |
309 |
DeleteWindowById(WC_GAME_OPTIONS, 0); |
|
310 |
AllocateWindowDesc(&_about_desc); |
|
311 |
} |
|
312 |
||
313 |
static int _tree_to_plant; |
|
314 |
||
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
315 |
static const PalSpriteID _tree_sprites[] = { |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
316 |
{ 0x655, PAL_NONE }, { 0x663, PAL_NONE }, { 0x678, PAL_NONE }, { 0x62B, PAL_NONE }, |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
317 |
{ 0x647, PAL_NONE }, { 0x639, PAL_NONE }, { 0x64E, PAL_NONE }, { 0x632, PAL_NONE }, |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
318 |
{ 0x67F, PAL_NONE }, { 0x68D, PAL_NONE }, { 0x69B, PAL_NONE }, { 0x6A9, PAL_NONE }, |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
319 |
{ 0x6AF, PAL_NONE }, { 0x6D2, PAL_NONE }, { 0x6D9, PAL_NONE }, { 0x6C4, PAL_NONE }, |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
320 |
{ 0x6CB, PAL_NONE }, { 0x6B6, PAL_NONE }, { 0x6BD, PAL_NONE }, { 0x6E0, PAL_NONE }, |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
321 |
{ 0x72E, PAL_NONE }, { 0x734, PAL_NONE }, { 0x74A, PAL_NONE }, { 0x74F, PAL_NONE }, |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
322 |
{ 0x76B, PAL_NONE }, { 0x78F, PAL_NONE }, { 0x788, PAL_NONE }, { 0x77B, PAL_NONE }, |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
323 |
{ 0x75F, PAL_NONE }, { 0x774, PAL_NONE }, { 0x720, PAL_NONE }, { 0x797, PAL_NONE }, |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
324 |
{ 0x79E, PAL_NONE }, { 0x7A5, PALETTE_TO_GREEN }, { 0x7AC, PALETTE_TO_RED }, { 0x7B3, PAL_NONE }, |
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
325 |
{ 0x7BA, PAL_NONE }, { 0x7C1, PALETTE_TO_RED, }, { 0x7C8, PALETTE_TO_PALE_GREEN }, { 0x7CF, PALETTE_TO_YELLOW }, { 0x7D6, PALETTE_TO_RED } |
0 | 326 |
}; |
327 |
||
328 |
static void BuildTreesWndProc(Window *w, WindowEvent *e) |
|
329 |
{ |
|
2639 | 330 |
switch (e->event) { |
0 | 331 |
case WE_PAINT: { |
332 |
int x,y; |
|
333 |
int i, count; |
|
334 |
||
335 |
DrawWindowWidgets(w); |
|
336 |
||
337 |
WP(w,tree_d).base = i = _tree_base_by_landscape[_opt.landscape]; |
|
338 |
WP(w,tree_d).count = count = _tree_count_by_landscape[_opt.landscape]; |
|
339 |
||
340 |
x = 18; |
|
341 |
y = 54; |
|
342 |
do { |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
343 |
DrawSprite(_tree_sprites[i].sprite, _tree_sprites[i].pal, x, y); |
0 | 344 |
x += 35; |
345 |
if (!(++i & 3)) { |
|
2639 | 346 |
x -= 35 * 4; |
0 | 347 |
y += 47; |
348 |
} |
|
349 |
} while (--count); |
|
350 |
} break; |
|
351 |
||
352 |
case WE_CLICK: { |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
353 |
int wid = e->we.click.widget; |
0 | 354 |
|
2639 | 355 |
switch (wid) { |
0 | 356 |
case 0: |
357 |
ResetObjectToPlace(); |
|
2639 | 358 |
break; |
359 |
||
0 | 360 |
case 3: case 4: case 5: case 6: |
361 |
case 7: case 8: case 9: case 10: |
|
362 |
case 11:case 12: case 13: case 14: |
|
2639 | 363 |
if (wid - 3 >= WP(w,tree_d).count) break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
364 |
|
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
365 |
if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, 1, NULL)) |
0 | 366 |
_tree_to_plant = WP(w,tree_d).base + wid - 3; |
367 |
break; |
|
368 |
||
369 |
case 15: // tree of random type. |
|
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
370 |
if (HandlePlacePushButton(w, 15, SPR_CURSOR_TREE, 1, NULL)) |
0 | 371 |
_tree_to_plant = -1; |
372 |
break; |
|
373 |
||
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
|
374 |
case 16: // place trees randomly over the landscape |
4719
fc6e14219f72
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4672
diff
changeset
|
375 |
LowerWindowWidget(w, 16); |
0 | 376 |
w->flags4 |= 5 << WF_TIMEOUT_SHL; |
541 | 377 |
SndPlayFx(SND_15_BEEP); |
0 | 378 |
PlaceTreesRandomly(); |
379 |
MarkWholeScreenDirty(); |
|
380 |
break; |
|
381 |
} |
|
382 |
} break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
383 |
|
0 | 384 |
case WE_PLACE_OBJ: |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
385 |
VpStartPlaceSizing(e->we.place.tile, VPM_X_AND_Y_LIMITED); |
0 | 386 |
VpSetPlaceSizingLimit(20); |
387 |
break; |
|
388 |
||
389 |
case WE_PLACE_DRAG: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
390 |
VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.userdata); |
0 | 391 |
return; |
392 |
||
393 |
case WE_PLACE_MOUSEUP: |
|
4994
aec94128f5d5
(svn r7000) -Fix: Incorrect use of e->we.click when the event is a 'place'. This didn't cause any
Darkvater
parents:
4958
diff
changeset
|
394 |
if (e->we.place.pt.x != -1) { |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
395 |
DoCommandP(e->we.place.tile, _tree_to_plant, e->we.place.starttile, NULL, |
0 | 396 |
CMD_PLANT_TREE | CMD_AUTO | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE)); |
397 |
} |
|
398 |
break; |
|
399 |
||
400 |
case WE_TIMEOUT: |
|
4719
fc6e14219f72
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4672
diff
changeset
|
401 |
RaiseWindowWidget(w, 16); |
0 | 402 |
break; |
403 |
||
404 |
case WE_ABORT_PLACE_OBJ: |
|
4719
fc6e14219f72
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4672
diff
changeset
|
405 |
RaiseWindowButtons(w); |
0 | 406 |
break; |
407 |
} |
|
408 |
} |
|
409 |
||
410 |
static const Widget _build_trees_widgets[] = { |
|
4344
7e123fec5b0b
(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
|
411 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(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
|
412 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
7e123fec5b0b
(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
|
413 |
{ WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 170, 0x0, STR_NULL}, |
7e123fec5b0b
(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
|
414 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
415 |
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
416 |
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
417 |
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
418 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
419 |
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
420 |
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
421 |
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
422 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
423 |
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
424 |
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
425 |
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
426 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
427 |
{ WIDGETS_END}, |
0 | 428 |
}; |
429 |
||
430 |
static const WindowDesc _build_trees_desc = { |
|
431 |
497, 22, 143, 171, |
|
606
da90c837064c
(svn r1030) Some toolbar icons are arranged differently:
dominik
parents:
598
diff
changeset
|
432 |
WC_BUILD_TREES, WC_SCEN_LAND_GEN, |
0 | 433 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
434 |
_build_trees_widgets, |
|
435 |
BuildTreesWndProc |
|
436 |
}; |
|
437 |
||
438 |
static const Widget _build_trees_scen_widgets[] = { |
|
4344
7e123fec5b0b
(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
|
439 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(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
|
440 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
7e123fec5b0b
(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
|
441 |
{ WWT_PANEL, RESIZE_NONE, 7, 0, 142, 14, 183, 0x0, STR_NULL}, |
7e123fec5b0b
(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
|
442 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
443 |
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
444 |
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
445 |
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
446 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
447 |
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
448 |
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
449 |
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
450 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
451 |
{ WWT_PANEL, RESIZE_NONE, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
452 |
{ WWT_PANEL, RESIZE_NONE, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
453 |
{ WWT_PANEL, RESIZE_NONE, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
7e123fec5b0b
(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
|
454 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, |
7e123fec5b0b
(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
|
455 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 140, 170, 181, STR_028A_RANDOM_TREES, STR_028B_PLANT_TREES_RANDOMLY_OVER}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
456 |
{ WIDGETS_END}, |
0 | 457 |
}; |
458 |
||
459 |
static const WindowDesc _build_trees_scen_desc = { |
|
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
5039
diff
changeset
|
460 |
WDP_AUTO, WDP_AUTO, 143, 184, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
461 |
WC_BUILD_TREES, WC_NONE, |
0 | 462 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
463 |
_build_trees_scen_widgets, |
|
464 |
BuildTreesWndProc |
|
465 |
}; |
|
466 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
467 |
|
6247 | 468 |
void ShowBuildTreesToolbar() |
0 | 469 |
{ |
5005
f5086bd3945a
(svn r7022) -Fix [FS#292]: Properly guard against viewing company-sensitive information from
Darkvater
parents:
4994
diff
changeset
|
470 |
if (!IsValidPlayer(_current_player)) return; |
1846
7fcf64b5ba45
(svn r2351) -Fix: It was possible to open more than one tree window
tron
parents:
1843
diff
changeset
|
471 |
AllocateWindowDescFront(&_build_trees_desc, 0); |
0 | 472 |
} |
473 |
||
6247 | 474 |
void ShowBuildTreesScenToolbar() |
0 | 475 |
{ |
476 |
AllocateWindowDescFront(&_build_trees_scen_desc, 0); |
|
477 |
} |
|
478 |
||
674
9604d4d8de7d
(svn r1112) -Fix: _decode_parameters was increased to [20], but not all temp-dparams were
truelight
parents:
635
diff
changeset
|
479 |
static uint32 _errmsg_decode_params[20]; |
0 | 480 |
static StringID _errmsg_message_1, _errmsg_message_2; |
481 |
static uint _errmsg_duration; |
|
482 |
||
483 |
||
484 |
static const Widget _errmsg_widgets[] = { |
|
4344
7e123fec5b0b
(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
|
485 |
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(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
|
486 |
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 239, 0, 13, STR_00B2_MESSAGE, STR_NULL}, |
7e123fec5b0b
(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
|
487 |
{ WWT_PANEL, RESIZE_NONE, 4, 0, 239, 14, 45, 0x0, STR_NULL}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
488 |
{ WIDGETS_END}, |
0 | 489 |
}; |
490 |
||
491 |
static const Widget _errmsg_face_widgets[] = { |
|
4344
7e123fec5b0b
(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
|
492 |
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(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
|
493 |
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 333, 0, 13, STR_00B3_MESSAGE_FROM, STR_NULL}, |
7e123fec5b0b
(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
|
494 |
{ WWT_PANEL, RESIZE_NONE, 4, 0, 333, 14, 136, 0x0, STR_NULL}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
495 |
{ WIDGETS_END}, |
0 | 496 |
}; |
497 |
||
498 |
static void ErrmsgWndProc(Window *w, WindowEvent *e) |
|
499 |
{ |
|
2639 | 500 |
switch (e->event) { |
0 | 501 |
case WE_PAINT: |
502 |
COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params)); |
|
503 |
DrawWindowWidgets(w); |
|
504 |
COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params)); |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
505 |
if (!IsWindowOfPrototype(w, _errmsg_face_widgets)) { |
0 | 506 |
DrawStringMultiCenter( |
507 |
120, |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
508 |
(_errmsg_message_1 == INVALID_STRING_ID ? 25 : 15), |
0 | 509 |
_errmsg_message_2, |
6197
558f3a9b5bd4
(svn r8977) -Codechange: Remove the hardcoded maximum width for some drawstrings and replace them with a portion of w->width. Only visible improvement is QueryWndProc which will not write exactly to the edge of the window anymore.
Darkvater
parents:
6190
diff
changeset
|
510 |
w->width - 2); |
0 | 511 |
if (_errmsg_message_1 != INVALID_STRING_ID) |
512 |
DrawStringMultiCenter( |
|
513 |
120, |
|
514 |
30, |
|
515 |
_errmsg_message_1, |
|
6197
558f3a9b5bd4
(svn r8977) -Codechange: Remove the hardcoded maximum width for some drawstrings and replace them with a portion of w->width. Only visible improvement is QueryWndProc which will not write exactly to the edge of the window anymore.
Darkvater
parents:
6190
diff
changeset
|
516 |
w->width - 2); |
0 | 517 |
} else { |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
518 |
const Player *p = GetPlayer((PlayerID)GetDParamX(_errmsg_decode_params,2)); |
0 | 519 |
DrawPlayerFace(p->face, p->player_color, 2, 16); |
520 |
||
521 |
DrawStringMultiCenter( |
|
522 |
214, |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
523 |
(_errmsg_message_1 == INVALID_STRING_ID ? 65 : 45), |
0 | 524 |
_errmsg_message_2, |
6197
558f3a9b5bd4
(svn r8977) -Codechange: Remove the hardcoded maximum width for some drawstrings and replace them with a portion of w->width. Only visible improvement is QueryWndProc which will not write exactly to the edge of the window anymore.
Darkvater
parents:
6190
diff
changeset
|
525 |
w->width - 2); |
0 | 526 |
if (_errmsg_message_1 != INVALID_STRING_ID) |
527 |
DrawStringMultiCenter( |
|
528 |
214, |
|
529 |
90, |
|
530 |
_errmsg_message_1, |
|
6197
558f3a9b5bd4
(svn r8977) -Codechange: Remove the hardcoded maximum width for some drawstrings and replace them with a portion of w->width. Only visible improvement is QueryWndProc which will not write exactly to the edge of the window anymore.
Darkvater
parents:
6190
diff
changeset
|
531 |
w->width - 2); |
0 | 532 |
} |
533 |
break; |
|
534 |
||
535 |
case WE_MOUSELOOP: |
|
2639 | 536 |
if (_right_button_down) DeleteWindow(w); |
0 | 537 |
break; |
2639 | 538 |
|
0 | 539 |
case WE_4: |
2639 | 540 |
if (--_errmsg_duration == 0) DeleteWindow(w); |
0 | 541 |
break; |
2639 | 542 |
|
543 |
case WE_DESTROY: |
|
1860
cc2044ad6ad3
(svn r2366) Use SetRedErrorSquare() instead of home brewed version
tron
parents:
1846
diff
changeset
|
544 |
SetRedErrorSquare(0); |
172
8d8b3383470d
(svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents:
155
diff
changeset
|
545 |
_switch_mode_errorstr = INVALID_STRING_ID; |
0 | 546 |
break; |
547 |
||
548 |
case WE_KEYPRESS: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
549 |
if (e->we.keypress.keycode == WKC_SPACE) { |
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
|
550 |
/* Don't continue. */ |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
551 |
e->we.keypress.cont = false; |
0 | 552 |
DeleteWindow(w); |
553 |
} |
|
554 |
break; |
|
555 |
} |
|
556 |
} |
|
557 |
||
558 |
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y) |
|
559 |
{ |
|
560 |
Window *w; |
|
5120
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5116
diff
changeset
|
561 |
const ViewPort *vp; |
0 | 562 |
Point pt; |
563 |
||
564 |
DeleteWindowById(WC_ERRMSG, 0); |
|
565 |
||
566 |
//assert(msg_2); |
|
567 |
if (msg_2 == 0) msg_2 = STR_EMPTY; |
|
568 |
||
569 |
_errmsg_message_1 = msg_1; |
|
570 |
_errmsg_message_2 = msg_2; |
|
571 |
COPY_OUT_DPARAM(_errmsg_decode_params, 0, lengthof(_errmsg_decode_params)); |
|
572 |
_errmsg_duration = _patches.errmsg_duration; |
|
5120
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5116
diff
changeset
|
573 |
if (!_errmsg_duration) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
574 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
575 |
if (_errmsg_message_1 != STR_013B_OWNED_BY || GetDParamX(_errmsg_decode_params,2) >= 8) { |
0 | 576 |
|
577 |
if ( (x|y) != 0) { |
|
578 |
pt = RemapCoords2(x, y); |
|
5120
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5116
diff
changeset
|
579 |
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; |
0 | 580 |
|
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
|
581 |
/* move x pos to opposite corner */ |
0 | 582 |
pt.x = ((pt.x - vp->virtual_left) >> vp->zoom) + vp->left; |
583 |
pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - 260 : 20; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
584 |
|
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
|
585 |
/* move y pos to opposite corner */ |
0 | 586 |
pt.y = ((pt.y - vp->virtual_top) >> vp->zoom) + vp->top; |
587 |
pt.y = (pt.y < (_screen.height >> 1)) ? _screen.height - 80 : 100; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
588 |
|
0 | 589 |
} else { |
590 |
pt.x = (_screen.width - 240) >> 1; |
|
591 |
pt.y = (_screen.height - 46) >> 1; |
|
592 |
} |
|
593 |
w = AllocateWindow(pt.x, pt.y, 240, 46, ErrmsgWndProc, WC_ERRMSG, _errmsg_widgets); |
|
594 |
} else { |
|
595 |
if ( (x|y) != 0) { |
|
596 |
pt = RemapCoords2(x, y); |
|
5120
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5116
diff
changeset
|
597 |
vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; |
0 | 598 |
pt.x = clamp(((pt.x - vp->virtual_left) >> vp->zoom) + vp->left - (334/2), 0, _screen.width - 334); |
599 |
pt.y = clamp(((pt.y - vp->virtual_top) >> vp->zoom) + vp->top - (137/2), 22, _screen.height - 137); |
|
600 |
} else { |
|
601 |
pt.x = (_screen.width - 334) >> 1; |
|
602 |
pt.y = (_screen.height - 137) >> 1; |
|
603 |
} |
|
604 |
w = AllocateWindow(pt.x, pt.y, 334, 137, ErrmsgWndProc, WC_ERRMSG, _errmsg_face_widgets); |
|
605 |
} |
|
606 |
||
607 |
w->desc_flags = WDF_STD_BTN | WDF_DEF_WIDGET; |
|
608 |
} |
|
609 |
||
610 |
||
611 |
void ShowEstimatedCostOrIncome(int32 cost, int x, int y) |
|
612 |
{ |
|
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2475
diff
changeset
|
613 |
StringID msg = STR_0805_ESTIMATED_COST; |
0 | 614 |
|
615 |
if (cost < 0) { |
|
616 |
cost = -cost; |
|
617 |
msg = STR_0807_ESTIMATED_INCOME; |
|
618 |
} |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
619 |
SetDParam(0, cost); |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2475
diff
changeset
|
620 |
ShowErrorMessage(INVALID_STRING_ID, msg, x, y); |
0 | 621 |
} |
622 |
||
623 |
void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost) |
|
624 |
{ |
|
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2475
diff
changeset
|
625 |
StringID msg; |
0 | 626 |
Point pt = RemapCoords(x,y,z); |
627 |
||
628 |
msg = STR_0801_COST; |
|
629 |
if (cost < 0) { |
|
630 |
cost = -cost; |
|
631 |
msg = STR_0803_INCOME; |
|
632 |
} |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
633 |
SetDParam(0, cost); |
0 | 634 |
AddTextEffect(msg, pt.x, pt.y, 0x250); |
635 |
} |
|
636 |
||
1935
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1914
diff
changeset
|
637 |
void ShowFeederIncomeAnimation(int x, int y, int z, int32 cost) |
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1914
diff
changeset
|
638 |
{ |
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1914
diff
changeset
|
639 |
Point pt = RemapCoords(x,y,z); |
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1914
diff
changeset
|
640 |
|
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1914
diff
changeset
|
641 |
SetDParam(0, cost); |
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1914
diff
changeset
|
642 |
AddTextEffect(STR_FEEDER, pt.x, pt.y, 0x250); |
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1914
diff
changeset
|
643 |
} |
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1914
diff
changeset
|
644 |
|
2275
11a1dac70c45
(svn r2799) Make the only two non-const widget lists const
tron
parents:
2261
diff
changeset
|
645 |
static const Widget _tooltips_widgets[] = { |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
646 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 199, 0, 31, 0x0, STR_NULL}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
647 |
{ WIDGETS_END}, |
0 | 648 |
}; |
649 |
||
650 |
||
651 |
static void TooltipsWndProc(Window *w, WindowEvent *e) |
|
652 |
{ |
|
2639 | 653 |
switch (e->event) { |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
654 |
case WE_PAINT: { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
655 |
uint arg; |
2639 | 656 |
GfxFillRect(0, 0, w->width - 1, w->height - 1, 0); |
657 |
GfxFillRect(1, 1, w->width - 2, w->height - 2, 0x44); |
|
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
658 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
659 |
for (arg = 0; arg < WP(w, tooltips_d).paramcount; arg++) { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
660 |
SetDParam(arg, WP(w, tooltips_d).params[arg]); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
661 |
} |
6197
558f3a9b5bd4
(svn r8977) -Codechange: Remove the hardcoded maximum width for some drawstrings and replace them with a portion of w->width. Only visible improvement is QueryWndProc which will not write exactly to the edge of the window anymore.
Darkvater
parents:
6190
diff
changeset
|
662 |
DrawStringMultiCenter((w->width >> 1), (w->height >> 1) - 5, WP(w, tooltips_d).string_id, w->width - 2); |
2639 | 663 |
break; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
664 |
} |
0 | 665 |
|
2639 | 666 |
case WE_MOUSELOOP: |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
667 |
/* We can show tooltips while dragging tools. These are shown as long as |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
668 |
* we are dragging the tool. Normal tooltips work with rmb */ |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
669 |
if (WP(w, tooltips_d).paramcount == 0 ) { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
670 |
if (!_right_button_down) DeleteWindow(w); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
671 |
} else { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
672 |
if (!_left_button_down) DeleteWindow(w); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
673 |
} |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
674 |
|
2639 | 675 |
break; |
0 | 676 |
} |
677 |
} |
|
678 |
||
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
679 |
/** Shows a tooltip |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
680 |
* @param str String to be displayed |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
681 |
* @param paramcount number of params to deal with |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
682 |
* @param params (optional) up to 5 pieces of additional information that may be |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
683 |
* added to a tooltip; currently only supports parameters of {NUM} (integer) */ |
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4850
diff
changeset
|
684 |
void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint32 params[]) |
0 | 685 |
{ |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1329
diff
changeset
|
686 |
char buffer[512]; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
687 |
BoundingRect br; |
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4850
diff
changeset
|
688 |
Window *w; |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
689 |
uint i; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
690 |
int x, y; |
0 | 691 |
|
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4850
diff
changeset
|
692 |
DeleteWindowById(WC_TOOLTIPS, 0); |
0 | 693 |
|
4884
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4850
diff
changeset
|
694 |
/* We only show measurement tooltips with patch setting on */ |
94dd5df0d584
(svn r6821) -Codechange: For the measurement tool do not show the tooltip when the selection
Darkvater
parents:
4850
diff
changeset
|
695 |
if (str == STR_NULL || (paramcount != 0 && !_patches.measure_tooltip)) return; |
0 | 696 |
|
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
697 |
for (i = 0; i != paramcount; i++) SetDParam(i, params[i]); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4909
diff
changeset
|
698 |
GetString(buffer, str, lastof(buffer)); |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
699 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
700 |
br = GetStringBoundingBox(buffer); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
701 |
br.width += 6; br.height += 4; // increase slightly to have some space around the box |
0 | 702 |
|
4558
0c21ecb2b34e
(svn r6405) -Codechange: When showing tooltips, properly position the tooltip, considering
Darkvater
parents:
4416
diff
changeset
|
703 |
/* Cut tooltip length to 200 pixels max, wrap to new line if longer */ |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
704 |
if (br.width > 200) { |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
705 |
br.height += ((br.width - 4) / 176) * 10; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
706 |
br.width = 200; |
0 | 707 |
} |
708 |
||
4558
0c21ecb2b34e
(svn r6405) -Codechange: When showing tooltips, properly position the tooltip, considering
Darkvater
parents:
4416
diff
changeset
|
709 |
/* Correctly position the tooltip position, watch out for window and cursor size |
0c21ecb2b34e
(svn r6405) -Codechange: When showing tooltips, properly position the tooltip, considering
Darkvater
parents:
4416
diff
changeset
|
710 |
* Clamp value to below main toolbar and above statusbar. If tooltip would |
0c21ecb2b34e
(svn r6405) -Codechange: When showing tooltips, properly position the tooltip, considering
Darkvater
parents:
4416
diff
changeset
|
711 |
* go below window, flip it so it is shown above the cursor */ |
0c21ecb2b34e
(svn r6405) -Codechange: When showing tooltips, properly position the tooltip, considering
Darkvater
parents:
4416
diff
changeset
|
712 |
y = clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, 22, _screen.height - 12); |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
713 |
if (y + br.height > _screen.height - 12) y = _cursor.pos.y + _cursor.offs.y - br.height - 5; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
714 |
x = clamp(_cursor.pos.x - (br.width >> 1), 0, _screen.width - br.width); |
0 | 715 |
|
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
716 |
w = AllocateWindow(x, y, br.width, br.height, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
717 |
|
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
718 |
WP(w, tooltips_d).string_id = str; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
719 |
assert(sizeof(WP(w, tooltips_d).params[0]) == sizeof(params[0])); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
720 |
memcpy(WP(w, tooltips_d).params, params, sizeof(WP(w, tooltips_d).params[0]) * paramcount); |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
721 |
WP(w, tooltips_d).paramcount = paramcount; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
722 |
|
4558
0c21ecb2b34e
(svn r6405) -Codechange: When showing tooltips, properly position the tooltip, considering
Darkvater
parents:
4416
diff
changeset
|
723 |
w->flags4 &= ~WF_WHITE_BORDER_MASK; // remove white-border from tooltip |
4834
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
724 |
w->widget[0].right = br.width; |
3c6e8a547174
(svn r6758) -Feature: Add a measurement tool that will show dimensions and height
Darkvater
parents:
4719
diff
changeset
|
725 |
w->widget[0].bottom = br.height; |
0 | 726 |
} |
727 |
||
728 |
||
1556
d7c2d5289be9
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
729 |
static void DrawStationCoverageText(const AcceptedCargo accepts, |
d7c2d5289be9
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
730 |
int str_x, int str_y, uint mask) |
0 | 731 |
{ |
1556
d7c2d5289be9
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
732 |
char *b = _userstring; |
5038
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
733 |
bool first = true; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
734 |
|
1553
cf513e731bd3
(svn r2057) Add InlineString() to make _userstring construction a bit cleaner.
tron
parents:
1500
diff
changeset
|
735 |
b = InlineString(b, STR_000D_ACCEPTS); |
0 | 736 |
|
6350
04b19f551aec
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138
parents:
6332
diff
changeset
|
737 |
for (CargoID i = 0; i < NUM_CARGO; i++, mask >>= 1) { |
5038
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
738 |
if (b >= lastof(_userstring) - 5) break; |
1556
d7c2d5289be9
(svn r2060) Clean up some string construction and remove now unused macro
tron
parents:
1553
diff
changeset
|
739 |
if (accepts[i] >= 8 && mask & 1) { |
5038
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
740 |
if (first) { |
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
741 |
first = false; |
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
742 |
} else { |
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
743 |
/* Add a comma if this is not the first item */ |
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
744 |
*b++ = ','; |
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
745 |
*b++ = ' '; |
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
746 |
} |
6091
c8827d9ae04a
(svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents:
5893
diff
changeset
|
747 |
b = InlineString(b, GetCargo(i)->name); |
0 | 748 |
} |
749 |
} |
|
750 |
||
5038
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
751 |
/* If first is still true then no cargo is accepted */ |
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
752 |
if (first) b = InlineString(b, STR_00D0_NOTHING); |
0 | 753 |
|
5038
12fd4db0cdb5
(svn r7080) -Codechange: Remove negative array indexes, and only add ", " when needed, when building station acceptance lists.
peter1138
parents:
5005
diff
changeset
|
754 |
*b = '\0'; |
0 | 755 |
DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144); |
756 |
} |
|
757 |
||
568
b0d0df062880
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
758 |
void DrawStationCoverageAreaText(int sx, int sy, uint mask, int rad) { |
2873 | 759 |
TileIndex tile = TileVirtXY(_thd.pos.x, _thd.pos.y); |
2498
3ed05caa4449
(svn r3024) -Codechange: Another batch of replacements of int/uint/int16/byte/-1 with proper types and constants
tron
parents:
2475
diff
changeset
|
760 |
AcceptedCargo accepts; |
2873 | 761 |
if (tile < MapSize()) { |
3421
7968a4b5ff0a
(svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents:
3329
diff
changeset
|
762 |
GetAcceptanceAroundTiles(accepts, tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE , rad); |
0 | 763 |
DrawStationCoverageText(accepts, sx, sy, mask); |
764 |
} |
|
765 |
} |
|
766 |
||
4171 | 767 |
void CheckRedrawStationCoverage(const Window *w) |
0 | 768 |
{ |
2549 | 769 |
if (_thd.dirty & 1) { |
770 |
_thd.dirty &= ~1; |
|
0 | 771 |
SetWindowDirty(w); |
772 |
} |
|
773 |
} |
|
774 |
||
775 |
void SetVScrollCount(Window *w, int num) |
|
776 |
{ |
|
777 |
w->vscroll.count = num; |
|
778 |
num -= w->vscroll.cap; |
|
779 |
if (num < 0) num = 0; |
|
780 |
if (num < w->vscroll.pos) w->vscroll.pos = num; |
|
781 |
} |
|
782 |
||
842 | 783 |
void SetVScroll2Count(Window *w, int num) |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
784 |
{ |
842 | 785 |
w->vscroll2.count = num; |
786 |
num -= w->vscroll2.cap; |
|
787 |
if (num < 0) num = 0; |
|
788 |
if (num < w->vscroll2.pos) w->vscroll2.pos = num; |
|
789 |
} |
|
790 |
||
0 | 791 |
void SetHScrollCount(Window *w, int num) |
792 |
{ |
|
793 |
w->hscroll.count = num; |
|
794 |
num -= w->hscroll.cap; |
|
795 |
if (num < 0) num = 0; |
|
796 |
if (num < w->hscroll.pos) w->hscroll.pos = num; |
|
797 |
} |
|
798 |
||
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
799 |
/* Delete a character at the caret position in a text buf. |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
800 |
* If backspace is set, delete the character before the caret, |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
801 |
* else delete the character after it. */ |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
802 |
static void DelChar(Textbuf *tb, bool backspace) |
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
|
803 |
{ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
804 |
WChar c; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
805 |
uint width; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
806 |
size_t len; |
6214
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
807 |
char *s = tb->buf + tb->caretpos; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
808 |
|
6214
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
809 |
if (backspace) s = Utf8PrevChar(s); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
810 |
|
6214
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
811 |
len = Utf8Decode(&c, s); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
812 |
width = GetCharacterWidth(FS_NORMAL, c); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
813 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
814 |
tb->width -= width; |
6214
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
815 |
if (backspace) { |
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
816 |
tb->caretpos -= len; |
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
817 |
tb->caretxoffs -= width; |
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
818 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
819 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
820 |
/* Move the remaining characters over the marker */ |
6214
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
821 |
memmove(s, s + len, tb->length - (s - tb->buf) - len + 1); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
822 |
tb->length -= len; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
823 |
} |
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
|
824 |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
825 |
/** |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
826 |
* Delete a character from a textbuffer, either with 'Delete' or 'Backspace' |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
827 |
* The character is delete from the position the caret is at |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
828 |
* @param tb Textbuf type to be changed |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
829 |
* @param delmode Type of deletion, either WKC_BACKSPACE or WKC_DELETE |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
830 |
* @return Return true on successfull change of Textbuf, or false otherwise |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
831 |
*/ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
832 |
bool DeleteTextBufferChar(Textbuf *tb, int delmode) |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
833 |
{ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
834 |
if (delmode == WKC_BACKSPACE && tb->caretpos != 0) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
835 |
DelChar(tb, true); |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
836 |
return true; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
837 |
} else if (delmode == WKC_DELETE && tb->caretpos < tb->length) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
838 |
DelChar(tb, false); |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
839 |
return true; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
840 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
841 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
842 |
return false; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
843 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
844 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
845 |
/** |
1879
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
846 |
* Delete every character in the textbuffer |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
847 |
* @param tb Textbuf buffer to be emptied |
1879
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
848 |
*/ |
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
849 |
void DeleteTextBufferAll(Textbuf *tb) |
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
850 |
{ |
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
851 |
memset(tb->buf, 0, tb->maxlength); |
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
852 |
tb->length = tb->width = 0; |
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
853 |
tb->caretpos = tb->caretxoffs = 0; |
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
854 |
} |
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
855 |
|
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
856 |
/** |
3459
c6096d4423aa
(svn r4302) - Fix: s/maxlength/maxwidth of course, the buffer size is always set. Comment-change only
Darkvater
parents:
3458
diff
changeset
|
857 |
* Insert a character to a textbuffer. If maxwidth of the Textbuf is zero, |
c6096d4423aa
(svn r4302) - Fix: s/maxlength/maxwidth of course, the buffer size is always set. Comment-change only
Darkvater
parents:
3458
diff
changeset
|
858 |
* we don't care about the visual-length but only about the physical |
3458
26360c9a3743
(svn r4301) - Fix: the maxlength parameter of Textbuf is supposed to be the size of the buffer (so length of string + '\0'), but in the code it was a mix of both. It didn't cause any problems though, only an occasionaly one-less character than allowed. (thanks Tron for noticing)
Darkvater
parents:
3421
diff
changeset
|
859 |
* length of the string |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
860 |
* @param tb Textbuf type to be changed |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
861 |
* @param key Character to be inserted |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
862 |
* @return Return true on successfull change of Textbuf, or false otherwise |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
863 |
*/ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
864 |
bool InsertTextBufferChar(Textbuf *tb, WChar key) |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
865 |
{ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3719
diff
changeset
|
866 |
const byte charwidth = GetCharacterWidth(FS_NORMAL, key); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
867 |
size_t len = Utf8CharLen(key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
868 |
if (tb->length < (tb->maxlength - len) && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
869 |
memmove(tb->buf + tb->caretpos + len, tb->buf + tb->caretpos, tb->length - tb->caretpos + 1); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
870 |
Utf8Encode(tb->buf + tb->caretpos, key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
871 |
tb->length += len; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
872 |
tb->width += charwidth; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
873 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
874 |
tb->caretpos += len; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
875 |
tb->caretxoffs += charwidth; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
876 |
return true; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
877 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
878 |
return false; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
879 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
880 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
881 |
/** |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
882 |
* Handle text navigation with arrow keys left/right. |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
883 |
* This defines where the caret will blink and the next characer interaction will occur |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
884 |
* @param tb Textbuf type where navigation occurs |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
885 |
* @param navmode Direction in which navigation occurs WKC_LEFT, WKC_RIGHT, WKC_END, WKC_HOME |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
886 |
* @return Return true on successfull change of Textbuf, or false otherwise |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
887 |
*/ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
888 |
bool MoveTextBufferPos(Textbuf *tb, int navmode) |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
889 |
{ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
890 |
switch (navmode) { |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
891 |
case WKC_LEFT: |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
892 |
if (tb->caretpos != 0) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
893 |
WChar c; |
6214
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
894 |
const char *s = Utf8PrevChar(tb->buf + tb->caretpos); |
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
895 |
Utf8Decode(&c, s); |
1f361897ed7f
(svn r9011) -Codechange (r9003): Rework Utf8PrevChar so that it returns a pointer to the previous UTF8 character's first byte instead of a byte-length offset
Darkvater
parents:
6211
diff
changeset
|
896 |
tb->caretpos = s - tb->buf; // -= (tb->buf + tb->caretpos - s) |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
897 |
tb->caretxoffs -= GetCharacterWidth(FS_NORMAL, c); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
898 |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
899 |
return true; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
900 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
901 |
break; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
902 |
case WKC_RIGHT: |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
903 |
if (tb->caretpos < tb->length) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
904 |
WChar c; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
905 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
906 |
tb->caretpos += Utf8Decode(&c, tb->buf + tb->caretpos); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
907 |
tb->caretxoffs += GetCharacterWidth(FS_NORMAL, c); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
908 |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
909 |
return true; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
910 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
911 |
break; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
912 |
case WKC_HOME: |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
913 |
tb->caretpos = 0; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
914 |
tb->caretxoffs = 0; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
915 |
return true; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
916 |
case WKC_END: |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
917 |
tb->caretpos = tb->length; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
918 |
tb->caretxoffs = tb->width; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
919 |
return true; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
920 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
921 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
922 |
return false; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
923 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
924 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
925 |
/** |
4948
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
926 |
* Initialize the textbuffer by supplying it the buffer to write into |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
927 |
* and the maximum length of this buffer |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
928 |
* @param tb Textbuf type which is getting initialized |
4948
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
929 |
* @param buf the buffer that will be holding the data for input |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
930 |
* @param maxlength maximum length in characters of this buffer |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
931 |
* @param maxwidth maximum length in pixels of this buffer. If reached, buffer |
4958 | 932 |
* cannot grow, even if maxlength would allow because there is space. A length |
933 |
* of zero '0' means the buffer is only restricted by maxlength */ |
|
4948
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
934 |
void InitializeTextBuffer(Textbuf *tb, const char *buf, uint16 maxlength, uint16 maxwidth) |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
935 |
{ |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
936 |
tb->buf = (char*)buf; |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
937 |
tb->maxlength = maxlength; |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
938 |
tb->maxwidth = maxwidth; |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
939 |
tb->caret = true; |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
940 |
UpdateTextBufferSize(tb); |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
941 |
} |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
942 |
|
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
943 |
/** |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
944 |
* Update Textbuf type with its actual physical character and screenlength |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
945 |
* Get the count of characters in the string as well as the width in pixels. |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
946 |
* Useful when copying in a larger amount of text at once |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
947 |
* @param tb Textbuf type which length is calculated |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
948 |
*/ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
949 |
void UpdateTextBufferSize(Textbuf *tb) |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
950 |
{ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
951 |
const char *buf = tb->buf; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
952 |
WChar c = Utf8Consume(&buf); |
2630 | 953 |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
954 |
tb->width = 0; |
5447
4bdf874190e8
(svn r7700) -Fix (r7182): the caret 'randomly' jumped back and forth when getting a new randomised seed in the Generation World GUI.
rubidium
parents:
5431
diff
changeset
|
955 |
tb->length = 0; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
956 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
957 |
for (; c != '\0' && tb->length < (tb->maxlength - 1); c = Utf8Consume(&buf)) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
958 |
tb->width += GetCharacterWidth(FS_NORMAL, c); |
5447
4bdf874190e8
(svn r7700) -Fix (r7182): the caret 'randomly' jumped back and forth when getting a new randomised seed in the Generation World GUI.
rubidium
parents:
5431
diff
changeset
|
959 |
tb->length += Utf8CharLen(c); |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
960 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
961 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
962 |
tb->caretpos = tb->length; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
963 |
tb->caretxoffs = tb->width; |
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
|
964 |
} |
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
|
965 |
|
4909
955f318a24cd
(svn r6879) -Codechange: Remove the superflouos argument CharsetFilter parameter from HandleEditBoxKey
Darkvater
parents:
4884
diff
changeset
|
966 |
int HandleEditBoxKey(Window *w, querystr_d *string, int wid, WindowEvent *e) |
0 | 967 |
{ |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
968 |
e->we.keypress.cont = false; |
0 | 969 |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
970 |
switch (e->we.keypress.keycode) { |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
971 |
case WKC_ESC: return 2; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
972 |
case WKC_RETURN: case WKC_NUM_ENTER: return 1; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
973 |
case (WKC_CTRL | 'V'): |
2887
810e555d5249
(svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents:
2873
diff
changeset
|
974 |
if (InsertTextBufferClipboard(&string->text)) |
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
|
975 |
InvalidateWidget(w, wid); |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
976 |
break; |
1879
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
977 |
case (WKC_CTRL | 'U'): |
2887
810e555d5249
(svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents:
2873
diff
changeset
|
978 |
DeleteTextBufferAll(&string->text); |
1879
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
979 |
InvalidateWidget(w, wid); |
b037d07154c6
(svn r2385) - Feature: shortcut CTRL + U that clears the commandline of the current input-box. As requested by Tron.
Darkvater
parents:
1860
diff
changeset
|
980 |
break; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
981 |
case WKC_BACKSPACE: case WKC_DELETE: |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
982 |
if (DeleteTextBufferChar(&string->text, e->we.keypress.keycode)) |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
983 |
InvalidateWidget(w, wid); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
984 |
break; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
985 |
case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME: |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
986 |
if (MoveTextBufferPos(&string->text, e->we.keypress.keycode)) |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
987 |
InvalidateWidget(w, wid); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
988 |
break; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
989 |
default: |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
990 |
if (IsValidChar(e->we.keypress.key, string->afilter)) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
991 |
if (InsertTextBufferChar(&string->text, e->we.keypress.key)) { |
0 | 992 |
InvalidateWidget(w, wid); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5079
diff
changeset
|
993 |
} |
4299
91f5d2bedcff
(svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents:
4293
diff
changeset
|
994 |
} else { // key wasn't caught. Continue only if standard entry specified |
4909
955f318a24cd
(svn r6879) -Codechange: Remove the superflouos argument CharsetFilter parameter from HandleEditBoxKey
Darkvater
parents:
4884
diff
changeset
|
995 |
e->we.keypress.cont = (string->afilter == CS_ALPHANUMERAL); |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
996 |
} |
0 | 997 |
} |
998 |
||
999 |
return 0; |
|
1000 |
} |
|
1001 |
||
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1002 |
bool HandleCaret(Textbuf *tb) |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1003 |
{ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1004 |
/* caret changed? */ |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1005 |
bool b = !!(_caret_timer & 0x20); |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1006 |
|
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1007 |
if (b != tb->caret) { |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1008 |
tb->caret = b; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1009 |
return true; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1010 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1011 |
return false; |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1012 |
} |
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1013 |
|
2887
810e555d5249
(svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents:
2873
diff
changeset
|
1014 |
void HandleEditBox(Window *w, querystr_d *string, int wid) |
0 | 1015 |
{ |
2887
810e555d5249
(svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents:
2873
diff
changeset
|
1016 |
if (HandleCaret(&string->text)) InvalidateWidget(w, wid); |
0 | 1017 |
} |
1018 |
||
2887
810e555d5249
(svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents:
2873
diff
changeset
|
1019 |
void DrawEditBox(Window *w, querystr_d *string, int wid) |
0 | 1020 |
{ |
4955
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1021 |
DrawPixelInfo dpi, *old_dpi; |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1022 |
int delta; |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1023 |
const Widget *wi = &w->widget[wid]; |
2887
810e555d5249
(svn r3439) - CodeChange: Remove a whole bunch of global variables and put them into the WP() macro. Also combine more than one WP-custom element. For this the maximum size of w->custom (WP) has been increased, and multiple types put inside one with possibly moved to the corresponding gui file if it is only used there.
Darkvater
parents:
2873
diff
changeset
|
1024 |
const Textbuf *tb = &string->text; |
0 | 1025 |
|
5639
c9c55071b0ea
(svn r8098) -Fix (r6964): For editboxen, always fill the background with black, and not only after a valid call to FillDrawPixelInfo. This solves some graphics glitches with background widget-colour showing through on frequent redraws.
Darkvater
parents:
5596
diff
changeset
|
1026 |
GfxFillRect(wi->left + 1, wi->top + 1, wi->right - 1, wi->bottom - 1, 215); |
c9c55071b0ea
(svn r8098) -Fix (r6964): For editboxen, always fill the background with black, and not only after a valid call to FillDrawPixelInfo. This solves some graphics glitches with background widget-colour showing through on frequent redraws.
Darkvater
parents:
5596
diff
changeset
|
1027 |
|
4955
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1028 |
/* Limit the drawing of the string inside the widget boundaries */ |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1029 |
if (!FillDrawPixelInfo(&dpi, |
5120
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5116
diff
changeset
|
1030 |
wi->left + 4, |
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5116
diff
changeset
|
1031 |
wi->top + 1, |
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5116
diff
changeset
|
1032 |
wi->right - wi->left - 4, |
1ff65e874ce3
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5116
diff
changeset
|
1033 |
wi->bottom - wi->top - 1) |
4955
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1034 |
) return; |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1035 |
|
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1036 |
old_dpi = _cur_dpi; |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1037 |
_cur_dpi = &dpi; |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1038 |
|
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1039 |
/* We will take the current widget length as maximum width, with a small |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1040 |
* space reserved at the end for the caret to show */ |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1041 |
delta = (wi->right - wi->left) - tb->width - 10; |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1042 |
if (delta > 0) delta = 0; |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1043 |
|
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1044 |
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs; |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1045 |
|
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1046 |
DoDrawString(tb->buf, delta, 0, 8); |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1047 |
if (tb->caret) DoDrawString("_", tb->caretxoffs + delta, 0, 12); |
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1048 |
|
1ffc9ce449a8
(svn r6954) -Feature: Constrain the drawing of a string inside an editbox to the dimensions of
Darkvater
parents:
4949
diff
changeset
|
1049 |
_cur_dpi = old_dpi; |
0 | 1050 |
} |
1051 |
||
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1052 |
enum QueryStringWidgets { |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1053 |
QUERY_STR_WIDGET_TEXT = 3, |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1054 |
QUERY_STR_WIDGET_CANCEL, |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1055 |
QUERY_STR_WIDGET_OK |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1056 |
}; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1057 |
|
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1058 |
|
0 | 1059 |
static void QueryStringWndProc(Window *w, WindowEvent *e) |
1060 |
{ |
|
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1061 |
querystr_d *qs = &WP(w, querystr_d); |
0 | 1062 |
|
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1063 |
switch (e->event) { |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1064 |
case WE_CREATE: |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1065 |
SETBIT(_no_scroll, SCROLL_EDIT); |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1066 |
break; |
390
c67581486cde
(svn r582) -Fix: [ 1034318 ] place sign and blue message box
tron
parents:
337
diff
changeset
|
1067 |
|
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1068 |
case WE_PAINT: |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1069 |
SetDParam(0, qs->caption); |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1070 |
DrawWindowWidgets(w); |
598
b8c5ae66f9ff
(svn r1022) -Fix: [Network] [ 1083690 ] The password dialog made the network
truelight
parents:
596
diff
changeset
|
1071 |
|
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1072 |
DrawEditBox(w, qs, QUERY_STR_WIDGET_TEXT); |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1073 |
break; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1074 |
|
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1075 |
case WE_CLICK: |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1076 |
switch (e->we.click.widget) { |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1077 |
case QUERY_STR_WIDGET_OK: |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1078 |
press_ok:; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1079 |
if (qs->orig == NULL || strcmp(qs->text.buf, qs->orig) != 0) { |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1080 |
Window *parent = w->parent; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1081 |
qs->handled = true; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1082 |
|
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1083 |
/* If the parent is NULL, the editbox is handled by general function |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1084 |
* HandleOnEditText */ |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1085 |
if (parent != NULL) { |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1086 |
WindowEvent e; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1087 |
e.event = WE_ON_EDIT_TEXT; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1088 |
e.we.edittext.str = qs->text.buf; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1089 |
parent->wndproc(parent, &e); |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1090 |
} else { |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1091 |
HandleOnEditText(qs->text.buf); |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1092 |
} |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1093 |
} |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1094 |
/* Fallthrough */ |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1095 |
case QUERY_STR_WIDGET_CANCEL: |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1096 |
DeleteWindow(w); |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1097 |
break; |
0 | 1098 |
} |
1099 |
break; |
|
1100 |
||
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1101 |
case WE_MOUSELOOP: |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1102 |
HandleEditBox(w, qs, QUERY_STR_WIDGET_TEXT); |
0 | 1103 |
break; |
1104 |
||
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1105 |
case WE_KEYPRESS: |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1106 |
switch (HandleEditBoxKey(w, qs, QUERY_STR_WIDGET_TEXT, e)) { |
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
|
1107 |
case 1: goto press_ok; // Enter pressed, confirms change |
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
|
1108 |
case 2: DeleteWindow(w); break; // ESC pressed, closes window, abandons changes |
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1109 |
} |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1110 |
break; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1111 |
|
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
|
1112 |
case WE_DESTROY: // Call cancellation of query, if we have not handled it before |
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1113 |
if (!qs->handled && w->parent != NULL) { |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1114 |
WindowEvent e; |
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1115 |
Window *parent = w->parent; |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1116 |
|
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1117 |
qs->handled = true; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1118 |
e.event = WE_ON_EDIT_TEXT_CANCEL; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1119 |
parent->wndproc(parent, &e); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1120 |
} |
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1121 |
CLRBIT(_no_scroll, SCROLL_EDIT); |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1122 |
break; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1123 |
} |
0 | 1124 |
} |
1125 |
||
1126 |
static const Widget _query_string_widgets[] = { |
|
4344
7e123fec5b0b
(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
|
1127 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(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
|
1128 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 259, 0, 13, STR_012D, STR_NULL}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4912
diff
changeset
|
1129 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 259, 14, 29, 0x0, STR_NULL}, |
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1130 |
{ WWT_PANEL, RESIZE_NONE, 14, 2, 257, 16, 27, 0x0, STR_NULL}, |
4344
7e123fec5b0b
(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
|
1131 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 129, 30, 41, STR_012E_CANCEL, STR_NULL}, |
7e123fec5b0b
(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
|
1132 |
{ WWT_TEXTBTN, RESIZE_NONE, 14, 130, 259, 30, 41, STR_012F_OK, STR_NULL}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
1133 |
{ WIDGETS_END}, |
0 | 1134 |
}; |
1135 |
||
1136 |
static const WindowDesc _query_string_desc = { |
|
1137 |
190, 219, 260, 42, |
|
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
1138 |
WC_QUERY_STRING, WC_NONE, |
0 | 1139 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
1140 |
_query_string_widgets, |
|
1141 |
QueryStringWndProc |
|
1142 |
}; |
|
1143 |
||
1386
0de4f8541aea
(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
tron
parents:
1363
diff
changeset
|
1144 |
static char _edit_str_buf[64]; |
0 | 1145 |
|
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1146 |
/** Show a query popup window with a textbox in it. |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1147 |
* @param str StringID for the text shown in the textbox |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1148 |
* @param caption StringID of text shown in caption of querywindow |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1149 |
* @param maxlen maximum length in characters allowed. If bit 12 is set we |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1150 |
* will not check the resulting string against to original string to return success |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1151 |
* @param maxwidth maximum width in pixels allowed |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1152 |
* @param parent pointer to a Window that will handle the events (ok/cancel) of this |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1153 |
* window. If NULL, results are handled by global function HandleOnEditText |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1154 |
* @param afilter filters out unwanted character input */ |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1155 |
void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, Window *parent, CharSetFilter afilter) |
0 | 1156 |
{ |
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1157 |
static char orig_str_buf[lengthof(_edit_str_buf)]; |
0 | 1158 |
Window *w; |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1159 |
uint realmaxlen = maxlen & ~0x1000; |
0 | 1160 |
|
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1161 |
assert(realmaxlen < lengthof(_edit_str_buf)); |
0 | 1162 |
|
1163 |
DeleteWindowById(WC_QUERY_STRING, 0); |
|
1164 |
DeleteWindowById(WC_SAVELOAD, 0); |
|
1165 |
||
1386
0de4f8541aea
(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
tron
parents:
1363
diff
changeset
|
1166 |
w = AllocateWindowDesc(&_query_string_desc); |
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1167 |
w->parent = parent; |
1386
0de4f8541aea
(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
tron
parents:
1363
diff
changeset
|
1168 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4909
diff
changeset
|
1169 |
GetString(_edit_str_buf, str, lastof(_edit_str_buf)); |
4949
6bf60913767f
(svn r6938) -Codechange: Comments, typo, variable naming, whitespace, strecpy and simplification
Darkvater
parents:
4948
diff
changeset
|
1170 |
_edit_str_buf[realmaxlen - 1] = '\0'; |
596
a787fc8fba4a
(svn r1018) -Fix: Buffer overflow in edit box, because we misuse maxlen for a flag..
truelight
parents:
568
diff
changeset
|
1171 |
|
a787fc8fba4a
(svn r1018) -Fix: Buffer overflow in edit box, because we misuse maxlen for a flag..
truelight
parents:
568
diff
changeset
|
1172 |
if (maxlen & 0x1000) { |
1386
0de4f8541aea
(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
tron
parents:
1363
diff
changeset
|
1173 |
WP(w, querystr_d).orig = NULL; |
0de4f8541aea
(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
tron
parents:
1363
diff
changeset
|
1174 |
} else { |
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1175 |
strecpy(orig_str_buf, _edit_str_buf, lastof(orig_str_buf)); |
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1176 |
WP(w, querystr_d).orig = orig_str_buf; |
1386
0de4f8541aea
(svn r1890) Begin to clean up the edit box: Remove one global variable and split the combined edit/original buffer into two
tron
parents:
1363
diff
changeset
|
1177 |
} |
0 | 1178 |
|
5431
6e56b4f13dd7
(svn r7637) -Codechange: Change ShowQueryString to use a window pointer as a parent. If the
Darkvater
parents:
5429
diff
changeset
|
1179 |
LowerWindowWidget(w, QUERY_STR_WIDGET_TEXT); |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1180 |
WP(w, querystr_d).caption = caption; |
4299
91f5d2bedcff
(svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents:
4293
diff
changeset
|
1181 |
WP(w, querystr_d).afilter = afilter; |
4948
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
1182 |
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, realmaxlen, maxwidth); |
0 | 1183 |
} |
1184 |
||
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1185 |
|
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1186 |
enum QueryWidgets { |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1187 |
QUERY_WIDGET_CAPTION = 1, |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1188 |
QUERY_WIDGET_NO = 3, |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1189 |
QUERY_WIDGET_YES |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1190 |
}; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1191 |
|
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1192 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
1193 |
struct query_d { |
5473
6dc579e62412
(svn r7757) -Fix (r7621): x64 did not compile because query_d was too big. Reorder the elements
Darkvater
parents:
5469
diff
changeset
|
1194 |
void (*proc)(Window*, bool); ///< callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' clicked, false otherwise |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1195 |
StringID message; ///< message shown for query window |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1196 |
uint32 params[20]; ///< local copy of _decode_parameters |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1197 |
bool calledback; ///< has callback been executed already (internal usage for WE_DESTROY event) |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
1198 |
}; |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1199 |
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(query_d)); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1200 |
|
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1201 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1202 |
static void QueryWndProc(Window *w, WindowEvent *e) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1203 |
{ |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1204 |
query_d *q = &WP(w, query_d); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1205 |
|
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1206 |
switch (e->event) { |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1207 |
case WE_PAINT: |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1208 |
COPY_IN_DPARAM(0, q->params, lengthof(q->params)); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1209 |
DrawWindowWidgets(w); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1210 |
COPY_IN_DPARAM(0, q->params, lengthof(q->params)); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1211 |
|
6197
558f3a9b5bd4
(svn r8977) -Codechange: Remove the hardcoded maximum width for some drawstrings and replace them with a portion of w->width. Only visible improvement is QueryWndProc which will not write exactly to the edge of the window anymore.
Darkvater
parents:
6190
diff
changeset
|
1212 |
DrawStringMultiCenter(w->width / 2, (w->height / 2) - 10, q->message, w->width - 2); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1213 |
break; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1214 |
|
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1215 |
case WE_CLICK: |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1216 |
switch (e->we.click.widget) { |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1217 |
case QUERY_WIDGET_YES: |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1218 |
q->calledback = true; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1219 |
if (q->proc != NULL) q->proc(w->parent, true); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1220 |
/* Fallthrough */ |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1221 |
case QUERY_WIDGET_NO: |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1222 |
DeleteWindow(w); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1223 |
break; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1224 |
} |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1225 |
break; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1226 |
|
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
|
1227 |
case WE_KEYPRESS: // ESC closes the window, Enter confirms the action |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1228 |
switch (e->we.keypress.keycode) { |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1229 |
case WKC_RETURN: |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1230 |
case WKC_NUM_ENTER: |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1231 |
q->calledback = true; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1232 |
if (q->proc != NULL) q->proc(w->parent, true); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1233 |
/* Fallthrough */ |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1234 |
case WKC_ESC: |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1235 |
e->we.keypress.cont = false; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1236 |
DeleteWindow(w); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1237 |
break; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1238 |
} |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1239 |
break; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1240 |
|
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
|
1241 |
case WE_DESTROY: // Call callback function (if any) on window close if not yet called |
5429
a664da42d64e
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5418
diff
changeset
|
1242 |
if (!q->calledback && q->proc != NULL) { |
a664da42d64e
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5418
diff
changeset
|
1243 |
q->calledback = true; |
a664da42d64e
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5418
diff
changeset
|
1244 |
q->proc(w->parent, false); |
a664da42d64e
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5418
diff
changeset
|
1245 |
} |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1246 |
break; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1247 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1248 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1249 |
|
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1250 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1251 |
static const Widget _query_widgets[] = { |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1252 |
{ WWT_CLOSEBOX, RESIZE_NONE, 4, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1253 |
{ WWT_CAPTION, RESIZE_NONE, 4, 11, 209, 0, 13, STR_NULL, STR_NULL}, |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1254 |
{ WWT_PANEL, RESIZE_NONE, 4, 0, 209, 14, 81, 0x0, /*OVERRIDE*/STR_NULL}, |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1255 |
{WWT_PUSHTXTBTN, RESIZE_NONE, 3, 20, 90, 62, 73, STR_00C9_NO, STR_NULL}, |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1256 |
{WWT_PUSHTXTBTN, RESIZE_NONE, 3, 120, 190, 62, 73, STR_00C8_YES, STR_NULL}, |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1257 |
{ WIDGETS_END }, |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1258 |
}; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1259 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1260 |
static const WindowDesc _query_desc = { |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1261 |
WDP_CENTER, WDP_CENTER, 210, 82, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
1262 |
WC_CONFIRM_POPUP_QUERY, WC_NONE, |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1263 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_DEF_WIDGET | WDF_MODAL, |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1264 |
_query_widgets, |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1265 |
QueryWndProc |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1266 |
}; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1267 |
|
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1268 |
/** Show a modal confirmation window with standard 'yes' and 'no' buttons |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1269 |
* The window is aligned to the centre of its parent. |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1270 |
* NOTE: You cannot use BindCString as parameter for this window! |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1271 |
* @param caption string shown as window caption |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1272 |
* @param message string that will be shown for the window |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1273 |
* @param parent pointer to parent window, if this pointer is NULL the parent becomes |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1274 |
* the main window WC_MAIN_WINDOW |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
1275 |
* @param callback callback function pointer to set in the window descriptor*/ |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1276 |
void ShowQuery(StringID caption, StringID message, Window *parent, void (*callback)(Window*, bool)) |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1277 |
{ |
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1278 |
Window *w = AllocateWindowDesc(&_query_desc); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1279 |
if (w == NULL) return; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1280 |
|
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1281 |
if (parent == NULL) parent = FindWindowById(WC_MAIN_WINDOW, 0); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1282 |
w->parent = parent; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1283 |
w->left = parent->left + (parent->width / 2) - (w->width / 2); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1284 |
w->top = parent->top + (parent->height / 2) - (w->height / 2); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1285 |
|
5418
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1286 |
/* Create a backup of the variadic arguments to strings because it will be |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1287 |
* overridden pretty often. We will copy these back for drawing */ |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1288 |
COPY_OUT_DPARAM(WP(w, query_d).params, 0, lengthof(WP(w, query_d).params)); |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1289 |
w->widget[QUERY_WIDGET_CAPTION].data = caption; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1290 |
WP(w, query_d).message = message; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1291 |
WP(w, query_d).proc = callback; |
793a133c6d2a
(svn r7621) -Codechange: Rework ShowQuery into a general modal popup window. It gets passed
Darkvater
parents:
5380
diff
changeset
|
1292 |
WP(w, query_d).calledback = false; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1293 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1294 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1295 |
|
5079
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1296 |
static const Widget _load_dialog_widgets[] = { |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1297 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1298 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 256, 0, 13, STR_NULL, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1299 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 127, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1300 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 128, 256, 14, 25, STR_SORT_BY_DATE, STR_SORT_ORDER_TIP}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1301 |
{ WWT_PANEL, RESIZE_RIGHT, 14, 0, 256, 26, 47, 0x0, STR_NULL}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1302 |
{ WWT_PANEL, RESIZE_RB, 14, 0, 256, 48, 293, 0x0, STR_NULL}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1303 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 245, 256, 48, 59, SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1304 |
{ WWT_INSET, RESIZE_RB, 14, 2, 243, 50, 291, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1305 |
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 245, 256, 60, 281, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1306 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 245, 256, 282, 293, 0x0, STR_RESIZE_BUTTON}, |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1307 |
{ WIDGETS_END}, |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1308 |
}; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1309 |
|
0 | 1310 |
static const Widget _save_dialog_widgets[] = { |
5079
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1311 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1312 |
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 256, 0, 13, STR_NULL, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1313 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 127, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1314 |
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 128, 256, 14, 25, STR_SORT_BY_DATE, STR_SORT_ORDER_TIP}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1315 |
{ WWT_PANEL, RESIZE_RIGHT, 14, 0, 256, 26, 47, 0x0, STR_NULL}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1316 |
{ WWT_PANEL, RESIZE_RB, 14, 0, 256, 48, 291, 0x0, STR_NULL}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1317 |
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 245, 256, 48, 59, SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1318 |
{ WWT_INSET, RESIZE_RB, 14, 2, 243, 50, 290, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1319 |
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 245, 256, 60, 291, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1320 |
{ WWT_PANEL, RESIZE_RTB, 14, 0, 256, 292, 307, 0x0, STR_NULL}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1321 |
{ WWT_PANEL, RESIZE_RTB, 14, 2, 254, 294, 305, 0x0, STR_400B_CURRENTLY_SELECTED_NAME}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1322 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 127, 308, 319, STR_4003_DELETE, STR_400C_DELETE_THE_CURRENTLY_SELECTED}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1323 |
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 128, 244, 308, 319, STR_4002_SAVE, STR_400D_SAVE_THE_CURRENT_GAME_USING}, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1324 |
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 245, 256, 308, 319, 0x0, STR_RESIZE_BUTTON}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
172
diff
changeset
|
1325 |
{ WIDGETS_END}, |
0 | 1326 |
}; |
1327 |
||
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
|
1328 |
/* Colors for fios types */ |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1329 |
const byte _fios_colors[] = {13, 9, 9, 6, 5, 6, 5, 6, 6, 8}; |
2261
d3554e5d3e86
(svn r2781) Fix some of the issues with variables in .h files.
ludde
parents:
2255
diff
changeset
|
1330 |
|
6247 | 1331 |
void BuildFileList() |
0 | 1332 |
{ |
1596
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1333 |
_fios_path_changed = true; |
0 | 1334 |
FiosFreeSavegameList(); |
4223
d4c9ef555f43
(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents:
4217
diff
changeset
|
1335 |
|
2549 | 1336 |
switch (_saveload_mode) { |
1337 |
case SLD_NEW_GAME: |
|
1338 |
case SLD_LOAD_SCENARIO: |
|
1339 |
case SLD_SAVE_SCENARIO: |
|
4223
d4c9ef555f43
(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents:
4217
diff
changeset
|
1340 |
_fios_list = FiosGetScenarioList(_saveload_mode); break; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1341 |
case SLD_LOAD_HEIGHTMAP: |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1342 |
_fios_list = FiosGetHeightmapList(_saveload_mode); break; |
2549 | 1343 |
|
4223
d4c9ef555f43
(svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents:
4217
diff
changeset
|
1344 |
default: _fios_list = FiosGetSavegameList(_saveload_mode); break; |
2549 | 1345 |
} |
0 | 1346 |
} |
1347 |
||
2100
217ea6fdfd18
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2070
diff
changeset
|
1348 |
static void DrawFiosTexts(uint maxw) |
0 | 1349 |
{ |
1596
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1350 |
static const char *path = NULL; |
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1351 |
static StringID str = STR_4006_UNABLE_TO_READ_DRIVE; |
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1352 |
static uint32 tot = 0; |
0 | 1353 |
|
1596
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1354 |
if (_fios_path_changed) { |
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1355 |
str = FiosGetDescText(&path, &tot); |
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1356 |
_fios_path_changed = false; |
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1357 |
} |
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1358 |
|
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1359 |
if (str != STR_4006_UNABLE_TO_READ_DRIVE) SetDParam(0, tot); |
483007886b59
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
darkvater
parents:
1594
diff
changeset
|
1360 |
DrawString(2, 37, str, 0); |
2103
a2b3106d33d5
(svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents:
2100
diff
changeset
|
1361 |
DoDrawStringTruncated(path, 2, 27, 16, maxw); |
0 | 1362 |
} |
1363 |
||
6247 | 1364 |
static void MakeSortedSaveGameList() |
0 | 1365 |
{ |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1366 |
uint sort_start = 0; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1367 |
uint sort_end = 0; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1368 |
uint s_amount; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1369 |
int i; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1370 |
|
4171 | 1371 |
/* Directories are always above the files (FIOS_TYPE_DIR) |
1372 |
* Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE) |
|
1373 |
* Only sort savegames/scenarios, not directories |
|
0 | 1374 |
*/ |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1375 |
for (i = 0; i < _fios_num; i++) { |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1376 |
switch (_fios_list[i].type) { |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1377 |
case FIOS_TYPE_DIR: sort_start++; break; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1378 |
case FIOS_TYPE_PARENT: sort_start++; break; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1379 |
case FIOS_TYPE_DRIVE: sort_end++; break; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1380 |
} |
0 | 1381 |
} |
1382 |
||
1383 |
s_amount = _fios_num - sort_start - sort_end; |
|
1105 | 1384 |
if (s_amount > 0) |
0 | 1385 |
qsort(_fios_list + sort_start, s_amount, sizeof(FiosItem), compare_FiosItems); |
1386 |
} |
|
1387 |
||
6247 | 1388 |
static void GenerateFileName() |
402
457f7c7022e3
(svn r594) -Fix/Feature: [ 1066121 ] Resetting file name after deleting a file
tron
parents:
390
diff
changeset
|
1389 |
{ |
635
38f9209f5caa
(svn r1066) -Fix: Crash when saving game as spectator (tnx to GeniusDex for reporting)
truelight
parents:
606
diff
changeset
|
1390 |
/* Check if we are not a specatator who wants to generate a name.. |
38f9209f5caa
(svn r1066) -Fix: Crash when saving game as spectator (tnx to GeniusDex for reporting)
truelight
parents:
606
diff
changeset
|
1391 |
Let's use the name of player #0 for now. */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1392 |
const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST); |
635
38f9209f5caa
(svn r1066) -Fix: Crash when saving game as spectator (tnx to GeniusDex for reporting)
truelight
parents:
606
diff
changeset
|
1393 |
|
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1394 |
SetDParam(0, p->name_1); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1395 |
SetDParam(1, p->name_2); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
1396 |
SetDParam(2, _date); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4909
diff
changeset
|
1397 |
GetString(_edit_str_buf, STR_4004, lastof(_edit_str_buf)); |
402
457f7c7022e3
(svn r594) -Fix/Feature: [ 1066121 ] Resetting file name after deleting a file
tron
parents:
390
diff
changeset
|
1398 |
} |
457f7c7022e3
(svn r594) -Fix/Feature: [ 1066121 ] Resetting file name after deleting a file
tron
parents:
390
diff
changeset
|
1399 |
|
6247 | 1400 |
extern void StartupEngines(); |
1131
305545b1f671
(svn r1632) -Fix: [1108008] Scenario creation bug; engines are of correct year when scenario is saved
darkvater
parents:
1126
diff
changeset
|
1401 |
|
0 | 1402 |
static void SaveLoadDlgWndProc(Window *w, WindowEvent *e) |
1403 |
{ |
|
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1404 |
static FiosItem o_dir; |
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1405 |
|
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1406 |
switch (e->event) { |
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
|
1407 |
case WE_CREATE: { // Set up OPENTTD button |
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1408 |
o_dir.type = FIOS_TYPE_DIRECT; |
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1409 |
switch (_saveload_mode) { |
2639 | 1410 |
case SLD_SAVE_GAME: |
1411 |
case SLD_LOAD_GAME: |
|
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5269
diff
changeset
|
1412 |
ttd_strlcpy(&o_dir.name[0], _paths.save_dir, sizeof(o_dir.name)); |
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1413 |
break; |
2639 | 1414 |
|
1415 |
case SLD_SAVE_SCENARIO: |
|
1416 |
case SLD_LOAD_SCENARIO: |
|
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5269
diff
changeset
|
1417 |
ttd_strlcpy(&o_dir.name[0], _paths.scenario_dir, sizeof(o_dir.name)); |
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1418 |
break; |
2639 | 1419 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1420 |
case SLD_LOAD_HEIGHTMAP: |
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5269
diff
changeset
|
1421 |
ttd_strlcpy(&o_dir.name[0], _paths.heightmap_dir, sizeof(o_dir.name)); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1422 |
break; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1423 |
|
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1424 |
default: |
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5269
diff
changeset
|
1425 |
ttd_strlcpy(&o_dir.name[0], _paths.personal_dir, sizeof(o_dir.name)); |
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1426 |
} |
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1427 |
break; |
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1428 |
} |
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1429 |
|
0 | 1430 |
case WE_PAINT: { |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
1431 |
int pos; |
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
1432 |
int y; |
0 | 1433 |
|
1434 |
SetVScrollCount(w, _fios_num); |
|
1435 |
DrawWindowWidgets(w); |
|
2100
217ea6fdfd18
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2070
diff
changeset
|
1436 |
DrawFiosTexts(w->width); |
0 | 1437 |
|
1438 |
if (_savegame_sort_dirty) { |
|
1439 |
_savegame_sort_dirty = false; |
|
1440 |
MakeSortedSaveGameList(); |
|
1441 |
} |
|
1442 |
||
2750
f682b3cc8ff1
(svn r3295) - Regressionfix: scrolling with mousewheel no longer worked in saveload dialogs because of restriction that scroller is only active for widget + next widget is scrollbar. Yes, we need a better window system.
Darkvater
parents:
2748
diff
changeset
|
1443 |
GfxFillRect(w->widget[7].left + 1, w->widget[7].top + 1, w->widget[7].right, w->widget[7].bottom, 0xD7); |
2526
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2498
diff
changeset
|
1444 |
DoDrawString( |
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2498
diff
changeset
|
1445 |
_savegame_sort_order & SORT_DESCENDING ? DOWNARROW : UPARROW, |
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2498
diff
changeset
|
1446 |
_savegame_sort_order & SORT_BY_NAME ? w->widget[2].right - 9 : w->widget[3].right - 9, |
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2498
diff
changeset
|
1447 |
15, 16 |
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2498
diff
changeset
|
1448 |
); |
0 | 1449 |
|
2750
f682b3cc8ff1
(svn r3295) - Regressionfix: scrolling with mousewheel no longer worked in saveload dialogs because of restriction that scroller is only active for widget + next widget is scrollbar. Yes, we need a better window system.
Darkvater
parents:
2748
diff
changeset
|
1450 |
y = w->widget[7].top + 1; |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
1451 |
for (pos = w->vscroll.pos; pos < _fios_num; pos++) { |
4171 | 1452 |
const FiosItem *item = _fios_list + pos; |
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
1453 |
|
2103
a2b3106d33d5
(svn r2613) - Truncate savegames, and vehicle-texts in their window.
Darkvater
parents:
2100
diff
changeset
|
1454 |
DoDrawStringTruncated(item->title, 4, y, _fios_colors[item->type], w->width - 18); |
2549 | 1455 |
y += 10; |
2750
f682b3cc8ff1
(svn r3295) - Regressionfix: scrolling with mousewheel no longer worked in saveload dialogs because of restriction that scroller is only active for widget + next widget is scrollbar. Yes, we need a better window system.
Darkvater
parents:
2748
diff
changeset
|
1456 |
if (y >= w->vscroll.cap * 10 + w->widget[7].top + 1) break; |
0 | 1457 |
} |
1458 |
||
1459 |
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { |
|
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6481
diff
changeset
|
1460 |
DrawEditBox(w, &WP(w, querystr_d), 10); |
0 | 1461 |
} |
1462 |
break; |
|
1463 |
} |
|
4000
4009d092b306
(svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents:
3890
diff
changeset
|
1464 |
|
0 | 1465 |
case WE_CLICK: |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1466 |
switch (e->we.click.widget) { |
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
|
1467 |
case 2: // Sort save names by name |
2526
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2498
diff
changeset
|
1468 |
_savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ? |
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2498
diff
changeset
|
1469 |
SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME; |
0 | 1470 |
_savegame_sort_dirty = true; |
1471 |
SetWindowDirty(w); |
|
1472 |
break; |
|
1473 |
||
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
|
1474 |
case 3: // Sort save names by date |
2526
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2498
diff
changeset
|
1475 |
_savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ? |
29eef390cabb
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
tron
parents:
2498
diff
changeset
|
1476 |
SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE; |
0 | 1477 |
_savegame_sort_dirty = true; |
1478 |
SetWindowDirty(w); |
|
1479 |
break; |
|
1480 |
||
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
|
1481 |
case 6: // OpenTTD 'button', jumps to OpenTTD directory |
2750
f682b3cc8ff1
(svn r3295) - Regressionfix: scrolling with mousewheel no longer worked in saveload dialogs because of restriction that scroller is only active for widget + next widget is scrollbar. Yes, we need a better window system.
Darkvater
parents:
2748
diff
changeset
|
1482 |
FiosBrowseTo(&o_dir); |
f682b3cc8ff1
(svn r3295) - Regressionfix: scrolling with mousewheel no longer worked in saveload dialogs because of restriction that scroller is only active for widget + next widget is scrollbar. Yes, we need a better window system.
Darkvater
parents:
2748
diff
changeset
|
1483 |
SetWindowDirty(w); |
f682b3cc8ff1
(svn r3295) - Regressionfix: scrolling with mousewheel no longer worked in saveload dialogs because of restriction that scroller is only active for widget + next widget is scrollbar. Yes, we need a better window system.
Darkvater
parents:
2748
diff
changeset
|
1484 |
BuildFileList(); |
f682b3cc8ff1
(svn r3295) - Regressionfix: scrolling with mousewheel no longer worked in saveload dialogs because of restriction that scroller is only active for widget + next widget is scrollbar. Yes, we need a better window system.
Darkvater
parents:
2748
diff
changeset
|
1485 |
break; |
f682b3cc8ff1
(svn r3295) - Regressionfix: scrolling with mousewheel no longer worked in saveload dialogs because of restriction that scroller is only active for widget + next widget is scrollbar. Yes, we need a better window system.
Darkvater
parents:
2748
diff
changeset
|
1486 |
|
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
|
1487 |
case 7: { // Click the listbox |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1488 |
int y = (e->we.click.pt.y - w->widget[e->we.click.widget].top - 1) / 10; |
0 | 1489 |
char *name; |
1490 |
const FiosItem *file; |
|
1491 |
||
2639 | 1492 |
if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count) return; |
0 | 1493 |
|
1494 |
file = _fios_list + y; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
1495 |
|
2639 | 1496 |
name = FiosBrowseTo(file); |
1497 |
if (name != NULL) { |
|
2100
217ea6fdfd18
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2070
diff
changeset
|
1498 |
if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) { |
217ea6fdfd18
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2070
diff
changeset
|
1499 |
_switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD; |
217ea6fdfd18
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2070
diff
changeset
|
1500 |
|
0 | 1501 |
SetFiosType(file->type); |
2100
217ea6fdfd18
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2070
diff
changeset
|
1502 |
ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name)); |
217ea6fdfd18
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2070
diff
changeset
|
1503 |
ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title)); |
217ea6fdfd18
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2070
diff
changeset
|
1504 |
|
0 | 1505 |
DeleteWindow(w); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1506 |
} else if (_saveload_mode == SLD_LOAD_HEIGHTMAP) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1507 |
SetFiosType(file->type); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1508 |
ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name)); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1509 |
ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title)); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1510 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1511 |
DeleteWindow(w); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1512 |
ShowHeightmapLoad(); |
0 | 1513 |
} else { |
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
|
1514 |
/* SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox */ |
3287
609b5f5fdccb
(svn r4001) - Add length parameter to FiosMakeSavegameName() and use this function for creating the full path instead of home-brewn snprintf.
Darkvater
parents:
3193
diff
changeset
|
1515 |
ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength); |
1390
e7cdf3ce0fb6
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents:
1386
diff
changeset
|
1516 |
UpdateTextBufferSize(&WP(w, querystr_d).text); |
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1517 |
InvalidateWidget(w, 10); |
0 | 1518 |
} |
1519 |
} else { |
|
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
|
1520 |
/* Changed directory, need repaint. */ |
0 | 1521 |
SetWindowDirty(w); |
1522 |
BuildFileList(); |
|
1523 |
} |
|
1524 |
break; |
|
1525 |
} |
|
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1526 |
|
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
|
1527 |
case 11: case 12: // Delete, Save game |
0 | 1528 |
break; |
1529 |
} |
|
1530 |
break; |
|
1531 |
case WE_MOUSELOOP: |
|
5230
080fa7517b4e
(svn r7350) -Fix: do not handle the save game/scenario filename edit box when loading a game/scenario/heightmap.
rubidium
parents:
5167
diff
changeset
|
1532 |
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { |
080fa7517b4e
(svn r7350) -Fix: do not handle the save game/scenario filename edit box when loading a game/scenario/heightmap.
rubidium
parents:
5167
diff
changeset
|
1533 |
HandleEditBox(w, &WP(w, querystr_d), 10); |
080fa7517b4e
(svn r7350) -Fix: do not handle the save game/scenario filename edit box when loading a game/scenario/heightmap.
rubidium
parents:
5167
diff
changeset
|
1534 |
} |
0 | 1535 |
break; |
1536 |
case WE_KEYPRESS: |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1537 |
if (e->we.keypress.keycode == WKC_ESC) { |
2165
ae3653f5ee34
(svn r2675) - Fix: pressing enter on a load-window resulted in saving the game (Luca)
Darkvater
parents:
2163
diff
changeset
|
1538 |
DeleteWindow(w); |
ae3653f5ee34
(svn r2675) - Fix: pressing enter on a load-window resulted in saving the game (Luca)
Darkvater
parents:
2163
diff
changeset
|
1539 |
return; |
ae3653f5ee34
(svn r2675) - Fix: pressing enter on a load-window resulted in saving the game (Luca)
Darkvater
parents:
2163
diff
changeset
|
1540 |
} |
ae3653f5ee34
(svn r2675) - Fix: pressing enter on a load-window resulted in saving the game (Luca)
Darkvater
parents:
2163
diff
changeset
|
1541 |
|
ae3653f5ee34
(svn r2675) - Fix: pressing enter on a load-window resulted in saving the game (Luca)
Darkvater
parents:
2163
diff
changeset
|
1542 |
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { |
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
|
1543 |
if (HandleEditBoxKey(w, &WP(w, querystr_d), 10, e) == 1) // Press Enter |
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1544 |
HandleButtonClick(w, 12); |
0 | 1545 |
} |
1546 |
break; |
|
1547 |
case WE_TIMEOUT: |
|
5039
6681c1fc24ed
(svn r7083) -Fix 6631: Protect out of boundaries widget testing
belugas
parents:
5038
diff
changeset
|
1548 |
/* This test protects against using widgets 11 and 12 which are only available |
6681c1fc24ed
(svn r7083) -Fix 6631: Protect out of boundaries widget testing
belugas
parents:
5038
diff
changeset
|
1549 |
* in those two saveload mode */ |
6681c1fc24ed
(svn r7083) -Fix 6631: Protect out of boundaries widget testing
belugas
parents:
5038
diff
changeset
|
1550 |
if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) break; |
6681c1fc24ed
(svn r7083) -Fix 6631: Protect out of boundaries widget testing
belugas
parents:
5038
diff
changeset
|
1551 |
|
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
|
1552 |
if (IsWindowWidgetLowered(w, 11)) { // Delete button clicked |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6481
diff
changeset
|
1553 |
if (!FiosDelete(WP(w, querystr_d).text.buf)) { |
2255
fd5d5adee9d9
(svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents:
2201
diff
changeset
|
1554 |
ShowErrorMessage(INVALID_STRING_ID, STR_4008_UNABLE_TO_DELETE_FILE, 0, 0); |
3288
5e0c047edca4
(svn r4002) - Fix: Use the title of a savegame in the saveload dialog-editbox. This gets rid of the '.sav' appended to each game as well as properly showing UTF-8 saves when this is implemented. Also don't change the text if the save has failed.
Darkvater
parents:
3287
diff
changeset
|
1555 |
} else { |
5e0c047edca4
(svn r4002) - Fix: Use the title of a savegame in the saveload dialog-editbox. This gets rid of the '.sav' appended to each game as well as properly showing UTF-8 saves when this is implemented. Also don't change the text if the save has failed.
Darkvater
parents:
3287
diff
changeset
|
1556 |
BuildFileList(); |
5e0c047edca4
(svn r4002) - Fix: Use the title of a savegame in the saveload dialog-editbox. This gets rid of the '.sav' appended to each game as well as properly showing UTF-8 saves when this is implemented. Also don't change the text if the save has failed.
Darkvater
parents:
3287
diff
changeset
|
1557 |
/* Reset file name to current date on successfull delete */ |
5e0c047edca4
(svn r4002) - Fix: Use the title of a savegame in the saveload dialog-editbox. This gets rid of the '.sav' appended to each game as well as properly showing UTF-8 saves when this is implemented. Also don't change the text if the save has failed.
Darkvater
parents:
3287
diff
changeset
|
1558 |
if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName(); |
2255
fd5d5adee9d9
(svn r2775) Deleting a file can fail, display an error message when it happens
tron
parents:
2201
diff
changeset
|
1559 |
} |
3288
5e0c047edca4
(svn r4002) - Fix: Use the title of a savegame in the saveload dialog-editbox. This gets rid of the '.sav' appended to each game as well as properly showing UTF-8 saves when this is implemented. Also don't change the text if the save has failed.
Darkvater
parents:
3287
diff
changeset
|
1560 |
|
5e0c047edca4
(svn r4002) - Fix: Use the title of a savegame in the saveload dialog-editbox. This gets rid of the '.sav' appended to each game as well as properly showing UTF-8 saves when this is implemented. Also don't change the text if the save has failed.
Darkvater
parents:
3287
diff
changeset
|
1561 |
UpdateTextBufferSize(&WP(w, querystr_d).text); |
0 | 1562 |
SetWindowDirty(w); |
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
|
1563 |
} else if (IsWindowWidgetLowered(w, 12)) { // Save button clicked |
0 | 1564 |
_switch_mode = SM_SAVE; |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6481
diff
changeset
|
1565 |
FiosMakeSavegameName(_file_to_saveload.name, WP(w, querystr_d).text.buf, sizeof(_file_to_saveload.name)); |
1131
305545b1f671
(svn r1632) -Fix: [1108008] Scenario creation bug; engines are of correct year when scenario is saved
darkvater
parents:
1126
diff
changeset
|
1566 |
|
305545b1f671
(svn r1632) -Fix: [1108008] Scenario creation bug; engines are of correct year when scenario is saved
darkvater
parents:
1126
diff
changeset
|
1567 |
/* In the editor set up the vehicle engines correctly (date might have changed) */ |
305545b1f671
(svn r1632) -Fix: [1108008] Scenario creation bug; engines are of correct year when scenario is saved
darkvater
parents:
1126
diff
changeset
|
1568 |
if (_game_mode == GM_EDITOR) StartupEngines(); |
0 | 1569 |
} |
1570 |
break; |
|
1571 |
case WE_DESTROY: |
|
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
|
1572 |
/* pause is only used in single-player, non-editor mode, non menu mode */ |
2952 | 1573 |
if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) { |
278
a0a9b0d903aa
(svn r284) Fix: on opening the saveload dialog the game pauses again in single player games
dominik
parents:
258
diff
changeset
|
1574 |
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
2952 | 1575 |
} |
0 | 1576 |
FiosFreeSavegameList(); |
1397
fa8539dcab46
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1392
diff
changeset
|
1577 |
CLRBIT(_no_scroll, SCROLL_SAVE); |
0 | 1578 |
break; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1579 |
case WE_RESIZE: { |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1580 |
/* Widget 2 and 3 have to go with halve speed, make it so obiwan */ |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1581 |
uint diff = e->we.sizing.diff.x / 2; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1582 |
w->widget[2].right += diff; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1583 |
w->widget[3].left += diff; |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1584 |
w->widget[3].right += e->we.sizing.diff.x; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1585 |
|
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1586 |
/* Same for widget 11 and 12 in save-dialog */ |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1587 |
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { |
2559
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1588 |
w->widget[11].right += diff; |
fe757666278c
(svn r3096) - Feature: 'HOME' icon to saveload dialogs that jumps to the default save/load directory based on the dialog (added icon to openttd.grf, introduced FIOS_TYPE_DIRECT that allows arbitrary directory jumping).
Darkvater
parents:
2549
diff
changeset
|
1589 |
w->widget[12].left += diff; |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1590 |
w->widget[12].right += e->we.sizing.diff.x; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1591 |
} |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1592 |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1593 |
w->vscroll.cap += e->we.sizing.diff.y / 10; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1594 |
} break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
1595 |
} |
0 | 1596 |
} |
1597 |
||
1598 |
static const WindowDesc _load_dialog_desc = { |
|
1599 |
WDP_CENTER, WDP_CENTER, 257, 294, |
|
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
1600 |
WC_SAVELOAD, WC_NONE, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1601 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
5079
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1602 |
_load_dialog_widgets, |
0 | 1603 |
SaveLoadDlgWndProc, |
1604 |
}; |
|
1605 |
||
1606 |
static const WindowDesc _save_dialog_desc = { |
|
1607 |
WDP_CENTER, WDP_CENTER, 257, 320, |
|
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
1608 |
WC_SAVELOAD, WC_NONE, |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1609 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
0 | 1610 |
_save_dialog_widgets, |
1611 |
SaveLoadDlgWndProc, |
|
1612 |
}; |
|
1613 |
||
1614 |
void ShowSaveLoadDialog(int mode) |
|
1615 |
{ |
|
5079
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1616 |
static const StringID saveload_captions[] = { |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1617 |
STR_4001_LOAD_GAME, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1618 |
STR_0298_LOAD_SCENARIO, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1619 |
STR_4000_SAVE_GAME, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1620 |
STR_0299_SAVE_SCENARIO, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1621 |
STR_4011_LOAD_HEIGHTMAP, |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1622 |
}; |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1623 |
|
0 | 1624 |
Window *w; |
5079
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1625 |
const WindowDesc *sld = &_save_dialog_desc; |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1626 |
|
0 | 1627 |
|
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
1628 |
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, 0, WC_MAIN_WINDOW, 0); |
0 | 1629 |
DeleteWindowById(WC_QUERY_STRING, 0); |
1630 |
DeleteWindowById(WC_SAVELOAD, 0); |
|
1631 |
||
1632 |
_saveload_mode = mode; |
|
1397
fa8539dcab46
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1392
diff
changeset
|
1633 |
SETBIT(_no_scroll, SCROLL_SAVE); |
fa8539dcab46
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1392
diff
changeset
|
1634 |
|
fa8539dcab46
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1392
diff
changeset
|
1635 |
switch (mode) { |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1636 |
case SLD_SAVE_GAME: GenerateFileName(); break; |
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1637 |
case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break; |
5079
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1638 |
default: sld = &_load_dialog_desc; break; |
1397
fa8539dcab46
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1392
diff
changeset
|
1639 |
} |
0 | 1640 |
|
5079
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1641 |
assert((uint)mode < lengthof(saveload_captions)); |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1642 |
w = AllocateWindowDesc(sld); |
15816766b4ee
(svn r7143) -CodeChange: remove redondancy in saveload dialogs
glx
parents:
5070
diff
changeset
|
1643 |
w->widget[1].data = saveload_captions[mode]; |
0 | 1644 |
w->vscroll.cap = 24; |
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1645 |
w->resize.step_width = 2; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1646 |
w->resize.step_height = 10; |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
860
diff
changeset
|
1647 |
w->resize.height = w->height - 14 * 10; // Minimum of 10 items |
4719
fc6e14219f72
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4672
diff
changeset
|
1648 |
LowerWindowWidget(w, 7); |
4948
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
1649 |
|
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
1650 |
WP(w, querystr_d).afilter = CS_ALPHANUMERAL; |
22ff05c1a3b1
(svn r6937) -Codechange: Add an InitializeTextBuffer() function that handles setting up the
Darkvater
parents:
4939
diff
changeset
|
1651 |
InitializeTextBuffer(&WP(w, querystr_d).text, _edit_str_buf, lengthof(_edit_str_buf), 240); |
0 | 1652 |
|
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
|
1653 |
/* pause is only used in single-player, non-editor mode, non-menu mode. It |
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
|
1654 |
* will be unpaused in the WE_DESTROY event handler. */ |
2639 | 1655 |
if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) { |
278
a0a9b0d903aa
(svn r284) Fix: on opening the saveload dialog the game pauses again in single player games
dominik
parents:
258
diff
changeset
|
1656 |
DoCommandP(0, 1, 0, NULL, CMD_PAUSE); |
2639 | 1657 |
} |
278
a0a9b0d903aa
(svn r284) Fix: on opening the saveload dialog the game pauses again in single player games
dominik
parents:
258
diff
changeset
|
1658 |
|
0 | 1659 |
BuildFileList(); |
1660 |
||
1661 |
ResetObjectToPlace(); |
|
1662 |
} |
|
1663 |
||
6247 | 1664 |
void RedrawAutosave() |
0 | 1665 |
{ |
1666 |
SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0)); |
|
1667 |
} |
|
1668 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
1669 |
void SetFiosType(const byte fiostype) |
0 | 1670 |
{ |
1671 |
switch (fiostype) { |
|
2549 | 1672 |
case FIOS_TYPE_FILE: |
1673 |
case FIOS_TYPE_SCENARIO: |
|
1674 |
_file_to_saveload.mode = SL_LOAD; |
|
1675 |
break; |
|
1676 |
||
1677 |
case FIOS_TYPE_OLDFILE: |
|
1678 |
case FIOS_TYPE_OLD_SCENARIO: |
|
1679 |
_file_to_saveload.mode = SL_OLD_LOAD; |
|
1680 |
break; |
|
1681 |
||
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1682 |
#ifdef WITH_PNG |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1683 |
case FIOS_TYPE_PNG: |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1684 |
_file_to_saveload.mode = SL_PNG; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1685 |
break; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1686 |
#endif /* WITH_PNG */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1687 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1688 |
case FIOS_TYPE_BMP: |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1689 |
_file_to_saveload.mode = SL_BMP; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1690 |
break; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4299
diff
changeset
|
1691 |
|
2549 | 1692 |
default: |
1693 |
_file_to_saveload.mode = SL_INVALID; |
|
1694 |
break; |
|
0 | 1695 |
} |
1696 |
} |
|
1697 |
||
410 | 1698 |
static int32 ClickMoneyCheat(int32 p1, int32 p2) |
0 | 1699 |
{ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1700 |
DoCommandP(0, 10000000, 0, NULL, CMD_MONEY_CHEAT); |
0 | 1701 |
return true; |
1702 |
} |
|
1703 |
||
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
|
1704 |
/** |
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
|
1705 |
* @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
|
1706 |
* @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
|
1707 |
*/ |
410 | 1708 |
static int32 ClickChangePlayerCheat(int32 p1, int32 p2) |
0 | 1709 |
{ |
4850
93095755db8c
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4834
diff
changeset
|
1710 |
while (IsValidPlayer((PlayerID)p1)) { |
2639 | 1711 |
if (_players[p1].is_active) { |
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
|
1712 |
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
|
1713 |
|
138
6ab4d97d1034
(svn r139) Added MarkWholeScreenDirty() on switch player screen
dominik
parents:
108
diff
changeset
|
1714 |
MarkWholeScreenDirty(); |
0 | 1715 |
return _local_player; |
1716 |
} |
|
1717 |
p1 += p2; |
|
1718 |
} |
|
155
81e9878f3678
(svn r156) -Codechange: remove obsolete callback arrays
darkvater
parents:
147
diff
changeset
|
1719 |
|
81e9878f3678
(svn r156) -Codechange: remove obsolete callback arrays
darkvater
parents:
147
diff
changeset
|
1720 |
return _local_player; |
0 | 1721 |
} |
1722 |
||
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
|
1723 |
/** |
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
|
1724 |
* @param p1 -1 or +1 (down/up) |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
1725 |
* @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
|
1726 |
*/ |
1095 | 1727 |
static int32 ClickChangeClimateCheat(int32 p1, int32 p2) |
100 | 1728 |
{ |
2639 | 1729 |
if (p1 == -1) p1 = 3; |
1730 |
if (p1 == 4) p1 = 0; |
|
100 | 1731 |
_opt.landscape = p1; |
5352
86fca6a41aa1
(svn r7523) -Feature: Add the possibility to change the newgrf configuration of a running game.
Darkvater
parents:
5320
diff
changeset
|
1732 |
ReloadNewGRFData(); |
100 | 1733 |
return _opt.landscape; |
1734 |
} |
|
1735 |
||
6247 | 1736 |
extern void EnginesMonthlyLoop(); |
108
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
1737 |
|
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
|
1738 |
/** |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6453
diff
changeset
|
1739 |
* @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
|
1740 |
* @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
|
1741 |
*/ |
1095 | 1742 |
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
|
1743 |
{ |
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
1744 |
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
|
1745 |
ConvertDateToYMD(_date, &ymd); |
108
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
1746 |
|
4293
4b7006c1b5eb
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4288
diff
changeset
|
1747 |
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
|
1748 |
|
4288
393de75451b1
(svn r5918) -Cleanup: rename ConvertDayToYMD/ConvertYMDToDay as they really convert a Date to/from a YearMonthDay.
rubidium
parents:
4286
diff
changeset
|
1749 |
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
|
1750 |
EnginesMonthlyLoop(); |
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
1751 |
SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0)); |
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
1752 |
return _cur_year; |
8e2e584a9500
(svn r109) added/heavily modified patch by truesatan: cheat change date
dominik
parents:
104
diff
changeset
|
1753 |
} |
100 | 1754 |
|
0 | 1755 |
typedef int32 CheckButtonClick(int32, int32); |
1756 |
||
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1757 |
enum ce_flags_long |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1758 |
{ |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1759 |
CE_NONE = 0, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1760 |
CE_CLICK = 1 << 0, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1761 |
CE_END = 1 << 1, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1762 |
}; |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1763 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1764 |
/** Define basic enum properties */ |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1765 |
template <> struct EnumPropsT<ce_flags_long> : MakeEnumPropsT<ce_flags_long, byte, CE_NONE, CE_END, CE_END> {}; |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1766 |
typedef TinyEnumT<ce_flags_long> ce_flags; |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1767 |
|
1345
d68d969eb662
(svn r1849) Use the cheat entry enum for CheatEntry.type and remove unused enum values
tron
parents:
1344
diff
changeset
|
1768 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
1769 |
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
|
1770 |
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
|
1771 |
ce_flags flags; ///< selector flags |
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
|
1772 |
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
|
1773 |
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
|
1774 |
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
|
1775 |
CheckButtonClick *proc;///< procedure |
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
|
1776 |
int16 min, max; ///< range for spinbox setting |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
1777 |
}; |
0 | 1778 |
|
1779 |
static const CheatEntry _cheats_ui[] = { |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1780 |
{SLE_BOOL, {CE_CLICK}, STR_CHEAT_MONEY, &_cheats.money.value, &_cheats.money.been_used, &ClickMoneyCheat, 0, 0}, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1781 |
{SLE_UINT8, {CE_NONE}, STR_CHEAT_CHANGE_PLAYER, &_local_player, &_cheats.switch_player.been_used, &ClickChangePlayerCheat, 0, 11}, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1782 |
{SLE_BOOL, {CE_NONE}, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL, 0, 0}, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1783 |
{SLE_BOOL, {CE_NONE}, STR_CHEAT_CROSSINGTUNNELS,&_cheats.crossing_tunnels.value,&_cheats.crossing_tunnels.been_used,NULL, 0, 0}, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1784 |
{SLE_BOOL, {CE_NONE}, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used, NULL, 0, 0}, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1785 |
{SLE_BOOL, {CE_NONE}, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL, 0, 0}, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1786 |
{SLE_BOOL, {CE_NONE}, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, NULL, 0, 0}, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1787 |
{SLE_UINT8, {CE_NONE}, STR_CHEAT_SWITCH_CLIMATE, &_opt.landscape, &_cheats.switch_climate.been_used, &ClickChangeClimateCheat,-1, 4}, |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1788 |
{SLE_INT32, {CE_NONE}, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat, -1, 1}, |
0 | 1789 |
}; |
1790 |
||
1791 |
||
1792 |
static const Widget _cheat_widgets[] = { |
|
4344
7e123fec5b0b
(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
|
1793 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
7e123fec5b0b
(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
|
1794 |
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 399, 0, 13, STR_CHEATS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
7e123fec5b0b
(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
|
1795 |
{ WWT_PANEL, RESIZE_NONE, 14, 0, 399, 14, 169, 0x0, STR_NULL}, |
4938
0447845fd1b3
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4912
diff
changeset
|
1796 |
{ 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
|
1797 |
{ WIDGETS_END}, |
0 | 1798 |
}; |
1799 |
||
1800 |
static void CheatsWndProc(Window *w, WindowEvent *e) |
|
1801 |
{ |
|
2639 | 1802 |
switch (e->event) { |
0 | 1803 |
case WE_PAINT: { |
1804 |
int clk = WP(w,def_d).data_1; |
|
1805 |
int x, y; |
|
1806 |
int i; |
|
1807 |
||
1808 |
DrawWindowWidgets(w); |
|
1809 |
||
6197
558f3a9b5bd4
(svn r8977) -Codechange: Remove the hardcoded maximum width for some drawstrings and replace them with a portion of w->width. Only visible improvement is QueryWndProc which will not write exactly to the edge of the window anymore.
Darkvater
parents:
6190
diff
changeset
|
1810 |
DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, w->width - 50); |
0 | 1811 |
|
2639 | 1812 |
x = 0; |
1813 |
y = 45; |
|
0 | 1814 |
|
2639 | 1815 |
for (i = 0; i != lengthof(_cheats_ui); i++) { |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1816 |
const CheatEntry *ce = &_cheats_ui[i]; |
2639 | 1817 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5639
diff
changeset
|
1818 |
DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, x + 5, y + 2); |
0 | 1819 |
|
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1820 |
switch (ce->type) { |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1821 |
case SLE_BOOL: { |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1822 |
bool on = (*(bool*)ce->variable); |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1823 |
|
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1824 |
if (ce->flags & CE_CLICK) { |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1825 |
DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, 0, (clk - (i * 2) == 1) ? FR_LOWERED : FR_NONE); |
3193
047858d3b9c9
(svn r3853) - Fix a change of SetDParam64 to SetDParam in r3713 that caused slightly vibrating text when pressing the cheat-button. Thanks to peter1138 for noticing.
Darkvater
parents:
3110
diff
changeset
|
1826 |
if (i == 0) { // XXX - hack/hack for first element which is increase money. Told ya it's a mess |
047858d3b9c9
(svn r3853) - Fix a change of SetDParam64 to SetDParam in r3713 that caused slightly vibrating text when pressing the cheat-button. Thanks to peter1138 for noticing.
Darkvater
parents:
3110
diff
changeset
|
1827 |
SetDParam64(0, 10000000); |
047858d3b9c9
(svn r3853) - Fix a change of SetDParam64 to SetDParam in r3713 that caused slightly vibrating text when pressing the cheat-button. Thanks to peter1138 for noticing.
Darkvater
parents:
3110
diff
changeset
|
1828 |
} else { |
047858d3b9c9
(svn r3853) - Fix a change of SetDParam64 to SetDParam in r3713 that caused slightly vibrating text when pressing the cheat-button. Thanks to peter1138 for noticing.
Darkvater
parents:
3110
diff
changeset
|
1829 |
SetDParam(0, false); |
047858d3b9c9
(svn r3853) - Fix a change of SetDParam64 to SetDParam in r3713 that caused slightly vibrating text when pressing the cheat-button. Thanks to peter1138 for noticing.
Darkvater
parents:
3110
diff
changeset
|
1830 |
} |
2639 | 1831 |
} else { |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1832 |
DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, on ? 6 : 4, on ? FR_LOWERED : FR_NONE); |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1833 |
SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF); |
2639 | 1834 |
} |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1835 |
} break; |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1836 |
default: { |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1837 |
int32 val = (int32)ReadValue(ce->variable, ce->type); |
3589
9d646fb01e17
(svn r4478) -Fix (FS#107) In the cheat menu, don't hard-code the player icon, but compute its position from the length of the string.
celestar
parents:
3491
diff
changeset
|
1838 |
char buf[512]; |
2639 | 1839 |
|
3107
d743cfa2d832
(svn r3710) - Use the general function DrawArrowButtons() instead of doing it manually. The function has two parameters added, colour and an enabled flag.
Darkvater
parents:
2952
diff
changeset
|
1840 |
/* Draw [<][>] boxes for settings of an integer-type */ |
4211
5ee54ab361c9
(svn r5714) Backport from branches/TGP (r5701 and r5711)
miham
parents:
4171
diff
changeset
|
1841 |
DrawArrowButtons(x + 20, y, 3, clk - (i * 2), true, true); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
1842 |
|
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1843 |
switch (ce->str) { |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1844 |
/* Display date for change date cheat */ |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1845 |
case STR_CHEAT_CHANGE_DATE: SetDParam(0, _date); break; |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1846 |
/* Draw colored flag for change player cheat */ |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1847 |
case STR_CHEAT_CHANGE_PLAYER: |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1848 |
SetDParam(0, val); |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4909
diff
changeset
|
1849 |
GetString(buf, STR_CHEAT_CHANGE_PLAYER, lastof(buf)); |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4558
diff
changeset
|
1850 |
DrawPlayerIcon(_current_player, 60 + GetStringBoundingBox(buf).width, y + 2); |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1851 |
break; |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1852 |
/* Set correct string for switch climate cheat */ |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1853 |
case STR_CHEAT_SWITCH_CLIMATE: val += STR_TEMPERATE_LANDSCAPE; |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1854 |
/* Fallthrough */ |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1855 |
default: SetDParam(0, val); |
2639 | 1856 |
} |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1857 |
} break; |
0 | 1858 |
} |
1859 |
||
2639 | 1860 |
DrawString(50, y + 1, ce->str, 0); |
0 | 1861 |
|
2639 | 1862 |
y += 12; |
0 | 1863 |
} |
1864 |
break; |
|
1865 |
} |
|
2639 | 1866 |
|
0 | 1867 |
case WE_CLICK: { |
1868 |
const CheatEntry *ce; |
|
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1869 |
uint btn = (e->we.click.pt.y - 46) / 12; |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1870 |
int32 value, oldvalue; |
4634
07699ac2bf37
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4609
diff
changeset
|
1871 |
uint x = e->we.click.pt.x; |
0 | 1872 |
|
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
|
1873 |
/* not clicking a button? */ |
2639 | 1874 |
if (!IS_INT_INSIDE(x, 20, 40) || btn >= lengthof(_cheats_ui)) break; |
0 | 1875 |
|
1876 |
ce = &_cheats_ui[btn]; |
|
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1877 |
oldvalue = value = (int32)ReadValue(ce->variable, ce->type); |
0 | 1878 |
|
1879 |
*ce->been_used = true; |
|
1880 |
||
2639 | 1881 |
switch (ce->type) { |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1882 |
case SLE_BOOL: |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1883 |
if (ce->flags & CE_CLICK) WP(w,def_d).data_1 = btn * 2 + 1; |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1884 |
value ^= 1; |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1885 |
if (ce->proc != NULL) ce->proc(value, 0); |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1886 |
break; |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1887 |
default: { |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1888 |
/* Add a dynamic step-size to the scroller. In a maximum of |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1889 |
* 50-steps you should be able to get from min to max */ |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1890 |
uint16 step = ((ce->max - ce->min) / 20); |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1891 |
if (step == 0) step = 1; |
0 | 1892 |
|
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1893 |
/* Increase or decrease the value and clamp it to extremes */ |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1894 |
value += (x >= 30) ? step : -step; |
5730
fee10dbec24d
(svn r8273) -Fix: return value from clamp was ignored
KUDr
parents:
5726
diff
changeset
|
1895 |
value = clamp(value, ce->min, ce->max); |
0 | 1896 |
|
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
|
1897 |
/* take whatever the function returns */ |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1898 |
value = ce->proc(value, (x >= 30) ? 1 : -1); |
0 | 1899 |
|
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1900 |
if (value != oldvalue) { |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1901 |
WP(w,def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0); |
0 | 1902 |
} |
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1903 |
} break; |
0 | 1904 |
} |
1905 |
||
3110
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1906 |
if (value != oldvalue) { |
53cc5f8754aa
(svn r3713) - Fix up the cheats window a little. The cheats code is still abominable, but at least a bit more readable now.
Darkvater
parents:
3107
diff
changeset
|
1907 |
WriteValue(ce->variable, ce->type, (int64)value); |
0 | 1908 |
SetWindowDirty(w); |
1909 |
} |
|
1910 |
||
1911 |
w->flags4 |= 5 << WF_TIMEOUT_SHL; |
|
1912 |
||
1913 |
SetWindowDirty(w); |
|
1914 |
} |
|
1915 |
break; |
|
1916 |
case WE_TIMEOUT: |
|
1917 |
WP(w,def_d).data_1 = 0; |
|
1918 |
SetWindowDirty(w); |
|
1919 |
break; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
179
diff
changeset
|
1920 |
} |
0 | 1921 |
} |
2639 | 1922 |
|
0 | 1923 |
static const WindowDesc _cheats_desc = { |
3890
e04bc34bc50c
(svn r4946) "Feature": Add a cheat that allows running electric engines on normal rail
celestar
parents:
3798
diff
changeset
|
1924 |
240, 22, 400, 170, |
5893
7e431a4abebb
(svn r8511) -Codechange: make WindowClass an enumerated value.
rubidium
parents:
5750
diff
changeset
|
1925 |
WC_CHEATS, WC_NONE, |
0 | 1926 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
1927 |
_cheat_widgets, |
|
1928 |
CheatsWndProc |
|
1929 |
}; |
|
1930 |
||
1931 |
||
6247 | 1932 |
void ShowCheatWindow() |
0 | 1933 |
{ |
1934 |
DeleteWindowById(WC_CHEATS, 0); |
|
5137
54425dc8b5b3
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5125
diff
changeset
|
1935 |
AllocateWindowDesc(&_cheats_desc); |
0 | 1936 |
} |