211 lines
6.8 KiB
C++
211 lines
6.8 KiB
C++
#include "service_menu.h"
|
|
#include "screen.h"
|
|
#include <SDL3/SDL.h>
|
|
#include <array>
|
|
#include <string>
|
|
#include "text.h"
|
|
#include "resource.h"
|
|
#include "options.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();
|
|
initializeOptions();
|
|
}
|
|
|
|
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, 0xFB, 0x8A), // Amarillo suave
|
|
Color(0xFF, 0xE4, 0x5D), // Dorado medio
|
|
Color(0xFF, 0xD1, 0x3C), // Amarillo pastel intenso
|
|
Color(0xFF, 0xBF, 0x23), // Amarillo anaranjado
|
|
Color(0xFF, 0xAA, 0x12), // Amarillo cálido
|
|
Color(0xE6, 0x9A, 0x08), // Mostaza oscuro
|
|
Color(0xE6, 0x9A, 0x08), // Mostaza oscuro (regreso, cierre)
|
|
Color(0xFF, 0xAA, 0x12), // Amarillo cálido (regreso)
|
|
Color(0xFF, 0xBF, 0x23), // Amarillo anaranjado (regreso)
|
|
Color(0xFF, 0xD1, 0x3C), // Amarillo pastel intenso (regreso)
|
|
Color(0xFF, 0xE4, 0x5D), // Dorado medio (regreso)
|
|
Color(0xFF, 0xFB, 0x8A) // Amarillo suave (regreso)
|
|
};
|
|
|
|
const size_t index = counter_ % colors.size();
|
|
|
|
return colors.at(index);
|
|
}
|
|
|
|
void ServiceMenu::setSelectorUp()
|
|
{
|
|
if (selected_ > 0)
|
|
{
|
|
--selected_;
|
|
}
|
|
else
|
|
{
|
|
selected_ = 4;
|
|
}
|
|
}
|
|
|
|
void ServiceMenu::setSelectorDown()
|
|
{
|
|
selected_ = (selected_ + 1) % 5;
|
|
}
|
|
|
|
void ServiceMenu::acceptSelection()
|
|
{
|
|
}
|
|
|
|
void ServiceMenu::cancelSelection()
|
|
{
|
|
}
|
|
|
|
void ServiceMenu::initializeOptions()
|
|
{
|
|
// Video
|
|
options_.emplace_back("FULLSCREEN", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.fullscreen, ValueType::BOOL);
|
|
options_.emplace_back("WINDOW SIZE", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.window.size, ValueType::INT);
|
|
options_.emplace_back("SHADERS", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.shaders, ValueType::BOOL);
|
|
options_.emplace_back("VSYNC", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.v_sync, ValueType::BOOL);
|
|
options_.emplace_back("INTEGER SCALE", SettingsGroup::VIDEO, OptionBehavior::ADJUST, &options.video.integer_scale, ValueType::BOOL);
|
|
|
|
// Audio
|
|
options_.emplace_back("AUDIO", SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.enabled, ValueType::BOOL);
|
|
options_.emplace_back("MAIN VOLUME", SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.volume, ValueType::INT);
|
|
options_.emplace_back("MUSIC VOLUME", SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.music.volume, ValueType::INT);
|
|
options_.emplace_back("SFX VOLUME", SettingsGroup::AUDIO, OptionBehavior::ADJUST, &options.audio.sound.volume, ValueType::INT);
|
|
|
|
// Game
|
|
options_.emplace_back("AUTOFIRE", SettingsGroup::GAME, OptionBehavior::ADJUST, &options.game.autofire, ValueType::BOOL);
|
|
//options_.emplace_back("LANG", SettingsGroup::GAME, OptionBehavior::ADJUST, &options.game.language, ValueType::BOOL);
|
|
|
|
// System
|
|
options_.emplace_back("RESET", SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
|
|
options_.emplace_back("QUIT", SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
|
|
options_.emplace_back("SHUTDOWN", SettingsGroup::SYSTEM, OptionBehavior::SELECT, nullptr, ValueType::NONE);
|
|
} |