author | dominik |
Tue, 24 Aug 2004 11:53:30 +0000 | |
changeset 129 | df1a60bc0d70 |
parent 126 | 152df0cc4ac2 |
child 161 | 74453c59315c |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
||
4 |
#include "window.h" |
|
5 |
#include "gui.h" |
|
6 |
#include "viewport.h" |
|
7 |
#include "gfx.h" |
|
8 |
#include "player.h" |
|
129
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
126
diff
changeset
|
9 |
#include "command.h" |
126 | 10 |
#include "console.h" |
0 | 11 |
|
12 |
extern void MakeNewGame(); |
|
13 |
extern void StartScenario(); |
|
14 |
||
15 |
/* |
|
16 |
static void ShowSelectTutorialWindow() |
|
17 |
{ |
|
18 |
} |
|
19 |
*/ |
|
20 |
||
21 |
static const Widget _select_game_widgets[] = { |
|
74
d23a80ef6361
(svn r75) -Add proper crediting to graphics artists to about box.
darkvater
parents:
0
diff
changeset
|
22 |
{ WWT_CAPTION, 13, 0, 335, 0, 13, STR_0307_OPENTTD}, |
0 | 23 |
{ WWT_IMGBTN, 13, 0, 335, 14, 196, 0x0}, |
24 |
{ WWT_PUSHTXTBTN, 12, 10, 167, 22, 33, STR_0140_NEW_GAME, STR_02FB_START_A_NEW_GAME}, |
|
25 |
{ WWT_PUSHTXTBTN, 12, 168, 325, 22, 33, STR_0141_LOAD_GAME, STR_02FC_LOAD_A_SAVED_GAME_FROM}, |
|
26 |
//{ WWT_PUSHTXTBTN, 12, 10, 167, 177, 188, STR_0142_TUTORIAL_DEMONSTRATION, STR_02FD_VIEW_DEMONSTRATIONS_TUTORIALS}, |
|
27 |
{ WWT_PUSHTXTBTN, 12, 10, 167, 177, 188, STR_CONFIG_PATCHES, STR_CONFIG_PATCHES_TIP}, |
|
28 |
{ WWT_PUSHTXTBTN, 12, 10, 167, 40, 51, STR_0220_CREATE_SCENARIO, STR_02FE_CREATE_A_CUSTOMIZED_GAME}, |
|
29 |
{ WWT_PUSHTXTBTN, 12, 10, 167, 136, 147, STR_SINGLE_PLAYER, STR_02FF_SELECT_SINGLE_PLAYER_GAME}, |
|
30 |
{ WWT_PUSHTXTBTN, 12, 168, 325, 136, 147, STR_MULTIPLAYER, STR_0300_SELECT_TWO_PLAYER_GAME}, |
|
31 |
{ WWT_PUSHTXTBTN, 12, 10, 167, 159, 170, STR_0148_GAME_OPTIONS, STR_0301_DISPLAY_GAME_OPTIONS}, |
|
32 |
{ WWT_PUSHTXTBTN, 12, 168, 325, 159, 170, STR_01FE_DIFFICULTY,STR_0302_DISPLAY_DIFFICULTY_OPTIONS}, |
|
33 |
{ WWT_PUSHTXTBTN, 12, 168, 325, 40, 51, STR_029A_PLAY_SCENARIO, STR_0303_START_A_NEW_GAME_USING}, |
|
74
d23a80ef6361
(svn r75) -Add proper crediting to graphics artists to about box.
darkvater
parents:
0
diff
changeset
|
34 |
{ WWT_PUSHTXTBTN, 12, 168, 325, 177, 188, STR_0304_QUIT, STR_0305_LEAVE_OPENTTD}, |
0 | 35 |
{ WWT_PANEL_2, 12, 10, 85, 69, 122, 0x1312, STR_030E_SELECT_TEMPERATE_LANDSCAPE}, |
36 |
{ WWT_PANEL_2, 12, 90, 165, 69, 122, 0x1314, STR_030F_SELECT_SUB_ARCTIC_LANDSCAPE}, |
|
37 |
{ WWT_PANEL_2, 12, 170, 245, 69, 122, 0x1316, STR_0310_SELECT_SUB_TROPICAL_LANDSCAPE}, |
|
38 |
{ WWT_PANEL_2, 12, 250, 325, 69, 122, 0x1318, STR_0311_SELECT_TOYLAND_LANDSCAPE}, |
|
39 |
{ WWT_LAST}, |
|
40 |
}; |
|
41 |
||
42 |
static void SelectGameWndProc(Window *w, WindowEvent *e) { |
|
43 |
switch(e->event) { |
|
44 |
case WE_PAINT: |
|
45 |
w->click_state = (w->click_state & ~(0xC0) & ~(0xF << 12)) | (1 << (_new_opt.landscape+12)) | (!_networking?(1<<6):(1<<7)); |
|
46 |
w->disabled_state = _networking ? 0x30 : 0; |
|
47 |
SET_DPARAM16(0, STR_6801_EASY + _new_opt.diff_level); |
|
48 |
DrawWindowWidgets(w); |
|
49 |
break; |
|
50 |
||
51 |
case WE_CLICK: |
|
52 |
switch(e->click.widget) { |
|
53 |
case 2: DoCommandP(0, 0, 0, NULL, CMD_START_NEW_GAME); break; |
|
54 |
case 3: ShowSaveLoadDialog(SLD_LOAD_GAME); break; |
|
55 |
case 4: ShowPatchesSelection(); break; |
|
56 |
case 5: DoCommandP(0, InteractiveRandom(), 0, NULL, CMD_CREATE_SCENARIO); break; |
|
57 |
case 6: |
|
58 |
if (_networking) |
|
59 |
DoCommandP(0, 0, 0, NULL, CMD_SET_SINGLE_PLAYER); |
|
60 |
break; |
|
61 |
case 7: |
|
105 | 62 |
if (!_network_available) { |
63 |
ShowErrorMessage(-1,STR_NETWORK_ERR_NOTAVAILABLE, 0, 0); |
|
64 |
} else ShowNetworkGameWindow(); |
|
0 | 65 |
break; |
66 |
case 8: ShowGameOptions(); break; |
|
67 |
case 9: ShowGameDifficulty(); break; |
|
68 |
case 10:ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break; |
|
69 |
case 11:AskExitGame(); break; |
|
70 |
case 12: case 13: case 14: case 15: |
|
71 |
DoCommandP(0, e->click.widget - 12, 0, NULL, CMD_SET_NEW_LANDSCAPE_TYPE); |
|
72 |
break; |
|
129
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
126
diff
changeset
|
73 |
} |
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
126
diff
changeset
|
74 |
case WE_KEYPRESS: |
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
126
diff
changeset
|
75 |
switch(e->keypress.keycode) { |
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
126
diff
changeset
|
76 |
case WKC_BACKQUOTE: IConsoleSwitch(); break; |
df1a60bc0d70
(svn r130) Change: hotkey for console is Backquote (the key left to '1', regardless of keyboard layout
dominik
parents:
126
diff
changeset
|
77 |
} |
0 | 78 |
break; |
79 |
} |
|
80 |
} |
|
81 |
||
82 |
static const WindowDesc _select_game_desc = { |
|
83 |
WDP_CENTER, WDP_CENTER, 336, 197, |
|
84 |
WC_SELECT_GAME,0, |
|
85 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
86 |
_select_game_widgets, |
|
87 |
SelectGameWndProc |
|
88 |
}; |
|
89 |
||
90 |
void ShowSelectGameWindow() |
|
91 |
{ |
|
92 |
AllocateWindowDesc(&_select_game_desc); |
|
93 |
} |
|
94 |
||
95 |
||
96 |
// p1 = mode |
|
97 |
// 0 - start new game |
|
98 |
// 1 - close new game dialog |
|
99 |
||
100 |
int32 CmdStartNewGame(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
101 |
{ |
|
102 |
if (!(flags & DC_EXEC)) |
|
103 |
return 0; |
|
104 |
||
105 |
switch(p1) { |
|
106 |
case 0: // show select game window |
|
107 |
AskForNewGameToStart(); |
|
108 |
break; |
|
109 |
case 1: // close select game window |
|
110 |
DeleteWindowById(WC_SAVELOAD, 0); |
|
111 |
break; |
|
112 |
} |
|
113 |
||
114 |
return 0; |
|
115 |
} |
|
116 |
||
117 |
int32 CmdGenRandomNewGame(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
118 |
{ |
|
119 |
if (!(flags & DC_EXEC)) |
|
120 |
return 0; |
|
121 |
||
122 |
// this forces stuff into test mode. |
|
123 |
_docommand_recursive = 0; |
|
124 |
||
125 |
_random_seed_1 = p1; |
|
126 |
_random_seed_2 = p2; |
|
127 |
||
105 | 128 |
if (_networking) { NetworkStartSync(true); } |
0 | 129 |
|
130 |
MakeNewGame(); |
|
131 |
return 0; |
|
132 |
} |
|
133 |
||
134 |
int32 CmdLoadGame(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
135 |
{ |
|
136 |
if (!(flags & DC_EXEC)) |
|
137 |
return 0; |
|
138 |
||
139 |
// ShowSaveLoadDialog(0); |
|
140 |
return 0; |
|
141 |
} |
|
142 |
||
143 |
int32 CmdCreateScenario(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
144 |
{ |
|
145 |
if (!(flags & DC_EXEC)) |
|
146 |
return 0; |
|
147 |
||
148 |
_switch_mode = SM_EDITOR; |
|
149 |
return 0; |
|
150 |
} |
|
151 |
||
152 |
int32 CmdSetSinglePlayer(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
153 |
{ |
|
154 |
printf("CmdSetSinglePlayer\n"); |
|
155 |
return 0; |
|
156 |
} |
|
157 |
||
158 |
int32 CmdStartScenario(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
159 |
{ |
|
160 |
if (!(flags & DC_EXEC)) |
|
161 |
return 0; |
|
162 |
||
163 |
// this forces stuff into test mode. |
|
164 |
_docommand_recursive = 0; |
|
165 |
||
166 |
_random_seed_1 = p1; |
|
167 |
_random_seed_2 = p2; |
|
168 |
||
105 | 169 |
if (_networking) { NetworkStartSync(true); } |
0 | 170 |
|
171 |
StartScenario(); |
|
172 |
return 0; |
|
173 |
} |
|
174 |
||
175 |
||
176 |
static const Widget _ask_abandon_game_widgets[] = { |
|
177 |
{ WWT_TEXTBTN, 4, 0, 10, 0, 13, STR_00C5}, |
|
178 |
{ WWT_CAPTION, 4, 11, 179, 0, 13, STR_00C7_QUIT}, |
|
179 |
{ WWT_IMGBTN, 4, 0, 179, 14, 91, 0x0}, |
|
180 |
{ WWT_TEXTBTN, 12, 25, 84, 72, 83, STR_00C9_NO}, |
|
181 |
{ WWT_TEXTBTN, 12, 95, 154, 72, 83, STR_00C8_YES}, |
|
182 |
{ WWT_LAST}, |
|
183 |
}; |
|
184 |
||
185 |
static void AskAbandonGameWndProc(Window *w, WindowEvent *e) { |
|
186 |
switch(e->event) { |
|
187 |
case WE_PAINT: |
|
188 |
DrawWindowWidgets(w); |
|
189 |
#if defined(_WIN32) |
|
190 |
SET_DPARAM16(0, STR_0133_WINDOWS); |
|
191 |
#elif defined(__APPLE__) |
|
192 |
SET_DPARAM16(0, STR_0135_OSX); |
|
193 |
#elif defined(__BEOS__) |
|
194 |
SET_DPARAM16(0, STR_OSNAME_BEOS); |
|
195 |
#elif defined(__MORPHOS__) |
|
196 |
SET_DPARAM16(0, STR_OSNAME_MORPHOS); |
|
197 |
#else |
|
198 |
SET_DPARAM16(0, STR_0134_UNIX); |
|
199 |
#endif |
|
200 |
DrawStringMultiCenter(0x5A, 0x26, STR_00CA_ARE_YOU_SURE_YOU_WANT_TO, 178); |
|
201 |
return; |
|
202 |
||
203 |
case WE_CLICK: |
|
204 |
switch(e->click.widget) { |
|
205 |
case 3: |
|
206 |
DeleteWindow(w); |
|
207 |
break; |
|
208 |
case 4: |
|
209 |
_exit_game = true; |
|
210 |
break; |
|
211 |
} |
|
212 |
break; |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
static const WindowDesc _ask_abandon_game_desc = { |
|
217 |
WDP_CENTER, WDP_CENTER, 180, 92, |
|
218 |
WC_ASK_ABANDON_GAME,0, |
|
219 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS, |
|
220 |
_ask_abandon_game_widgets, |
|
221 |
AskAbandonGameWndProc |
|
222 |
}; |
|
223 |
||
224 |
void AskExitGame() |
|
225 |
{ |
|
226 |
AllocateWindowDescFront(&_ask_abandon_game_desc, 0); |
|
227 |
} |
|
228 |
||
229 |
||
230 |
static const Widget _ask_quit_game_widgets[] = { |
|
231 |
{ WWT_TEXTBTN, 4, 0, 10, 0, 13, STR_00C5}, |
|
232 |
{ WWT_CAPTION, 4, 11, 179, 0, 13, STR_0161_QUIT_GAME}, |
|
233 |
{ WWT_IMGBTN, 4, 0, 179, 14, 91, 0x0}, |
|
234 |
{ WWT_TEXTBTN, 12, 25, 84, 72, 83, STR_00C9_NO}, |
|
235 |
{ WWT_TEXTBTN, 12, 95, 154, 72, 83, STR_00C8_YES}, |
|
236 |
{ WWT_LAST}, |
|
237 |
}; |
|
238 |
||
239 |
static void AskQuitGameWndProc(Window *w, WindowEvent *e) { |
|
240 |
switch(e->event) { |
|
241 |
case WE_PAINT: |
|
242 |
DrawWindowWidgets(w); |
|
243 |
DrawStringMultiCenter(0x5A, 0x26, |
|
244 |
_game_mode != GM_EDITOR ? STR_0160_ARE_YOU_SURE_YOU_WANT_TO : |
|
245 |
STR_029B_ARE_YOU_SURE_YOU_WANT_TO, |
|
246 |
178); |
|
247 |
return; |
|
248 |
||
249 |
case WE_CLICK: |
|
250 |
switch(e->click.widget) { |
|
251 |
case 3: |
|
252 |
DeleteWindow(w); |
|
253 |
break; |
|
254 |
case 4: |
|
255 |
_switch_mode = SM_MENU; |
|
256 |
break; |
|
257 |
} |
|
258 |
break; |
|
259 |
} |
|
260 |
} |
|
261 |
||
262 |
static const WindowDesc _ask_quit_game_desc = { |
|
263 |
WDP_CENTER, WDP_CENTER, 180, 92, |
|
264 |
WC_QUIT_GAME,0, |
|
265 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS, |
|
266 |
_ask_quit_game_widgets, |
|
267 |
AskQuitGameWndProc |
|
268 |
}; |
|
269 |
||
270 |
||
271 |
void AskExitToGameMenu() |
|
272 |
{ |
|
273 |
AllocateWindowDescFront(&_ask_quit_game_desc, 0); |
|
274 |
} |
|
275 |
||
276 |
int32 CmdSetNewLandscapeType(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
277 |
{ |
|
278 |
if (flags & DC_EXEC) { |
|
279 |
// XXX: some stuff |
|
280 |
_new_opt.landscape = p1; |
|
281 |
InvalidateWindowClasses(WC_SELECT_GAME); |
|
282 |
} |
|
283 |
return 0; |
|
284 |
} |