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 #include "texture.h" // for Texture
// Constructor // 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 // Inicializa variables
bgColor = options.notification.color; 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); iconTexture = std::make_unique<Texture>(renderer, iconFile);
} }
textTexture = std::make_unique<Texture>(renderer, bitmapFile); text = std::make_unique<Text>(bitmapFile, textFile, renderer);
text = std::make_unique<Text>(textFile, textTexture.get());
sound = JA_LoadSound(soundFile.c_str()); 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; offset = (int)notifications.size() > 0 ? notifications.back().y - travelDist : despV;
} }
// Crea la notificacion // Crea la textura de fondo de la notificación
notification_t n; auto texture = std::make_unique<Texture>(renderer);
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
// Inicializa variables texture->setBlendMode(SDL_BLENDMODE_BLEND);
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);
// Prepara para dibujar en la textura // 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_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
SDL_Rect rect; SDL_Rect rect;
if (shape == notification_shape_rounded) if (shape == notification_shape_rounded)
@@ -303,13 +283,28 @@ void Notify::showText(std::string text1, std::string text2, int icon)
SDL_SetRenderTarget(renderer, nullptr); SDL_SetRenderTarget(renderer, nullptr);
// Crea el sprite de la notificación // 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 // Deja la notificación invisible
n.texture->setAlpha(0); n.texture->setAlpha(0);
// Añade la notificación a la lista // Añade la notificación a la lista
notifications.push_back(n); notifications.push_back(std::move(n));
} }
// Indica si hay notificaciones activas // Indica si hay notificaciones activas

View File

@@ -1,11 +1,11 @@
#pragma once #pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect #include <SDL2/SDL_rect.h> // for SDL_Rect
#include <SDL2/SDL_render.h> // for SDL_Renderer #include <SDL2/SDL_render.h> // for SDL_Renderer
#include <string> // for basic_string, string #include <string> // for basic_string, string
#include <vector> // for vector #include <vector> // for vector
#include <memory> #include <memory>
#include "utils.h" // for color_t #include "utils.h" // for color_t
#include "text.h" #include "text.h"
#include "texture.h" #include "texture.h"
#include "sprite.h" #include "sprite.h"
@@ -42,25 +42,51 @@ private:
struct notification_t struct notification_t
{ {
std::unique_ptr<Texture> texture;
std::unique_ptr<Sprite> sprite;
std::string text1; std::string text1;
std::string text2; std::string text2;
int counter; int counter;
notification_state_e state; notification_state_e state;
notification_position_e position; notification_position_e position;
std::unique_ptr<Texture> texture;
std::unique_ptr<Sprite> sprite;
SDL_Rect rect; SDL_Rect rect;
int y; int y;
int travelDist; int travelDist;
notification_shape_t shape; notification_shape_t shape;
// Constructor
notification_t(std::unique_ptr<Texture> texture, std::unique_ptr<Sprite> sprite)
: texture(std::move(texture)), sprite(std::move(sprite)) {}
// Constructor de movimiento
notification_t(notification_t &&other) noexcept
: texture(std::move(other.texture)), sprite(std::move(other.sprite))
{
// Mover otros miembros si es necesario
}
// Operador de asignación por movimiento
notification_t &operator=(notification_t &&other) noexcept
{
if (this != &other)
{
texture = std::move(other.texture);
sprite = std::move(other.sprite);
// Mover otros miembros si es necesario
}
return *this;
}
// Deshabilitar el constructor de copia y operador de asignación por copia
notification_t(const notification_t &) = delete;
notification_t &operator=(const notification_t &) = delete;
}; };
// Objetos y punteros // Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana SDL_Renderer *renderer; // El renderizador de la ventana
std::unique_ptr<Texture> textTexture; // Textura para la fuente de las notificaciones std::unique_ptr<Texture> iconTexture; // Textura para los iconos de las notificaciones
std::unique_ptr<Texture> iconTexture; // Textura para los iconos de las notificaciones std::unique_ptr<Text> text; // Objeto para dibujar texto
std::unique_ptr<Text> text; // Objeto para dibujar texto
// Variables // Variables
color_t bgColor; // Color de fondo de las notificaciones color_t bgColor; // Color de fondo de las notificaciones