Commit de "guardar partida"

This commit is contained in:
2024-10-08 18:07:54 +02:00
parent 9ce0f16d33
commit c00f4326ae
2 changed files with 63 additions and 42 deletions

View File

@@ -10,7 +10,8 @@
#include "texture.h" // for Texture
// Constructor
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile) : renderer(renderer)
Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile)
: renderer(renderer)
{
// Inicializa variables
bgColor = options.notification.color;
@@ -23,8 +24,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapF
{
iconTexture = std::make_unique<Texture>(renderer, iconFile);
}
textTexture = std::make_unique<Texture>(renderer, bitmapFile);
text = std::make_unique<Text>(textFile, textTexture.get());
text = std::make_unique<Text>(bitmapFile, textFile, renderer);
sound = JA_LoadSound(soundFile.c_str());
}
@@ -227,35 +227,15 @@ void Notify::showText(std::string text1, std::string text2, int icon)
offset = (int)notifications.size() > 0 ? notifications.back().y - travelDist : despV;
}
// Crea la notificacion
notification_t n;
// Inicializa variables
n.y = offset;
n.travelDist = travelDist;
n.counter = 0;
n.state = ns_rising;
n.text1 = text1;
n.text2 = text2;
n.shape = shape;
if (options.notification.posV == pos_top)
{
n.rect = {despH, offset - travelDist, width, height};
}
else
{
n.rect = {despH, offset + travelDist, width, height};
}
// Crea la textura
n.texture = std::make_unique<Texture>(renderer);
n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
// Crea la textura de fondo de la notificación
auto texture = std::make_unique<Texture>(renderer);
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
texture->setBlendMode(SDL_BLENDMODE_BLEND);
// Prepara para dibujar en la textura
n.texture->setAsRenderTarget(renderer);
texture->setAsRenderTarget(renderer);
// Dibuja el fondo de la notificación
// Dibuja fondo de la notificación sobre la textura
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
SDL_Rect rect;
if (shape == notification_shape_rounded)
@@ -303,13 +283,28 @@ void Notify::showText(std::string text1, std::string text2, int icon)
SDL_SetRenderTarget(renderer, nullptr);
// Crea el sprite de la notificación
n.sprite = std::make_unique<Sprite>(n.rect, n.texture);
auto sprite = std::make_unique<Sprite>((SDL_Rect){despH, 50, width, height}, texture.get());
// Crea la notificacion
notification_t n(std::move(texture), std::move(sprite));
// Inicializa variables
n.y = offset;
n.travelDist = travelDist;
n.counter = 0;
n.state = ns_rising;
n.text1 = text1;
n.text2 = text2;
n.shape = shape;
const int yPos = offset + (options.notification.posV == pos_top ? -travelDist : travelDist);
n.rect = {despH, yPos, width, height};
n.sprite->setPos(n.rect);
// Deja la notificación invisible
n.texture->setAlpha(0);
// Añade la notificación a la lista
notifications.push_back(n);
notifications.push_back(std::move(n));
}
// Indica si hay notificaciones activas