| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file setup.cpp |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd of August 2005: Created main.c and menu.c |
| 10 | * - 3rd of February 2009: Renamed main.c to main.cpp and menu.c to menu.cpp |
| 11 | * - 18th July 2009: Created menusetup.cpp from parts of menu.cpp |
| 12 | * - 26th July 2009: Renamed menusetup.cpp to setupmenu.cpp |
| 13 | * - 21st July 2013: Created setup.cpp from parts of main.cpp and setupmenu.cpp |
| 14 | * |
| 15 | * @par Licence: |
| 16 | * Copyright (c) 2005-2017 AJ Thomson |
| 17 | * Copyright (c) 2015-2026 Carsten Teibes |
| 18 | * |
| 19 | * OpenJazz is distributed under the terms of |
| 20 | * the GNU General Public License, version 2.0 |
| 21 | * |
| 22 | * @par Description: |
| 23 | * Deals with the running of setup menus. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | #include "io/controls.h"cxx . . $ `<file>/src/io/controls.h`/ |
| 29 | #include "io/file.h"cxx . . $ `<file>/src/io/file.h`/ |
| 30 | #include "io/gfx/video.h"cxx . . $ `<file>/src/io/gfx/video.h`/ |
| 31 | #include "io/sound.h"cxx . . $ `<file>/src/io/sound.h`/ |
| 32 | #include "player/player.h"cxx . . $ `<file>/src/player/player.h`/ |
| 33 | #include "setup.h"cxx . . $ `<file>/src/setup.h`/ |
| 34 | #include "util.h"cxx . . $ `<file>/src/util.h`/ |
| 35 | #include "io/log.h"cxx . . $ `<file>/src/io/log.h`/ |
| 36 | |
| 37 | #define CONFIG_FILEcxx . . $ `src/setup.cpp:37:9`! "openjazz.cfg" |
| 38 | |
| 39 | |
| 40 | /** |
| 41 | * Create default setup |
| 42 | */ |
| 43 | Setupcxx . . $ Setup#::Setupcxx . . $ Setup#Setup(49f6e7a06ebc5aa8). () { |
| 44 | |
| 45 | // Create the player's name |
| 46 | characterNamecxx . . $ Setup#characterName. = createEditableStringcxx . . $ createEditableString(a8b8e32347182212).(CHAR_NAMEcxx . . $ `src/player/player.h:38:9`!); |
| 47 | |
| 48 | // Assign the player's colour |
| 49 | characterColscxx . . $ Setup#characterCols.[0] = CHAR_FURcxx . . $ `src/player/player.h:39:9`!; |
| 50 | characterColscxx . . $ Setup#characterCols.[1] = CHAR_BANDcxx . . $ `src/player/player.h:40:9`!; |
| 51 | characterColscxx . . $ Setup#characterCols.[2] = CHAR_GUNcxx . . $ `src/player/player.h:41:9`!; |
| 52 | characterColscxx . . $ Setup#characterCols.[3] = CHAR_WBANDcxx . . $ `src/player/player.h:42:9`!; |
| 53 | |
| 54 | // defaults |
| 55 | manyBirdscxx . . $ Setup#manyBirds. = false; |
| 56 | leaveUnneededcxx . . $ Setup#leaveUnneeded. = true; |
| 57 | slowMotioncxx . . $ Setup#slowMotion. = false; |
| 58 | hudStylecxx . . $ Setup#hudStyle. = hudTypecxx . . $ hudType#::Classiccxx . . $ hudType#Classic.; |
| 59 | |
| 60 | } |
| 61 | |
| 62 | |
| 63 | /** |
| 64 | * Delete the setup data |
| 65 | */ |
| 66 | Setupcxx . . $ Setup#::~cxx . . $ Setup#`~Setup`(49f6e7a06ebc5aa8).Setupcxx . . $ Setup# () { |
| 67 | |
| 68 | delete[] characterNamecxx . . $ Setup#characterName.; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /** |
| 74 | * Load settings from config file. |
| 75 | */ |
| 76 | SetupOptionscxx . . $ SetupOptions# Setupcxx . . $ Setup#::loadcxx . . $ Setup#load(48f624f2413f693b). () { |
| 77 | |
| 78 | Filecxx . . $ File#* file; |
| 79 | SetupOptionscxx . . $ SetupOptions# cfg = { false, 0, 0, false, 0, scalerTypecxx . . $ scalerType#::Nonecxx . . $ scalerType#None. }; |
| 80 | #ifdef FULLSCREEN_ONLY |
| 81 | cfg.fullScreen = true; |
| 82 | #endif |
| 83 | |
| 84 | // Open config file |
| 85 | |
| 86 | try { |
| 87 | |
| 88 | file = new Filecxx . . $ File#File(e99a0a23efd851c6).(CONFIG_FILEcxx . . $ `src/setup.cpp:37:9`!, PATH_TYPE_CONFIGcxx . . $ PATH_TYPE_CONFIG., false); |
| 89 | |
| 90 | } catch (int e) { |
| 91 | |
| 92 | LOG_INFOcxx . . $ `src/io/log.h:76:9`!("Configuration file not found. Using defaults."); |
| 93 | |
| 94 | return cfg; |
| 95 | |
| 96 | } |
| 97 | |
| 98 | // Check that the config file has the correct version |
| 99 | if (file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).() != 7) { |
| 100 | |
| 101 | LOG_WARNcxx . . $ `src/io/log.h:77:9`!("Valid configuration file not found."); |
| 102 | delete file; |
| 103 | |
| 104 | return cfg; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | // Read video settings |
| 109 | cfg.videoWidthcxx . . $ SetupOptions#videoWidth. = file->loadShortcxx . . $ File#loadShort(a18c05e4017afb3d).(MAX_SCREEN_WIDTHcxx . . $ `src/io/gfx/video.h:49:9`!); |
| 110 | cfg.videoHeightcxx . . $ SetupOptions#videoHeight. = file->loadShortcxx . . $ File#loadShort(a18c05e4017afb3d).(MAX_SCREEN_HEIGHTcxx . . $ `src/io/gfx/video.h:50:9`!); |
| 111 | |
| 112 | #ifdef FULLSCREEN_ONLY |
| 113 | file->loadChar(); // skip |
| 114 | #else |
| 115 | cfg.fullScreencxx . . $ SetupOptions#fullScreen. = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).(); |
| 116 | #endif |
| 117 | |
| 118 | unsigned int scaleOpt = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).(); |
| 119 | cfg.videoScalecxx . . $ SetupOptions#videoScale. = CLAMPcxx . . $ `src/types.h:58:9`!(scaleOpt, MIN_SCALEcxx . . $ `src/io/gfx/video.h:41:9`!, MAX_SCALEcxx . . $ `src/io/gfx/video.h:43:10`!); |
| 120 | |
| 121 | scaleOpt = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).(); |
| 122 | cfg.scaleMethodcxx . . $ SetupOptions#scaleMethod. = static_cast<scalerTypecxx . . $ scalerType#>(CLAMPcxx . . $ `src/types.h:58:9`!(scaleOpt, +scalerType::None, +scalerType::hqx)); |
| 123 | |
| 124 | cfg.validcxx . . $ SetupOptions#valid. = true; |
| 125 | |
| 126 | // Read controls |
| 127 | for (int i = 0; i < CONTROLScxx . . $ `src/io/controls.h:50:9`! - 4; i++) |
| 128 | controlscxx . . $ controls..setKeycxx . . $ Controls#setKey(3e454b8ccf442868).(i, file->loadIntcxx . . $ File#loadInt(b126dc7c1de90089).()); |
| 129 | |
| 130 | for (int i = 0; i < CONTROLScxx . . $ `src/io/controls.h:50:9`!; i++) |
| 131 | controlscxx . . $ controls..setButtoncxx . . $ Controls#setButton(3e454b8ccf442868).(i, file->loadIntcxx . . $ File#loadInt(b126dc7c1de90089).()); |
| 132 | |
| 133 | for (int i = 0; i < CONTROLScxx . . $ `src/io/controls.h:50:9`!; i++) { |
| 134 | |
| 135 | int a, d; |
| 136 | |
| 137 | a = file->loadIntcxx . . $ File#loadInt(b126dc7c1de90089).(); |
| 138 | d = file->loadIntcxx . . $ File#loadInt(b126dc7c1de90089).(); |
| 139 | controlscxx . . $ controls..setAxiscxx . . $ Controls#setAxis(6908015b96d379c0).(i, a, d); |
| 140 | |
| 141 | } |
| 142 | |
| 143 | for (int i = 0; i < CONTROLScxx . . $ `src/io/controls.h:50:9`!; i++) { |
| 144 | |
| 145 | int h, d; |
| 146 | |
| 147 | h = file->loadIntcxx . . $ File#loadInt(b126dc7c1de90089).(); |
| 148 | d = file->loadIntcxx . . $ File#loadInt(b126dc7c1de90089).(); |
| 149 | controlscxx . . $ controls..setHatcxx . . $ Controls#setHat(b1146eedae1e1d0b).(i, h, d); |
| 150 | |
| 151 | } |
| 152 | |
| 153 | // Read the player's name |
| 154 | for (int i = 0; i < STRING_LENGTHcxx . . $ `src/OpenJazz.h:46:9`!; i++) |
| 155 | setupcxx . . $ setup..characterNamecxx . . $ Setup#characterName.[i] = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).(); |
| 156 | |
| 157 | setupcxx . . $ setup..characterNamecxx . . $ Setup#characterName.[STRING_LENGTHcxx . . $ `src/OpenJazz.h:46:9`!] = 0; |
| 158 | |
| 159 | // Read the player's colours |
| 160 | setupcxx . . $ setup..characterColscxx . . $ Setup#characterCols.[0] = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).(); |
| 161 | setupcxx . . $ setup..characterColscxx . . $ Setup#characterCols.[1] = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).(); |
| 162 | setupcxx . . $ setup..characterColscxx . . $ Setup#characterCols.[2] = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).(); |
| 163 | setupcxx . . $ setup..characterColscxx . . $ Setup#characterCols.[3] = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).(); |
| 164 | |
| 165 | // Read the music and sound effect volume |
| 166 | setMusicVolumecxx . . $ setMusicVolume(d4f767463ce0a6b3).(file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).()); |
| 167 | setSoundVolumecxx . . $ setSoundVolume(d4f767463ce0a6b3).(file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).()); |
| 168 | |
| 169 | // Read gameplay options |
| 170 | int opt = file->loadCharcxx . . $ File#loadChar(7c4be072098b358f).(); |
| 171 | setupcxx . . $ setup..manyBirdscxx . . $ Setup#manyBirds. = ((opt & 1) != 0); |
| 172 | setupcxx . . $ setup..leaveUnneededcxx . . $ Setup#leaveUnneeded. = ((opt & 2) != 0); |
| 173 | setupcxx . . $ setup..slowMotioncxx . . $ Setup#slowMotion. = ((opt & 4) != 0); |
| 174 | if((opt & 8) != 0) { |
| 175 | setupcxx . . $ setup..hudStylecxx . . $ Setup#hudStyle. = hudTypecxx . . $ hudType#::FPScxx . . $ hudType#FPS.; |
| 176 | } else { |
| 177 | setupcxx . . $ setup..hudStylecxx . . $ Setup#hudStyle. = hudTypecxx . . $ hudType#::Classiccxx . . $ hudType#Classic.; |
| 178 | } |
| 179 | |
| 180 | delete file; |
| 181 | |
| 182 | return cfg; |
| 183 | |
| 184 | } |
| 185 | |
| 186 | |
| 187 | /** |
| 188 | * Save settings to config file. |
| 189 | */ |
| 190 | void Setupcxx . . $ Setup#::savecxx . . $ Setup#save(49f6e7a06ebc5aa8). () { |
| 191 | |
| 192 | Filecxx . . $ File# *file; |
| 193 | int count; |
| 194 | |
| 195 | // Open config file |
| 196 | try { |
| 197 | |
| 198 | file = new Filecxx . . $ File#File(e99a0a23efd851c6).(CONFIG_FILEcxx . . $ `src/setup.cpp:37:9`!, PATH_TYPE_CONFIGcxx . . $ PATH_TYPE_CONFIG., true); |
| 199 | |
| 200 | } catch (int e) { |
| 201 | |
| 202 | file = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 203 | |
| 204 | } |
| 205 | |
| 206 | // Check that the config file was opened |
| 207 | if (!file) { |
| 208 | |
| 209 | LOG_ERRORcxx . . $ `src/io/log.h:78:9`!("Could not write configuration file: File could not be opened."); |
| 210 | |
| 211 | return; |
| 212 | |
| 213 | } |
| 214 | |
| 215 | |
| 216 | // Write the version number |
| 217 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(7); |
| 218 | |
| 219 | // Write video settings |
| 220 | file->storeShortcxx . . $ File#storeShort(ed53e3bbd3fa2f69).(videocxx . . $ video..getWidthcxx . . $ Video#getWidth(455f465bc33b4cdf).()); |
| 221 | file->storeShortcxx . . $ File#storeShort(ed53e3bbd3fa2f69).(videocxx . . $ video..getHeightcxx . . $ Video#getHeight(455f465bc33b4cdf).()); |
| 222 | |
| 223 | #ifdef FULLSCREEN_ONLY |
| 224 | file->storeChar(1); |
| 225 | #else |
| 226 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(videocxx . . $ video..isFullscreencxx . . $ Video#isFullscreen(50ce9a9e25b4a850).()? 1: 0); |
| 227 | #endif |
| 228 | |
| 229 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(videocxx . . $ video..getScaleFactorcxx . . $ Video#getScaleFactor(455f465bc33b4cdf).()); |
| 230 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(+cxx . . $ operator+(a7273123dcc02b2b).videocxx . . $ video..getScaleMethodcxx . . $ Video#getScaleMethod(79c99e9ca623648).()); |
| 231 | |
| 232 | // Write controls |
| 233 | for (count = 0; count < CONTROLScxx . . $ `src/io/controls.h:50:9`! - 4; count++) |
| 234 | file->storeIntcxx . . $ File#storeInt(d4f767463ce0a6b3).(controlscxx . . $ controls..getKeycxx . . $ Controls#getKey(7864480464b09eea).(count)); |
| 235 | |
| 236 | for (count = 0; count < CONTROLScxx . . $ `src/io/controls.h:50:9`!; count++) |
| 237 | file->storeIntcxx . . $ File#storeInt(d4f767463ce0a6b3).(controlscxx . . $ controls..getButtoncxx . . $ Controls#getButton(7864480464b09eea).(count)); |
| 238 | |
| 239 | for (count = 0; count < CONTROLScxx . . $ `src/io/controls.h:50:9`!; count++) { |
| 240 | |
| 241 | file->storeIntcxx . . $ File#storeInt(d4f767463ce0a6b3).(controlscxx . . $ controls..getAxiscxx . . $ Controls#getAxis(7864480464b09eea).(count)); |
| 242 | file->storeIntcxx . . $ File#storeInt(d4f767463ce0a6b3).(controlscxx . . $ controls..getAxisDirectioncxx . . $ Controls#getAxisDirection(7864480464b09eea).(count)); |
| 243 | |
| 244 | } |
| 245 | |
| 246 | for (count = 0; count < CONTROLScxx . . $ `src/io/controls.h:50:9`!; count++) { |
| 247 | |
| 248 | file->storeIntcxx . . $ File#storeInt(d4f767463ce0a6b3).(controlscxx . . $ controls..getHatcxx . . $ Controls#getHat(7864480464b09eea).(count)); |
| 249 | file->storeIntcxx . . $ File#storeInt(d4f767463ce0a6b3).(controlscxx . . $ controls..getHatDirectioncxx . . $ Controls#getHatDirection(7864480464b09eea).(count)); |
| 250 | |
| 251 | } |
| 252 | |
| 253 | // Write the player's name |
| 254 | for (count = 0; count < STRING_LENGTHcxx . . $ `src/OpenJazz.h:46:9`!; count++) |
| 255 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(setupcxx . . $ setup..characterNamecxx . . $ Setup#characterName.[count]); |
| 256 | |
| 257 | // Write the player's colour |
| 258 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(setupcxx . . $ setup..characterColscxx . . $ Setup#characterCols.[0]); |
| 259 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(setupcxx . . $ setup..characterColscxx . . $ Setup#characterCols.[1]); |
| 260 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(setupcxx . . $ setup..characterColscxx . . $ Setup#characterCols.[2]); |
| 261 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(setupcxx . . $ setup..characterColscxx . . $ Setup#characterCols.[3]); |
| 262 | |
| 263 | // Write the music and sound effect volume |
| 264 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(getMusicVolumecxx . . $ getMusicVolume(b126dc7c1de90089).()); |
| 265 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(getSoundVolumecxx . . $ getSoundVolume(b126dc7c1de90089).()); |
| 266 | |
| 267 | // Write gameplay options |
| 268 | |
| 269 | count = 0; |
| 270 | |
| 271 | if (setupcxx . . $ setup..manyBirdscxx . . $ Setup#manyBirds.) count |= 1; |
| 272 | if (setupcxx . . $ setup..leaveUnneededcxx . . $ Setup#leaveUnneeded.) count |= 2; |
| 273 | if (setupcxx . . $ setup..slowMotioncxx . . $ Setup#slowMotion.) count |= 4; |
| 274 | if (setupcxx . . $ setup..hudStylecxx . . $ Setup#hudStyle. == hudTypecxx . . $ hudType#::FPScxx . . $ hudType#FPS.) count |= 8; |
| 275 | |
| 276 | file->storeCharcxx . . $ File#storeChar(ac50b47256ae7414).(count); |
| 277 | |
| 278 | delete file; |
| 279 | |
| 280 | } |