Ya dibuja el nuevo menu. Falta pulir un par de cosas en el dibujado

This commit is contained in:
2023-10-08 16:17:47 +02:00
parent e259313cc9
commit 38aadb984d
4 changed files with 70 additions and 40 deletions

View File

@@ -499,7 +499,7 @@ void Director::loadResources(section_t *section)
std::vector<std::string> textureList;
textureList.push_back("loading_screen_color.png");
textureList.push_back("loading_screen_color_zxarne.png");
textureList.push_back("smb2.png");
textureList.push_back("gauntlet.png");
textureList.push_back("debug.png");
textureList.push_back("notify.png");
@@ -507,7 +507,7 @@ void Director::loadResources(section_t *section)
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
offsetsList.push_back("gauntlet.txt");
offsetsList.push_back("debug.txt");
resource->loadOffsets(offsetsList);
@@ -1380,6 +1380,8 @@ bool Director::setFileList()
asset->add(prefix + "/data/font/smb2.txt", t_font);
asset->add(prefix + "/data/font/debug.png", t_font);
asset->add(prefix + "/data/font/debug.txt", t_font);
asset->add(prefix + "/data/font/gauntlet.png", t_font);
asset->add(prefix + "/data/font/gauntlet.txt", t_font);
// Datos
asset->add(prefix + "/data/input/gamecontrollerdb.txt", t_data);

View File

@@ -49,6 +49,7 @@ EnterID::~EnterID()
delete eventHandler;
delete text;
delete texture;
SDL_DestroyTexture(textTexture);
}
// Bucle para el logo del juego

View File

@@ -24,9 +24,20 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
texture = resource->getTexture("loading_screen_color_zxarne.png");
}
sprite = new Sprite(0, 0, texture->getWidth(), texture->getHeight(), texture, renderer);
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
text = new Text(resource->getOffset("gauntlet.txt"), resource->getTexture("gauntlet.png"), renderer);
infoText = new Text(resource->getOffset("debug.txt"), resource->getTexture("debug.png"), renderer);
// Crea la textura para los graficos que aparecen en el fondo de la pantalla de titulo
bgTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (bgTexture == nullptr)
{
if (options->console)
{
std::cout << "Error: bgTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureBlendMode(bgTexture, SDL_BLENDMODE_BLEND);
// Inicializa variables
counter = 0;
section->name = SECTION_PROG_TITLE;
@@ -37,25 +48,6 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
initMarquee();
showCheevos = false;
// Crea el cartel de PRESS ENTER
#ifdef GAME_CONSOLE
const std::string caption = "PRESS START TO PLAY";
#else
const std::string caption = "PRESS ENTER TO PLAY";
#endif
const color_t textColor = stringToColor(options->palette, "white");
const color_t strokeColor = stringToColor(options->palette, "bright_blue");
// Crea la textura
pressEnterTexture = new Texture(renderer);
pressEnterTexture->createBlank(renderer, text->lenght(caption) + 2, text->getCharacterSize() + 2, SDL_TEXTUREACCESS_TARGET);
pressEnterTexture->setAsRenderTarget(renderer);
pressEnterTexture->setBlendMode(SDL_BLENDMODE_BLEND);
text->writeDX(TXT_COLOR | TXT_STROKE, 1, 1, caption, 1, textColor, 1, strokeColor);
// Crea el sprite
pressEnterSprite = new Sprite(128 - (pressEnterTexture->getWidth() / 2), 192 / 5 * 4, pressEnterTexture->getWidth(), pressEnterTexture->getHeight(), pressEnterTexture, renderer);
// Crea la textura con el listado de logros
const std::vector<cheevos_t> cheevosList = cheevos->list();
const int iconSize = 16; // Altura del icono que representa a cada logro
@@ -101,6 +93,9 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
// Cambia el color del borde
screen->setBorderColor(stringToColor(options->palette, "black"));
// Rellena la textura de fondo con todos los gráficos
fillTexture();
}
// Destructor
@@ -109,12 +104,11 @@ Title::~Title()
delete cheevos;
delete eventHandler;
delete sprite;
delete pressEnterSprite;
delete pressEnterTexture;
delete cheevosSprite;
delete cheevosTexture;
delete text;
delete infoText;
SDL_DestroyTexture(bgTexture);
}
// Inicializa la marquesina
@@ -260,9 +254,6 @@ void Title::renderMarquee()
void Title::renderInfo()
{
const std::string loginText = options->online.enabled ? "OnLine: " + options->online.jailerID : "OnLine: OFF";
// infoText->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_FIRST_QUARTER_X, 1, loginText, 1, stringToColor(options->palette, "white"));
// infoText->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, 1, "H: Help", 1, stringToColor(options->palette, "white"));
// infoText->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_THIRD_QUARTER_X, 1, "A: Achievements", 1, stringToColor(options->palette, "white"));
infoText->write(1, 1, loginText);
const std::string version = "v.1.09";
const int x = GAMECANVAS_WIDTH - infoText->lenght(version) - 1;
@@ -313,21 +304,12 @@ void Title::render()
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Dibuja el fondo del titulo
sprite->render();
// Dibuja el texto de PRESS ENTER TO PLAY
if (counter % 80 < 60)
{
pressEnterSprite->render();
}
// Dibuja la textura de fondo
SDL_RenderCopy(renderer, bgTexture, nullptr, nullptr);
// Dibuja la marquesina
renderMarquee();
// Dibuja la linea de información inferior
renderInfo();
// Dibuja la información de logros
if (showCheevos)
{
@@ -405,4 +387,47 @@ void Title::runEnterID()
enterID = new EnterID(renderer, screen, asset, options, section);
enterID->run();
delete enterID;
}
// Rellena la textura de fondo con todos los gráficos
void Title::fillTexture()
{
// Coloca el puntero del renderizador sobre la textura
SDL_SetRenderTarget(renderer, bgTexture);
// Rellena la textura de color
const color_t c = stringToColor(options->palette, "black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
SDL_RenderClear(renderer);
// Pinta el grafico del titulo a partir del sprite
sprite->setSpriteClip(0, 0, sprite->getWidth(), 63);
sprite->render();
sprite->setPosY(64);
sprite->setSpriteClip(0, 64, 5, 16);
sprite->render();
sprite->setPosX(16);
sprite->setSpriteClip(16, 64, 37, 8);
sprite->render();
sprite->setPosX(251);
sprite->setSpriteClip(251, 64, 5, 16);
sprite->render();
sprite->setPosX(203);
sprite->setSpriteClip(203, 64, 33, 8);
sprite->render();
// Escribe el texto en la textura
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);
text->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, 15 * textSize, "3. ONLINE MODE", 1, textColor);
text->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, 18 * textSize, "ESC. EXIT GAME", 1, textColor);
// Devuelve el puntero del renderizador a su sitio
SDL_SetRenderTarget(renderer, nullptr);
}

View File

@@ -36,11 +36,10 @@ private:
SDL_Event *eventHandler; // Manejador de eventos
Texture *texture; // Textura con los graficos
Sprite *sprite; // Sprite para manejar la textura
SDL_Texture *bgTexture; // Textura para dibujar el fondo de la pantalla
Text *text; // Objeto para escribir texto en pantalla
Text *infoText; // Objeto para escribir texto en pantalla
options_t *options; // Puntero a las opciones del juego
Texture *pressEnterTexture; // Textura con los graficos de PRESS ENTER
Sprite *pressEnterSprite; // Sprite para manejar la textura de PRESS ENTER
Texture *cheevosTexture; // Textura con lo lista de logros
Sprite *cheevosSprite; // Sprite para manejar la textura con la lista de logros
Cheevos *cheevos; // Objeto encargado de gestionar los logros del juego
@@ -93,6 +92,9 @@ private:
// Ejecuta la seccion en la que se solicita al usuario su ID online
void runEnterID();
// Rellena la textura de fondo con todos los gráficos
void fillTexture();
public:
// Constructor
Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section);