Demo: añadida la clase screen

This commit is contained in:
2023-05-07 12:09:52 +02:00
parent 8bcd3e6068
commit 3ba5f6cce0
7 changed files with 96 additions and 34 deletions

View File

@@ -3,16 +3,12 @@
#include <iostream>
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
{
// Inicializa variables
this->window = window;
this->renderer = renderer;
this->options = options;
this->asset = asset;
// Crea los objetos
notify = new Notify(renderer, asset->get("notify.png"), asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
gameCanvasWidth = options->gameWidth;
gameCanvasHeight = options->gameHeight;
@@ -41,13 +37,17 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
setVideoMode(options->videoMode);
// Inicializa variables
notifyAdded = false;
notifyActive = false;
}
// Destructor
Screen::~Screen()
{
delete notify;
if (notify != nullptr)
{
delete notify;
}
SDL_DestroyTexture(gameCanvas);
}
@@ -97,7 +97,7 @@ void Screen::setVideoMode(int videoMode)
SDL_ShowCursor(SDL_ENABLE);
// Esconde la ventana
//SDL_HideWindow(window);
// SDL_HideWindow(window);
if (options->borderEnabled)
{
@@ -118,7 +118,7 @@ void Screen::setVideoMode(int videoMode)
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
// Muestra la ventana
//SDL_ShowWindow(window);
// SDL_ShowWindow(window);
}
// Si está activo el modo de pantalla completa añade el borde
@@ -385,30 +385,46 @@ void Screen::renderFX()
renderSpectrumFade();
}
// Añade un notificador a la pantalla
void Screen::addNotifier(string iconsFile, string bitmapFontFile, string offsetFontFile, string soundFile)
{
notify = new Notify(renderer, iconsFile, bitmapFontFile, offsetFontFile, soundFile, options);
notifyAdded = true;
}
// Actualiza el notificador
void Screen::updateNotifier()
{
notify->update();
notifyActive = notify->active();
if (notifyAdded)
{
notify->update();
notifyActive = notify->active();
}
}
// Muestra una notificación de texto por pantalla;
void Screen::showNotification(std::string text1, std::string text2, int icon)
{
notify->showText(text1, text2, icon);
if (notifyAdded)
{
notify->showText(text1, text2, icon);
}
}
// Dibuja las notificaciones
void Screen::renderNotifications()
{
if (!notifyActive)
if (notifyAdded)
{
return;
}
if (!notifyActive)
{
return;
}
SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
notify->render();
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
notify->render();
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
}
}
// Establece el tamaño de las notificaciones

View File

@@ -1,7 +1,6 @@
#pragma once
#include <SDL2/SDL.h>
#include "asset.h"
#include "notify.h"
#include "utils.h"
#include <vector>
@@ -18,7 +17,6 @@ private:
// Objetos y punteros
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
@@ -32,6 +30,7 @@ private:
int borderHeight; // Anltura del borde
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
bool notifyAdded; // Indica si se ha añadido un notificador
bool notifyActive; // Indica si hay notificaciones activas
int notificationLogicalWidth; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
int notificationLogicalHeight; // Alto lógico de las notificaciones en relación al tamaño de pantalla
@@ -71,7 +70,7 @@ private:
public:
// Constructor
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options);
// Destructor
~Screen();
@@ -134,6 +133,9 @@ public:
// Dibuja los efectos
void renderFX();
// Añade un notificador a la pantalla
void addNotifier(string iconsFile, string bitmapFontFile, string offsetFontFile, string soundFile);
// Actualiza el notificador
void updateNotifier();

View File

@@ -553,4 +553,31 @@ bool colorAreEqual(color_t color1, color_t color2)
const bool b = color1.b == color2.b;
return (r && g && b);
}
// Inicializa la estructura de opciones
void initOptions(options_t *options)
{
options->configVersion = "";
options->videoMode = 0;
options->windowSize = 1;
options->filter = 0;
options->vSync = true;
options->gameWidth = 320;
options->gameHeight = 240;
options->integerScale = true;
options->keepAspect = true;
options->borderEnabled = false;
options->borderWidth = 0;
options->borderHeight = 0;
options->palette = p_zxspectrum;
options->console = false;
options->notifications.posV = pos_top;
options->notifications.posH = pos_left;
options->notifications.sound = true;
options->notifications.color = {48, 48, 48};
options->screen.windowWidth = options->gameWidth * options->windowSize;
options->screen.windowHeight = options->gameHeight * options->windowSize;
}

View File

@@ -102,20 +102,20 @@ struct cheat_t
// Estructura para el servicio online
struct online_t
{
bool enabled; // Indica si se quiere usar el modo online o no
bool sessionEnabled; // Indica ya se ha hecho login
string server; // Servidor para los servicios online
int port; // Puerto del servidor
string gameID; // Identificador del juego para los servicios online
string jailerID; // Identificador del jugador para los servicios online
int score; // Puntuación almacenada online
bool enabled; // Indica si se quiere usar el modo online o no
bool sessionEnabled; // Indica ya se ha hecho login
string server; // Servidor para los servicios online
int port; // Puerto del servidor
string gameID; // Identificador del juego para los servicios online
string jailerID; // Identificador del jugador para los servicios online
int score; // Puntuación almacenada online
};
// Estructura para almacenar estadísticas
struct op_stats_t
{
int rooms; // Cantidad de habitaciones visitadas
int items; // Cantidad de items obtenidos
int rooms; // Cantidad de habitaciones visitadas
int items; // Cantidad de items obtenidos
string worstNightmare; // Habitación con más muertes acumuladas
};
@@ -129,7 +129,7 @@ struct op_screen_t
// Estructura con todas las opciones de configuración del programa
struct options_t
{
string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
Uint32 filter; // Filtro usado para el escalado de la imagen
@@ -199,4 +199,7 @@ string boolToString(bool value);
// Compara dos colores
bool colorAreEqual(color_t color1, color_t color2);
// Inicializa la estructura de opciones
void initOptions(options_t *options);
#endif