Files
coffee_crisis_arcade_edition/source/service_menu.cpp
Sergio Valor 7ac0ce9354 arreglos estetics en ServiceMenu
afegides noves fonts de text
2025-06-03 09:56:41 +02:00

159 lines
4.7 KiB
C++

#include "service_menu.h"
#include "screen.h"
#include <SDL3/SDL.h>
#include <array>
#include <string>
#include "text.h"
#include "resource.h"
// Singleton
ServiceMenu *ServiceMenu::instance_ = nullptr;
// Inicializa la instancia única del singleton
void ServiceMenu::init() { ServiceMenu::instance_ = new ServiceMenu(); }
// Libera la instancia
void ServiceMenu::destroy() { delete ServiceMenu::instance_; }
// Obtiene la instancia
ServiceMenu *ServiceMenu::get() { return ServiceMenu::instance_; }
// Constructor
ServiceMenu::ServiceMenu()
: elementText_(Resource::get()->getText("04b_25_flat")),
titleText_(Resource::get()->getText("04b_25_flat_2x"))
{
setAnchors();
}
void ServiceMenu::toggle()
{
enabled_ = !enabled_;
}
void ServiceMenu::render()
{
if (enabled_)
{
int y = rect_.y;
constexpr int H_PADDING = 20;
constexpr std::array<const char *, 4> MAIN_LIST = {
"VIDEO",
"AUDIO",
"GAME",
"SYSTEM"};
constexpr std::array<const char *, 5> 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"};
constexpr std::array<const char *, 5> OPTIONS_LIST = {
"FULLSCREEN",
"3",
"OFF",
"ON",
"ON"};
// SOMBRA
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
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), bgColor_.r, bgColor_.g, bgColor_.b, 255);
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_);
// BORDE
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), titleColor_.r, titleColor_.g, titleColor_.b, 255);
SDL_RenderRect(Screen::get()->getRenderer(), &rect_);
// SERVICE MENU
y += lineHeight_;
titleText_->writeDX(TEXT_COLOR | TEXT_CENTER, param.game.game_area.center_x, y, "SERVICE MENU", -4, titleColor_);
// LINEA
y += lineHeight_ * 2;
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), titleColor_.r, titleColor_.g, titleColor_.b, 255);
SDL_RenderLine(Screen::get()->getRenderer(), rect_.x + H_PADDING, y, rect_.x + rect_.w - H_PADDING, y);
// LIST
for (size_t i = 0; i < VIDEO_LIST.size(); ++i)
{
y += lineHeight_;
elementText_->writeColored(rect_.x + H_PADDING, y, VIDEO_LIST.at(i), i == selected_ ? selectedColor_ : textColor_, -2);
elementText_->writeColored(rect_.x + H_PADDING + 100, y, ": " + std::string(OPTIONS_LIST.at(i)), i == selected_ ? selectedColor_ : textColor_, -2);
}
}
}
void ServiceMenu::update()
{
if (enabled_)
{
updateCounter();
selectedColor_ = getSelectedColor();
}
}
void ServiceMenu::setAnchors()
{
width_ = 220;
height_ = 200;
lineHeight_ = elementText_->getCharacterSize() + 5;
rect_ = {
(param.game.width - width_) / 2,
(param.game.height - height_) / 2,
static_cast<float>(width_),
static_cast<float>(height_)};
}
void ServiceMenu::updateCounter()
{
static Uint64 lastUpdate = SDL_GetTicks();
Uint64 currentTicks = SDL_GetTicks();
if (currentTicks - lastUpdate >= 50)
{
counter_++;
lastUpdate = currentTicks;
}
}
Color ServiceMenu::getSelectedColor()
{
static std::array<Color, 12> colors = {
Color(0xFF, 0xFF, 0x00), // Amarillo brillante
Color(0xFF, 0xD7, 0x00), // Dorado claro
Color(0xFF, 0xEF, 0x7C), // Amarillo pastel
Color(0xFF, 0xCC, 0x00), // Amarillo anaranjado
Color(0xFF, 0xF7, 0x00), // Amarillo limón
Color(0xCC, 0x99, 0x00), // Mostaza
Color(0xFF, 0xF7, 0x00), // Amarillo limón (regreso)
Color(0xFF, 0xCC, 0x00), // Amarillo anaranjado (regreso)
Color(0xFF, 0xEF, 0x7C), // Amarillo pastel (regreso)
Color(0xFF, 0xD7, 0x00), // Dorado claro (regreso)
Color(0xFF, 0xFF, 0x00), // Amarillo brillante (regreso)
Color(0xCC, 0x99, 0x00) // Mostaza (regreso, cierre)
};
const size_t index = counter_ % colors.size();
return colors.at(index);
}