Debian Codegraph @

src/menus.c

raw symbols SCIP
1 /*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2007-2009 The OpenTyrian Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 #include "menus.h"cxx . . $ `<file>/src/menus.h`/
20
21 #include "config.h"cxx . . $ `<file>/src/config.h`/
22 #include "episodes.h"cxx . . $ `<file>/src/episodes.h`/
23 #include "font.h"cxx . . $ `<file>/src/font.h`/
24 #include "fonthand.h"cxx . . $ `<file>/src/fonthand.h`/
25 #include "joystick.h"cxx . . $ `<file>/src/joystick.h`/
26 #include "keyboard.h"cxx . . $ `<file>/src/keyboard.h`/
27 #include "mouse.h"cxx . . $ `<file>/src/mouse.h`/
28 #include "network.h"cxx . . $ `<file>/src/network.h`/
29 #include "nortsong.h"cxx . . $ `<file>/src/nortsong.h`/
30 #include "opentyr.h"cxx . . $ `<file>/src/opentyr.h`/
31 #include "palette.h"cxx . . $ `<file>/src/palette.h`/
32 #include "picload.h"cxx . . $ `<file>/src/picload.h`/
33 #include "sprite.h"cxx . . $ `<file>/src/sprite.h`/
34 #include "vga256d.h"cxx . . $ `<file>/src/vga256d.h`/
35 #include "video.h"cxx . . $ `<file>/src/video.h`/
36
37 char episode_namecxx . . $ episode_name.[6][31];
38 char difficulty_namecxx . . $ difficulty_name.[7][21];
39 char gameplay_namecxx . . $ gameplay_name.[5][26];
40
41 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! gameplaySelectcxx . . $ gameplaySelect(c9857a73d68e59ba).(void)
42 {
43 enum MenuItemIndexcxx . . $ gameplaySelect(c9857a73d68e59ba).MenuItemIndex#
44 {
45 MENU_ITEM_1_PLAYER_FULL_GAMEcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_1_PLAYER_FULL_GAME. = 0,
46 MENU_ITEM_1_PLAYER_ARCADEcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_1_PLAYER_ARCADE.,
47 MENU_ITEM_2_PLAYER_ARCADEcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_2_PLAYER_ARCADE.,
48 MENU_ITEM_NETWORKcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_NETWORK.,
49 };
50
51 if (shopSpriteSheetcxx . . $ shopSpriteSheet..datacxx . . $ $anonymous_type_297934740aeafb7d_2#data. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
52 JE_loadCompShapescxx . . $ JE_loadCompShapes(676db0deaa5c5c40).(&shopSpriteSheetcxx . . $ shopSpriteSheet., '1'); // need mouse pointer sprites
53
54 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! restart = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
55
56 const size_t menuItemsCount = COUNTOFcxx . . $ `src/opentyr.h:27:9`!(gameplay_name) - 1;
57 size_t selectedIndex = MENU_ITEM_1_PLAYER_FULL_GAMEcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_1_PLAYER_FULL_GAME.;
58
59 const int xCenter = 320 / 2;
60 const int yMenuHeader = 20;
61 const int yMenuItems = 54;
62 const int dyMenuItems = 24;
63 const int hMenuItem = 13;
64 int wMenuItem[COUNTOFcxx . . $ `src/opentyr.h:27:9`!(gameplay_name) - 1] = { 0 };
65
66 for (; ; )
67 {
68 if (restart)
69 {
70 JE_loadPiccxx . . $ JE_loadPic(4846ed2ea5b0a844).(VGAScreen2cxx . . $ VGAScreen2., 2, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
71
72 // Draw header.
73 draw_font_hv_shadowcxx . . $ draw_font_hv_shadow(198b4ac5940c9e46).(VGAScreen2cxx . . $ VGAScreen2., xCenter, yMenuHeader, gameplay_namecxx . . $ gameplay_name.[0], large_fontcxx . . $ large_font., centeredcxx . . $ centered., 15, -3, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, 2);
74 }
75
76 // Restore background and header.
77 memcpycxx . . $ memcpy(cc817cb175f282d).(VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels., VGAScreen2cxx . . $ VGAScreen2.->pixelscxx . . $ SDL_Surface#pixels., (size_t)VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch. * VGAScreencxx . . $ VGAScreen.->hcxx . . $ SDL_Surface#h.);
78
79 // Draw menu items.
80 for (size_t i = 0; i < menuItemsCount; ++i)
81 {
82 const char *const text = gameplay_namecxx . . $ gameplay_name.[i + 1];
83
84 wMenuItem[i] = JE_textWidthcxx . . $ JE_textWidth(1df18506ef0a631b).(text, normal_fontcxx . . $ normal_font.);
85 const int x = xCenter - wMenuItem[i] / 2;
86 const int y = yMenuItems + dyMenuItems * i;
87
88 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! selected = i == selectedIndex;
89 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! disabled = i == MENU_ITEM_NETWORKcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_NETWORK.;
90
91 draw_font_hv_shadowcxx . . $ draw_font_hv_shadow(198b4ac5940c9e46).(VGAScreencxx . . $ VGAScreen., x, y, text, normal_fontcxx . . $ normal_font., left_alignedcxx . . $ left_aligned., 15, -4 + (selected ? 2 : 0) + (disabled ? -4 : 0), falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, 2);
92 }
93
94 if (restart)
95 {
96 mouseCursorcxx . . $ mouseCursor. = MOUSE_POINTER_NORMALcxx . . $ MOUSE_POINTER_NORMAL.;
97
98 fade_palettecxx . . $ fade_palette(59ab901998e00635).(colorscxx . . $ colors., 10, 0, 255);
99
100 restart = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
101 }
102
103 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
104
105 JE_mouseStartcxx . . $ JE_mouseStart(49f6e7a06ebc5aa8).();
106 JE_showVGAcxx . . $ JE_showVGA(49f6e7a06ebc5aa8).();
107 JE_mouseReplacecxx . . $ JE_mouseReplace(49f6e7a06ebc5aa8).();
108
109 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mouseMoved = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
110 do
111 {
112 SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(16);
113
114 Uint16cxx . . $ Uint16# oldMouseX = mouse_xcxx . . $ mouse_x.;
115 Uint16cxx . . $ Uint16# oldMouseY = mouse_ycxx . . $ mouse_y.;
116
117 push_joysticks_as_keyboardcxx . . $ push_joysticks_as_keyboard(49f6e7a06ebc5aa8).();
118 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
119
120 mouseMoved = mouse_xcxx . . $ mouse_x. != oldMouseX || mouse_ycxx . . $ mouse_y. != oldMouseY;
121 } while (!(newkeycxx . . $ newkey. || newmousecxx . . $ newmouse. || mouseMoved));
122
123 // Handle interaction.
124
125 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! action = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
126 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cancel = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
127
128 if (mouseMoved || newmousecxx . . $ newmouse.)
129 {
130 // Find menu item that was hovered or clicked.
131 for (size_t i = 0; i < menuItemsCount; ++i)
132 {
133 const int xMenuItem = xCenter - wMenuItem[i] / 2;
134 if (mouse_xcxx . . $ mouse_x. >= xMenuItem && mouse_xcxx . . $ mouse_x. < xMenuItem + wMenuItem[i])
135 {
136 const int yMenuItem = yMenuItems + dyMenuItems * i;
137 if (mouse_ycxx . . $ mouse_y. >= yMenuItem && mouse_ycxx . . $ mouse_y. < yMenuItem + hMenuItem)
138 {
139 if (selectedIndex != i)
140 {
141 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_CURSORcxx . . $ S_CURSOR.);
142
143 selectedIndex = i;
144 }
145
146 if (newmousecxx . . $ newmouse. && lastmouse_butcxx . . $ lastmouse_but. == SDL_BUTTON_LEFTcxx . . $ `<external>/13849749812924280863/SDL_mouse.h:445:9`! &&
147 lastmouse_xcxx . . $ lastmouse_x. >= xMenuItem && lastmouse_xcxx . . $ lastmouse_x. < xMenuItem + wMenuItem[i] &&
148 lastmouse_ycxx . . $ lastmouse_y. >= yMenuItem && lastmouse_ycxx . . $ lastmouse_y. < yMenuItem + hMenuItem)
149 {
150 action = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
151 }
152
153 break;
154 }
155 }
156 }
157 }
158
159 if (newmousecxx . . $ newmouse.)
160 {
161 if (lastmouse_butcxx . . $ lastmouse_but. == SDL_BUTTON_RIGHTcxx . . $ `<external>/13849749812924280863/SDL_mouse.h:447:9`!)
162 {
163 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SPRINGcxx . . $ S_SPRING.);
164
165 cancel = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
166 }
167 }
168 else if (newkeycxx . . $ newkey.)
169 {
170 switch (lastkey_scancxx . . $ lastkey_scan.)
171 {
172 case SDL_SCANCODE_UPcxx . . $ SDL_SCANCODE_UP.:
173 {
174 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_CURSORcxx . . $ S_CURSOR.);
175
176 selectedIndex = selectedIndex == 0
177 ? menuItemsCount - 1
178 : selectedIndex - 1;
179 break;
180 }
181 case SDL_SCANCODE_DOWNcxx . . $ SDL_SCANCODE_DOWN.:
182 {
183 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_CURSORcxx . . $ S_CURSOR.);
184
185 selectedIndex = selectedIndex == menuItemsCount - 1
186 ? 0
187 : selectedIndex + 1;
188 break;
189 }
190 case SDL_SCANCODE_SPACEcxx . . $ SDL_SCANCODE_SPACE.:
191 case SDL_SCANCODE_RETURNcxx . . $ SDL_SCANCODE_RETURN.:
192 {
193 action = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
194 break;
195 }
196 case SDL_SCANCODE_ESCAPEcxx . . $ SDL_SCANCODE_ESCAPE.:
197 {
198 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SPRINGcxx . . $ S_SPRING.);
199
200 cancel = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
201 break;
202 }
203 default:
204 break;
205 }
206 }
207
208 if (action)
209 {
210 switch (selectedIndex)
211 {
212 case MENU_ITEM_1_PLAYER_FULL_GAMEcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_1_PLAYER_FULL_GAME.:
213 case MENU_ITEM_1_PLAYER_ARCADEcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_1_PLAYER_ARCADE.:
214 case MENU_ITEM_2_PLAYER_ARCADEcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_2_PLAYER_ARCADE.:
215 {
216 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SELECTcxx . . $ S_SELECT.);
217
218 fade_blackcxx . . $ fade_black(d4f767463ce0a6b3).(10);
219
220 onePlayerActioncxx . . $ onePlayerAction. = selectedIndex == MENU_ITEM_1_PLAYER_ARCADEcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_1_PLAYER_ARCADE.;
221 twoPlayerModecxx . . $ twoPlayerMode. = selectedIndex == MENU_ITEM_2_PLAYER_ARCADEcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_2_PLAYER_ARCADE.;
222 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
223 }
224 case MENU_ITEM_NETWORKcxx . . $ gameplaySelect(c9857a73d68e59ba).MENU_ITEM_NETWORK.:
225 {
226 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SPRINGcxx . . $ S_SPRING.);
227 break;
228 }
229 default:
230 break;
231 }
232 }
233
234 if (cancel)
235 {
236 fade_blackcxx . . $ fade_black(d4f767463ce0a6b3).(15);
237
238 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
239 }
240 }
241 }
242
243 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! episodeSelectcxx . . $ episodeSelect(c9857a73d68e59ba).(void)
244 {
245 if (shopSpriteSheetcxx . . $ shopSpriteSheet..datacxx . . $ $anonymous_type_297934740aeafb7d_2#data. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
246 JE_loadCompShapescxx . . $ JE_loadCompShapes(676db0deaa5c5c40).(&shopSpriteSheetcxx . . $ shopSpriteSheet., '1'); // need mouse pointer sprites
247
248 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! restart = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
249
250 const size_t menuItemsCount = EPISODE_AVAILABLEcxx . . $ `src/episodes.h:30:9`!;
251 size_t selectedIndex = 0;
252
253 const int xCenter = 320 / 2;
254 const int yMenuHeader = 20;
255 const int xMenuItem = 20;
256 const int yMenuItems = 50;
257 const int dyMenuItems = 30;
258 const int hMenuItem = 13;
259 int wMenuItem[EPISODE_AVAILABLEcxx . . $ `src/episodes.h:30:9`!] = { 0 };
260
261 for (; ; )
262 {
263 if (restart)
264 {
265 JE_loadPiccxx . . $ JE_loadPic(4846ed2ea5b0a844).(VGAScreen2cxx . . $ VGAScreen2., 2, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
266
267 // Draw header.
268 draw_font_hv_shadowcxx . . $ draw_font_hv_shadow(198b4ac5940c9e46).(VGAScreen2cxx . . $ VGAScreen2., xCenter, yMenuHeader, episode_namecxx . . $ episode_name.[0], large_fontcxx . . $ large_font., centeredcxx . . $ centered., 15, -3, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, 2);
269 }
270
271 // Restore background and header.
272 memcpycxx . . $ memcpy(cc817cb175f282d).(VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels., VGAScreen2cxx . . $ VGAScreen2.->pixelscxx . . $ SDL_Surface#pixels., (size_t)VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch. * VGAScreencxx . . $ VGAScreen.->hcxx . . $ SDL_Surface#h.);
273
274 // Draw menu items.
275 for (size_t i = 0; i < menuItemsCount; ++i)
276 {
277 const char *const text = episode_namecxx . . $ episode_name.[i + 1];
278
279 wMenuItem[i] = JE_textWidthcxx . . $ JE_textWidth(1df18506ef0a631b).(text, normal_fontcxx . . $ normal_font.);
280 const int y = yMenuItems + dyMenuItems * i;
281
282 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! selected = i == selectedIndex;
283 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! disabled = !episodeAvailcxx . . $ episodeAvail.[i];
284
285 draw_font_hv_shadowcxx . . $ draw_font_hv_shadow(198b4ac5940c9e46).(VGAScreencxx . . $ VGAScreen., xMenuItem, y, text, normal_fontcxx . . $ normal_font., left_alignedcxx . . $ left_aligned., 15, -4 + (selected ? 2 : 0) + (disabled ? -4 : 0), falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, 2);
286 }
287
288 if (restart)
289 {
290 mouseCursorcxx . . $ mouseCursor. = MOUSE_POINTER_NORMALcxx . . $ MOUSE_POINTER_NORMAL.;
291
292 fade_palettecxx . . $ fade_palette(59ab901998e00635).(colorscxx . . $ colors., 10, 0, 255);
293
294 restart = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
295 }
296
297 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
298
299 JE_mouseStartcxx . . $ JE_mouseStart(49f6e7a06ebc5aa8).();
300 JE_showVGAcxx . . $ JE_showVGA(49f6e7a06ebc5aa8).();
301 JE_mouseReplacecxx . . $ JE_mouseReplace(49f6e7a06ebc5aa8).();
302
303 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mouseMoved = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
304 do
305 {
306 SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(16);
307
308 Uint16cxx . . $ Uint16# oldMouseX = mouse_xcxx . . $ mouse_x.;
309 Uint16cxx . . $ Uint16# oldMouseY = mouse_ycxx . . $ mouse_y.;
310
311 push_joysticks_as_keyboardcxx . . $ push_joysticks_as_keyboard(49f6e7a06ebc5aa8).();
312 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
313
314 NETWORK_KEEP_ALIVEcxx . . $ `src/network.h:88:9`!();
315
316 mouseMoved = mouse_xcxx . . $ mouse_x. != oldMouseX || mouse_ycxx . . $ mouse_y. != oldMouseY;
317 } while (!(newkeycxx . . $ newkey. || newmousecxx . . $ newmouse. || mouseMoved));
318
319 // Handle interaction.
320
321 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! action = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
322 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cancel = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
323
324 if (mouseMoved || newmousecxx . . $ newmouse.)
325 {
326 // Find menu item that was hovered or clicked.
327 for (size_t i = 0; i < menuItemsCount; ++i)
328 {
329 if (mouse_xcxx . . $ mouse_x. >= xMenuItem && mouse_xcxx . . $ mouse_x. < xMenuItem + wMenuItem[i])
330 {
331 const int yMenuItem = yMenuItems + dyMenuItems * i;
332 if (mouse_ycxx . . $ mouse_y. >= yMenuItem && mouse_ycxx . . $ mouse_y. < yMenuItem + hMenuItem)
333 {
334 if (selectedIndex != i)
335 {
336 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_CURSORcxx . . $ S_CURSOR.);
337
338 selectedIndex = i;
339 }
340
341 if (newmousecxx . . $ newmouse. && lastmouse_butcxx . . $ lastmouse_but. == SDL_BUTTON_LEFTcxx . . $ `<external>/13849749812924280863/SDL_mouse.h:445:9`! &&
342 lastmouse_xcxx . . $ lastmouse_x. >= xMenuItem && lastmouse_xcxx . . $ lastmouse_x. < xMenuItem + wMenuItem[i] &&
343 lastmouse_ycxx . . $ lastmouse_y. >= yMenuItem && lastmouse_ycxx . . $ lastmouse_y. < yMenuItem + hMenuItem)
344 {
345 action = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
346 }
347
348 break;
349 }
350 }
351 }
352 }
353
354 if (newmousecxx . . $ newmouse.)
355 {
356 if (lastmouse_butcxx . . $ lastmouse_but. == SDL_BUTTON_RIGHTcxx . . $ `<external>/13849749812924280863/SDL_mouse.h:447:9`!)
357 {
358 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SPRINGcxx . . $ S_SPRING.);
359
360 cancel = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
361 }
362 }
363 else if (newkeycxx . . $ newkey.)
364 {
365 switch (lastkey_scancxx . . $ lastkey_scan.)
366 {
367 case SDL_SCANCODE_UPcxx . . $ SDL_SCANCODE_UP.:
368 {
369 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_CURSORcxx . . $ S_CURSOR.);
370
371 selectedIndex = selectedIndex == 0
372 ? menuItemsCount - 1
373 : selectedIndex - 1;
374 break;
375 }
376 case SDL_SCANCODE_DOWNcxx . . $ SDL_SCANCODE_DOWN.:
377 {
378 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_CURSORcxx . . $ S_CURSOR.);
379
380 selectedIndex = selectedIndex == menuItemsCount - 1
381 ? 0
382 : selectedIndex + 1;
383 break;
384 }
385 case SDL_SCANCODE_SPACEcxx . . $ SDL_SCANCODE_SPACE.:
386 case SDL_SCANCODE_RETURNcxx . . $ SDL_SCANCODE_RETURN.:
387 {
388 action = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
389 break;
390 }
391 case SDL_SCANCODE_ESCAPEcxx . . $ SDL_SCANCODE_ESCAPE.:
392 {
393 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SPRINGcxx . . $ S_SPRING.);
394
395 cancel = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
396 break;
397 }
398 default:
399 break;
400 }
401 }
402
403 if (action)
404 {
405 if (episodeAvailcxx . . $ episodeAvail.[selectedIndex])
406 {
407 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SELECTcxx . . $ S_SELECT.);
408
409 fade_blackcxx . . $ fade_black(d4f767463ce0a6b3).(10);
410
411 JE_initEpisodecxx . . $ JE_initEpisode(ac50b47256ae7414).(selectedIndex + 1);
412 initial_episode_numcxx . . $ initial_episode_num. = episodeNumcxx . . $ episodeNum.;
413 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
414 }
415 else
416 {
417 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SPRINGcxx . . $ S_SPRING.);
418 }
419 }
420
421 if (cancel)
422 {
423 fade_blackcxx . . $ fade_black(d4f767463ce0a6b3).(15);
424
425 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
426 }
427 }
428 }
429
430 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! difficultySelectcxx . . $ difficultySelect(c9857a73d68e59ba).(void)
431 {
432 if (shopSpriteSheetcxx . . $ shopSpriteSheet..datacxx . . $ $anonymous_type_297934740aeafb7d_2#data. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
433 JE_loadCompShapescxx . . $ JE_loadCompShapes(676db0deaa5c5c40).(&shopSpriteSheetcxx . . $ shopSpriteSheet., '1'); // need mouse pointer sprites
434
435 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! restart = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
436
437 const size_t menuItemsCount = COUNTOFcxx . . $ `src/opentyr.h:27:9`!(difficulty_name) - 1;
438 size_t menuItemsVisibleCount = menuItemsCount - 3;
439 size_t selectedIndex = 1;
440 size_t lordProgress = 0;
441
442 const int xCenter = 320 / 2;
443 const int yMenuHeader = 20;
444 const int yMenuItems = 54;
445 const int dyMenuItems = 24;
446 const int hMenuItem = 13;
447 int wMenuItem[COUNTOFcxx . . $ `src/opentyr.h:27:9`!(difficulty_name) - 1] = { 0 };
448
449 for (; ; )
450 {
451 if (restart)
452 {
453 JE_loadPiccxx . . $ JE_loadPic(4846ed2ea5b0a844).(VGAScreen2cxx . . $ VGAScreen2., 2, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
454
455 // Draw header.
456 draw_font_hv_shadowcxx . . $ draw_font_hv_shadow(198b4ac5940c9e46).(VGAScreen2cxx . . $ VGAScreen2., xCenter, yMenuHeader, difficulty_namecxx . . $ difficulty_name.[0], large_fontcxx . . $ large_font., centeredcxx . . $ centered., 15, -3, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, 2);
457 }
458
459 // Restore background and header.
460 memcpycxx . . $ memcpy(cc817cb175f282d).(VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels., VGAScreen2cxx . . $ VGAScreen2.->pixelscxx . . $ SDL_Surface#pixels., (size_t)VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch. * VGAScreencxx . . $ VGAScreen.->hcxx . . $ SDL_Surface#h.);
461
462 // Draw menu items.
463 for (size_t i = 0; i < menuItemsVisibleCount; ++i)
464 {
465 const char *const text = difficulty_namecxx . . $ difficulty_name.[i + 1];
466
467 wMenuItem[i] = JE_textWidthcxx . . $ JE_textWidth(1df18506ef0a631b).(text, normal_fontcxx . . $ normal_font.);
468 const int x = xCenter - wMenuItem[i] / 2;
469 const int y = yMenuItems + dyMenuItems * i;
470
471 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! selected = i == selectedIndex;
472
473 draw_font_hv_shadowcxx . . $ draw_font_hv_shadow(198b4ac5940c9e46).(VGAScreencxx . . $ VGAScreen., x, y, text, normal_fontcxx . . $ normal_font., left_alignedcxx . . $ left_aligned., 15, -4 + (selected ? 2 : 0), falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, 2);
474 }
475
476 if (restart)
477 {
478 mouseCursorcxx . . $ mouseCursor. = MOUSE_POINTER_NORMALcxx . . $ MOUSE_POINTER_NORMAL.;
479
480 fade_palettecxx . . $ fade_palette(59ab901998e00635).(colorscxx . . $ colors., 10, 0, 255);
481
482 restart = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
483 }
484
485 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
486
487 JE_mouseStartcxx . . $ JE_mouseStart(49f6e7a06ebc5aa8).();
488 JE_showVGAcxx . . $ JE_showVGA(49f6e7a06ebc5aa8).();
489 JE_mouseReplacecxx . . $ JE_mouseReplace(49f6e7a06ebc5aa8).();
490
491 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mouseMoved = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
492 do
493 {
494 SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(16);
495
496 Uint16cxx . . $ Uint16# oldMouseX = mouse_xcxx . . $ mouse_x.;
497 Uint16cxx . . $ Uint16# oldMouseY = mouse_ycxx . . $ mouse_y.;
498
499 push_joysticks_as_keyboardcxx . . $ push_joysticks_as_keyboard(49f6e7a06ebc5aa8).();
500 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
501
502 NETWORK_KEEP_ALIVEcxx . . $ `src/network.h:88:9`!();
503
504 mouseMoved = mouse_xcxx . . $ mouse_x. != oldMouseX || mouse_ycxx . . $ mouse_y. != oldMouseY;
505 } while (!(newkeycxx . . $ newkey. || newmousecxx . . $ newmouse. || mouseMoved));
506
507 // Handle interaction.
508
509 if (menuItemsVisibleCount == 5)
510 {
511 const SDL_Scancodecxx . . $ SDL_Scancode# lordKeys[] = { SDL_SCANCODE_Lcxx . . $ SDL_SCANCODE_L., SDL_SCANCODE_Ocxx . . $ SDL_SCANCODE_O., SDL_SCANCODE_Rcxx . . $ SDL_SCANCODE_R., SDL_SCANCODE_Dcxx . . $ SDL_SCANCODE_D. };
512
513 for (size_t i = 0; ; ++i)
514 {
515 if (i == COUNTOFcxx . . $ `src/opentyr.h:27:9`!(lordKeys))
516 {
517 menuItemsVisibleCount = 6;
518 break;
519 }
520
521 if (!keysactivecxx . . $ keysactive.[lordKeys[i]])
522 break;
523 }
524
525 if (newkeycxx . . $ newkey.)
526 {
527 // Due to key jamming, holding down 4 keys simultaneous may not be possible, so an
528 // alternate input method is also provided.
529 if (lordProgress < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(lordKeys) &&
530 lastkey_scancxx . . $ lastkey_scan. == lordKeys[lordProgress])
531 {
532 lordProgress += 1;
533
534 if (lordProgress == COUNTOFcxx . . $ `src/opentyr.h:27:9`!(lordKeys))
535 menuItemsVisibleCount = 6;
536 }
537 else
538 {
539 lordProgress = 0;
540 }
541 }
542 }
543 if (SDL_GetModStatecxx . . $ SDL_GetModState(d49f17f06d681085).() & KMOD_SHIFTcxx . . $ KMOD_SHIFT.)
544 {
545 if (menuItemsVisibleCount == 4 && keysactivecxx . . $ keysactive.[SDL_SCANCODE_RIGHTBRACKETcxx . . $ SDL_SCANCODE_RIGHTBRACKET.])
546 menuItemsVisibleCount = 5;
547 if (menuItemsVisibleCount == 3 && keysactivecxx . . $ keysactive.[SDL_SCANCODE_Gcxx . . $ SDL_SCANCODE_G.])
548 menuItemsVisibleCount = 4;
549 }
550
551 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! action = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
552 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cancel = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
553
554 if (mouseMoved || newmousecxx . . $ newmouse.)
555 {
556 // Find menu item that was hovered or clicked.
557 for (size_t i = 0; i < menuItemsVisibleCount; ++i)
558 {
559 const int xMenuItem = xCenter - wMenuItem[i] / 2;
560 if (mouse_xcxx . . $ mouse_x. >= xMenuItem && mouse_xcxx . . $ mouse_x. < xMenuItem + wMenuItem[i])
561 {
562 const int yMenuItem = yMenuItems + dyMenuItems * i;
563 if (mouse_ycxx . . $ mouse_y. >= yMenuItem && mouse_ycxx . . $ mouse_y. < yMenuItem + hMenuItem)
564 {
565 if (selectedIndex != i)
566 {
567 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_CURSORcxx . . $ S_CURSOR.);
568
569 selectedIndex = i;
570 }
571
572 if (newmousecxx . . $ newmouse. && lastmouse_butcxx . . $ lastmouse_but. == SDL_BUTTON_LEFTcxx . . $ `<external>/13849749812924280863/SDL_mouse.h:445:9`! &&
573 lastmouse_xcxx . . $ lastmouse_x. >= xMenuItem && lastmouse_xcxx . . $ lastmouse_x. < xMenuItem + wMenuItem[i] &&
574 lastmouse_ycxx . . $ lastmouse_y. >= yMenuItem && lastmouse_ycxx . . $ lastmouse_y. < yMenuItem + hMenuItem)
575 {
576 action = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
577 }
578
579 break;
580 }
581 }
582 }
583 }
584
585 if (newmousecxx . . $ newmouse.)
586 {
587 if (lastmouse_butcxx . . $ lastmouse_but. == SDL_BUTTON_RIGHTcxx . . $ `<external>/13849749812924280863/SDL_mouse.h:447:9`!)
588 {
589 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SPRINGcxx . . $ S_SPRING.);
590
591 cancel = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
592 }
593 }
594 else if (newkeycxx . . $ newkey.)
595 {
596 switch (lastkey_scancxx . . $ lastkey_scan.)
597 {
598 case SDL_SCANCODE_UPcxx . . $ SDL_SCANCODE_UP.:
599 {
600 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_CURSORcxx . . $ S_CURSOR.);
601
602 selectedIndex = selectedIndex == 0
603 ? menuItemsVisibleCount - 1
604 : selectedIndex - 1;
605 break;
606 }
607 case SDL_SCANCODE_DOWNcxx . . $ SDL_SCANCODE_DOWN.:
608 {
609 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_CURSORcxx . . $ S_CURSOR.);
610
611 selectedIndex = selectedIndex == menuItemsVisibleCount - 1
612 ? 0
613 : selectedIndex + 1;
614 break;
615 }
616 case SDL_SCANCODE_SPACEcxx . . $ SDL_SCANCODE_SPACE.:
617 case SDL_SCANCODE_RETURNcxx . . $ SDL_SCANCODE_RETURN.:
618 {
619 action = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
620 break;
621 }
622 case SDL_SCANCODE_ESCAPEcxx . . $ SDL_SCANCODE_ESCAPE.:
623 {
624 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SPRINGcxx . . $ S_SPRING.);
625
626 cancel = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
627 break;
628 }
629 default:
630 break;
631 }
632 }
633
634 if (action)
635 {
636 JE_playSampleNumcxx . . $ JE_playSampleNum(ac50b47256ae7414).(S_SELECTcxx . . $ S_SELECT.);
637
638 switch (selectedIndex)
639 {
640 case 0:
641 difficultyLevelcxx . . $ difficultyLevel. = DIFFICULTY_EASYcxx . . $ DIFFICULTY_EASY.;
642 break;
643 case 1:
644 difficultyLevelcxx . . $ difficultyLevel. = DIFFICULTY_NORMALcxx . . $ DIFFICULTY_NORMAL.;
645 break;
646 case 2:
647 difficultyLevelcxx . . $ difficultyLevel. = DIFFICULTY_HARDcxx . . $ DIFFICULTY_HARD.;
648 break;
649 case 3:
650 difficultyLevelcxx . . $ difficultyLevel. = DIFFICULTY_IMPOSSIBLEcxx . . $ DIFFICULTY_IMPOSSIBLE.;
651 break;
652 case 4:
653 difficultyLevelcxx . . $ difficultyLevel. = DIFFICULTY_SUICIDEcxx . . $ DIFFICULTY_SUICIDE.;
654 break;
655 case 5:
656 difficultyLevelcxx . . $ difficultyLevel. = DIFFICULTY_ZINGLONcxx . . $ DIFFICULTY_ZINGLON.;
657 break;
658 }
659
660 fade_blackcxx . . $ fade_black(d4f767463ce0a6b3).(10);
661
662 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
663 }
664
665 if (cancel)
666 {
667 fade_blackcxx . . $ fade_black(d4f767463ce0a6b3).(15);
668
669 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
670 }
671 }
672 }