ServiceMenu: ja es funcional en totes les seccions del programa

This commit is contained in:
2025-06-06 19:45:47 +02:00
parent 71e1a035dd
commit 552eff2fc0
10 changed files with 92 additions and 92 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

View File

@@ -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)

View File

@@ -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<std::pair<std::string, std::string>>;
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<int *>(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

View File

@@ -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;
}
}
}
}

View File

@@ -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