diff --git a/source/credits.cpp b/source/credits.cpp index 1f4cb57..d993fd7 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -26,6 +26,7 @@ #include "texture.h" // Para Texture #include "tiled_bg.h" // Para TiledBG, TiledBGMode #include "utils.h" // Para Color, Zone, shdw_txt_color, no_color +#include "service_menu.h" // Textos constexpr const char TEXT_COPYRIGHT[] = "@2020,2025 JailDesigner"; @@ -140,15 +141,18 @@ void Credits::checkEvents() // Comprueba las entradas void Credits::checkInput() { - // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) - if (Input::get()->checkAnyButtonPressed(INPUT_ALLOW_REPEAT)) - { - want_to_pass_ = true; - fading_ = mini_logo_on_position_; - } - else - { - want_to_pass_ = false; + if (!ServiceMenu::get()->isEnabled()) + { + // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) + if (Input::get()->checkAnyButtonPressed(INPUT_ALLOW_REPEAT)) + { + want_to_pass_ = true; + fading_ = mini_logo_on_position_; + } + else + { + want_to_pass_ = false; + } } // Comprueba los inputs que se pueden introducir en cualquier sección del juego diff --git a/source/director.cpp b/source/director.cpp index 8090f1f..3dac7e3 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -49,7 +49,7 @@ Director::Director(int argc, const char *argv[]) section::name = section::Name::GAME; section::options = section::Options::GAME_PLAY_1P; #elif DEBUG - section::name = section::Name::GAME; + section::name = section::Name::LOGO; section::options = section::Options::GAME_PLAY_1P; #else // NORMAL GAME section::name = section::Name::LOGO; diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index a2abd9f..e25956b 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -215,21 +215,21 @@ namespace globalInputs // Derecha if (Input::get()->checkInput(InputAction::RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { - ServiceMenu::get()->setSelectorRight(); + ServiceMenu::get()->adjustOption(true); return; } // Izquierda if (Input::get()->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { - ServiceMenu::get()->setSelectorLeft(); + ServiceMenu::get()->adjustOption(false); return; } // Aceptar if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) { - ServiceMenu::get()->acceptSelection(); + ServiceMenu::get()->selectOption(); return; } @@ -304,7 +304,7 @@ namespace globalInputs } // Saltar sección - if (Input::get()->checkAnyButtonPressed()) + if (Input::get()->checkAnyButtonPressed() && !ServiceMenu::get()->isEnabled()) { skipSection(); return; diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 3410f62..3870e7e 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -142,10 +142,7 @@ void HiScoreTable::checkEvents() } // Comprueba las entradas -void HiScoreTable::checkInput() -{ - globalInputs::check(); -} +void HiScoreTable::checkInput() { globalInputs::check(); } // Bucle para la pantalla de instrucciones void HiScoreTable::run() diff --git a/source/instructions.cpp b/source/instructions.cpp index 0833d4a..b91f263 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -264,10 +264,7 @@ void Instructions::checkEvents() } // Comprueba las entradas -void Instructions::checkInput() -{ - globalInputs::check(); -} +void Instructions::checkInput() { globalInputs::check(); } // Bucle para la pantalla de instrucciones void Instructions::run() diff --git a/source/logo.cpp b/source/logo.cpp index 5fbe87e..bb0f5cf 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -74,10 +74,7 @@ void Logo::checkEvents() } // Comprueba las entradas -void Logo::checkInput() -{ - globalInputs::check(); -} +void Logo::checkInput() { globalInputs::check(); } // Gestiona el logo de JAILGAMES void Logo::updateJAILGAMES() diff --git a/source/service_menu.cpp b/source/service_menu.cpp index f5c4235..e0d2bff 100644 --- a/source/service_menu.cpp +++ b/source/service_menu.cpp @@ -47,12 +47,16 @@ void ServiceMenu::render() constexpr int H_PADDING = 20; // SOMBRA - SDL_FRect shadowRect = {rect_.x + 5, rect_.y + 5, rect_.w, rect_.h}; - SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 64); - SDL_RenderFillRect(Screen::get()->getRenderer(), &shadowRect); + if (aspect_ == Aspect::ASPECT1) + { + SDL_FRect shadowRect = {rect_.x + 5, rect_.y + 5, rect_.w, rect_.h}; + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 64); + SDL_RenderFillRect(Screen::get()->getRenderer(), &shadowRect); + } // FONDO - SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bg_color_.r, bg_color_.g, bg_color_.b, 255); + const Uint8 ALPHA = aspect_ == Aspect::ASPECT1 ? 255 : 255; + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bg_color_.r, bg_color_.g, bg_color_.b, ALPHA); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_); // BORDE @@ -134,35 +138,25 @@ Color ServiceMenu::getSelectedColor() void ServiceMenu::setSelectorUp() { - if (selected_ > 0) - { - --selected_; - } - else - { - selected_ = option_pairs_.size() - 1; - } + selected_ = (selected_ > 0) ? --selected_ : display_options_.size() - 1; } void ServiceMenu::setSelectorDown() { - selected_ = (selected_ + 1) % option_pairs_.size(); + selected_ = (selected_ + 1) % display_options_.size(); } -void ServiceMenu::setSelectorRight() +void ServiceMenu::adjustOption(bool adjust_up) { - display_options_.at(selected_).adjustValue(true); - option_pairs_ = getOptionPairs(current_settings_group_); - applySettings(current_settings_group_); -} -void ServiceMenu::setSelectorLeft() -{ - display_options_.at(selected_).adjustValue(false); - option_pairs_ = getOptionPairs(current_settings_group_); - applySettings(current_settings_group_); + if (display_options_.at(selected_).behavior == OptionBehavior::ADJUST) + { + display_options_.at(selected_).adjustValue(adjust_up); + option_pairs_ = getOptionPairs(current_settings_group_); + applySettings(current_settings_group_); + } } -void ServiceMenu::acceptSelection() +void ServiceMenu::selectOption() { // Carpeta if (display_options_.at(selected_).type == ValueType::FOLDER) diff --git a/source/service_menu.h b/source/service_menu.h index dd67757..d5d8175 100644 --- a/source/service_menu.h +++ b/source/service_menu.h @@ -25,9 +25,9 @@ public: // --- Métodos de control --- void setSelectorUp(); void setSelectorDown(); - void setSelectorRight(); + void adjustOption(bool adjust_up); void setSelectorLeft(); - void acceptSelection(); + void selectOption(); void moveBack(); // --- Getters --- @@ -36,6 +36,12 @@ public: private: using OptionPairs = std::vector>; + enum class Aspect + { + ASPECT1, // Fondo opaco y proyecta sombra + ASPECT2 // Fondo translucido + }; + enum class SettingsGroup { VIDEO, // Configuraciones relacionadas con la calidad y resolución de imagen @@ -89,14 +95,14 @@ private: min_value(0), max_value(0), step_value(0), target_group(tgtGrp) {} // Método para modificar el valor - void adjustValue(bool increase) + void adjustValue(bool adjust_up) { if (linked_variable) { if (type == ValueType::INT) { int &value = *(static_cast(linked_variable)); - int newValue = increase ? value + step_value : value - step_value; + int newValue = adjust_up ? value + step_value : value - step_value; // Asegurar que el nuevo valor se mantenga dentro de los límites value = std::clamp(newValue, min_value, max_value); @@ -136,6 +142,7 @@ private: OptionPairs option_pairs_; // Listado con las opciones de menu actuales (filtradas por grupo) SettingsGroup current_settings_group_; // Grupo actual SettingsGroup previous_settings_group_; // Grupo anterior + Aspect aspect_ = Aspect::ASPECT2; // -- Aspecto -- Color bg_color_ = SERV_MENU_BG_COLOR; // Color de fondo diff --git a/source/title.cpp b/source/title.cpp index dea174f..f55e117 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -24,6 +24,7 @@ #include "texture.h" // Para Texture #include "tiled_bg.h" // Para TiledBG, TiledBGMode #include "utils.h" // Para Color, Zone, fade_color, no_color, BLOCK +#include "service_menu.h" // Constructor Title::Title() @@ -188,52 +189,55 @@ void Title::checkEvents() // Comprueba las entradas void Title::checkInput() { - // Comprueba las entradas solo si no se estan definiendo los botones - if (!define_buttons_->isEnabled()) + if (!ServiceMenu::get()->isEnabled()) { - // Comprueba todos los métodos de control - for (const auto &CONTROLLER : options.controllers) + // Comprueba las entradas solo si no se estan definiendo los botones + if (!define_buttons_->isEnabled()) { - // START - if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) && - !Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) + // Comprueba todos los métodos de control + for (const auto &CONTROLLER : options.controllers) { - if ((state_ == TitleState::LOGO_FINISHED || ALLOW_TITLE_ANIMATION_SKIP) && !fade_->isEnabled()) + // START + if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) && + !Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) { - Audio::get()->playSound("game_start.wav"); - Audio::get()->fadeOutMusic(1500); - switch (CONTROLLER.player_id) + if ((state_ == TitleState::LOGO_FINISHED || ALLOW_TITLE_ANIMATION_SKIP) && !fade_->isEnabled()) { - case 1: - selection_ = section::Options::GAME_PLAY_1P; - break; - case 2: - selection_ = section::Options::GAME_PLAY_2P; - break; - default: - selection_ = section::Options::TITLE_TIME_OUT; - break; + Audio::get()->playSound("game_start.wav"); + Audio::get()->fadeOutMusic(1500); + switch (CONTROLLER.player_id) + { + case 1: + selection_ = section::Options::GAME_PLAY_1P; + break; + case 2: + selection_ = section::Options::GAME_PLAY_2P; + break; + default: + selection_ = section::Options::TITLE_TIME_OUT; + break; + } + state_ = TitleState::START_HAS_BEEN_PRESSED; + counter_ = 0; + return; } - state_ = TitleState::START_HAS_BEEN_PRESSED; - counter_ = 0; + } + + // SWAP_CONTROLLERS + if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) && + Input::get()->checkInput(InputAction::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) + { + swapControllers(); return; } - } - // SWAP_CONTROLLERS - if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) && - Input::get()->checkInput(InputAction::SWAP_CONTROLLERS, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) - { - swapControllers(); - return; - } - - // CONFIG - if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) && - Input::get()->checkInput(InputAction::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) - { - define_buttons_->enable(CONTROLLER.index); - return; + // CONFIG + if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index) && + Input::get()->checkInput(InputAction::CONFIG, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) + { + define_buttons_->enable(CONTROLLER.index); + return; + } } } } diff --git a/source/utils.h b/source/utils.h index 95cee43..2986acf 100644 --- a/source/utils.h +++ b/source/utils.h @@ -38,7 +38,7 @@ struct Color { Uint8 r, g, b; constexpr Color() : r(0), g(0), b(0) {} - explicit constexpr Color(int red, int green, int blue) : r(red), g(green), b(blue) {} + explicit constexpr Color(Uint8 red, Uint8 green, Uint8 blue) : r(red), g(green), b(blue) {} constexpr Color getInverse() const { return Color(255 - r, 255 - g, 255 - b); } Color lighten(int amount = 50) const