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