Transició a surface: vaig per title.cpp

This commit is contained in:
2025-03-02 21:56:19 +01:00
parent db3a0d7263
commit 8f1d1df5d6
27 changed files with 416 additions and 490 deletions

View File

@@ -15,21 +15,18 @@
#include "options.h" // for Options, options, OptionsVideo, Sect...
#include "resource.h" // for Resource
#include "screen.h" // for Screen
#include "sprite.h" // for Sprite
#include "s_sprite.h" // for SSprite
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
#include "texture.h" // for Texture
#include "surface.h" // for Texture
#include "utils.h" // for Color, stringToColor, Palette
#include "paleta.h"
// Constructor
Title::Title()
: texture_(Resource::get()->getTexture("title_logo.png")),
sprite_(std::make_shared<Sprite>(texture_, 0, 0, texture_->getWidth(), texture_->getHeight()))
: surface_(Resource::get()->getSurface("title_logo.gif")),
sprite_(std::make_shared<SSprite>(surface_, 0, 0, surface_->getWidth(), surface_->getHeight())),
bg_surface_(std::make_shared<Surface>(Screen::get()->getSurface(), options.game.width, options.game.height))
{
// Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo
bg_texture_ = createTexture(Screen::get()->getRenderer(), options.game.width, options.game.height);
SDL_SetTextureBlendMode(bg_texture_, SDL_BLENDMODE_BLEND);
// Carga la surface con los gráficos de la pantalla de carga
pInit(Screen::get()->getRenderer(), 256, 128);
loading_screen_ = pLoadSurface(Asset::get()->get("loading_screen_color.gif").c_str());
@@ -49,7 +46,7 @@ Title::Title()
Screen::get()->setBorderColor(stringToColor(options.video.palette, "black"));
// Rellena la textura de fondo con todos los gráficos
fillTexture();
fillSurface();
// Inicia la musica
playMusic("title.ogg");
@@ -59,7 +56,7 @@ Title::Title()
Title::~Title()
{
pDeleteSurface(loading_screen_);
SDL_DestroyTexture(bg_texture_);
SDL_DestroyTexture(bg_surface_);
}
// Inicializa la marquesina
@@ -255,7 +252,7 @@ void Title::render()
if (state_ == TitleState::SHOW_MENU)
{
// Dibuja la textura de fondo
SDL_RenderCopy(Screen::get()->getRenderer(), bg_texture_, nullptr, nullptr);
SDL_RenderCopy(Screen::get()->getRenderer(), bg_surface_, nullptr, nullptr);
// Dibuja la marquesina
renderMarquee();
@@ -296,28 +293,28 @@ void Title::run()
void Title::moveCheevosList(int direction)
{
const int speed = 2;
cheevos_texture_view_.y = direction == 0 ? cheevos_texture_view_.y - speed : cheevos_texture_view_.y + speed;
cheevos_surface_view_.y = direction == 0 ? cheevos_surface_view_.y - speed : cheevos_surface_view_.y + speed;
const int bottom = cheevos_texture_->getHeight() - cheevos_texture_view_.h;
if (cheevos_texture_view_.y < 0)
const int bottom = cheevos_surface_->getHeight() - cheevos_surface_view_.h;
if (cheevos_surface_view_.y < 0)
{
cheevos_texture_view_.y = 0;
cheevos_surface_view_.y = 0;
}
else if (cheevos_texture_view_.y > bottom)
else if (cheevos_surface_view_.y > bottom)
{
cheevos_texture_view_.y = bottom;
cheevos_surface_view_.y = bottom;
}
cheevos_sprite_->setClip(cheevos_texture_view_);
cheevos_sprite_->setClip(cheevos_surface_view_);
}
// Rellena la textura de fondo con todos los gráficos
void Title::fillTexture()
void Title::fillSurface()
{
auto renderer = Screen::get()->getRenderer();
// Coloca el puntero del renderizador sobre la textura
SDL_SetRenderTarget(renderer, bg_texture_);
SDL_SetRenderTarget(renderer, bg_surface_);
// Rellena la textura de color
const Color c = stringToColor(options.video.palette, "black");
@@ -352,10 +349,10 @@ void Title::createCheevosTexture()
constexpr int CHEEVOS_PADDING = 10;
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(Screen::get()->getRenderer());
cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND);
cheevos_surface_ = std::make_shared<Texture>(Screen::get()->getRenderer());
cheevos_surface_->createBlank(CHEEVOS_TEXTURE_WIDTH, CHEEVOS_TEXTURE_HEIGHT, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
cheevos_surface_->setAsRenderTarget(Screen::get()->getRenderer());
cheevos_surface_->setBlendMode(SDL_BLENDMODE_BLEND);
// Rellena la textura con color sólido
const Color CHEEVOS_BG_COLOR = stringToColor(options.video.palette, "black");
@@ -366,7 +363,7 @@ void Title::createCheevosTexture()
const std::string CHEEVOS_OWNER = "ACHIEVEMENTS";
const std::string CHEEVOS_LIST_CAPTION = CHEEVOS_OWNER + " (" + std::to_string(Cheevos::get()->getTotalUnlockedAchievements()) + " / " + std::to_string(Cheevos::get()->size()) + ")";
int pos = 2;
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_texture_->getWidth() / 2, pos, CHEEVOS_LIST_CAPTION, 1, stringToColor(options.video.palette, "bright_green"));
TEXT->writeDX(TEXT_CENTER | TEXT_COLOR, cheevos_surface_->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");
@@ -388,15 +385,15 @@ void Title::createCheevosTexture()
}
// Crea el sprite para el listado de logros
cheevos_sprite_ = std::make_shared<Sprite>(cheevos_texture_, (GAMECANVAS_WIDTH - cheevos_texture_->getWidth()) / 2, CHEEVOS_TEXTURE_POS_Y, cheevos_texture_->getWidth(), cheevos_texture_->getHeight());
cheevos_texture_view_ = {0, 0, cheevos_texture_->getWidth(), CHEEVOS_TEXTURE_VIEW_HEIGHT};
cheevos_sprite_->setClip(cheevos_texture_view_);
cheevos_sprite_ = std::make_shared<SSprite>(cheevos_surface_, (GAMECANVAS_WIDTH - cheevos_surface_->getWidth()) / 2, CHEEVOS_TEXTURE_POS_Y, cheevos_surface_->getWidth(), cheevos_surface_->getHeight());
cheevos_surface_view_ = {0, 0, cheevos_surface_->getWidth(), CHEEVOS_TEXTURE_VIEW_HEIGHT};
cheevos_sprite_->setClip(cheevos_surface_view_);
}
// Oculta la lista de logros
void Title::hideCheevosList()
{
show_cheevos_ = false;
cheevos_texture_view_.y = 0;
cheevos_sprite_->setClip(cheevos_texture_view_);
cheevos_surface_view_.y = 0;
cheevos_sprite_->setClip(cheevos_surface_view_);
}