ServiceMenu ja pinta alguns textos d'exemple

This commit is contained in:
2025-06-02 14:08:32 +02:00
parent 3e9716901b
commit 093b775360
2 changed files with 56 additions and 3 deletions

View File

@@ -1,6 +1,10 @@
#include "service_menu.h" #include "service_menu.h"
#include "screen.h" #include "screen.h"
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <array>
#include <string>
#include "text.h"
#include "resource.h"
// Singleton // Singleton
ServiceMenu *ServiceMenu::instance_ = nullptr; ServiceMenu *ServiceMenu::instance_ = nullptr;
@@ -16,8 +20,9 @@ ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
// Constructor // Constructor
ServiceMenu::ServiceMenu() ServiceMenu::ServiceMenu()
: text_(Resource::get()->getText("04b_25_metal"))
{ {
constexpr float GAP = 15.0f; constexpr float GAP = 30.0f;
rect_ = {GAP, GAP, param.game.width - GAP * 2, param.game.height - GAP * 2}; rect_ = {GAP, GAP, param.game.width - GAP * 2, param.game.height - GAP * 2};
} }
@@ -30,11 +35,55 @@ void ServiceMenu::render()
{ {
if (enabled_) if (enabled_)
{ {
constexpr int SEPARATION = 14;
constexpr std::array<const char *, 4> MAIN_LIST = {
"VIDEO",
"AUDIO",
"GAME",
"SYSTEM"};
constexpr std::array<const char *, 54> VIDEO_LIST = {
"VIDEO MODE",
"WINDOW SIZE",
"SHADERS",
"VSYNC",
"INTEGER SCALE"};
constexpr std::array<const char *, 4> AUDIO_LIST = {
"AUDIO",
"MAIN VOLUME",
"MUSIC VOLUME",
"SFX VOLUME"};
constexpr std::array<const char *, 2> GAME_LIST = {
"AUTOFIRE",
"LANG"};
constexpr std::array<const char *, 3> SYSTEM_LIST = {
"RESET",
"EXIT",
"SHUTDOWN"};
// FONDO
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 224); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 224);
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_); SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_);
// BORDE
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 224, 224, 224, 255); SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 224, 224, 224, 255);
SDL_RenderRect(Screen::get()->getRenderer(), &rect_); SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
// SERVICE MENU
text_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, rect_.y + SEPARATION, "SERVICE MENU", -2, BLUE_SKY_COLOR.lighten());
// LINEA
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), BLUE_SKY_COLOR.lighten().r, BLUE_SKY_COLOR.lighten().g, BLUE_SKY_COLOR.lighten().b, 255);
SDL_RenderLine(Screen::get()->getRenderer(), rect_.x + 20, rect_.y + SEPARATION * 3, rect_.x + rect_.w - 20, rect_.y + SEPARATION * 3);
// LIST
for (size_t i = 0; i < MAIN_LIST.size(); ++i)
{
text_->writeColored(rect_.x + 20, rect_.y + (SEPARATION * 4) + (i * (SEPARATION + SEPARATION * 0.5f)), MAIN_LIST.at(i), BLUE_SKY_COLOR.lighten(100), -2);
}
} }
} }

View File

@@ -2,8 +2,11 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <memory>
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
class Text;
class ServiceMenu class ServiceMenu
{ {
public: public:
@@ -19,8 +22,9 @@ public:
private: private:
// -- Variables internas --- // -- Variables internas ---
bool enabled_ = false; bool enabled_ = false; // Indica si el menú de servicio está activo
SDL_FRect rect_; // Rectangulo para definir el area del menú de servicio SDL_FRect rect_; // Rectangulo para definir el area del menú de servicio
std::shared_ptr<Text> text_; // Objeto para escribir texto;
// --- Patrón Singleton --- // --- Patrón Singleton ---
ServiceMenu(); // Constructor privado ServiceMenu(); // Constructor privado