forked from jaildesigner-jailgames/jaildoctors_dilemma
Arreglos en la estructura i format del codi
This commit is contained in:
108
source/title.cpp
108
source/title.cpp
@@ -23,26 +23,11 @@
|
||||
|
||||
// Constructor
|
||||
Title::Title()
|
||||
: screen_(Screen::get()),
|
||||
renderer_(Screen::get()->getRenderer()),
|
||||
resource_(Resource::get()),
|
||||
input_(Input::get())
|
||||
: texture_(Resource::get()->getTexture("title_logo.png")),
|
||||
sprite_(std::make_shared<Sprite>(texture_, 0, 0, texture_->getWidth(), texture_->getHeight()))
|
||||
{
|
||||
// Reserva memoria para los punteros
|
||||
if (options.video.palette == Palette::ZXSPECTRUM)
|
||||
{
|
||||
texture_ = resource_->getTexture("title_logo.png");
|
||||
}
|
||||
else if (options.video.palette == Palette::ZXARNE)
|
||||
{
|
||||
texture_ = resource_->getTexture("title_logo.png");
|
||||
}
|
||||
sprite_ = std::make_shared<Sprite>(texture_, 0, 0, texture_->getWidth(), texture_->getHeight());
|
||||
text_ = resource_->getText("smb2");
|
||||
info_text_ = resource_->getText("subatomic");
|
||||
|
||||
// Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo
|
||||
bg_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
bg_texture_ = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
if (bg_texture_ == nullptr)
|
||||
{
|
||||
if (options.console)
|
||||
@@ -53,7 +38,7 @@ Title::Title()
|
||||
SDL_SetTextureBlendMode(bg_texture_, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Carga la surface con los gráficos de la pantalla de carga
|
||||
pInit(renderer_, 256, 128);
|
||||
pInit(Screen::get()->getRenderer(), 256, 128);
|
||||
loading_screen_ = pLoadSurface(Asset::get()->get("loading_screen_color.gif").c_str());
|
||||
pLoadPal(Asset::get()->get("loading_screen_color.gif").c_str());
|
||||
pSetSource(loading_screen_);
|
||||
@@ -68,7 +53,7 @@ Title::Title()
|
||||
createCheevosTexture();
|
||||
|
||||
// Cambia el color del borde
|
||||
screen_->setBorderColor(stringToColor(options.video.palette, "black"));
|
||||
Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
|
||||
|
||||
// Rellena la textura de fondo con todos los gráficos
|
||||
fillTexture();
|
||||
@@ -137,22 +122,22 @@ void Title::checkInput()
|
||||
{
|
||||
if (show_cheevos_)
|
||||
{
|
||||
if (input_->checkInput(InputAction::DOWN, REPEAT_TRUE))
|
||||
if (Input::get()->checkInput(InputAction::DOWN, REPEAT_TRUE))
|
||||
{
|
||||
moveCheevosList(1);
|
||||
}
|
||||
else if (input_->checkInput(InputAction::UP, REPEAT_TRUE))
|
||||
else if (Input::get()->checkInput(InputAction::UP, REPEAT_TRUE))
|
||||
{
|
||||
moveCheevosList(0);
|
||||
}
|
||||
else if (input_->checkInput(InputAction::ACCEPT, REPEAT_FALSE))
|
||||
else if (Input::get()->checkInput(InputAction::ACCEPT, REPEAT_FALSE))
|
||||
{
|
||||
hideCheevosList();
|
||||
counter_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (input_->checkInput(InputAction::ACCEPT, REPEAT_FALSE))
|
||||
if (Input::get()->checkInput(InputAction::ACCEPT, REPEAT_FALSE))
|
||||
{
|
||||
if (state_ == TitleState::SHOW_LOADING_SCREEN)
|
||||
{
|
||||
@@ -166,6 +151,8 @@ void Title::checkInput()
|
||||
// Actualiza la marquesina
|
||||
void Title::updateMarquee()
|
||||
{
|
||||
const auto TEXT = Resource::get()->getText("smb2");
|
||||
|
||||
for (int i = 0; i < (int)letters_.size(); ++i)
|
||||
{
|
||||
if (letters_[i].enabled)
|
||||
@@ -181,7 +168,7 @@ void Title::updateMarquee()
|
||||
if (i > 0 && letters_[i - 1].x < 256 && letters_[i - 1].enabled)
|
||||
{
|
||||
letters_[i].enabled = true;
|
||||
letters_[i].x = letters_[i - 1].x + text_->lenght(letters_[i - 1].letter) + 1;
|
||||
letters_[i].x = letters_[i - 1].x + TEXT->lenght(letters_[i - 1].letter) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,11 +183,12 @@ void Title::updateMarquee()
|
||||
// Dibuja la marquesina
|
||||
void Title::renderMarquee()
|
||||
{
|
||||
const auto TEXT = Resource::get()->getText("smb2");
|
||||
for (const auto &l : letters_)
|
||||
{
|
||||
if (l.enabled)
|
||||
{
|
||||
text_->writeColored(l.x, 184, l.letter, stringToColor(options.video.palette, "white"));
|
||||
TEXT->writeColored(l.x, 184, l.letter, stringToColor(options.video.palette, "white"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,7 +205,7 @@ void Title::update()
|
||||
// Comprueba las entradas
|
||||
checkInput();
|
||||
|
||||
screen_->update();
|
||||
Screen::get()->update();
|
||||
|
||||
// Incrementa el contador
|
||||
counter_++;
|
||||
@@ -268,13 +256,13 @@ void Title::update()
|
||||
void Title::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
screen_->start();
|
||||
screen_->clean(stringToColor(options.video.palette, "black"));
|
||||
Screen::get()->start();
|
||||
Screen::get()->clean(stringToColor(options.video.palette, "black"));
|
||||
|
||||
if (state_ == TitleState::SHOW_MENU)
|
||||
{
|
||||
// Dibuja la textura de fondo
|
||||
SDL_RenderCopy(renderer_, bg_texture_, nullptr, nullptr);
|
||||
SDL_RenderCopy(Screen::get()->getRenderer(), bg_texture_, nullptr, nullptr);
|
||||
|
||||
// Dibuja la marquesina
|
||||
renderMarquee();
|
||||
@@ -290,14 +278,14 @@ void Title::render()
|
||||
// Dibuja la pantalla de carga
|
||||
pCls(4);
|
||||
pBlit(0, 0, 0, 0, 256, 128);
|
||||
pFlip(renderer_);
|
||||
pFlip(Screen::get()->getRenderer());
|
||||
|
||||
// Dibuja el logo del título
|
||||
sprite_->render();
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen_->render();
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Bucle para el logo del juego
|
||||
@@ -333,73 +321,77 @@ void Title::moveCheevosList(int direction)
|
||||
// Rellena la textura de fondo con todos los gráficos
|
||||
void Title::fillTexture()
|
||||
{
|
||||
auto renderer = Screen::get()->getRenderer();
|
||||
|
||||
// Coloca el puntero del renderizador sobre la textura
|
||||
SDL_SetRenderTarget(renderer_, bg_texture_);
|
||||
SDL_SetRenderTarget(renderer, bg_texture_);
|
||||
|
||||
// Rellena la textura de color
|
||||
const Color c = stringToColor(options.video.palette, "black");
|
||||
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
// Pinta el gráfico del titulo a partir del sprite
|
||||
sprite_->render();
|
||||
|
||||
// Escribe el texto en la textura
|
||||
const Color textColor = stringToColor(options.video.palette, "green");
|
||||
const int textSize = text_->getCharacterSize();
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 11 * textSize, "1.PLAY", 1, textColor);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 13 * textSize, "2.ACHIEVEMENTS", 1, textColor);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 15 * textSize, "3.REDEFINE KEYS", 1, textColor);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 20 * textSize, "ESC.EXIT GAME", 1, textColor);
|
||||
auto text = Resource::get()->getText("smb2");
|
||||
const Color COLOR = stringToColor(options.video.palette, "green");
|
||||
const int TEXT_SIZE = text->getCharacterSize();
|
||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 11 * TEXT_SIZE, "1.PLAY", 1, COLOR);
|
||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 13 * TEXT_SIZE, "2.ACHIEVEMENTS", 1, COLOR);
|
||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 15 * TEXT_SIZE, "3.REDEFINE KEYS", 1, COLOR);
|
||||
text->writeDX(TEXT_CENTER | TEXT_COLOR, PLAY_AREA_CENTER_X, 20 * TEXT_SIZE, "ESC.EXIT GAME", 1, COLOR);
|
||||
|
||||
// Devuelve el puntero del renderizador a su sitio
|
||||
SDL_SetRenderTarget(renderer_, nullptr);
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
}
|
||||
|
||||
// Crea y rellena la textura para mostrar los logros
|
||||
void Title::createCheevosTexture()
|
||||
{
|
||||
// Crea la textura con el listado de logros
|
||||
const auto cheevosList = Cheevos::get()->list();
|
||||
const auto CHEEVOS_LIST = Cheevos::get()->list();
|
||||
const auto TEXT = Resource::get()->getText("subatomic");
|
||||
constexpr int CHEEVOS_TEXTURE_WIDTH = 200;
|
||||
constexpr int CHEEVOS_TEXTURE_VIEW_HEIGHT = 110;
|
||||
constexpr int CHEEVOS_TEXTURE_POS_Y = 73;
|
||||
constexpr int CHEEVOS_PADDING = 10;
|
||||
const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (info_text_->getCharacterSize() * 2) + 1;
|
||||
const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * cheevosList.size()) + 2 + info_text_->getCharacterSize() + 8;
|
||||
cheevos_texture_ = std::make_shared<Texture>(renderer_);
|
||||
const int CHEEVO_HEIGHT = CHEEVOS_PADDING + (TEXT->getCharacterSize() * 2) + 1;
|
||||
const int CHEEVOS_TEXTURE_HEIGHT = (CHEEVO_HEIGHT * CHEEVOS_LIST.size()) + 2 + TEXT->getCharacterSize() + 8;
|
||||
cheevos_texture_ = std::make_shared<Texture>(Screen::get()->getRenderer());
|
||||
cheevos_texture_->createBlank(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
cheevos_texture_->setAsRenderTarget(renderer_);
|
||||
cheevos_texture_->setAsRenderTarget(Screen::get()->getRenderer());
|
||||
cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Rellena la textura con color sólido
|
||||
const Color CHEEVOS_BG_COLOR = stringToColor(options.video.palette, "black");
|
||||
SDL_SetRenderDrawColor(renderer_, CHEEVOS_BG_COLOR.r, CHEEVOS_BG_COLOR.g, CHEEVOS_BG_COLOR.b, 0xFF);
|
||||
SDL_RenderClear(renderer_);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), CHEEVOS_BG_COLOR.r, CHEEVOS_BG_COLOR.g, CHEEVOS_BG_COLOR.b, 0xFF);
|
||||
SDL_RenderClear(Screen::get()->getRenderer());
|
||||
|
||||
// Escribe la lista de logros en la textura
|
||||
const std::string CHEEVOS_OWNER = "ACHIEVEMENTS";
|
||||
const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->size()) + ")";
|
||||
int pos = 2;
|
||||
info_text_->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green"));
|
||||
pos += info_text_->getCharacterSize();
|
||||
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green"));
|
||||
pos += TEXT->getCharacterSize();
|
||||
const Color CHEEVO_LOCKED_COLOR = stringToColor(options.video.palette, "white");
|
||||
const Color CHEEVO_UNLOCKED_COLOR = stringToColor(options.video.palette, "bright_green");
|
||||
Color cheevoColor;
|
||||
SDL_SetRenderDrawColor(renderer_, CHEEVO_LOCKED_COLOR.r, CHEEVO_LOCKED_COLOR.g, CHEEVO_LOCKED_COLOR.b, 0xFF);
|
||||
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), CHEEVO_LOCKED_COLOR.r, CHEEVO_LOCKED_COLOR.g, CHEEVO_LOCKED_COLOR.b, 0xFF);
|
||||
constexpr int LINE_X1 = (CHEEVOS_TEXTURE_WIDTH / 7) * 3;
|
||||
constexpr int LINE_X2 = LINE_X1 + ((CHEEVOS_TEXTURE_WIDTH / 7) * 1);
|
||||
|
||||
for (const auto &cheevo : cheevosList)
|
||||
for (const auto &cheevo : CHEEVOS_LIST)
|
||||
{
|
||||
cheevoColor = cheevo.completed ? CHEEVO_UNLOCKED_COLOR : CHEEVO_LOCKED_COLOR;
|
||||
pos += CHEEVOS_PADDING;
|
||||
constexpr int HALF = CHEEVOS_PADDING / 2;
|
||||
SDL_RenderDrawLine(renderer_, LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1);
|
||||
info_text_->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, cheevoColor);
|
||||
pos += info_text_->getCharacterSize() + 1;
|
||||
info_text_->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, cheevoColor);
|
||||
pos += info_text_->getCharacterSize();
|
||||
SDL_RenderDrawLine(Screen::get()->getRenderer(), LINE_X1, pos - HALF - 1, LINE_X2, pos - HALF - 1);
|
||||
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.caption, 1, cheevoColor);
|
||||
pos += TEXT->getCharacterSize() + 1;
|
||||
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, CHEEVOS_TEXTURE_WIDTH / 2, pos, cheevo.description, 1, cheevoColor);
|
||||
pos += TEXT->getCharacterSize();
|
||||
}
|
||||
|
||||
// Crea el sprite para el listado de logros
|
||||
|
||||
Reference in New Issue
Block a user