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