ServiceMenu ja pinta un recuadro de prova

el ServiceMenu el pinta Screen
This commit is contained in:
2025-06-02 11:35:18 +02:00
parent 653bb7dc76
commit 16d9774519
7 changed files with 34 additions and 14 deletions

View File

@@ -100,9 +100,9 @@ void Director::init()
Input::init(Asset::get()->get("gamecontrollerdb.txt")); // Carga configuración de controles
bindInputs(); // Asigna los controles a la entrada del sistema
ServiceMenu::init(); // Inicializa el menú de servicio
Notifier::init(std::string(), Resource::get()->getText("8bithud")); // Inicialización del sistema de notificaciones
// Inicialización del sistema de notificaciones
Notifier::init(std::string(), Resource::get()->getText("8bithud"));
Screen::get()->getSingletons(); // Obtiene los punteros al resto de singletones
#ifdef DEBUG
// Configuración adicional en modo depuración

View File

@@ -28,7 +28,6 @@
#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
@@ -40,7 +39,6 @@
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)),
@@ -1068,9 +1066,6 @@ void Game::render()
fade_in_->render();
fade_out_->render();
// Service Menu
serviceMenu_->render();
// Vuelca el contenido del renderizador en pantalla
screen_->render();
}

View File

@@ -23,7 +23,6 @@ class Item;
class PathSprite;
class Scoreboard;
class Screen;
class ServiceMenu;
class SmartSprite;
class Texture;
enum class BulletType : Uint8;
@@ -106,7 +105,6 @@ private:
// --- Objetos y punteros ---
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

View File

@@ -18,6 +18,7 @@
#include "notifier.h" // Para Notifier
#include "options.h" // Para Options, options, WindowOptions, Vid...
#include "resource.h" // Para Resource
#include "service_menu.h" // Para ServiceMenu
#include "text.h" // Para Text
// Singleton
@@ -172,7 +173,7 @@ void Screen::update()
fps_.calculate(SDL_GetTicks());
shake_effect_.update(src_rect_, dst_rect_);
flash_effect_.update();
Notifier::get()->update();
notifier_->update();
Mouse::updateCursorVisibility();
}
@@ -277,7 +278,8 @@ void Screen::renderOverlays()
renderShake();
renderFlash();
renderAttenuate();
Notifier::get()->render();
serviceMenu_->render();
notifier_->render();
#ifdef DEBUG
renderInfo();
#endif
@@ -401,4 +403,11 @@ void Screen::toggleVSync()
{
options.video.v_sync = !options.video.v_sync;
SDL_SetRenderVSync(renderer_, options.video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
}
// Obtiene los punteros a los singletones
void Screen::getSingletons()
{
serviceMenu_ = ServiceMenu::get();
notifier_ = Notifier::get();
}

View File

@@ -16,6 +16,9 @@
#include "resource.h"
#endif
class Notifier;
class ServiceMenu;
// Clase Screen: gestiona la ventana, el renderizador y los efectos visuales globales
class Screen
{
@@ -50,6 +53,7 @@ public:
SDL_Renderer *getRenderer() { return renderer_; } // Obtiene el renderizador
void show() { SDL_ShowWindow(window_); } // Muestra la ventana
void hide() { SDL_HideWindow(window_); } // Oculta la ventana
void getSingletons(); // Obtiene los punteros a los singletones
#ifdef DEBUG
// --- Debug ---
@@ -184,6 +188,8 @@ private:
SDL_Window *window_; // Ventana de la aplicación
SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Texture *game_canvas_; // Textura donde se dibuja todo antes de volcarse al renderizador
ServiceMenu *serviceMenu_; // Objeto para mostrar el menú de servicio
Notifier *notifier_; // Objeto para mostrar las notificaciones por pantalla
// --- Variables de estado ---
SDL_FRect src_rect_; // Coordenadas de origen para dibujar la textura del juego

View File

@@ -14,6 +14,13 @@ void ServiceMenu::destroy() { delete ServiceMenu::instance_; }
// Obtiene la instancia
ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
// Constructor
ServiceMenu::ServiceMenu()
{
constexpr float GAP = 15.0f;
rect_ = {GAP, GAP, param.game.width - GAP * 2, param.game.height - GAP * 2};
}
void ServiceMenu::toggle()
{
enabled_ = !enabled_;
@@ -23,8 +30,11 @@ void ServiceMenu::render()
{
if (enabled_)
{
SDL_FRect rect = {10.0f, 10.0f, 100.0f, 100.0f};
SDL_RenderRect(Screen::get()->getRenderer(), &rect);
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 224);
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_);
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 224, 224, 224, 255);
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
}
}

View File

@@ -2,6 +2,7 @@
#include <vector>
#include <string>
#include <SDL3/SDL.h>
class ServiceMenu
{
@@ -19,9 +20,10 @@ public:
private:
// -- Variables internas ---
bool enabled_ = false;
SDL_FRect rect_; // Rectangulo para definir el area del menú de servicio
// --- Patrón Singleton ---
ServiceMenu() = default; // Constructor privado
ServiceMenu(); // Constructor privado
~ServiceMenu() = default; // Destructor privado
ServiceMenu(const ServiceMenu &) = delete; // Evitar copia
ServiceMenu &operator=(const ServiceMenu &) = delete; // Evitar asignación