diff --git a/source/audio.cpp b/source/audio.cpp index 81b0dd0..94b92b5 100644 --- a/source/audio.cpp +++ b/source/audio.cpp @@ -29,7 +29,7 @@ Audio::Audio() SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "\n** SDL_AUDIO: INITIALIZING\n"); JA_Init(48000, SDL_AUDIO_S16LE, 2); - enable(options.audio.enabled); + enable(Options::audio.enabled); SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_AUDIO: INITIALIZATION COMPLETE\n"); } @@ -104,7 +104,7 @@ void Audio::setSoundVolume(int sound_volume) if (sound_enabled_) { sound_volume = std::clamp(sound_volume, 0, 100); - const float CONVERTED_VOLUME = (sound_volume / 100.0f) * (options.audio.volume / 100.0f); + const float CONVERTED_VOLUME = (sound_volume / 100.0f) * (Options::audio.volume / 100.0f); JA_SetSoundVolume(CONVERTED_VOLUME); } } @@ -115,7 +115,7 @@ void Audio::setMusicVolume(int music_volume) if (music_enabled_) { music_volume = std::clamp(music_volume, 0, 100); - const float CONVERTED_VOLUME = (music_volume / 100.0f) * (options.audio.volume / 100.0f); + const float CONVERTED_VOLUME = (music_volume / 100.0f) * (Options::audio.volume / 100.0f); JA_SetMusicVolume(CONVERTED_VOLUME); } } @@ -123,7 +123,7 @@ void Audio::setMusicVolume(int music_volume) // Aplica la configuración void Audio::applySettings() { - enable(options.audio.enabled); + enable(Options::audio.enabled); } // Establecer estado general @@ -131,15 +131,6 @@ void Audio::enable(bool value) { enabled_ = value; - switch (enabled_) - { - case true: - setSoundVolume(options.audio.sound.volume); - setMusicVolume(options.audio.music.volume); - break; - case false: - setSoundVolume(0); - setMusicVolume(0); - break; - } + setSoundVolume(enabled_ ? Options::audio.sound.volume : 0); + setMusicVolume(enabled_ ? Options::audio.music.volume : 0); } \ No newline at end of file diff --git a/source/credits.cpp b/source/credits.cpp index 7faf4e1..2b8bd2d 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -488,15 +488,15 @@ void Credits::updateAllFades() // Establece el nivel de volumen void Credits::setVolume(int amount) { - options.audio.music.volume = std::clamp(amount, 0, 100); - Audio::get()->setMusicVolume(options.audio.music.volume); + Options::audio.music.volume = std::clamp(amount, 0, 100); + Audio::get()->setMusicVolume(Options::audio.music.volume); } // Reestablece el nivel de volumen void Credits::resetVolume() { - options.audio.music.volume = initial_volume_; - Audio::get()->setMusicVolume(options.audio.music.volume); + Options::audio.music.volume = initial_volume_; + Audio::get()->setMusicVolume(Options::audio.music.volume); } // Cambia el color del fondo diff --git a/source/credits.h b/source/credits.h index 4724323..3e2234a 100644 --- a/source/credits.h +++ b/source/credits.h @@ -57,7 +57,7 @@ private: int mini_logo_final_pos_ = 0; // Posición final del minilogo // --- Control de audio --- - int initial_volume_ = options.audio.music.volume; // Volumen inicial + int initial_volume_ = Options::audio.music.volume; // Volumen inicial int steps_ = 0; // Pasos para reducir audio // --- Rectángulos de renderizado --- diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 9981009..76ed610 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -28,7 +28,7 @@ void DefineButtons::render() { if (enabled_) { - text_->writeCentered(x_, y_ - 10, Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(options.controllers.at(index_controller_).player_id)); + text_->writeCentered(x_, y_ - 10, Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(Options::controllers.at(index_controller_).player_id)); text_->writeCentered(x_, y_, controller_names_.at(index_controller_)); text_->writeCentered(x_, y_ + 10, buttons_.at(index_button_).label); } @@ -110,7 +110,7 @@ void DefineButtons::incIndexButton() void DefineButtons::saveBindingsToOptions() { // Modifica las opciones para colocar los valores asignados - auto &controller = options.controllers.at(index_controller_); + auto &controller = Options::controllers.at(index_controller_); controller.name = input_->getControllerName(index_controller_); for (size_t j = 0; j < controller.inputs.size(); ++j) { diff --git a/source/director.cpp b/source/director.cpp index 2982e90..6ae47b4 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -46,14 +46,14 @@ Director::Director(int argc, const char *argv[]) { #ifdef RECORDING - section::name = section::Name::GAME; - section::options = section::Options::GAME_PLAY_1P; + Section::name = Section::Name::GAME; + Section::options = Section::Options::GAME_PLAY_1P; #elif DEBUG Section::name = Section::Name::LOGO; Section::options = Section::Options::GAME_PLAY_1P; #else // NORMAL GAME - section::name = section::Name::LOGO; - section::options = section::Options::NONE; + Section::name = Section::Name::LOGO; + Section::options = Section::Options::NONE; #endif Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO; @@ -88,12 +88,12 @@ void Director::init() // Configuración inicial de recursos Asset::init(executable_path_); // Inicializa el sistema de gestión de archivos setFileList(); // Crea el índice de archivos - loadOptionsFile(Asset::get()->get("config.txt")); // Carga el archivo de configuración + Options::loadOptionsFile(Asset::get()->get("config.txt")); // Carga el archivo de configuración loadParams(); // Carga los parámetros del programa loadScoreFile(); // Carga el archivo de puntuaciones // Inicialización de subsistemas principales - Lang::setLanguage(options.game.language); // Carga el archivo de idioma + Lang::setLanguage(Options::game.language); // Carga el archivo de idioma Screen::init(); // Inicializa la pantalla y el sistema de renderizado Audio::init(); // Activa el sistema de audio Resource::init(); // Inicializa el sistema de gestión de recursos @@ -108,7 +108,7 @@ void Director::init() void Director::close() { // Guarda las opciones actuales en el archivo de configuración - saveOptionsFile(Asset::get()->get("config.txt")); + Options::saveOptionsFile(Asset::get()->get("config.txt")); // Libera los singletons y recursos en orden inverso al de inicialización Notifier::destroy(); // Libera el sistema de notificaciones @@ -141,7 +141,7 @@ void Director::loadParams() // Carga el fichero de puntuaciones void Director::loadScoreFile() { - auto manager = std::make_unique(options.game.hi_score_table); + auto manager = std::make_unique(Options::game.hi_score_table); if (overrides.clear_hi_score_table) { manager->clear(); @@ -218,7 +218,7 @@ void Director::bindInputs() const size_t max_controllers = std::min(2, NUM_GAMEPADS); for (size_t i = 0; i < max_controllers; ++i) { - for (auto &controller : options.controllers) + for (auto &controller : Options::controllers) { if (Input::get()->getControllerName(i) == controller.name) { @@ -247,20 +247,20 @@ void Director::bindInputs() for (size_t i = 0; i < max_controllers; ++i) { // Variables asociadas al mando - options.controllers.at(i).index = i; - options.controllers.at(i).name = Input::get()->getControllerName(i); - options.controllers.at(i).plugged = true; + Options::controllers.at(i).index = i; + Options::controllers.at(i).name = Input::get()->getControllerName(i); + Options::controllers.at(i).plugged = true; // Asignaciones de botones - for (size_t j = 0; j < options.controllers.at(i).inputs.size(); ++j) + for (size_t j = 0; j < Options::controllers.at(i).inputs.size(); ++j) { - options.controllers.at(i).buttons.at(j) = Input::get()->getControllerBinding(i, options.controllers.at(i).inputs.at(j)); + Options::controllers.at(i).buttons.at(j) = Input::get()->getControllerBinding(i, Options::controllers.at(i).inputs.at(j)); } } // Asegura que algún jugador tenga el teclado asignado - if (getPlayerWhoUsesKeyboard() == 0) + if (Options::getPlayerWhoUsesKeyboard() == 0) { - setKeyboardToPlayer(1); + Options::setKeyboardToPlayer(1); } } @@ -617,9 +617,9 @@ void Director::runDemoGame() // Reinicia objetos y vuelve a la sección inicial void Director::reset() { - saveOptionsFile(Asset::get()->get("config.txt")); - loadOptionsFile(Asset::get()->get("config.txt")); - Lang::setLanguage(options.game.language); + Options::saveOptionsFile(Asset::get()->get("config.txt")); + Options::loadOptionsFile(Asset::get()->get("config.txt")); + Lang::setLanguage(Options::game.language); Audio::get()->stopMusic(); Audio::get()->stopAllSounds(); if (Section::options == Section::Options::RELOAD || true) diff --git a/source/game.cpp b/source/game.cpp index 4a6f8aa..1969b55 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -107,7 +107,7 @@ Game::~Game() else { // [Modo JUEGO] Guarda puntuaciones y transita a modo título - auto manager = std::make_unique(options.game.hi_score_table); + auto manager = std::make_unique(Options::game.hi_score_table); manager->saveToFile(Asset::get()->get("score.bin")); Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO; Audio::get()->stopMusic(); @@ -326,7 +326,7 @@ void Game::updateGameStateGameOver() if (fade_out_->isEnabled()) { - if (options.audio.enabled) + if (Options::audio.enabled) { const float VOL = static_cast(64 * (100 - fade_out_->getValue())) / 100.0f; Audio::get()->setSoundVolume(static_cast(VOL)); @@ -346,10 +346,10 @@ void Game::updateGameStateGameOver() Section::name = Section::Name::HI_SCORE_TABLE; } Section::options = Section::Options::HI_SCORE_AFTER_PLAYING; - if (options.audio.enabled) + if (Options::audio.enabled) { Audio::get()->stopAllSounds(); - Audio::get()->setSoundVolume(options.audio.sound.volume); + Audio::get()->setSoundVolume(Options::audio.sound.volume); } } } @@ -1267,10 +1267,10 @@ void Game::pause(bool value) void Game::addScoreToScoreBoard(const std::shared_ptr &player) { const auto entry = HiScoreEntry(trim(player->getRecordName()), player->getScore(), player->get1CC()); - auto manager = std::make_unique(options.game.hi_score_table); - options.game.last_hi_score_entry.at(player->getId() - 1) = manager->add(entry); + auto manager = std::make_unique(Options::game.hi_score_table); + Options::game.last_hi_score_entry.at(player->getId() - 1) = manager->add(entry); manager->saveToFile(Asset::get()->get("score.bin")); - hi_score_.name = options.game.hi_score_table.front().name; + hi_score_.name = Options::game.hi_score_table.front().name; } // Saca del estado de GAME OVER al jugador si el otro está activo @@ -1321,12 +1321,12 @@ std::shared_ptr Game::getPlayer(int id) // Obtiene un controlador a partir del "id" del jugador int Game::getController(int player_id) { - auto it = std::find_if(options.controllers.begin(), options.controllers.end(), [player_id](const auto &controller) + auto it = std::find_if(Options::controllers.begin(), Options::controllers.end(), [player_id](const auto &controller) { return controller.player_id == player_id; }); - if (it != options.controllers.end()) + if (it != Options::controllers.end()) { - return std::distance(options.controllers.begin(), it); + return std::distance(Options::controllers.begin(), it); } return -1; @@ -1443,7 +1443,7 @@ void Game::handleFireInput(const std::shared_ptr &player, BulletType bul Audio::get()->playSound("bullet.wav"); // Establece un tiempo de espera para el próximo disparo. - const int cooldown = player->isPowerUp() ? 5 : options.game.autofire ? 10 + const int cooldown = player->isPowerUp() ? 5 : Options::game.autofire ? 10 : 7; player->setFireCooldown(cooldown); } @@ -1475,8 +1475,8 @@ void Game::handlePlayersInput() // Maneja las entradas de movimiento y disparo para un jugador en modo normal. void Game::handleNormalPlayerInput(const std::shared_ptr &player) { - const auto &controller = options.controllers.at(player->getController()); - const bool autofire = player->isPowerUp() || options.game.autofire; + const auto &controller = Options::controllers.at(player->getController()); + const bool autofire = player->isPowerUp() || Options::game.autofire; if (input_->checkInput(InputAction::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) { @@ -1506,21 +1506,21 @@ void Game::handleNormalPlayerInput(const std::shared_ptr &player) // Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado. void Game::handleFireInputs(const std::shared_ptr &player, bool autofire, int controllerIndex) { - if (input_->checkInput(InputAction::FIRE_CENTER, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + if (input_->checkInput(InputAction::FIRE_CENTER, autofire, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { handleFireInput(player, BulletType::UP); #ifdef RECORDING demo_.keys.fire = 1; #endif } - else if (input_->checkInput(InputAction::FIRE_LEFT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + else if (input_->checkInput(InputAction::FIRE_LEFT, autofire, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { handleFireInput(player, BulletType::LEFT); #ifdef RECORDING demo_.keys.fire_left = 1; #endif } - else if (input_->checkInput(InputAction::FIRE_RIGHT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + else if (input_->checkInput(InputAction::FIRE_RIGHT, autofire, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { handleFireInput(player, BulletType::RIGHT); #ifdef RECORDING @@ -1533,16 +1533,16 @@ void Game::handleFireInputs(const std::shared_ptr &player, bool autofire void Game::handlePlayerContinue(const std::shared_ptr &player) { const auto controllerIndex = player->getController(); - if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { player->setPlayingState(PlayerState::PLAYING); player->addCredit(); } // Disminuye el contador de continuación si se presiona cualquier botón de disparo. - if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) || - input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) || - input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index) || + input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index) || + input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { if (player->getContinueCounter() < 7) { @@ -1555,9 +1555,9 @@ void Game::handlePlayerContinue(const std::shared_ptr &player) void Game::handleNameInput(const std::shared_ptr &player) { const auto controllerIndex = player->getController(); - if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) || - input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) || - input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index) || + input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index) || + input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { if (player->isShowingName()) { @@ -1574,19 +1574,19 @@ void Game::handleNameInput(const std::shared_ptr &player) player->setInput(InputAction::RIGHT); } } - else if (input_->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + else if (input_->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { player->setInput(InputAction::UP); } - else if (input_->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + else if (input_->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { player->setInput(InputAction::DOWN); } - else if (input_->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + else if (input_->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { player->setInput(InputAction::LEFT); } - else if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index)) + else if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index)) { player->setInput(InputAction::START); addScoreToScoreBoard(player); @@ -1689,7 +1689,7 @@ void Game::initDifficultyVars() // Variables relacionadas con la dificultad switch (difficulty_) { - case DifficultyCode::EASY: + case Options::DifficultyCode::EASY: { balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]); difficulty_score_multiplier_ = 0.5f; @@ -1697,7 +1697,7 @@ void Game::initDifficultyVars() break; } - case DifficultyCode::NORMAL: + case Options::DifficultyCode::NORMAL: { balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]); difficulty_score_multiplier_ = 1.0f; @@ -1705,7 +1705,7 @@ void Game::initDifficultyVars() break; } - case DifficultyCode::HARD: + case Options::DifficultyCode::HARD: { balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[4]); difficulty_score_multiplier_ = 1.5f; @@ -1935,7 +1935,7 @@ void Game::evaluateAndSetMenace() // Actualiza la velocidad de los globos en funcion del poder acumulado de la fase void Game::checkAndUpdateBalloonSpeed() { - if (difficulty_ != DifficultyCode::NORMAL) + if (difficulty_ != Options::DifficultyCode::NORMAL) return; const float percent = static_cast(Stage::power) / Stage::get(Stage::number).power_to_complete; diff --git a/source/game.h b/source/game.h index eb63f25..540a519 100644 --- a/source/game.h +++ b/source/game.h @@ -135,11 +135,11 @@ private: // --- Variables de estado --- HiScoreEntry hi_score_ = HiScoreEntry( - options.game.hi_score_table[0].name, - options.game.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta + Options::game.hi_score_table[0].name, + Options::game.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta Demo demo_; // Variable con todas las variables relacionadas con el modo demo - DifficultyCode difficulty_ = options.game.difficulty; // Dificultad del juego + Options::DifficultyCode difficulty_ = Options::game.difficulty; // Dificultad del juego Helper helper_; // Variable para gestionar las ayudas Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 86509b5..830b3ad 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -51,30 +51,30 @@ namespace GlobalInputs // Activa o desactiva el audio void toggleAudio() { - options.audio.enabled = !options.audio.enabled; - Audio::get()->enable(options.audio.enabled); - Notifier::get()->show({"Audio " + boolToOnOff(options.audio.enabled)}); + Options::audio.enabled = !Options::audio.enabled; + Audio::get()->enable(Options::audio.enabled); + Notifier::get()->show({"Audio " + boolToOnOff(Options::audio.enabled)}); } // Cambia el modo de escalado entero void toggleIntegerScale() { Screen::get()->toggleIntegerScale(); - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 12") + " " + boolToOnOff(options.video.integer_scale)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 12") + " " + boolToOnOff(Options::video.integer_scale)}); } // Activa / desactiva el vsync void toggleVSync() { Screen::get()->toggleVSync(); - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 14") + " " + boolToOnOff(options.video.v_sync)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 14") + " " + boolToOnOff(Options::video.v_sync)}); } // Activa o desactiva los shaders void toggleShaders() { Screen::get()->toggleShaders(); - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 13") + " " + boolToOnOff(options.video.shaders)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 13") + " " + boolToOnOff(Options::video.shaders)}); } // Obtiene una fichero a partir de un lang::Code @@ -117,15 +117,15 @@ namespace GlobalInputs const std::string CODE = "LANG"; if (Notifier::get()->checkCode(CODE)) { - options.game.language = Lang::getNextLangCode(options.game.language); - Lang::loadFromFile(getLangFile(static_cast(options.game.language))); + Options::game.language = Lang::getNextLangCode(Options::game.language); + Lang::loadFromFile(getLangFile(static_cast(Options::game.language))); Section::name = Section::Name::RESET; Section::options = Section::Options::RELOAD; - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 05") + getLangName(options.game.language)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 05") + getLangName(Options::game.language)}); } else { - const auto NEXT = Lang::getNextLangCode(options.game.language); + const auto NEXT = Lang::getNextLangCode(Options::game.language); Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 04") + getLangName(NEXT), std::string()}, -1, CODE); } } @@ -133,8 +133,8 @@ namespace GlobalInputs // Cambia el modo de disparo void toggleFireMode() { - options.game.autofire = !options.game.autofire; - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 08") + " " + boolToOnOff(options.game.autofire)}); + Options::game.autofire = !Options::game.autofire; + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 08") + " " + boolToOnOff(Options::game.autofire)}); } // Salta una sección del juego @@ -169,7 +169,7 @@ namespace GlobalInputs void toggleFullscreen() { Screen::get()->toggleFullscreen(); - const std::string MODE = options.video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10"); + const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10"); Notifier::get()->show({MODE}); } @@ -178,7 +178,7 @@ namespace GlobalInputs { if (Screen::get()->decWindowSize()) { - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(options.window.size)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)}); } } @@ -187,7 +187,7 @@ namespace GlobalInputs { if (Screen::get()->incWindowSize()) { - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(options.window.size)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)}); } } @@ -323,7 +323,7 @@ namespace GlobalInputs if (Input::get()->checkInput(InputAction::WINDOW_FULLSCREEN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { Screen::get()->toggleFullscreen(); - const std::string MODE = options.video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10"); + const std::string MODE = Options::video.fullscreen ? Lang::getText("[NOTIFICATIONS] 11") : Lang::getText("[NOTIFICATIONS] 10"); Notifier::get()->show({MODE}); return; } @@ -333,7 +333,7 @@ namespace GlobalInputs { if (Screen::get()->decWindowSize()) { - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(options.window.size)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)}); } return; } @@ -343,7 +343,7 @@ namespace GlobalInputs { if (Screen::get()->incWindowSize()) { - Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(options.window.size)}); + Notifier::get()->show({Lang::getText("[NOTIFICATIONS] 09") + " x" + std::to_string(Options::window.size)}); } return; } diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index c387ec2..0e66161 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -51,7 +51,7 @@ HiScoreTable::HiScoreTable() HiScoreTable::~HiScoreTable() { SDL_DestroyTexture(backbuffer_); - options.game.clearLastHiScoreEntries(); + Options::game.clearLastHiScoreEntries(); } // Actualiza las variables @@ -232,15 +232,15 @@ void HiScoreTable::createSprites() for (int i = 0; i < MAX_NAMES; ++i) { const auto table_position = format(i + 1) + ". "; - const auto score = format(options.game.hi_score_table.at(i).score); - const auto num_dots = ENTRY_LENGHT - options.game.hi_score_table.at(i).name.size() - score.size(); - const auto one_cc = options.game.hi_score_table.at(i).one_credit_complete ? " }" : ""; + const auto score = format(Options::game.hi_score_table.at(i).score); + const auto num_dots = ENTRY_LENGHT - Options::game.hi_score_table.at(i).name.size() - score.size(); + const auto one_cc = Options::game.hi_score_table.at(i).one_credit_complete ? " }" : ""; std::string dots; for (int j = 0; j < (int)num_dots; ++j) { dots = dots + "."; } - const auto line = table_position + options.game.hi_score_table.at(i).name + dots + score + one_cc; + const auto line = table_position + Options::game.hi_score_table.at(i).name + dots + score + one_cc; entry_names_.emplace_back(std::make_shared(entry_text->writeDXToTexture(TEXT_SHADOW, line, 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR))); const int default_pos_x = (backbuffer_width - entry_width) / 2; @@ -402,7 +402,7 @@ void HiScoreTable::iniEntryColors() void HiScoreTable::glowEntryNames() { const Color entry_color = getEntryColor(counter_ / 5); - for (const auto &entry_index : options.game.last_hi_score_entry) + for (const auto &entry_index : Options::game.last_hi_score_entry) { if (entry_index != -1) { diff --git a/source/lang.cpp b/source/lang.cpp index 7a67c4b..55b1bf4 100644 --- a/source/lang.cpp +++ b/source/lang.cpp @@ -131,7 +131,7 @@ namespace Lang // Establece el idioma void setLanguage(Code lang) { - options.game.language = lang; + Options::game.language = lang; loadFromFile(Asset::get()->get(getLanguage(lang).file_name)); updateLanguageNames(); } diff --git a/source/options.cpp b/source/options.cpp index 8710f14..01a13e9 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -10,404 +10,412 @@ namespace Options { -// Vector con las dificultades -std::vector difficulties = { - {DifficultyCode::EASY, "Easy"}, - {DifficultyCode::NORMAL, "Normal"}, - {DifficultyCode::HARD, "Hard"}}; + // --- Variables globales --- + WindowOptions window; // Opciones de la ventana + GameOptions game; // Opciones del juego + VideoOptions video; // Opciones de vídeo + AudioOptions audio; // Opciones de audio + std::vector controllers; // Opciones de mando para cada jugador + PendingChanges pending_changes; // Opciones que se aplican al cerrar + + // Vector con las dificultades + std::vector difficulties = { + {DifficultyCode::EASY, "Easy"}, + {DifficultyCode::NORMAL, "Normal"}, + {DifficultyCode::HARD, "Hard"}}; // Declaraciones -bool setOptions(const std::string &var, const std::string &value); + bool setOptions(const std::string &var, const std::string &value); -// Inicializa las opciones del programa -void initOptions() -{ - window.caption = "Coffee Crisis Arcade Edition"; - window.size = 2; - - // Opciones de video - video.fullscreen = false; - video.scale_mode = SDL_ScaleMode::SDL_SCALEMODE_NEAREST; - video.v_sync = true; - video.integer_scale = true; - video.shaders = false; - - // Opciones de audio - audio.enabled = true; - audio.volume = 100; - audio.music.enabled = true; - audio.music.volume = 100; - audio.sound.enabled = true; - audio.sound.volume = 50; - - // Opciones de juego - game.difficulty = DifficultyCode::NORMAL; - game.language = Lang::Code::VALENCIAN; - game.autofire = true; - game.shutdown_enabled = false; - game.clearLastHiScoreEntries(); - - // Opciones de control - controllers.clear(); - controllers.resize(2); - controllers.at(0).player_id = 1; - controllers.at(1).player_id = 2; - setKeyboardToPlayer(1); - - // Opciones pendientes - pending_changes.new_language = game.language; - pending_changes.new_difficulty = game.difficulty; - pending_changes.has_pending_changes = false; -} - -// Carga el fichero de configuración -bool loadOptionsFile(std::string file_path) -{ // Inicializa las opciones del programa - initOptions(); - - // Indicador de éxito en la carga - bool success = true; - - // Variables para manejar el fichero - std::ifstream file(file_path); - - // Si el fichero se puede abrir - if (file.good()) + void initOptions() { - // Procesa el fichero línea a línea - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(file_path).c_str()); - std::string line; - while (std::getline(file, line)) + window.caption = "Coffee Crisis Arcade Edition"; + window.size = 2; + + // Opciones de video + video.fullscreen = false; + video.scale_mode = SDL_ScaleMode::SDL_SCALEMODE_NEAREST; + video.v_sync = true; + video.integer_scale = true; + video.shaders = false; + + // Opciones de audio + audio.enabled = true; + audio.volume = 100; + audio.music.enabled = true; + audio.music.volume = 100; + audio.sound.enabled = true; + audio.sound.volume = 50; + + // Opciones de juego + game.difficulty = DifficultyCode::NORMAL; + game.language = Lang::Code::VALENCIAN; + game.autofire = true; + game.shutdown_enabled = false; + game.clearLastHiScoreEntries(); + + // Opciones de control + controllers.clear(); + controllers.resize(2); + controllers.at(0).player_id = 1; + controllers.at(1).player_id = 2; + setKeyboardToPlayer(1); + + // Opciones pendientes + pending_changes.new_language = game.language; + pending_changes.new_difficulty = game.difficulty; + pending_changes.has_pending_changes = false; + } + + // Carga el fichero de configuración + bool loadOptionsFile(std::string file_path) + { + // Inicializa las opciones del programa + initOptions(); + + // Indicador de éxito en la carga + bool success = true; + + // Variables para manejar el fichero + std::ifstream file(file_path); + + // Si el fichero se puede abrir + if (file.good()) { - // Comprueba que la línea no sea un comentario - if (line.substr(0, 1) != "#") + // Procesa el fichero línea a línea + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(file_path).c_str()); + std::string line; + while (std::getline(file, line)) { - // Encuentra la posición del carácter '=' - int pos = line.find("="); - // Procesa las dos subcadenas - if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length()))) + // Comprueba que la línea no sea un comentario + if (line.substr(0, 1) != "#") { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown parameter: %s", line.substr(0, pos).c_str()); - success = false; + // Encuentra la posición del carácter '=' + int pos = line.find("="); + // Procesa las dos subcadenas + if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length()))) + { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown parameter: %s", line.substr(0, pos).c_str()); + success = false; + } } } + file.close(); } - file.close(); - } - // El fichero no existe - else - { - // Crea el fichero con los valores por defecto - saveOptionsFile(file_path); - } - - // Normaliza los valores - if (game.language != Lang::Code::ENGLISH && - game.language != Lang::Code::VALENCIAN && - game.language != Lang::Code::SPANISH) - { - game.language = Lang::Code::ENGLISH; - } - - return success; -} - -// Guarda el fichero de configuración -bool saveOptionsFile(std::string file_path) -{ - std::ofstream file(file_path); - - if (!file.good()) - { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: %s can't be opened", getFileName(file_path).c_str()); - return false; - } - - SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file: %s", getFileName(file_path).c_str()); - - applyPendingChanges(); - - // Opciones de video - file << "## VIDEO\n"; - file << "## video.scale_mode [" << static_cast(SDL_ScaleMode::SDL_SCALEMODE_NEAREST) << ": nearest, " << static_cast(SDL_ScaleMode::SDL_SCALEMODE_LINEAR) << ": lineal]\n"; - file << "\n"; - - file << "window.zoom=" << window.size << "\n"; - file << "video.fullscreen=" << boolToString(video.fullscreen) << "\n"; - file << "video.scale_mode=" << static_cast(video.scale_mode) << "\n"; - file << "video.v_sync=" << boolToString(video.v_sync) << "\n"; - file << "video.integer_scale=" << boolToString(video.integer_scale) << "\n"; - file << "video.shaders=" << boolToString(video.shaders) << "\n"; - - // Opciones de audio - file << "\n\n## AUDIO\n"; - file << "## volume [0 .. 100]\n"; - file << "\n"; - - file << "audio.enabled=" << boolToString(audio.enabled) << "\n"; - file << "audio.volume=" << audio.volume << "\n"; - file << "audio.music.enabled=" << boolToString(audio.music.enabled) << "\n"; - file << "audio.music.volume=" << audio.music.volume << "\n"; - file << "audio.sound.enabled=" << boolToString(audio.sound.enabled) << "\n"; - file << "audio.sound.volume=" << audio.sound.volume << "\n"; - - // Opciones del juego - file << "\n\n## GAME\n"; - file << "## game.language [0: spanish, 1: valencian, 2: english]\n"; - file << "## game.difficulty [" << static_cast(DifficultyCode::EASY) << ": easy, " << static_cast(DifficultyCode::NORMAL) << ": normal, " << static_cast(DifficultyCode::HARD) << ": hard]\n"; - file << "\n"; - - file << "game.language=" << static_cast(game.language) << "\n"; - file << "game.difficulty=" << static_cast(game.difficulty) << "\n"; - file << "game.autofire=" << boolToString(game.autofire) << "\n"; - file << "game.shutdown_enabled=" << boolToString(game.shutdown_enabled) << "\n"; - - // Opciones de mandos - file << "\n\n## CONTROLLERS\n"; - - int controller_index = 0; - for (const auto &controller : controllers) - { - file << "\n"; - file << "controller." << controller_index << ".name=" << controller.name << "\n"; - file << "controller." << controller_index << ".player=" << controller.player_id << "\n"; - file << "controller." << controller_index << ".type=" << static_cast(controller.type) << "\n"; - file << "controller." << controller_index << ".button.fire_left=" << controller.buttons.at(0) << "\n"; - file << "controller." << controller_index << ".button.fire_center=" << controller.buttons.at(1) << "\n"; - file << "controller." << controller_index << ".button.fire_right=" << controller.buttons.at(2) << "\n"; - file << "controller." << controller_index << ".button.start=" << controller.buttons.at(3) << "\n"; - file << "controller." << controller_index << ".button.service=" << controller.buttons.at(4) << "\n"; - - // Incrementa el índice - ++controller_index; - } - - // Cierra el fichero - file.close(); - - return true; -} - -// Asigna variables a partir de dos cadenas -bool setOptions(const std::string &var, const std::string &value) -{ - // Indicador de éxito en la asignación - auto success = true; - - // Opciones de video - if (var == "video.fullscreen") - { - video.fullscreen = stringToBool(value); - } - else if (var == "window.zoom") - { - window.size = std::stoi(value); - } - else if (var == "video.scale_mode") - { - video.scale_mode = static_cast(std::stoi(value)); - } - else if (var == "video.shaders") - { - video.shaders = stringToBool(value); - } - else if (var == "video.integer_scale") - { - video.integer_scale = stringToBool(value); - } - else if (var == "video.v_sync") - { - video.v_sync = stringToBool(value); - } - - // Opciones de audio - else if (var == "audio.enabled") - { - audio.enabled = stringToBool(value); - } - else if (var == "audio.volume") - { - audio.volume = std::clamp(std::stoi(value), 0, 100); - } - else if (var == "audio.music.enabled") - { - audio.music.enabled = stringToBool(value); - } - else if (var == "audio.music.volume") - { - audio.music.volume = std::clamp(std::stoi(value), 0, 100); - } - else if (var == "audio.sound.enabled") - { - audio.sound.enabled = stringToBool(value); - } - else if (var == "audio.sound.volume") - { - audio.sound.volume = std::clamp(std::stoi(value), 0, 100); - } - - // Opciones de juego - else if (var == "game.language") - { - game.language = static_cast(std::stoi(value)); - pending_changes.new_language = game.language; - } - else if (var == "game.difficulty") - { - game.difficulty = static_cast(std::stoi(value)); - pending_changes.new_difficulty = game.difficulty; - } - else if (var == "game.autofire") - { - game.autofire = stringToBool(value); - } - else if (var == "game.shutdown_enabled") - { - game.shutdown_enabled = stringToBool(value); - } - - // Opciones de mandos - else if (var == "controller.0.name") - { - controllers.at(0).name = value; - } - else if (var == "controller.0.player") - { - controllers.at(0).player_id = std::clamp(std::stoi(value), 1, 2); - } - else if (var == "controller.0.type") - { - controllers.at(0).type = static_cast(std::stoi(value)); - } - else if (var == "controller.0.button.fire_left") - { - controllers.at(0).buttons.at(0) = static_cast(std::stoi(value)); - } - else if (var == "controller.0.button.fire_center") - { - controllers.at(0).buttons.at(1) = static_cast(std::stoi(value)); - } - else if (var == "controller.0.button.fire_right") - { - controllers.at(0).buttons.at(2) = static_cast(std::stoi(value)); - } - else if (var == "controller.0.button.start") - { - controllers.at(0).buttons.at(3) = static_cast(std::stoi(value)); - } - else if (var == "controller.0.button.service") - { - controllers.at(0).buttons.at(4) = static_cast(std::stoi(value)); - } - else if (var == "controller.1.name") - { - controllers.at(1).name = value; - } - else if (var == "controller.1.player") - { - controllers.at(1).player_id = std::clamp(std::stoi(value), 1, 2); - } - else if (var == "controller.1.type") - { - controllers.at(1).type = static_cast(std::stoi(value)); - } - else if (var == "controller.1.button.fire_left") - { - controllers.at(1).buttons.at(0) = static_cast(std::stoi(value)); - } - else if (var == "controller.1.button.fire_center") - { - controllers.at(1).buttons.at(1) = static_cast(std::stoi(value)); - } - else if (var == "controller.1.button.fire_right") - { - controllers.at(1).buttons.at(2) = static_cast(std::stoi(value)); - } - else if (var == "controller.1.button.start") - { - controllers.at(1).buttons.at(3) = static_cast(std::stoi(value)); - } - else if (var == "controller.1.button.service") - { - controllers.at(1).buttons.at(4) = static_cast(std::stoi(value)); - } - - // Lineas vacias o que empiezan por comentario - else if (var.empty() || var.starts_with("#")) - { - } - else - { - success = false; - } - - return success; -} - -// Asigna el teclado al jugador -void setKeyboardToPlayer(int player_id) -{ - for (auto &controller : controllers) - { - if (controller.player_id == player_id) + // El fichero no existe + else + { + // Crea el fichero con los valores por defecto + saveOptionsFile(file_path); + } + + // Normaliza los valores + if (game.language != Lang::Code::ENGLISH && + game.language != Lang::Code::VALENCIAN && + game.language != Lang::Code::SPANISH) + { + game.language = Lang::Code::ENGLISH; + } + + return success; + } + + // Guarda el fichero de configuración + bool saveOptionsFile(std::string file_path) + { + std::ofstream file(file_path); + + if (!file.good()) + { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: %s can't be opened", getFileName(file_path).c_str()); + return false; + } + + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file: %s", getFileName(file_path).c_str()); + + applyPendingChanges(); + + // Opciones de video + file << "## VIDEO\n"; + file << "## video.scale_mode [" << static_cast(SDL_ScaleMode::SDL_SCALEMODE_NEAREST) << ": nearest, " << static_cast(SDL_ScaleMode::SDL_SCALEMODE_LINEAR) << ": lineal]\n"; + file << "\n"; + + file << "window.zoom=" << window.size << "\n"; + file << "video.fullscreen=" << boolToString(video.fullscreen) << "\n"; + file << "video.scale_mode=" << static_cast(video.scale_mode) << "\n"; + file << "video.v_sync=" << boolToString(video.v_sync) << "\n"; + file << "video.integer_scale=" << boolToString(video.integer_scale) << "\n"; + file << "video.shaders=" << boolToString(video.shaders) << "\n"; + + // Opciones de audio + file << "\n\n## AUDIO\n"; + file << "## volume [0 .. 100]\n"; + file << "\n"; + + file << "audio.enabled=" << boolToString(audio.enabled) << "\n"; + file << "audio.volume=" << audio.volume << "\n"; + file << "audio.music.enabled=" << boolToString(audio.music.enabled) << "\n"; + file << "audio.music.volume=" << audio.music.volume << "\n"; + file << "audio.sound.enabled=" << boolToString(audio.sound.enabled) << "\n"; + file << "audio.sound.volume=" << audio.sound.volume << "\n"; + + // Opciones del juego + file << "\n\n## GAME\n"; + file << "## game.language [0: spanish, 1: valencian, 2: english]\n"; + file << "## game.difficulty [" << static_cast(DifficultyCode::EASY) << ": easy, " << static_cast(DifficultyCode::NORMAL) << ": normal, " << static_cast(DifficultyCode::HARD) << ": hard]\n"; + file << "\n"; + + file << "game.language=" << static_cast(game.language) << "\n"; + file << "game.difficulty=" << static_cast(game.difficulty) << "\n"; + file << "game.autofire=" << boolToString(game.autofire) << "\n"; + file << "game.shutdown_enabled=" << boolToString(game.shutdown_enabled) << "\n"; + + // Opciones de mandos + file << "\n\n## CONTROLLERS\n"; + + int controller_index = 0; + for (const auto &controller : controllers) + { + file << "\n"; + file << "controller." << controller_index << ".name=" << controller.name << "\n"; + file << "controller." << controller_index << ".player=" << controller.player_id << "\n"; + file << "controller." << controller_index << ".type=" << static_cast(controller.type) << "\n"; + file << "controller." << controller_index << ".button.fire_left=" << controller.buttons.at(0) << "\n"; + file << "controller." << controller_index << ".button.fire_center=" << controller.buttons.at(1) << "\n"; + file << "controller." << controller_index << ".button.fire_right=" << controller.buttons.at(2) << "\n"; + file << "controller." << controller_index << ".button.start=" << controller.buttons.at(3) << "\n"; + file << "controller." << controller_index << ".button.service=" << controller.buttons.at(4) << "\n"; + + // Incrementa el índice + ++controller_index; + } + + // Cierra el fichero + file.close(); + + return true; + } + + // Asigna variables a partir de dos cadenas + bool setOptions(const std::string &var, const std::string &value) + { + // Indicador de éxito en la asignación + auto success = true; + + // Opciones de video + if (var == "video.fullscreen") + { + video.fullscreen = stringToBool(value); + } + else if (var == "window.zoom") + { + window.size = std::stoi(value); + } + else if (var == "video.scale_mode") + { + video.scale_mode = static_cast(std::stoi(value)); + } + else if (var == "video.shaders") + { + video.shaders = stringToBool(value); + } + else if (var == "video.integer_scale") + { + video.integer_scale = stringToBool(value); + } + else if (var == "video.v_sync") + { + video.v_sync = stringToBool(value); + } + + // Opciones de audio + else if (var == "audio.enabled") + { + audio.enabled = stringToBool(value); + } + else if (var == "audio.volume") + { + audio.volume = std::clamp(std::stoi(value), 0, 100); + } + else if (var == "audio.music.enabled") + { + audio.music.enabled = stringToBool(value); + } + else if (var == "audio.music.volume") + { + audio.music.volume = std::clamp(std::stoi(value), 0, 100); + } + else if (var == "audio.sound.enabled") + { + audio.sound.enabled = stringToBool(value); + } + else if (var == "audio.sound.volume") + { + audio.sound.volume = std::clamp(std::stoi(value), 0, 100); + } + + // Opciones de juego + else if (var == "game.language") + { + game.language = static_cast(std::stoi(value)); + pending_changes.new_language = game.language; + } + else if (var == "game.difficulty") + { + game.difficulty = static_cast(std::stoi(value)); + pending_changes.new_difficulty = game.difficulty; + } + else if (var == "game.autofire") + { + game.autofire = stringToBool(value); + } + else if (var == "game.shutdown_enabled") + { + game.shutdown_enabled = stringToBool(value); + } + + // Opciones de mandos + else if (var == "controller.0.name") + { + controllers.at(0).name = value; + } + else if (var == "controller.0.player") + { + controllers.at(0).player_id = std::clamp(std::stoi(value), 1, 2); + } + else if (var == "controller.0.type") + { + controllers.at(0).type = static_cast(std::stoi(value)); + } + else if (var == "controller.0.button.fire_left") + { + controllers.at(0).buttons.at(0) = static_cast(std::stoi(value)); + } + else if (var == "controller.0.button.fire_center") + { + controllers.at(0).buttons.at(1) = static_cast(std::stoi(value)); + } + else if (var == "controller.0.button.fire_right") + { + controllers.at(0).buttons.at(2) = static_cast(std::stoi(value)); + } + else if (var == "controller.0.button.start") + { + controllers.at(0).buttons.at(3) = static_cast(std::stoi(value)); + } + else if (var == "controller.0.button.service") + { + controllers.at(0).buttons.at(4) = static_cast(std::stoi(value)); + } + else if (var == "controller.1.name") + { + controllers.at(1).name = value; + } + else if (var == "controller.1.player") + { + controllers.at(1).player_id = std::clamp(std::stoi(value), 1, 2); + } + else if (var == "controller.1.type") + { + controllers.at(1).type = static_cast(std::stoi(value)); + } + else if (var == "controller.1.button.fire_left") + { + controllers.at(1).buttons.at(0) = static_cast(std::stoi(value)); + } + else if (var == "controller.1.button.fire_center") + { + controllers.at(1).buttons.at(1) = static_cast(std::stoi(value)); + } + else if (var == "controller.1.button.fire_right") + { + controllers.at(1).buttons.at(2) = static_cast(std::stoi(value)); + } + else if (var == "controller.1.button.start") + { + controllers.at(1).buttons.at(3) = static_cast(std::stoi(value)); + } + else if (var == "controller.1.button.service") + { + controllers.at(1).buttons.at(4) = static_cast(std::stoi(value)); + } + + // Lineas vacias o que empiezan por comentario + else if (var.empty() || var.starts_with("#")) { - controller.type = InputDeviceToUse::ANY; } else { - controller.type = InputDeviceToUse::CONTROLLER; + success = false; } + + return success; } -} -// Intercambia el teclado de jugador -void swapOptionsKeyboard() -{ - std::swap(controllers.at(0).type, controllers.at(1).type); -} - -// Intercambia los jugadores asignados a los dos primeros mandos -void swapOptionsControllers() -{ - std::swap(controllers.at(0).player_id, controllers.at(1).player_id); - std::swap(controllers.at(0).type, controllers.at(1).type); -} - -// Averigua quien está usando el teclado -int getPlayerWhoUsesKeyboard() -{ - for (const auto &controller : controllers) + // Asigna el teclado al jugador + void setKeyboardToPlayer(int player_id) { - if (controller.type == InputDeviceToUse::ANY) + for (auto &controller : controllers) { - return controller.player_id; + if (controller.player_id == player_id) + { + controller.type = InputDeviceToUse::ANY; + } + else + { + controller.type = InputDeviceToUse::CONTROLLER; + } } } - return 0; -} -// Aplica los cambios pendientes copiando los valores a sus variables -void applyPendingChanges() -{ - if (pending_changes.has_pending_changes) + // Intercambia el teclado de jugador + void swapOptionsKeyboard() { - game.language = pending_changes.new_language; - game.difficulty = pending_changes.new_difficulty; - pending_changes.has_pending_changes = false; + std::swap(controllers.at(0).type, controllers.at(1).type); } -} -void checkPendingChanges() -{ - if (game.language != pending_changes.new_language || - game.difficulty != pending_changes.new_difficulty) + // Intercambia los jugadores asignados a los dos primeros mandos + void swapOptionsControllers() { - pending_changes.has_pending_changes = true; + std::swap(controllers.at(0).player_id, controllers.at(1).player_id); + std::swap(controllers.at(0).type, controllers.at(1).type); } - else + + // Averigua quien está usando el teclado + int getPlayerWhoUsesKeyboard() { - pending_changes.has_pending_changes = false; + for (const auto &controller : controllers) + { + if (controller.type == InputDeviceToUse::ANY) + { + return controller.player_id; + } + } + return 0; + } + + // Aplica los cambios pendientes copiando los valores a sus variables + void applyPendingChanges() + { + if (pending_changes.has_pending_changes) + { + game.language = pending_changes.new_language; + game.difficulty = pending_changes.new_difficulty; + pending_changes.has_pending_changes = false; + } + } + + void checkPendingChanges() + { + if (game.language != pending_changes.new_language || + game.difficulty != pending_changes.new_difficulty) + { + pending_changes.has_pending_changes = true; + } + else + { + pending_changes.has_pending_changes = false; + } } -} } // namespace Options \ No newline at end of file diff --git a/source/options.h b/source/options.h index 35e8f48..f2a43ff 100644 --- a/source/options.h +++ b/source/options.h @@ -119,12 +119,12 @@ namespace Options }; // --- Variables globales --- - WindowOptions window; // Opciones de la ventana - GameOptions game; // Opciones del juego - VideoOptions video; // Opciones de vídeo - AudioOptions audio; // Opciones de audio - std::vector controllers; // Opciones de mando para cada jugador - PendingChanges pending_changes; // Opciones que se aplican al cerrar + extern WindowOptions window; // Opciones de la ventana + extern GameOptions game; // Opciones del juego + extern VideoOptions video; // Opciones de vídeo + extern AudioOptions audio; // Opciones de audio + extern std::vector controllers; // Opciones de mando para cada jugador + extern PendingChanges pending_changes; // Opciones que se aplican al cerrar // --- Funciones de configuración --- void initOptions(); // Inicializa las opciones del programa diff --git a/source/player.h b/source/player.h index b3e6792..12a034c 100644 --- a/source/player.h +++ b/source/player.h @@ -108,7 +108,7 @@ public: bool canFire() const { return cool_down_ <= 0; } bool hasExtraHit() const { return extra_hit_; } bool isCooling() const { return firing_state_ == PlayerState::COOLING_LEFT || firing_state_ == PlayerState::COOLING_UP || firing_state_ == PlayerState::COOLING_RIGHT; } - bool IsEligibleForHighScore() const { return score_ > options.game.hi_score_table.back().score; } + bool IsEligibleForHighScore() const { return score_ > Options::game.hi_score_table.back().score; } bool isInvulnerable() const { return invulnerable_; } bool isPowerUp() const { return power_up_; } Circle &getCollider() { return collider_; } diff --git a/source/screen.cpp b/source/screen.cpp index c352b43..d31fc64 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -111,7 +111,7 @@ void Screen::renderScreen() SDL_SetRenderTarget(renderer_, nullptr); clean(); - if (options.video.shaders) + if (Options::video.shaders) { shader::render(); } @@ -126,10 +126,10 @@ void Screen::renderScreen() void Screen::setFullscreenMode(bool mode) { // Actualiza las opciones - options.video.fullscreen = mode; + Options::video.fullscreen = mode; // Configura el modo de pantalla - SDL_SetWindowFullscreen(window_, options.video.fullscreen); + SDL_SetWindowFullscreen(window_, Options::video.fullscreen); initShaders(); } @@ -137,27 +137,27 @@ void Screen::setFullscreenMode(bool mode) // Camibia entre pantalla completa y ventana void Screen::toggleFullscreen() { - options.video.fullscreen = !options.video.fullscreen; + Options::video.fullscreen = !Options::video.fullscreen; setFullscreenMode(); } // Cambia el tamaño de la ventana void Screen::setWindowZoom(int zoom) { - options.window.size = zoom; + Options::window.size = zoom; adjustWindowSize(); } // Reduce el tamaño de la ventana bool Screen::decWindowSize() { - if (!options.video.fullscreen) + if (!Options::video.fullscreen) { - const int PREVIOUS_ZOOM = options.window.size; - --options.window.size; - options.window.size = std::max(options.window.size, 1); + const int PREVIOUS_ZOOM = Options::window.size; + --Options::window.size; + Options::window.size = std::max(Options::window.size, 1); - if (options.window.size != PREVIOUS_ZOOM) + if (Options::window.size != PREVIOUS_ZOOM) { adjustWindowSize(); return true; @@ -170,13 +170,13 @@ bool Screen::decWindowSize() // Aumenta el tamaño de la ventana bool Screen::incWindowSize() { - if (!options.video.fullscreen) + if (!Options::video.fullscreen) { - const int PREVIOUS_ZOOM = options.window.size; - ++options.window.size; - options.window.size = std::min(options.window.size, options.window.max_size); + const int PREVIOUS_ZOOM = Options::window.size; + ++Options::window.size; + Options::window.size = std::min(Options::window.size, Options::window.max_size); - if (options.window.size != PREVIOUS_ZOOM) + if (Options::window.size != PREVIOUS_ZOOM) { adjustWindowSize(); return true; @@ -249,7 +249,7 @@ void Screen::renderInfo() if (debug_info_.show) { // Resolution - debug_info_.text->writeDX(TEXT_COLOR | TEXT_SHADOW, param.game.width - debug_info_.text->lenght(options.video.info) - 2, 1, options.video.info, 1, DEBUG_COLOR, 1, DEBUG_COLOR.darken(150)); + debug_info_.text->writeDX(TEXT_COLOR | TEXT_SHADOW, param.game.width - debug_info_.text->lenght(Options::video.info) - 2, 1, Options::video.info, 1, DEBUG_COLOR, 1, DEBUG_COLOR.darken(150)); // FPS const std::string FPS_TEXT = std::to_string(fps_.lastValue) + " FPS"; @@ -280,10 +280,10 @@ void Screen::initShaders() void Screen::adjustWindowSize() { // Establece el nuevo tamaño - if (!options.video.fullscreen) + if (!Options::video.fullscreen) { - const int WIDTH = param.game.width * options.window.size; - const int HEIGHT = param.game.height * options.window.size; + const int WIDTH = param.game.width * Options::window.size; + const int HEIGHT = param.game.height * Options::window.size; int old_width, old_height; SDL_GetWindowSize(window_, &old_width, &old_height); @@ -349,7 +349,7 @@ bool Screen::initSDL() } // Crea la ventana - window_ = SDL_CreateWindow(options.window.caption.c_str(), param.game.width * options.window.size, param.game.height * options.window.size, SDL_WINDOW_OPENGL); + window_ = SDL_CreateWindow(Options::window.caption.c_str(), param.game.width * Options::window.size, param.game.height * Options::window.size, SDL_WINDOW_OPENGL); if (!window_) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window could not be created! SDL Error: %s", SDL_GetError()); @@ -368,9 +368,9 @@ bool Screen::initSDL() { SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE); - SDL_SetWindowFullscreen(window_, options.video.fullscreen); + SDL_SetWindowFullscreen(window_, Options::video.fullscreen); SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND); - SDL_SetRenderVSync(renderer_, options.video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); + SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); } } } @@ -397,17 +397,17 @@ void Screen::getDisplayInfo() auto DM = SDL_GetCurrentDisplayMode(displays[0]); // Calcula el máximo factor de zoom que se puede aplicar a la pantalla - options.window.max_size = std::min(DM->w / param.game.width, DM->h / param.game.height); - options.window.size = std::min(options.window.size, options.window.max_size); + Options::window.max_size = std::min(DM->w / param.game.width, DM->h / param.game.height); + Options::window.size = std::min(Options::window.size, Options::window.max_size); // Muestra información sobre el tamaño de la pantalla y de la ventana de juego SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Current display mode: %dx%d @ %dHz", static_cast(DM->w), static_cast(DM->h), static_cast(DM->refresh_rate)); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d", - static_cast(param.game.width), static_cast(param.game.height), options.window.size); + static_cast(param.game.width), static_cast(param.game.height), Options::window.size); - options.video.info = std::to_string(static_cast(DM->w)) + "x" + + Options::video.info = std::to_string(static_cast(DM->w)) + "x" + std::to_string(static_cast(DM->h)) + " @ " + std::to_string(static_cast(DM->refresh_rate)) + " Hz"; @@ -415,7 +415,7 @@ void Screen::getDisplayInfo() const int MAX_ZOOM = std::min(DM->w / param.game.width, (DM->h - WINDOWS_DECORATIONS_) / param.game.height); // Normaliza los valores de zoom - options.window.size = std::min(options.window.size, MAX_ZOOM); + Options::window.size = std::min(Options::window.size, MAX_ZOOM); SDL_free(displays); } @@ -424,21 +424,21 @@ void Screen::getDisplayInfo() // Alterna entre activar y desactivar el escalado entero void Screen::toggleIntegerScale() { - options.video.integer_scale = !options.video.integer_scale; - SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, options.video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX); + Options::video.integer_scale = !Options::video.integer_scale; + SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX); } // Alterna entre activar y desactivar el V-Sync void Screen::toggleVSync() { - options.video.v_sync = !options.video.v_sync; - SDL_SetRenderVSync(renderer_, options.video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); + Options::video.v_sync = !Options::video.v_sync; + SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); } // Establece el estado del V-Sync void Screen::setVSync(bool enabled) { - options.video.v_sync = enabled; + Options::video.v_sync = enabled; SDL_SetRenderVSync(renderer_, enabled ? 1 : SDL_RENDERER_VSYNC_DISABLED); } @@ -452,8 +452,8 @@ void Screen::getSingletons() // Aplica los valores de las opciones void Screen::applySettings() { - SDL_SetRenderVSync(renderer_, options.video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); - SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, options.video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX); + SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); + SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX); adjustWindowSize(); setFullscreenMode(); } diff --git a/source/screen.h b/source/screen.h index 4142a64..ddc8509 100644 --- a/source/screen.h +++ b/source/screen.h @@ -33,7 +33,7 @@ public: void coreRender(); // Vuelca el contenido del renderizador en pantalla exceptuando ciertas partes // --- Configuración de ventana y render --- - void setFullscreenMode(bool mode = options.video.fullscreen); // Establece el modo de video + void setFullscreenMode(bool mode = Options::video.fullscreen); // Establece el modo de video void toggleFullscreen(); // Cambia entre pantalla completa y ventana void setWindowZoom(int size); // Cambia el tamaño de la ventana bool decWindowSize(); // Reduce el tamaño de la ventana @@ -43,7 +43,7 @@ public: // --- Efectos visuales --- void shake() { shake_effect_.enable(src_rect_, dst_rect_); } // Agita la pantalla void flash(Color color, int lenght = 10, int delay = 0) { flash_effect_ = FlashEffect(true, lenght, delay, color); } // Pone la pantalla de color - void toggleShaders() { options.video.shaders = !options.video.shaders; } // Alterna entre activar y desactivar los shaders + void toggleShaders() { Options::video.shaders = !Options::video.shaders; } // Alterna entre activar y desactivar los shaders void toggleIntegerScale(); // Alterna entre activar y desactivar el escalado entero void toggleVSync(); // Alterna entre activar y desactivar el V-Sync void setVSync(bool enabled); // Establece el estado del V-Sync @@ -54,7 +54,7 @@ public: void show() { SDL_ShowWindow(window_); } // Muestra la ventana void hide() { SDL_HideWindow(window_); } // Oculta la ventana void getSingletons(); // Obtiene los punteros a los singletones - bool getVSync() const { return options.video.v_sync; } // Obtiene el valor de V-Sync + bool getVSync() const { return Options::video.v_sync; } // Obtiene el valor de V-Sync std::shared_ptr getText() const { return text_; } // Obtiene el puntero al texto de Screen #ifdef DEBUG diff --git a/source/service_menu.cpp b/source/service_menu.cpp index 870aee6..5141293 100644 --- a/source/service_menu.cpp +++ b/source/service_menu.cpp @@ -76,7 +76,7 @@ void ServiceMenu::render() // LINEA y = rect_.y + upper_height_; - SDL_SetRenderDrawColor(Screen::get()->getRenderer(), options.pending_changes.has_pending_changes ? 0 : title_color_.r, title_color_.g, title_color_.b, 255); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), Options::pending_changes.has_pending_changes ? 0 : title_color_.r, title_color_.g, title_color_.b, 255); SDL_RenderLine(Screen::get()->getRenderer(), rect_.x + OPTIONS_HORIZONTAL_PADDING_, y, rect_.x + rect_.w - OPTIONS_HORIZONTAL_PADDING_, y); // OPCIONES @@ -352,25 +352,25 @@ void ServiceMenu::initializeOptions() options_.clear(); // Video - options_.emplace_back(Lang::getText("[SERVICE_MENU] FULLSCREEN"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.fullscreen, ValueType::BOOL); - options_.emplace_back(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.window.size, ValueType::INT, 1, options.window.max_size, 1); - options_.emplace_back(Lang::getText("[SERVICE_MENU] SHADERS"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.shaders, ValueType::BOOL); - options_.emplace_back(Lang::getText("[SERVICE_MENU] VSYNC"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.v_sync, ValueType::BOOL); - options_.emplace_back(Lang::getText("[SERVICE_MENU] INTEGER_SCALE"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.integer_scale, ValueType::BOOL); + options_.emplace_back(Lang::getText("[SERVICE_MENU] FULLSCREEN"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &Options::video.fullscreen, ValueType::BOOL); + options_.emplace_back(Lang::getText("[SERVICE_MENU] WINDOW_SIZE"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &Options::window.size, ValueType::INT, 1, Options::window.max_size, 1); + options_.emplace_back(Lang::getText("[SERVICE_MENU] SHADERS"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &Options::video.shaders, ValueType::BOOL); + options_.emplace_back(Lang::getText("[SERVICE_MENU] VSYNC"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &Options::video.v_sync, ValueType::BOOL); + options_.emplace_back(Lang::getText("[SERVICE_MENU] INTEGER_SCALE"), SettingsGroup::VIDEO, OptionBehavior::ADJUST, &Options::video.integer_scale, ValueType::BOOL); // Audio - options_.emplace_back(Lang::getText("[SERVICE_MENU] AUDIO"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.enabled, ValueType::BOOL); - options_.emplace_back(Lang::getText("[SERVICE_MENU] MAIN_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.volume, ValueType::INT, 0, 100, 5); - options_.emplace_back(Lang::getText("[SERVICE_MENU] MUSIC_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.music.volume, ValueType::INT, 0, 100, 5); - options_.emplace_back(Lang::getText("[SERVICE_MENU] SFX_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.sound.volume, ValueType::INT, 0, 100, 5); + options_.emplace_back(Lang::getText("[SERVICE_MENU] AUDIO"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &Options::audio.enabled, ValueType::BOOL); + options_.emplace_back(Lang::getText("[SERVICE_MENU] MAIN_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &Options::audio.volume, ValueType::INT, 0, 100, 5); + options_.emplace_back(Lang::getText("[SERVICE_MENU] MUSIC_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &Options::audio.music.volume, ValueType::INT, 0, 100, 5); + options_.emplace_back(Lang::getText("[SERVICE_MENU] SFX_VOLUME"), SettingsGroup::AUDIO, OptionBehavior::ADJUST, &Options::audio.sound.volume, ValueType::INT, 0, 100, 5); // Settings - options_.emplace_back(Lang::getText("[SERVICE_MENU] AUTOFIRE"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &options.game.autofire, ValueType::BOOL); + options_.emplace_back(Lang::getText("[SERVICE_MENU] AUTOFIRE"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &Options::game.autofire, ValueType::BOOL); options_.emplace_back( Lang::getText("[SERVICE_MENU] LANGUAGE"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, - &options.pending_changes.new_language, + &Options::pending_changes.new_language, std::vector{ Lang::getText("[SERVICE_MENU] LANG_ES"), Lang::getText("[SERVICE_MENU] LANG_BA"), @@ -379,17 +379,17 @@ void ServiceMenu::initializeOptions() Lang::getText("[SERVICE_MENU] DIFFICULTY"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, - &options.pending_changes.new_difficulty, + &Options::pending_changes.new_difficulty, std::vector{ Lang::getText("[SERVICE_MENU] EASY"), Lang::getText("[SERVICE_MENU] NORMAL"), Lang::getText("[SERVICE_MENU] HARD")}); - options_.emplace_back(Lang::getText("[SERVICE_MENU] ENABLE_SHUTDOWN"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &options.game.shutdown_enabled, ValueType::BOOL); + options_.emplace_back(Lang::getText("[SERVICE_MENU] ENABLE_SHUTDOWN"), SettingsGroup::SETTINGS, OptionBehavior::ADJUST, &Options::game.shutdown_enabled, ValueType::BOOL); // System options_.emplace_back(Lang::getText("[SERVICE_MENU] RESET"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE); options_.emplace_back(Lang::getText("[SERVICE_MENU] QUIT"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE); - if (options.game.shutdown_enabled) + if (Options::game.shutdown_enabled) options_.emplace_back(Lang::getText("[SERVICE_MENU] SHUTDOWN"), SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE); // Menu principal @@ -526,7 +526,7 @@ void ServiceMenu::AdjustListValues() auto option = getOptionEntryByCaption(Lang::getText("[SERVICE_MENU] LANGUAGE")); for (size_t i = 0; i < option->value_list.size(); ++i) { - if (Lang::getCodeFromName(option->value_list[i]) == options.game.language) + if (Lang::getCodeFromName(option->value_list[i]) == Options::game.language) { option->list_index = i; } diff --git a/source/service_menu.h b/source/service_menu.h index 2ceac0a..eafa877 100644 --- a/source/service_menu.h +++ b/source/service_menu.h @@ -144,17 +144,17 @@ private: : (list_index - 1 + value_list.size()) % value_list.size(); // Idioma - if (linked_variable == &options.pending_changes.new_language) + if (linked_variable == &Options::pending_changes.new_language) { - options.pending_changes.new_language = Lang::getCodeFromName(value_list[list_index]); - checkPendingChanges(); + Options::pending_changes.new_language = Lang::getCodeFromName(value_list[list_index]); + Options::checkPendingChanges(); } // Dificultad - if (linked_variable == &options.pending_changes.new_difficulty) + if (linked_variable == &Options::pending_changes.new_difficulty) { - // options.pending_changes.new_difficulty = - checkPendingChanges(); + // Options::pending_changes.new_difficulty = + Options::checkPendingChanges(); } } } @@ -207,7 +207,6 @@ private: size_t upper_height_; // Altura de la parte de arriba del menu: la del titulo size_t lower_height_; // Altira de la parte baja del menu: la que tiene las opciones size_t lower_padding_; // Espaciado vertical mínimo entre los bordes y el contenido de la zona inferior - size_t options_width_; // Anchura de la opcion + valor más larga // --- Variables para animación de resize --- SDL_FRect rect_anim_from_{}; // Estado inicial de la animación diff --git a/source/title.cpp b/source/title.cpp index 4bbb55e..e75c578 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -195,7 +195,7 @@ void Title::checkInput() if (!define_buttons_->isEnabled()) { // Comprueba todos los métodos de control - for (const auto &CONTROLLER : options.controllers) + for (const auto &CONTROLLER : Options::controllers) { // START if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) && @@ -269,15 +269,15 @@ void Title::swapControllers() return; } - swapOptionsControllers(); + Options::swapOptionsControllers(); showControllers(); } // Intercambia el teclado de jugador void Title::swapKeyboard() { - swapOptionsKeyboard(); - std::string text = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(getPlayerWhoUsesKeyboard()) + ": " + Lang::getText("[DEFINE_BUTTONS] KEYBOARD"); + Options::swapOptionsKeyboard(); + std::string text = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(Options::getPlayerWhoUsesKeyboard()) + ": " + Lang::getText("[DEFINE_BUTTONS] KEYBOARD"); Notifier::get()->show({text}); } @@ -293,16 +293,16 @@ void Title::showControllers() for (size_t i = 0; i < NUM_CONTROLLERS; ++i) { // Ejemplo: el jugador 1 tiene el mando 2 - player_controller_index.at(options.controllers.at(i).player_id - 1) = i; + player_controller_index.at(Options::controllers.at(i).player_id - 1) = i; } // Genera el texto correspondiente for (size_t i = 0; i < NUM_CONTROLLERS; ++i) { const size_t index = player_controller_index.at(i); - if (options.controllers.at(index).plugged) + if (Options::controllers.at(index).plugged) { - text.at(i) = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(i + 1) + ": " + options.controllers.at(index).name; + text.at(i) = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(i + 1) + ": " + Options::controllers.at(index).name; } }