Reestructurant la classe Options

This commit is contained in:
2025-02-23 18:12:02 +01:00
parent 3ba4293e8a
commit 2ee0c70319
48 changed files with 898 additions and 984 deletions

View File

@@ -27,11 +27,11 @@ Title::Title()
input_(Input::get())
{
// Reserva memoria para los punteros
if (options.palette == p_zxspectrum)
if (options.video.palette == Palette::ZXSPECTRUM)
{
texture_ = resource_->getTexture("title_logo.png");
}
else if (options.palette == p_zxarne)
else if (options.video.palette == Palette::ZXARNE)
{
texture_ = resource_->getTexture("title_logo.png");
}
@@ -57,16 +57,16 @@ Title::Title()
pSetSource(loading_screen_);
// Inicializa variables
state_ = options.section.subsection == SUBSECTION_TITLE_WITH_LOADING_SCREEN ? show_loading_screen : show_menu;
options.section.name = SECTION_TITLE;
options.section.subsection = 0;
state_ = options.section.subsection == Subsection::TITLE_WITH_LOADING_SCREEN ? show_loading_screen : show_menu;
options.section.section = Section::TITLE;
options.section.subsection = Subsection::NONE;
initMarquee();
// Crea y rellena la textura para mostrar los logros
createCheevosTexture();
// Cambia el color del borde
screen_->setBorderColor(stringToColor(options.palette, "black"));
screen_->setBorderColor(stringToColor(options.video.palette, "black"));
// Rellena la textura de fondo con todos los gráficos
fillTexture();
@@ -107,7 +107,7 @@ void Title::checkEvents()
while (SDL_PollEvent(&event))
{
globalEvents::check(event);
// Solo se comprueban estas teclas si no está activo el menu de logros
if (event.type == SDL_KEYDOWN)
{
@@ -116,8 +116,8 @@ void Title::checkEvents()
switch (event.key.keysym.scancode)
{
case SDL_SCANCODE_1:
options.section.name = SECTION_GAME;
options.section.subsection = 0;
options.section.section = Section::GAME;
options.section.subsection = Subsection::NONE;
break;
case SDL_SCANCODE_2:
@@ -200,7 +200,7 @@ void Title::renderMarquee()
{
if (l.enabled)
{
text_->writeColored(l.x, 184, l.letter, stringToColor(options.palette, "white"));
text_->writeColored(l.x, 184, l.letter, stringToColor(options.video.palette, "white"));
}
}
}
@@ -258,8 +258,8 @@ void Title::update()
{
if (!show_cheevos_)
{
options.section.name = SECTION_CREDITS;
options.section.subsection = 0;
options.section.section = Section::CREDITS;
options.section.subsection = Subsection::NONE;
}
}
break;
@@ -275,7 +275,7 @@ void Title::render()
{
// Prepara para empezar a dibujar en la textura de juego
screen_->start();
screen_->clean(stringToColor(options.palette, "black"));
screen_->clean(stringToColor(options.video.palette, "black"));
if (state_ == show_menu)
{
@@ -309,7 +309,7 @@ void Title::render()
// Bucle para el logo del juego
void Title::run()
{
while (options.section.name == SECTION_TITLE)
while (options.section.section == Section::TITLE)
{
update();
checkEvents();
@@ -321,11 +321,11 @@ void Title::run()
void Title::reLoadTextures()
{
// Carga la textura adecuada
if (options.palette == p_zxspectrum)
if (options.video.palette == Palette::ZXSPECTRUM)
{
texture_ = resource_->getTexture("loading_screen_color.png");
}
else if (options.palette == p_zxarne)
else if (options.video.palette == Palette::ZXARNE)
{
texture_ = resource_->getTexture("loading_screen_color_zxarne.png");
}
@@ -336,19 +336,19 @@ void Title::reLoadTextures()
// Cambia la paleta
void Title::switchPalette()
{
if (options.palette == p_zxspectrum)
if (options.video.palette == Palette::ZXSPECTRUM)
{
options.palette = p_zxarne;
options.video.palette = Palette::ZXARNE;
sprite_->setTexture(resource_->getTexture("loading_screen_color_zxarne.png"));
}
else
{
options.palette = p_zxspectrum;
options.video.palette = Palette::ZXSPECTRUM;
sprite_->setTexture(resource_->getTexture("loading_screen_color.png"));
}
// Cambia el color del borde
screen_->setBorderColor(stringToColor(options.palette, "bright_blue"));
screen_->setBorderColor(stringToColor(options.video.palette, "bright_blue"));
}
// Desplaza la lista de logros
@@ -377,7 +377,7 @@ void Title::fillTexture()
SDL_SetRenderTarget(renderer_, bg_texture_);
// Rellena la textura de color
const color_t c = stringToColor(options.palette, "black");
const Color c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
SDL_RenderClear(renderer_);
@@ -385,7 +385,7 @@ void Title::fillTexture()
sprite_->render();
// Escribe el texto en la textura
const color_t textColor = stringToColor(options.palette, "green");
const Color textColor = stringToColor(options.video.palette, "green");
const int textSize = text_->getCharacterSize();
text_->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, 11 * textSize, "1.PLAY", 1, textColor);
text_->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, 13 * textSize, "2.ACHIEVEMENTS", 1, textColor);
@@ -413,7 +413,7 @@ void Title::createCheevosTexture()
cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND);
// Rellena la textura con color sólido
const color_t cheevosBGColor = stringToColor(options.palette, "black");
const Color cheevosBGColor = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, cheevosBGColor.r, cheevosBGColor.g, cheevosBGColor.b, 0xFF);
SDL_RenderClear(renderer_);
@@ -421,11 +421,11 @@ void Title::createCheevosTexture()
const std::string cheevosOwner = "ACHIEVEMENTS";
const std::string cheevosListCaption = cheevosOwner + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->count()) + ")";
int pos = 2;
info_text_->writeDX(TXT_CENTER | TXT_COLOR, cheevos_texture_->getWidth() / 2, pos, cheevosListCaption, 1, stringToColor(options.palette, "bright_green"));
info_text_->writeDX(TXT_CENTER | TXT_COLOR, cheevos_texture_->getWidth() / 2, pos, cheevosListCaption, 1, stringToColor(options.video.palette, "bright_green"));
pos += info_text_->getCharacterSize();
const color_t cheevoLockedColor = stringToColor(options.palette, "white");
const color_t cheevoUnlockedColor = stringToColor(options.palette, "bright_green");
color_t cheevoColor;
const Color cheevoLockedColor = stringToColor(options.video.palette, "white");
const Color cheevoUnlockedColor = stringToColor(options.video.palette, "bright_green");
Color cheevoColor;
SDL_SetRenderDrawColor(renderer_, cheevoLockedColor.r, cheevoLockedColor.g, cheevoLockedColor.b, 0xFF);
const int lineX1 = (cheevosTextureWidth / 7) * 3;
const int lineX2 = lineX1 + ((cheevosTextureWidth / 7) * 1);