fix: les notificacions ja no embruten la pantalla de càrrega

This commit is contained in:
2025-02-28 14:00:59 +01:00
parent 7a685c0cc8
commit 5bb2b5e7c4
2 changed files with 62 additions and 13 deletions

View File

@@ -14,6 +14,7 @@
#include "sprite.h" // for Sprite
#include "texture.h" // for Texture
#include "utils.h" // for Color, stringToColor, Palette
#include <iostream>
// Constructor
LoadingScreen::LoadingScreen()
@@ -40,6 +41,16 @@ LoadingScreen::LoadingScreen()
loading_sound2_ = resource_->getMusic("loading_sound2.ogg");
loading_sound3_ = resource_->getMusic("loading_sound3.ogg");
texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height);
if (texture_ == nullptr)
{
if (options.console)
{
std::cout << "LoadingScreen::texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
clearTexture();
// Inicializa variables
options.section.section = Section::LOADING_SCREEN;
options.section.subsection = Subsection::NONE;
@@ -71,6 +82,7 @@ LoadingScreen::LoadingScreen()
LoadingScreen::~LoadingScreen()
{
JA_StopMusic();
SDL_DestroyTexture(texture_);
}
// Comprueba el manejador de eventos
@@ -193,6 +205,7 @@ void LoadingScreen::update()
checkInput();
updateCounter();
updateLoad();
fillTexture();
screen_->update();
}
}
@@ -212,8 +225,8 @@ void LoadingScreen::render()
// Prepara para empezar a dibujar en la textura de juego
screen_->start();
// Dibuja la pantalla de carga
renderLoad();
// Copila la textura a la pantalla
SDL_RenderCopy(renderer_, texture_, nullptr, nullptr);
// Vuelca el contenido del renderizador en pantalla
screen_->render();
@@ -278,4 +291,33 @@ void LoadingScreen::recreateLoadingScreen()
// Vuelca el contenido del renderizador en pantalla
screen_->render();
}
// Dibuja sobre la textura
void LoadingScreen::fillTexture()
{
// Empieza a dibujar en la textura
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, texture_);
// Dibuja la pantalla de carga
renderLoad();
// Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp);
}
// Limpia la textura
void LoadingScreen::clearTexture()
{
// Empieza a dibujar en la textura
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, texture_);
// Limpia
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer_);
// Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp);
}

View File

@@ -1,16 +1,16 @@
#pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr
class Asset; // lines 8-8
class Input; // lines 9-9
class Resource; // lines 10-10
class Screen; // lines 11-11
class Sprite; // lines 12-12
class Texture; // lines 13-13
struct JA_Music_t; // lines 14-14
#include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer
#include <SDL2/SDL_stdinc.h> // for Uint32
#include <memory> // for shared_ptr
class Asset; // lines 8-8
class Input; // lines 9-9
class Resource; // lines 10-10
class Screen; // lines 11-11
class Sprite; // lines 12-12
class Texture; // lines 13-13
struct JA_Music_t; // lines 14-14
class LoadingScreen
{
@@ -37,6 +37,7 @@ private:
JA_Music_t *loading_sound3_; // Sonidos para imitar la carga tipo spectrum
int line_index_[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga
SDL_Rect load_rect_ = {0, 0, 51, 1}; // Rectangulo para dibujar la pantalla de carga
SDL_Texture *texture_; // Textura para dibujar la pantalla de carga
// Actualiza las variables
void update();
@@ -65,6 +66,12 @@ private:
// Reconstruye la pantalla de carga
void recreateLoadingScreen();
// Dibuja sobre la textura
void fillTexture();
// Limpia la textura
void clearTexture();
public:
// Constructor
LoadingScreen();