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