Debian Codegraph @

src/menu/mainmenu.cpp

raw symbols SCIP
1
2 /**
3 *
4 * @file mainmenu.cpp
5 *
6 * Part of the OpenJazz project
7 *
8 * @par History:
9 * - 23rd of August 2005: Created menu.c
10 * - 3rd of February 2009: Renamed menu.c to menu.cpp
11 * - 19th July 2009: Created menumain.cpp from parts of menu.cpp
12 * - 26th July 2009: Renamed menumain.cpp to mainmenu.cpp
13 *
14 * @par Licence:
15 * Copyright (c) 2005-2017 AJ Thomson
16 *
17 * OpenJazz is distributed under the terms of
18 * the GNU General Public License, version 2.0
19 *
20 * @par Description:
21 * Deals with the running of the main menu and its generic sub-menus.
22 *
23 */
24
25
26 #include "menu.h"cxx . . $ `<file>/src/menu/menu.h`/
27 #include "plasma.h"cxx . . $ `<file>/src/menu/plasma.h`/
28
29 #include "game/game.h"cxx . . $ `<file>/src/game/game.h`/
30 #include "io/controls.h"cxx . . $ `<file>/src/io/controls.h`/
31 #include "io/gfx/video.h"cxx . . $ `<file>/src/io/gfx/video.h`/
32 #include "io/gfx/font.h"cxx . . $ `<file>/src/io/gfx/font.h`/
33 #include "io/sound.h"cxx . . $ `<file>/src/io/sound.h`/
34 #include "jj1/scene/jj1scene.h"cxx . . $ `<file>/src/jj1/scene/jj1scene.h`/
35 #include "loop.h"cxx . . $ `<file>/src/loop.h`/
36 #include "util.h"cxx . . $ `<file>/src/util.h`/
37 #include "io/log.h"cxx . . $ `<file>/src/io/log.h`/
38 #include "logo.h"cxx . . $ `<file>/src/logo.h`/
39 #include "version.h"cxx . . $ `<file>/src/version.h`/
40
41 #include <miniz.h>cxx . . $ `<file>/ext/miniz/miniz.h`/
42 #include <time.h>
43
44
45 /**
46 * Create the main menu.
47 */
48 MainMenucxx . . $ MainMenu#::MainMenucxx . . $ MainMenu#MainMenu(49f6e7a06ebc5aa8). () {
49
50 Filecxx . . $ File# *file;
51 time_t currentTime;
52
53 // Load the OpenJazz logo
54
55 unsigned char* pixels = new unsigned char[oj_logocxx . . $ oj_logo..sizecxx . . $ compressed_image#size.];
56 size_t res = tinfl_decompress_mem_to_mem(pixels, oj_logocxx . . $ oj_logo..sizecxx . . $ compressed_image#size., oj_logocxx . . $ oj_logo..datacxx . . $ compressed_image#data.,
57 oj_logocxx . . $ oj_logo..compressed_sizecxx . . $ compressed_image#compressed_size., TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF|TINFL_FLAG_PARSE_ZLIB_HEADER);
58 if (res == TINFL_DECOMPRESS_MEM_TO_MEM_FAILEDcxx . . $ `ext/miniz/miniz.h:783:9`! || res != oj_logocxx . . $ oj_logo..sizecxx . . $ compressed_image#size.) {
59
60 LOG_WARNcxx . . $ `src/io/log.h:77:9`!("Could not uncompress logo (expected: %d, actual: %zu).", oj_logo.size, res);
61 logocxx . . $ MainMenu#logo. = nullptr;
62
63 } else {
64
65 logocxx . . $ MainMenu#logo. = videocxx . . $ video..createSurfacecxx . . $ Video#createSurface(5ec4649223a2dfef).(pixels, oj_logocxx . . $ oj_logo..widthcxx . . $ compressed_image#width., oj_logocxx . . $ oj_logo..heightcxx . . $ compressed_image#height.);
66
67 }
68 delete[] pixels;
69
70 // Load the menu graphics
71
72 try {
73
74 file = new Filecxx . . $ File#File(e99a0a23efd851c6).("MENU.000", PATH_TYPE_GAMEcxx . . $ PATH_TYPE_GAME.);
75
76 } catch (int e) {
77
78 videocxx . . $ video..destroySurfacecxx . . $ Video#destroySurface(60a0b30a00b4fc6d).(logocxx . . $ MainMenu#logo.);
79
80 throw;
81
82 }
83
84 // only available in Holiday Hare 94/95
85 if (file->getSizecxx . . $ File#getSize(b126dc7c1de90089).() > 200000) {
86
87 time(&currentTime);
88
89 // In December, load the Christmas menu graphics
90 if (localtime(&currentTime)->tm_moncxx . . $ tm#tm_mon. == 11) {
91
92 LOG_TRACEcxx . . $ `src/io/log.h:74:9`!("Loading christmas menu theme.");
93
94 file->skipRLEcxx . . $ File#skipRLE(49f6e7a06ebc5aa8).();
95 file->skipRLEcxx . . $ File#skipRLE(49f6e7a06ebc5aa8).();
96 file->skipRLEcxx . . $ File#skipRLE(49f6e7a06ebc5aa8).();
97
98 file->loadPalettecxx . . $ File#loadPalette(a8e7e0a5cf0a5bef).(palettecxx . . $ MainMenu#palette.);
99 backgroundcxx . . $ MainMenu#background. = file->loadSurfacecxx . . $ File#loadSurface(efa8a2aaf13882cf).(SWcxx . . $ `src/io/gfx/video.h:38:9`!, SHcxx . . $ `src/io/gfx/video.h:39:9`!);
100 highlightcxx . . $ MainMenu#highlight. = file->loadSurfacecxx . . $ File#loadSurface(efa8a2aaf13882cf).(SWcxx . . $ `src/io/gfx/video.h:38:9`!, SHcxx . . $ `src/io/gfx/video.h:39:9`!);
101
102 } else {
103
104 file->loadPalettecxx . . $ File#loadPalette(a8e7e0a5cf0a5bef).(palettecxx . . $ MainMenu#palette.);
105 backgroundcxx . . $ MainMenu#background. = file->loadSurfacecxx . . $ File#loadSurface(efa8a2aaf13882cf).(SWcxx . . $ `src/io/gfx/video.h:38:9`!, SHcxx . . $ `src/io/gfx/video.h:39:9`!);
106 highlightcxx . . $ MainMenu#highlight. = file->loadSurfacecxx . . $ File#loadSurface(efa8a2aaf13882cf).(SWcxx . . $ `src/io/gfx/video.h:38:9`!, SHcxx . . $ `src/io/gfx/video.h:39:9`!);
107
108 file->skipRLEcxx . . $ File#skipRLE(49f6e7a06ebc5aa8).();
109 file->skipRLEcxx . . $ File#skipRLE(49f6e7a06ebc5aa8).();
110 file->skipRLEcxx . . $ File#skipRLE(49f6e7a06ebc5aa8).();
111
112 }
113
114 } else {
115
116 file->loadPalettecxx . . $ File#loadPalette(a8e7e0a5cf0a5bef).(palettecxx . . $ MainMenu#palette.);
117 backgroundcxx . . $ MainMenu#background. = file->loadSurfacecxx . . $ File#loadSurface(efa8a2aaf13882cf).(SWcxx . . $ `src/io/gfx/video.h:38:9`!, SHcxx . . $ `src/io/gfx/video.h:39:9`!);
118 highlightcxx . . $ MainMenu#highlight. = file->loadSurfacecxx . . $ File#loadSurface(efa8a2aaf13882cf).(SWcxx . . $ `src/io/gfx/video.h:38:9`!, SHcxx . . $ `src/io/gfx/video.h:39:9`!);
119
120 }
121
122 videocxx . . $ video..enableColorKeycxx . . $ Video#enableColorKey(905504f46e4e09c1).(backgroundcxx . . $ MainMenu#background., 0);
123 videocxx . . $ video..enableColorKeycxx . . $ Video#enableColorKey(905504f46e4e09c1).(highlightcxx . . $ MainMenu#highlight., 0);
124 if (logocxx . . $ MainMenu#logo.) videocxx . . $ video..enableColorKeycxx . . $ Video#enableColorKey(905504f46e4e09c1).(logocxx . . $ MainMenu#logo., 28);
125
126 gameMenucxx . . $ MainMenu#gameMenu. = new GameMenucxx . . $ GameMenu#(file);
127
128 delete file;
129
130 }
131
132
133 /**
134 * Delete the main menu.
135 */
136 MainMenucxx . . $ MainMenu#::~cxx . . $ MainMenu#`~MainMenu`(49f6e7a06ebc5aa8).MainMenucxx . . $ MainMenu# () {
137
138 videocxx . . $ video..destroySurfacecxx . . $ Video#destroySurface(60a0b30a00b4fc6d).(backgroundcxx . . $ MainMenu#background.);
139 videocxx . . $ video..destroySurfacecxx . . $ Video#destroySurface(60a0b30a00b4fc6d).(highlightcxx . . $ MainMenu#highlight.);
140 videocxx . . $ video..destroySurfacecxx . . $ Video#destroySurface(60a0b30a00b4fc6d).(logocxx . . $ MainMenu#logo.);
141
142 delete gameMenucxx . . $ MainMenu#gameMenu.;
143
144 }
145
146
147 /**
148 * Process a main menu selection.
149 *
150 * @param option Chosen menu option
151 *
152 * @return Error code
153 */
154 int MainMenucxx . . $ MainMenu#::selectcxx . . $ MainMenu#select(7864480464b09eea). (int option) {
155
156 JJ1Scenecxx . . $ JJ1Scene# *scene;
157 SetupMenucxx . . $ SetupMenu# setupMenu;
158
159 playConfirmSoundcxx . . $ playConfirmSound(49f6e7a06ebc5aa8).();
160
161 switch (option) {
162
163 case 0: // New game
164
165 if (gameMenucxx . . $ MainMenu#gameMenu.->newGamecxx . . $ GameMenu#newGame(b126dc7c1de90089).() == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
166
167 break;
168
169 case 1: // Load game
170
171 if (gameMenucxx . . $ MainMenu#gameMenu.->loadGamecxx . . $ GameMenu#loadGame(b126dc7c1de90089).() == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
172
173 break;
174
175 case 2: // Instructions
176
177 try {
178
179 scene = new JJ1Scenecxx . . $ JJ1Scene#("INSTRUCT.0SC");
180
181 } catch (int e) {
182
183 if (messagecxx . . $ Menu#message(5c4306d8553b3696).("COULD NOT LOAD INSTRUCTIONS") == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
184
185 break;
186
187 }
188
189 if (scene->playcxx . . $ JJ1Scene#play(b126dc7c1de90089).() == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) {
190
191 delete scene;
192
193 return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
194
195 }
196
197 delete scene;
198
199 break;
200
201 case 3: // Setup options
202
203 if (setupMenu.setupMaincxx . . $ SetupMenu#setupMain(b126dc7c1de90089).() == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
204
205 break;
206
207 case 4: // Order info
208
209 try {
210
211 scene = new JJ1Scenecxx . . $ JJ1Scene#("ORDER.0SC");
212
213 } catch (int e) {
214
215 if (messagecxx . . $ Menu#message(5c4306d8553b3696).("COULD NOT LOAD ORDER INFO") == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
216
217 break;
218
219 }
220
221 if (scene->playcxx . . $ JJ1Scene#play(b126dc7c1de90089).() == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) {
222
223 delete scene;
224
225 return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
226
227 }
228
229 delete scene;
230
231 break;
232
233 case 5: // Exit
234
235 return E_RETURNcxx . . $ `src/OpenJazz.h:66:9`!;
236
237 }
238
239 // Restore the main menu palette
240 videocxx . . $ video..setPalettecxx . . $ Video#setPalette(d5421d17e1a4b2b2).(palettecxx . . $ MainMenu#palette.);
241
242 return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!;
243
244 }
245
246
247 /**
248 * Run the main menu.
249 *
250 * @return Error code
251 */
252 int MainMenucxx . . $ MainMenu#::maincxx . . $ MainMenu#main(b126dc7c1de90089). () {
253
254 SDL_Rect options[6] = {
255 {92, 35, 136, 22},
256 {92, 57, 140, 22},
257 {88, 83, 144, 22},
258 {86, 109, 150, 23},
259 {82, 137, 156, 26},
260 {78, 166, 166, 29}};
261 int macroType[4];
262 Filecxx . . $ File#* file;
263 char* fileName;
264 Plasmacxx . . $ Plasma# plasmacxx . . $ Plasma#Plasma(49f6e7a06ebc5aa8).;
265 SDL_Rect dst;
266 int option, macro, x, y, ret;
267 unsigned int idleTime;
268
269 option = 0;
270
271 videocxx . . $ video..setPalettecxx . . $ Video#setPalette(d5421d17e1a4b2b2).(palettecxx . . $ MainMenu#palette.);
272
273 playMusiccxx . . $ playMusic(90ef5b561fbcb8de).("MENUSNG.PSM");
274
275
276 // Demo timeout
277 idleTime = globalTickscxx . . $ globalTicks. + T_DEMOcxx . . $ `src/menu/menu.h:44:9`!;
278
279 // Check for demo macros
280
281 fileName = createStringcxx . . $ createString(a8b8e32347182212).("MACRO.1");
282
283 for (macro = 0; macro < 4; macro++)
284 {
285
286 try {
287
288 file = new Filecxx . . $ File#File(e99a0a23efd851c6).(fileName, PATH_TYPE_GAMEcxx . . $ PATH_TYPE_GAME.);
289 macroType[macro] = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).();
290 delete file;
291
292 } catch (int e) {
293
294 macroType[macro] = -1;
295
296 }
297
298 fileName[6]++;
299
300 }
301
302 macro = 3;
303
304 delete[] fileName;
305
306
307 while (true) {
308
309 if (loopcxx . . $ loop(fd873fd06cfe1135).(NORMAL_LOOPcxx . . $ NORMAL_LOOP.) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
310
311 if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ESCAPEcxx . . $ `src/io/controls.h:39:9`!)) option = 5;
312
313 if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_UPcxx . . $ `src/io/controls.h:30:9`!)) option = (option + 5) % 6;
314
315 if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_DOWNcxx . . $ `src/io/controls.h:31:9`!)) option = (option + 1) % 6;
316
317 if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ENTERcxx . . $ `src/io/controls.h:38:9`!)) {
318
319 ret = selectcxx . . $ MainMenu#select(7864480464b09eea).(option);
320
321 if (ret < 0) return ret;
322
323 // New demo timeout
324 idleTime = globalTickscxx . . $ globalTicks. + T_DEMOcxx . . $ `src/menu/menu.h:44:9`!;
325
326 }
327
328 if (controlscxx . . $ controls..getCursorcxx . . $ Controls#getCursor(8a990ad1ed500b42).(x, y)) {
329
330 int count;
331
332 x -= (canvasWcxx . . $ canvasW. - SWcxx . . $ `src/io/gfx/video.h:38:9`!) >> 1;
333 y -= (canvasHcxx . . $ canvasH. - SHcxx . . $ `src/io/gfx/video.h:39:9`!) >> 1;
334
335 for (count = 0; count < 6; count++) {
336
337 if ((x >= options[count].x) &&
338 (x < options[count].x + options[count].w) &&
339 (y >= options[count].y) &&
340 (y < options[count].y + options[count].h)) {
341
342 option = count;
343
344 if (controlscxx . . $ controls..wasCursorReleasedcxx . . $ Controls#wasCursorReleased(c9857a73d68e59ba).()) {
345
346 ret = selectcxx . . $ MainMenu#select(7864480464b09eea).(option);
347
348 if (ret < 0) return ret;
349
350 }
351
352 // New demo timeout
353 idleTime = globalTickscxx . . $ globalTicks. + T_DEMOcxx . . $ `src/menu/menu.h:44:9`!;
354
355 break;
356
357 }
358 }
359
360 }
361
362
363 if (idleTime <= globalTickscxx . . $ globalTicks.) {
364
365 Gamecxx . . $ Game#* game = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
366
367 try {
368
369 game = new LocalGamecxx . . $ LocalGame#("", difficultyTypecxx . . $ difficultyType#::Easycxx . . $ difficultyType#Easy.);
370
371 } catch (int e) {
372
373 // Do nothing
374
375 }
376
377 if (game) {
378
379 // Load the macro
380
381 x = macro;
382 macro = (macro + 1) & 3;
383
384 while ((macroType[macro] != 0xFF) && (macro != x))
385 macro = (macro + 1) & 3;
386
387 if (macro != x) {
388
389 fileName = createStringcxx . . $ createString(a8b8e32347182212).("MACRO.1");
390 fileName[6] += macro;
391
392 if (game->playLevelcxx . . $ Game#playLevel(1ef8e6ec083aabb9).(fileName) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) {
393
394 delete[] fileName;
395 delete game;
396
397 return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
398
399 }
400
401 delete[] fileName;
402
403 }
404
405
406 delete game;
407
408 playMusiccxx . . $ playMusic(90ef5b561fbcb8de).("MENUSNG.PSM");
409
410 // Restore the main menu palette
411 videocxx . . $ video..setPalettecxx . . $ Video#setPalette(d5421d17e1a4b2b2).(palettecxx . . $ MainMenu#palette.);
412
413 }
414
415 idleTime = globalTickscxx . . $ globalTicks. + T_DEMOcxx . . $ `src/menu/menu.h:44:9`!;
416
417 }
418
419 SDL_Delay(T_MENU_FRAMEcxx . . $ `src/io/gfx/video.h:78:9`!);
420
421
422 //as long as we're drawing plasma, we don't need to clear the screen.
423 //video.clearScreen(28);
424
425 plasma.drawcxx . . $ Plasma#draw(b126dc7c1de90089).();
426
427 // draw logo and version string
428
429 if (logocxx . . $ MainMenu#logo.) {
430 dst.x = (canvasWcxx . . $ canvasW. >> 2) - 72;
431 dst.y = canvasHcxx . . $ canvasH. - (canvasHcxx . . $ canvasH. >> 2);
432 SDL_BlitSurfacecxx . . $ `<external>/18043084669712134795/SDL_surface.h:873:9`!(logocxx . . $ MainMenu#logo., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, canvascxx . . $ canvas., &dst);
433 }
434
435 panelBigFontcxx . . $ panelBigFont.->mapPalettecxx . . $ Font#mapPalette(748afa4755bc9595).(0, MAX_PALETTE_COLORScxx . . $ `src/OpenJazz.h:71:9`!, 8, 8);
436 if(canvasWcxx . . $ canvasW. > SWcxx . . $ `src/io/gfx/video.h:38:9`!)
437 panelBigFontcxx . . $ panelBigFont.->showStringcxx . . $ Font#showString(7e50a619d5a117f1).("OpenJazz", 16, canvasHcxx . . $ canvasH., alignXcxx . . $ alignX#::Leftcxx . . $ alignX#Left., alignYcxx . . $ alignY#::Bottomcxx . . $ alignY#Bottom.);
438 panelBigFontcxx . . $ panelBigFont.->showStringcxx . . $ Font#showString(7e50a619d5a117f1).(oj_versioncxx . . $ oj_version., canvasWcxx . . $ canvasW. - 16, canvasHcxx . . $ canvasH., alignXcxx . . $ alignX#::Rightcxx . . $ alignX#Right., alignYcxx . . $ alignY#::Bottomcxx . . $ alignY#Bottom.);
439 panelBigFontcxx . . $ panelBigFont.->restorePalettecxx . . $ Font#restorePalette(49f6e7a06ebc5aa8).();
440
441 dst.x = (canvasWcxx . . $ canvasW. - SWcxx . . $ `src/io/gfx/video.h:38:9`!) >> 1;
442 dst.y = (canvasHcxx . . $ canvasH. - SHcxx . . $ `src/io/gfx/video.h:39:9`!) >> 1;
443 SDL_BlitSurfacecxx . . $ `<external>/18043084669712134795/SDL_surface.h:873:9`!(backgroundcxx . . $ MainMenu#background., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, canvascxx . . $ canvas., &dst);
444
445 dst.x = ((canvasWcxx . . $ canvasW. - SWcxx . . $ `src/io/gfx/video.h:38:9`!) >> 1) + options[option].x;
446 dst.y = ((canvasHcxx . . $ canvasH. - SHcxx . . $ `src/io/gfx/video.h:39:9`!) >> 1) + options[option].y;
447 SDL_BlitSurfacecxx . . $ `<external>/18043084669712134795/SDL_surface.h:873:9`!(highlightcxx . . $ MainMenu#highlight., options + option, canvascxx . . $ canvas., &dst);
448
449 }
450
451 return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!;
452
453 }
454
455
456 /**
457 * Skip the main menu. Directly loads game
458 *
459 * @return Error code
460 */
461 int MainMenucxx . . $ MainMenu#::skipcxx . . $ MainMenu#skip(9b79fb6aee4c0440). (int levelNum, int worldNum) {
462
463 if (gameMenucxx . . $ MainMenu#gameMenu.->loadGamecxx . . $ GameMenu#loadGame(9b79fb6aee4c0440).(levelNum, worldNum) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!;
464
465 return E_RETURNcxx . . $ `src/OpenJazz.h:66:9`!;
466
467 }