Ya se ven las notificaciones por pantalla
This commit is contained in:
@@ -80,8 +80,10 @@ void Notify::showText(std::string text)
|
||||
n.texture = new Texture(renderer);
|
||||
n.texture->createBlank(renderer, width, height, SDL_TEXTUREACCESS_TARGET);
|
||||
n.texture->setAsRenderTarget(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
this->text->writeDX(TXT_CENTER | TXT_STROKE, desp, desp / 2, text, 1, {255, 255, 255}, 1, {0, 0, 0});
|
||||
this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, desp / 2, text, 1, {255, 255, 255}, 1, {0, 0, 0});
|
||||
|
||||
// Crea el sprite
|
||||
n.sprite = new Sprite({0, 0, width, height}, n.texture, renderer);
|
||||
|
||||
@@ -37,16 +37,16 @@ private:
|
||||
color_t bgColor; // Color de fondo de las notificaciones
|
||||
std::vector<notification_t> notifications; // La lista de notificaciones activas
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void clearFinishedNotifications();
|
||||
|
||||
public:
|
||||
// Dibuja las notificaciones por pantalla
|
||||
void render();
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void update();
|
||||
|
||||
// Elimina las notificaciones finalizadas
|
||||
void clearFinishedNotifications();
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile);
|
||||
|
||||
|
||||
@@ -3,12 +3,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY)
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options, int gameInternalResX, int gameInternalResY)
|
||||
{
|
||||
// Inicializa variables
|
||||
this->window = window;
|
||||
this->renderer = renderer;
|
||||
this->options = options;
|
||||
this->asset = asset;
|
||||
|
||||
// Crea los objetos
|
||||
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"));
|
||||
|
||||
gameCanvasWidth = gameInternalResX;
|
||||
gameCanvasHeight = gameInternalResY;
|
||||
@@ -41,7 +45,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, i
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
renderer = nullptr;
|
||||
delete notify;
|
||||
}
|
||||
|
||||
// Limpia la pantalla
|
||||
@@ -70,6 +74,9 @@ void Screen::blit()
|
||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
||||
|
||||
// Dibuja las notificaciones
|
||||
notify->render();
|
||||
|
||||
// Muestra por pantalla el renderizador
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
@@ -362,4 +369,16 @@ void Screen::renderFX()
|
||||
{
|
||||
renderFade();
|
||||
renderSpectrumFade();
|
||||
}
|
||||
|
||||
// Actualiza el notificador
|
||||
void Screen::updateNotifier()
|
||||
{
|
||||
notify->update();
|
||||
}
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void Screen::showText(std::string text)
|
||||
{
|
||||
notify->showText(text);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "asset.h"
|
||||
#include "notify.h"
|
||||
#include "utils.h"
|
||||
#include <vector>
|
||||
|
||||
@@ -24,10 +26,13 @@ struct anchor_t
|
||||
class Screen
|
||||
{
|
||||
private:
|
||||
// Objetos y variables
|
||||
SDL_Window *window; // Ventana de la aplicación
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Asset *asset; // Objeto con el listado de recursos
|
||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
||||
options_t *options; // Variable con todas las opciones del programa
|
||||
Notify *notify; // Dibuja notificaciones por pantalla
|
||||
|
||||
int screenWidth; // Ancho de la pantalla o ventana
|
||||
int screenHeight; // Alto de la pantalla o ventana
|
||||
@@ -38,12 +43,12 @@ private:
|
||||
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||
|
||||
// EFECTOS
|
||||
bool fade; // Indica si esta activo el efecto de fade
|
||||
int fadeCounter; // Temporizador para el efecto de fade
|
||||
int fadeLenght; // Duración del fade
|
||||
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
||||
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
||||
int spectrumFadeLenght; // Duración del fade spectrum
|
||||
bool fade; // Indica si esta activo el efecto de fade
|
||||
int fadeCounter; // Temporizador para el efecto de fade
|
||||
int fadeLenght; // Duración del fade
|
||||
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
||||
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
||||
int spectrumFadeLenght; // Duración del fade spectrum
|
||||
std::vector<color_t> spectrumColor; // Colores para el fade spectrum
|
||||
|
||||
// Inicializa las variables para el fade
|
||||
@@ -66,7 +71,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY);
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options, int gameInternalResX, int gameInternalResY);
|
||||
|
||||
// Destructor
|
||||
~Screen();
|
||||
@@ -121,6 +126,12 @@ public:
|
||||
|
||||
// Dibuja los efectos
|
||||
void renderFX();
|
||||
|
||||
// Actualiza el notificador
|
||||
void updateNotifier();
|
||||
|
||||
// Muestra una notificación de texto por pantalla;
|
||||
void showText(std::string text);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,7 +36,7 @@ Director::Director(std::string path)
|
||||
input = new Input(asset->get("controllerdb.txt"));
|
||||
initInput();
|
||||
|
||||
screen = new Screen(window, renderer, options, GAME_WIDTH, GAME_HEIGHT);
|
||||
screen = new Screen(window, renderer, asset, options, GAME_WIDTH, GAME_HEIGHT);
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
|
||||
@@ -187,10 +187,6 @@ void Intro::checkEventHandler()
|
||||
// Cualquier tecla pulsada
|
||||
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
JA_StopMusic();
|
||||
section.name = PROG_SECTION_TITLE;
|
||||
section.subsection = TITLE_SECTION_1;
|
||||
|
||||
switch (eventHandler->key.keysym.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_F:
|
||||
@@ -218,7 +214,14 @@ void Intro::checkEventHandler()
|
||||
texture->reLoad();
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F5:
|
||||
screen->showText("HOLA MAMA!");
|
||||
break;
|
||||
|
||||
default:
|
||||
JA_StopMusic();
|
||||
section.name = PROG_SECTION_TITLE;
|
||||
section.subsection = TITLE_SECTION_1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -404,6 +407,8 @@ void Intro::update()
|
||||
|
||||
// Actualiza las escenas de la intro
|
||||
updateScenes();
|
||||
|
||||
screen->updateNotifier();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user