| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file filemenu.cpp |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par Licence: |
| 9 | * Copyright (c) 2015-2026 Carsten Teibes |
| 10 | * |
| 11 | * OpenJazz is distributed under the terms of |
| 12 | * the GNU General Public License, version 2.0 |
| 13 | * |
| 14 | * @par Description: |
| 15 | * Deals with the running of the menus used save and load a game. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include "menu.h"cxx . . $ `<file>/src/menu/menu.h`/ |
| 20 | |
| 21 | #include "io/controls.h"cxx . . $ `<file>/src/io/controls.h`/ |
| 22 | #include "io/gfx/font.h"cxx . . $ `<file>/src/io/gfx/font.h`/ |
| 23 | #include "io/gfx/video.h"cxx . . $ `<file>/src/io/gfx/video.h`/ |
| 24 | #include "io/sound.h"cxx . . $ `<file>/src/io/sound.h`/ |
| 25 | #include "jj1/save/jj1save.h"cxx . . $ `<file>/src/jj1/save/jj1save.h`/ |
| 26 | #include "loop.h"cxx . . $ `<file>/src/loop.h`/ |
| 27 | #include "util.h"cxx . . $ `<file>/src/util.h`/ |
| 28 | #include <memory> |
| 29 | |
| 30 | int FileMenucxx . . $ FileMenu#::maincxx . . $ FileMenu#main(9f1afb2e1f195c72). (bool forSaving, bool showCustom) { |
| 31 | int x, y; |
| 32 | int chosen = 0; |
| 33 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<JJ1Savecxx . . $ JJ1Save#> savecxx . . $ std/unique_ptr#unique_ptr(49f6e7a06ebc5aa8).[4]; |
| 34 | int options = showCustom ? 5 : 4; |
| 35 | |
| 36 | // load save games |
| 37 | |
| 38 | char* fileName = createStringcxx . . $ createString(a8b8e32347182212).("SAVE.0"); |
| 39 | for (int i = 0; i < 4; i++) { |
| 40 | save[i] =cxx . . $ std/unique_ptr#`operator=`(1b63e42eaa758a73). stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<JJ1Savecxx . . $ JJ1Save#>(fileName); |
| 41 | fileName[5]++; |
| 42 | } |
| 43 | delete[] fileName; |
| 44 | |
| 45 | const char *loadGameOptions[5] = {save[0]->cxx . . $ std/unique_ptr#`operator->`(ca399b2b6292c808).namecxx . . $ JJ1Save#name., save[1]->cxx . . $ std/unique_ptr#`operator->`(ca399b2b6292c808).namecxx . . $ JJ1Save#name., save[2]->cxx . . $ std/unique_ptr#`operator->`(ca399b2b6292c808).namecxx . . $ JJ1Save#name., save[3]->cxx . . $ std/unique_ptr#`operator->`(ca399b2b6292c808).namecxx . . $ JJ1Save#name., "custom"}; |
| 46 | |
| 47 | auto fileChosen = [&]() -> bool { |
| 48 | if (chosen < 4 && !forSaving) { |
| 49 | if(!save[chosen]->cxx . . $ std/unique_ptr#`operator->`(ca399b2b6292c808).validcxx . . $ JJ1Save#valid.) { |
| 50 | playSoundcxx . . $ playSound(80b838f98135e5b).(SEcxx . . $ SE/::WAITcxx . . $ SE/WAIT.); |
| 51 | |
| 52 | return false; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | playConfirmSoundcxx . . $ playConfirmSound(49f6e7a06ebc5aa8).(); |
| 57 | return true; |
| 58 | }; |
| 59 | |
| 60 | videocxx . . $ video..setPalettecxx . . $ Video#setPalette(d5421d17e1a4b2b2).(menuPalettecxx . . $ menuPalette.); |
| 61 | |
| 62 | while (true) { |
| 63 | |
| 64 | if (loopcxx . . $ loop(fd873fd06cfe1135).(NORMAL_LOOPcxx . . $ NORMAL_LOOP.) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!; |
| 65 | |
| 66 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ESCAPEcxx . . $ `src/io/controls.h:39:9`!)) return E_RETURNcxx . . $ `src/OpenJazz.h:66:9`!; |
| 67 | |
| 68 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_UPcxx . . $ `src/io/controls.h:30:9`!)) chosen = (chosen + options - 1) % options; |
| 69 | |
| 70 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_DOWNcxx . . $ `src/io/controls.h:31:9`!)) chosen = (chosen + 1) % options; |
| 71 | |
| 72 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ENTERcxx . . $ `src/io/controls.h:38:9`!)) { |
| 73 | if(fileChosen(cxx . . $ FileMenu#main(9f1afb2e1f195c72).$anonymous_type_0#`operator()`(50ce9a9e25b4a850).)) |
| 74 | return chosen; |
| 75 | } |
| 76 | |
| 77 | if (controlscxx . . $ controls..getCursorcxx . . $ Controls#getCursor(8a990ad1ed500b42).(x, y)) { |
| 78 | |
| 79 | if ((x < 100) && (y >= canvasHcxx . . $ canvasH. - 12) && controlscxx . . $ controls..wasCursorReleasedcxx . . $ Controls#wasCursorReleased(c9857a73d68e59ba).()) return E_RETURNcxx . . $ `src/OpenJazz.h:66:9`!; |
| 80 | |
| 81 | x -= canvasWcxx . . $ canvasW. >> 2; |
| 82 | y -= (canvasHcxx . . $ canvasH. >> 1) - (options << 3); |
| 83 | |
| 84 | if ((x >= 0) && (x < 256) && (y >= 0) && (y < (options << 4))) { |
| 85 | |
| 86 | chosen = y >> 4; |
| 87 | |
| 88 | if (controlscxx . . $ controls..wasCursorReleasedcxx . . $ Controls#wasCursorReleased(c9857a73d68e59ba).()) { |
| 89 | if(fileChosen(cxx . . $ FileMenu#main(9f1afb2e1f195c72).$anonymous_type_0#`operator()`(50ce9a9e25b4a850).)) |
| 90 | return chosen; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | } |
| 95 | |
| 96 | SDL_Delay(T_MENU_FRAMEcxx . . $ `src/io/gfx/video.h:78:9`!); |
| 97 | |
| 98 | videocxx . . $ video..clearScreencxx . . $ Video#clearScreen(d4f767463ce0a6b3).(0); |
| 99 | |
| 100 | fontmn2cxx . . $ fontmn2.->showStringcxx . . $ Font#showString(7e50a619d5a117f1).(forSaving ? "SAVE GAME" : "LOAD GAME", canvasWcxx . . $ canvasW. >> 1, (canvasHcxx . . $ canvasH. >> 1) - (options << 3) - 32, alignXcxx . . $ alignX#::Centercxx . . $ alignX#Center.); |
| 101 | |
| 102 | for (int i = 0; i < options; i++) { |
| 103 | |
| 104 | if (i == chosen) fontmn2cxx . . $ fontmn2.->mapPalettecxx . . $ Font#mapPalette(748afa4755bc9595).(240, 8, 114, 16); |
| 105 | |
| 106 | fontmn2cxx . . $ fontmn2.->showStringcxx . . $ Font#showString(7e50a619d5a117f1).(loadGameOptions[i], (canvasWcxx . . $ canvasW. >> 1) - 80, |
| 107 | (canvasHcxx . . $ canvasH. >> 1) + (i << 4) - (options << 3)); |
| 108 | |
| 109 | if (i == chosen) fontmn2cxx . . $ fontmn2.->restorePalettecxx . . $ Font#restorePalette(49f6e7a06ebc5aa8).(); |
| 110 | |
| 111 | } |
| 112 | |
| 113 | showEscStringcxx . . $ Menu#showEscString(b45ddcbc8423892c).(); |
| 114 | } |
| 115 | |
| 116 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 117 | } |