treballant en ServiceMenu
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode, SCOREB...
|
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode, SCOREB...
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "section.h" // Para Name, name, AttractMode, Options
|
#include "section.h" // Para Name, name, AttractMode, Options
|
||||||
|
#include "service_menu.h" // Para ServiceMenu
|
||||||
#include "smart_sprite.h" // Para SmartSprite
|
#include "smart_sprite.h" // Para SmartSprite
|
||||||
#include "stage.h" // Para number, get, Stage, total_power
|
#include "stage.h" // Para number, get, Stage, total_power
|
||||||
#include "tabe.h" // Para Tabe, TabeState
|
#include "tabe.h" // Para Tabe, TabeState
|
||||||
@@ -39,6 +40,7 @@
|
|||||||
Game::Game(int player_id, int current_stage, bool demo)
|
Game::Game(int player_id, int current_stage, bool demo)
|
||||||
: renderer_(Screen::get()->getRenderer()),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
screen_(Screen::get()),
|
screen_(Screen::get()),
|
||||||
|
serviceMenu_(ServiceMenu::get()),
|
||||||
input_(Input::get()),
|
input_(Input::get()),
|
||||||
background_(std::make_unique<Background>()),
|
background_(std::make_unique<Background>()),
|
||||||
canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h)),
|
canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h)),
|
||||||
@@ -1066,6 +1068,9 @@ void Game::render()
|
|||||||
fade_in_->render();
|
fade_in_->render();
|
||||||
fade_out_->render();
|
fade_out_->render();
|
||||||
|
|
||||||
|
// Service Menu
|
||||||
|
serviceMenu_->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen_->render();
|
screen_->render();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class Item;
|
|||||||
class PathSprite;
|
class PathSprite;
|
||||||
class Scoreboard;
|
class Scoreboard;
|
||||||
class Screen;
|
class Screen;
|
||||||
|
class ServiceMenu;
|
||||||
class SmartSprite;
|
class SmartSprite;
|
||||||
class Texture;
|
class Texture;
|
||||||
enum class BulletType : Uint8;
|
enum class BulletType : Uint8;
|
||||||
@@ -105,6 +106,7 @@ private:
|
|||||||
// --- Objetos y punteros ---
|
// --- Objetos y punteros ---
|
||||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
|
ServiceMenu *serviceMenu_; // Objeto para mostrar el menu de servicio
|
||||||
Input *input_; // Manejador de entrada
|
Input *input_; // Manejador de entrada
|
||||||
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
|
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,11 @@
|
|||||||
#include "param.h" // Para Param, ParamGame, param
|
#include "param.h" // Para Param, ParamGame, param
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "section.h" // Para Name, name, Options, options, AttractMode
|
#include "section.h" // Para Name, name, Options, options, AttractMode
|
||||||
|
#include "service_menu.h" // Para ServiceMenu
|
||||||
#include "utils.h" // Para boolToOnOff
|
#include "utils.h" // Para boolToOnOff
|
||||||
|
|
||||||
namespace globalInputs
|
namespace globalInputs
|
||||||
{
|
{
|
||||||
// Variables
|
|
||||||
int service_pressed_counter = 0;
|
|
||||||
bool service_pressed = false;
|
|
||||||
|
|
||||||
// Termina
|
// Termina
|
||||||
void quit(section::Options code)
|
void quit(section::Options code)
|
||||||
{
|
{
|
||||||
@@ -146,7 +143,7 @@ namespace globalInputs
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Salta una sección del juego
|
// Salta una sección del juego
|
||||||
void skip_section()
|
void skipSection()
|
||||||
{
|
{
|
||||||
switch (section::name)
|
switch (section::name)
|
||||||
{
|
{
|
||||||
@@ -167,6 +164,12 @@ namespace globalInputs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Activa el menu de servicio
|
||||||
|
void toggleServiceMenu()
|
||||||
|
{
|
||||||
|
ServiceMenu::get()->toggle();
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
void check()
|
void check()
|
||||||
{
|
{
|
||||||
@@ -211,7 +214,7 @@ namespace globalInputs
|
|||||||
// Saltar sección
|
// Saltar sección
|
||||||
if (Input::get()->checkAnyButtonPressed())
|
if (Input::get()->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
skip_section();
|
skipSection();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,6 +266,14 @@ namespace globalInputs
|
|||||||
toggleVSync();
|
toggleVSync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Service Menu
|
||||||
|
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
|
{
|
||||||
|
toggleServiceMenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Debug info
|
// Debug info
|
||||||
if (Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
if (Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
||||||
@@ -271,12 +282,6 @@ namespace globalInputs
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// OnScreenHelp
|
|
||||||
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD))
|
|
||||||
{
|
|
||||||
service_pressed = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mandos
|
// Mandos
|
||||||
@@ -284,49 +289,9 @@ namespace globalInputs
|
|||||||
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
for (int i = 0; i < Input::get()->getNumControllers(); ++i)
|
||||||
{
|
{
|
||||||
// Salir
|
// Salir
|
||||||
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
|
||||||
Input::get()->checkInput(InputAction::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
|
||||||
{
|
|
||||||
quit(section::Options::QUIT_WITH_CONTROLLER);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset
|
|
||||||
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
|
||||||
Input::get()->checkInput(InputAction::RESET, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Audio
|
|
||||||
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
|
||||||
Input::get()->checkInput(InputAction::TOGGLE_AUDIO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
|
||||||
{
|
|
||||||
toggleAudio();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shaders
|
|
||||||
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
|
||||||
Input::get()->checkInput(InputAction::TOGGLE_VIDEO_SHADERS, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
|
||||||
{
|
|
||||||
toggleShaders();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#ifdef DEBUG
|
|
||||||
// Debug Info
|
|
||||||
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i) &&
|
|
||||||
Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
|
||||||
{
|
|
||||||
Screen::get()->toggleDebugInfo();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// OnScreenHelp
|
|
||||||
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i))
|
||||||
{
|
{
|
||||||
service_pressed = true;
|
toggleServiceMenu();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "service_menu.h"
|
#include "service_menu.h"
|
||||||
#include <iostream>
|
#include "screen.h"
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
ServiceMenu *ServiceMenu::instance_ = nullptr;
|
ServiceMenu *ServiceMenu::instance_ = nullptr;
|
||||||
@@ -13,71 +14,20 @@ void ServiceMenu::destroy() { delete ServiceMenu::instance_; }
|
|||||||
// Obtiene la instancia
|
// Obtiene la instancia
|
||||||
ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
|
ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
|
||||||
|
|
||||||
// Constructor
|
void ServiceMenu::toggle()
|
||||||
ServiceMenu::ServiceMenu() {
|
{
|
||||||
// Inicializa los valores por defecto del menú de servicio
|
enabled_ = !enabled_;
|
||||||
is_active = false;
|
|
||||||
selected_option = 0;
|
|
||||||
options = {"Test de Sonido", "Test de Video", "Contadores", "Salir"};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceMenu::show() {
|
void ServiceMenu::render()
|
||||||
is_active = true;
|
{
|
||||||
while (is_active) {
|
if (enabled_)
|
||||||
render();
|
{
|
||||||
handle_input();
|
SDL_FRect rect = {10.0f, 10.0f, 100.0f, 100.0f};
|
||||||
|
SDL_RenderRect(Screen::get()->getRenderer(), &rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceMenu::render() {
|
void ServiceMenu::update()
|
||||||
std::cout << "=== MENÚ DE SERVICIO ===" << std::endl;
|
{
|
||||||
for (size_t i = 0; i < options.size(); ++i) {
|
|
||||||
if (i == selected_option)
|
|
||||||
std::cout << "> ";
|
|
||||||
else
|
|
||||||
std::cout << " ";
|
|
||||||
std::cout << options[i] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServiceMenu::handle_input() {
|
|
||||||
char input;
|
|
||||||
std::cin >> input;
|
|
||||||
switch (input) {
|
|
||||||
case 'w':
|
|
||||||
if (selected_option > 0) selected_option--;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
if (selected_option < options.size() - 1) selected_option++;
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
case '\r':
|
|
||||||
case 'e':
|
|
||||||
execute_option(selected_option);
|
|
||||||
break;
|
|
||||||
case 'q':
|
|
||||||
is_active = false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServiceMenu::execute_option(size_t option) {
|
|
||||||
switch (option) {
|
|
||||||
case 0:
|
|
||||||
std::cout << "Ejecutando test de sonido..." << std::endl;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
std::cout << "Ejecutando test de video..." << std::endl;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
std::cout << "Mostrando contadores..." << std::endl;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
is_active = false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -11,23 +11,21 @@ public:
|
|||||||
static void destroy(); // Libera el objeto ServiceMenu
|
static void destroy(); // Libera el objeto ServiceMenu
|
||||||
static ServiceMenu *get(); // Obtiene el puntero al objeto ServiceMenu
|
static ServiceMenu *get(); // Obtiene el puntero al objeto ServiceMenu
|
||||||
|
|
||||||
void show();
|
// -- Métodos ---
|
||||||
|
void toggle();
|
||||||
void render();
|
void render();
|
||||||
void handle_input();
|
void update();
|
||||||
void execute_option(size_t option);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// -- Variables internas ---
|
||||||
|
bool enabled_ = false;
|
||||||
|
|
||||||
// --- Patrón Singleton ---
|
// --- Patrón Singleton ---
|
||||||
ServiceMenu(); // Constructor privado
|
ServiceMenu() = default; // Constructor privado
|
||||||
~ServiceMenu() = default; // Destructor privado
|
~ServiceMenu() = default; // Destructor privado
|
||||||
ServiceMenu(const ServiceMenu &) = delete; // Evitar copia
|
ServiceMenu(const ServiceMenu &) = delete; // Evitar copia
|
||||||
ServiceMenu &operator=(const ServiceMenu &) = delete; // Evitar asignación
|
ServiceMenu &operator=(const ServiceMenu &) = delete; // Evitar asignación
|
||||||
|
|
||||||
// --- Singleton ---
|
// --- Singleton ---
|
||||||
static ServiceMenu *instance_;
|
static ServiceMenu *instance_;
|
||||||
|
|
||||||
// -- Variables internas ---
|
|
||||||
bool is_active;
|
|
||||||
size_t selected_option;
|
|
||||||
std::vector<std::string> options;
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user