forked from jaildesigner-jailgames/jaildoctors_dilemma
JA VA! Nomes s'havia de fer les coses be i no ser un ansias
This commit is contained in:
@@ -15,24 +15,23 @@
|
||||
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para color_t, stringToColor, options_t
|
||||
#include "options.h"
|
||||
|
||||
// Constructor
|
||||
Title::Title(Resource *resource, options_t *options, section_t *section)
|
||||
Title::Title(Resource *resource)
|
||||
: screen_(Screen::get()),
|
||||
renderer_(Screen::get()->getRenderer()),
|
||||
resource_(resource),
|
||||
input_(Input::get()),
|
||||
options_(options),
|
||||
section_(section)
|
||||
input_(Input::get())
|
||||
{
|
||||
// Reserva memoria para los punteros
|
||||
event_handler_ = new SDL_Event();
|
||||
cheevos_ = std::make_unique<Cheevos>(screen_, options, Asset::get()->get("cheevos.bin"));
|
||||
if (options->palette == p_zxspectrum)
|
||||
cheevos_ = std::make_unique<Cheevos>(screen_, Asset::get()->get("cheevos.bin"));
|
||||
if (options.palette == p_zxspectrum)
|
||||
{
|
||||
texture_ = resource->getTexture("title_logo.png");
|
||||
}
|
||||
else if (options->palette == p_zxarne)
|
||||
else if (options.palette == p_zxarne)
|
||||
{
|
||||
texture_ = resource->getTexture("title_logo.png");
|
||||
}
|
||||
@@ -44,7 +43,7 @@ Title::Title(Resource *resource, options_t *options, section_t *section)
|
||||
bg_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
if (bg_texture_ == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
if (options.console)
|
||||
{
|
||||
std::cout << "Error: bgTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
@@ -58,16 +57,16 @@ Title::Title(Resource *resource, options_t *options, section_t *section)
|
||||
pSetSource(loading_screen_);
|
||||
|
||||
// Inicializa variables
|
||||
state_ = section_->subsection == SUBSECTION_TITLE_WITH_LOADING_SCREEN ? show_loading_screen : show_menu;
|
||||
section_->name = SECTION_TITLE;
|
||||
section_->subsection = 0;
|
||||
state_ = options.section.subsection == SUBSECTION_TITLE_WITH_LOADING_SCREEN ? show_loading_screen : show_menu;
|
||||
options.section.name = SECTION_TITLE;
|
||||
options.section.subsection = 0;
|
||||
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.palette, "black"));
|
||||
|
||||
// Rellena la textura de fondo con todos los gráficos
|
||||
fillTexture();
|
||||
@@ -111,7 +110,7 @@ void Title::checkEvents()
|
||||
// Evento de salida de la aplicación
|
||||
if (event_handler_->type == SDL_QUIT)
|
||||
{
|
||||
section_->name = SECTION_QUIT;
|
||||
options.section.name = SECTION_QUIT;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -123,8 +122,8 @@ void Title::checkEvents()
|
||||
switch (event_handler_->key.keysym.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_1:
|
||||
section_->name = SECTION_GAME;
|
||||
section_->subsection = 0;
|
||||
options.section.name = SECTION_GAME;
|
||||
options.section.subsection = 0;
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_2:
|
||||
@@ -163,7 +162,7 @@ void Title::checkInput()
|
||||
}
|
||||
else
|
||||
{
|
||||
section_->name = SECTION_QUIT;
|
||||
options.section.name = SECTION_QUIT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +246,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.palette, "white"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -306,8 +305,8 @@ void Title::update()
|
||||
{
|
||||
if (!show_cheevos_)
|
||||
{
|
||||
section_->name = SECTION_CREDITS;
|
||||
section_->subsection = 0;
|
||||
options.section.name = SECTION_CREDITS;
|
||||
options.section.subsection = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -323,7 +322,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.palette, "black"));
|
||||
|
||||
if (state_ == show_menu)
|
||||
{
|
||||
@@ -357,7 +356,7 @@ void Title::render()
|
||||
// Bucle para el logo del juego
|
||||
void Title::run()
|
||||
{
|
||||
while (section_->name == SECTION_TITLE)
|
||||
while (options.section.name == SECTION_TITLE)
|
||||
{
|
||||
update();
|
||||
checkEvents();
|
||||
@@ -369,11 +368,11 @@ void Title::run()
|
||||
void Title::reLoadTextures()
|
||||
{
|
||||
// Carga la textura adecuada
|
||||
if (options_->palette == p_zxspectrum)
|
||||
if (options.palette == p_zxspectrum)
|
||||
{
|
||||
texture_ = resource_->getTexture("loading_screen_color.png");
|
||||
}
|
||||
else if (options_->palette == p_zxarne)
|
||||
else if (options.palette == p_zxarne)
|
||||
{
|
||||
texture_ = resource_->getTexture("loading_screen_color_zxarne.png");
|
||||
}
|
||||
@@ -384,19 +383,19 @@ void Title::reLoadTextures()
|
||||
// Cambia la paleta
|
||||
void Title::switchPalette()
|
||||
{
|
||||
if (options_->palette == p_zxspectrum)
|
||||
if (options.palette == p_zxspectrum)
|
||||
{
|
||||
options_->palette = p_zxarne;
|
||||
options.palette = p_zxarne;
|
||||
sprite_->setTexture(resource_->getTexture("loading_screen_color_zxarne.png"));
|
||||
}
|
||||
else
|
||||
{
|
||||
options_->palette = p_zxspectrum;
|
||||
options.palette = p_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.palette, "bright_blue"));
|
||||
}
|
||||
|
||||
// Desplaza la lista de logros
|
||||
@@ -425,7 +424,7 @@ void Title::fillTexture()
|
||||
SDL_SetRenderTarget(renderer_, bg_texture_);
|
||||
|
||||
// Rellena la textura de color
|
||||
const color_t c = stringToColor(options_->palette, "black");
|
||||
const color_t c = stringToColor(options.palette, "black");
|
||||
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
@@ -433,7 +432,7 @@ void Title::fillTexture()
|
||||
sprite_->render();
|
||||
|
||||
// Escribe el texto en la textura
|
||||
const color_t textColor = stringToColor(options_->palette, "green");
|
||||
const color_t textColor = stringToColor(options.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);
|
||||
@@ -461,7 +460,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_t cheevosBGColor = stringToColor(options.palette, "black");
|
||||
SDL_SetRenderDrawColor(renderer_, cheevosBGColor.r, cheevosBGColor.g, cheevosBGColor.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
|
||||
@@ -469,10 +468,10 @@ void Title::createCheevosTexture()
|
||||
const std::string cheevosOwner = "LOCAL ACHIEVEMENTS";
|
||||
const std::string cheevosListCaption = cheevosOwner + " (" + std::to_string(cheevos_->unlocked()) + " / " + std::to_string(cheevos_->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.palette, "bright_green"));
|
||||
pos += info_text_->getCharacterSize();
|
||||
const color_t cheevoLockedColor = stringToColor(options_->palette, "white");
|
||||
const color_t cheevoUnlockedColor = stringToColor(options_->palette, "bright_green");
|
||||
const color_t cheevoLockedColor = stringToColor(options.palette, "white");
|
||||
const color_t cheevoUnlockedColor = stringToColor(options.palette, "bright_green");
|
||||
color_t cheevoColor;
|
||||
SDL_SetRenderDrawColor(renderer_, cheevoLockedColor.r, cheevoLockedColor.g, cheevoLockedColor.b, 0xFF);
|
||||
const int lineX1 = (cheevosTextureWidth / 7) * 3;
|
||||
|
||||
Reference in New Issue
Block a user