From 256959505d42d6bfda01c05433d37815c03cf7fa Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 3 Aug 2024 12:10:41 +0200 Subject: [PATCH] afegides opcions per defecte per a les notificacions --- source/common/screen.cpp | 84 +++++---------------------------------- source/common/screen.h | 27 +++---------- source/director.cpp | 85 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 94 insertions(+), 102 deletions(-) diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 60798c3..32efdb3 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -25,10 +25,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input * borderHeight = options->video.border.height * 2; dest = {0, 0, 0, 0}; borderColor = {0, 0, 0}; - fadeEffect.enabled = false; - fadeEffect.counter = 0; - fadeEffect.lenght = 0; - fadeEffect.color = {0xFF, 0xFF, 0xFF}; flashEffect.enabled = false; flashEffect.counter = 0; flashEffect.lenght = 0; @@ -41,8 +37,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Input * shakeEffect.origin = 0; attenuateEffect = false; - iniFade(); - // Define el color del borde para el modo de pantalla completa borderColor = {0x00, 0x00, 0x00}; @@ -84,6 +78,9 @@ void Screen::blit() // Atenua la pantalla doAttenuate(); + // Pinta las notificaciones + notify->render(); + #ifdef NO_SHADERS // Vuelve a dejar el renderizador en modo normal SDL_SetRenderTarget(renderer, nullptr); @@ -299,78 +296,11 @@ void Screen::switchBorder() setVideoMode(VIDEO_MODE_WINDOW); } -// Activa el fade -void Screen::setFade() -{ - fadeEffect.enabled = true; -} - -// Comprueba si ha terminado el fade -bool Screen::fadeEnded() -{ - if (fadeEffect.enabled || fadeEffect.counter > 0) - { - return false; - } - - return true; -} - -// Inicializa las variables para el fade -void Screen::iniFade() -{ - fadeEffect.enabled = false; - fadeEffect.counter = 0; - fadeEffect.lenght = 200; -} - -// Actualiza el fade -void Screen::updateFade() -{ - if (!fadeEffect.enabled) - { - return; - } - - fadeEffect.counter++; - if (fadeEffect.counter > fadeEffect.lenght) - { - iniFade(); - } -} - -// Dibuja el fade -void Screen::renderFade() -{ - if (!fadeEffect.enabled) - { - return; - } - - const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight}; - color_t color = {0, 0, 0}; - const float step = (float)fadeEffect.counter / (float)fadeEffect.lenght; - const int alpha = 0 + (255 - 0) * step; - SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha); - SDL_RenderFillRect(renderer, &rect); -} - -// Actualiza los efectos -void Screen::updateFX() -{ - updateFade(); -} - -// Dibuja los efectos -void Screen::renderFX() -{ - renderFade(); -} - // Actualiza la lógica de la clase void Screen::update() { updateShake(); + notify->update(); } // Comprueba las entradas @@ -483,4 +413,10 @@ void Screen::switchShaders() void Screen::attenuate(bool value) { attenuateEffect = value; +} + +// Muestra una notificación de texto por pantalla; +void Screen::showNotification(std::string text1, std::string text2, int icon) +{ + notify->showText(text1, text2, icon); } \ No newline at end of file diff --git a/source/common/screen.h b/source/common/screen.h index 925c2cf..2d7de69 100644 --- a/source/common/screen.h +++ b/source/common/screen.h @@ -3,6 +3,7 @@ #include #include "asset.h" #include "utils.h" +#include "notify.h" #include "input.h" #include "../const.h" #include @@ -21,6 +22,7 @@ private: SDL_Renderer *renderer; // El renderizador de la ventana Asset *asset; // Objeto con el listado de recursos Input *input; // Objeto para leer las entradas de teclado o mando + Notify *notify; // Pinta notificaciones en pantalla SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa options_t *options; // Variable con todas las opciones del programa @@ -44,7 +46,6 @@ private: }; // Variables - Efectos - effect_t fadeEffect; // Variable para gestionar el efecto de fade effect_t flashEffect; // Variable para gestionar el efecto de flash struct shake_t @@ -57,21 +58,6 @@ private: int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento } shakeEffect; - // Inicializa las variables para el fade - void iniFade(); - - // Actualiza el fade - void updateFade(); - - // Dibuja el fade - void renderFade(); - - // Actualiza los efectos - void updateFX(); - - // Dibuja los efectos - void renderFX(); - // Actualiza la logica para agitar la pantalla void updateShake(); @@ -134,12 +120,6 @@ public: // Cambia entre borde visible y no visible void switchBorder(); - // Activa el fade - void setFade(); - - // Comprueba si ha terminado el fade - bool fadeEnded(); - // Agita la pantalla void shake(); @@ -151,4 +131,7 @@ public: // Atenua la pantalla void attenuate(bool value); + + // Muestra una notificación de texto por pantalla; + void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1); }; \ No newline at end of file diff --git a/source/director.cpp b/source/director.cpp index c6ab8f6..2446e7d 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -338,10 +338,10 @@ bool Director::setFileList() asset->add(prefix + "/data/gfx/explosion3.ani", t_animation); asset->add(prefix + "/data/gfx/explosion4.png", t_bitmap); asset->add(prefix + "/data/gfx/explosion4.ani", t_animation); - + asset->add(prefix + "/data/gfx/powerball.png", t_bitmap); asset->add(prefix + "/data/gfx/powerball.ani", t_animation); - + asset->add(prefix + "/data/gfx/bullet.png", t_bitmap); asset->add(prefix + "/data/gfx/game_buildings.png", t_bitmap); @@ -382,17 +382,17 @@ bool Director::setFileList() asset->add(prefix + "/data/gfx/player1_pal1.gif", t_palette); asset->add(prefix + "/data/gfx/player1_pal2.gif", t_palette); asset->add(prefix + "/data/gfx/player1_pal3.gif", t_palette); - + asset->add(prefix + "/data/gfx/player2.gif", t_bitmap); asset->add(prefix + "/data/gfx/player2_pal1.gif", t_palette); asset->add(prefix + "/data/gfx/player2_pal2.gif", t_palette); asset->add(prefix + "/data/gfx/player2_pal3.gif", t_palette); - + asset->add(prefix + "/data/gfx/player.ani", t_animation); - + asset->add(prefix + "/data/gfx/player1_power.gif", t_bitmap); asset->add(prefix + "/data/gfx/player2_power.gif", t_bitmap); - + asset->add(prefix + "/data/gfx/player_power.ani", t_animation); // Fuentes de texto @@ -458,6 +458,12 @@ void Director::initOptions() options->video.border.enabled = false; options->video.shaders = true; + // Opciones de las notificaciones + options->notification.posV = pos_top; + options->notification.posH = pos_left; + options->notification.sound = true; + options->notification.color = {48, 48, 48}; + // Opciones de audio options->audio.music.enabled = true; options->audio.music.volume = 128; @@ -692,6 +698,39 @@ bool Director::saveConfigFile() file << "video.border.width=" + std::to_string(options->video.border.width) + "\n"; file << "video.border.height=" + std::to_string(options->video.border.height) + "\n"; + // Opciones de notificaciones + file << "\n\n## NOTIFICATION\n"; + file << "## notification.posV [pos_top | pos_bottom]\n"; + file << "## notification.posH [pos_left | pos_middle | pos_right]\n"; + file << "\n"; + + if (options->notification.posV == pos_top) + { + file << "notification.posV=pos_top\n"; + } + + else + { + file << "notification.posV=pos_bottom\n"; + } + + if (options->notification.posH == pos_left) + { + file << "notification.posH=pos_left\n"; + } + + else if (options->notification.posH == pos_middle) + { + file << "notification.posH=pos_middle\n"; + } + + else + { + file << "notification.posH=pos_right\n"; + } + + file << "notification.sound=" + boolToString(options->notification.sound) + "\n"; + // Opciones de audio file << "\n\n## AUDIO\n"; file << "## volume [0 .. 128]\n"; @@ -965,6 +1004,40 @@ bool Director::setOptions(options_t *options, std::string var, std::string value options->video.border.height = std::stoi(value); } + // Opciones de notificaciones + else if (var == "notification.posH") + { + if (value == "pos_left") + { + options->notification.posH = pos_left; + } + else if (value == "pos_middle") + { + options->notification.posH = pos_middle; + } + else + { + options->notification.posH = pos_right; + } + } + + else if (var == "notification.posV") + { + if (value == "pos_top") + { + options->notification.posV = pos_top; + } + else + { + options->notification.posV = pos_bottom; + } + } + + else if (var == "notification.sound") + { + options->notification.sound = stringToBool(value); + } + // Opciones de audio else if (var == "audio.music.enabled") {