From e963251fd9ac66173254106eabd730ec629991d7 Mon Sep 17 00:00:00 2001 From: Sergio Valor Martinez Date: Thu, 29 Dec 2022 09:42:57 +0100 Subject: [PATCH] Modificadas las notificaciones a dos lineas de texto --- source/cheevos.cpp | 4 ++-- source/common/notify.cpp | 21 +++++++++++++++------ source/common/notify.h | 4 ++-- source/common/screen.cpp | 4 ++-- source/common/screen.h | 2 +- source/director.cpp | 2 +- source/game.cpp | 2 +- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/source/cheevos.cpp b/source/cheevos.cpp index 6efa055..356497c 100644 --- a/source/cheevos.cpp +++ b/source/cheevos.cpp @@ -55,10 +55,10 @@ void Cheevos::unlockCheevo(int id) { return; } - + if (!cheevos[index].completed) { cheevos[index].completed = true; - screen->showNotification(cheevos[index].caption); + screen->showNotification("ACHIEVEMENT UNLOCKED!", cheevos[index].caption); } } \ No newline at end of file diff --git a/source/common/notify.cpp b/source/common/notify.cpp index 108bdb7..d74c8f8 100644 --- a/source/common/notify.cpp +++ b/source/common/notify.cpp @@ -124,12 +124,13 @@ void Notify::clearFinishedNotifications() } // Muestra una notificación de texto por pantalla; -void Notify::showText(std::string text) +void Notify::showText(std::string text1, std::string text2) { // Inicializa variables - const int width = this->text->lenght(text) + (this->text->getCharacterSize() * 2); - const int height = this->text->getCharacterSize() * 2; - const int padding = (this->text->getCharacterSize() / 2); + const std::string txt = text1.length() > text2.length() ? text1 : text2; + const int width = text->lenght(txt) + text->getCharacterSize(); + const int height = text->getCharacterSize() * 3; + const int padding = text->getCharacterSize() / 2; // Posición horizontal int despH = 0; @@ -178,7 +179,7 @@ void Notify::showText(std::string text) n.travelDist = travelDist; n.counter = 0; n.state = ns_rising; - n.text = text; + n.text = text1; if (options->notifications.posV == pos_top) { n.rect = {despH, offset - travelDist, width, height}; @@ -195,7 +196,15 @@ void Notify::showText(std::string text) 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, width / 2, padding, text, 1, {255, 255, 255}, 1, {0, 0, 0}); + if (text2 != "") + { // Dos lineas de texto + text->writeDX(TXT_STROKE, padding, padding, text1, 1, {255, 255, 255}, 1, {0, 0, 0}); + text->writeDX(TXT_STROKE, padding, padding + text->getCharacterSize() + 1, text2, 1, {255, 255, 255}, 1, {0, 0, 0}); + } + else + { // Una linea de texto + text->writeDX(TXT_STROKE, padding, (height / 2) - (text->getCharacterSize() / 2), text1, 1, {255, 255, 255}, 1, {0, 0, 0}); + } SDL_SetRenderTarget(renderer, nullptr); // Crea el sprite diff --git a/source/common/notify.h b/source/common/notify.h index 746055d..78f3e70 100644 --- a/source/common/notify.h +++ b/source/common/notify.h @@ -57,7 +57,7 @@ private: color_t bgColor; // Color de fondo de las notificaciones int waitTime; // Tiempo que se ve la notificación std::vector notifications; // La lista de notificaciones activas - JA_Sound_t* sound; // Sonido a reproducir cuando suena la notificación + JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación // Elimina las notificaciones finalizadas void clearFinishedNotifications(); @@ -76,7 +76,7 @@ public: ~Notify(); // Muestra una notificación de texto por pantalla; - void showText(std::string text); + void showText(std::string text1 = "", std::string text2 = ""); // Indica si hay notificaciones activas bool active(); diff --git a/source/common/screen.cpp b/source/common/screen.cpp index bfe7a96..e863294 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -370,9 +370,9 @@ void Screen::updateNotifier() } // Muestra una notificación de texto por pantalla; -void Screen::showNotification(std::string text) +void Screen::showNotification(std::string text1, std::string text2) { - notify->showText(text); + notify->showText(text1, text2); } // Dibuja las notificaciones diff --git a/source/common/screen.h b/source/common/screen.h index 0c19343..966f47a 100644 --- a/source/common/screen.h +++ b/source/common/screen.h @@ -132,7 +132,7 @@ public: void updateNotifier(); // Muestra una notificación de texto por pantalla; - void showNotification(std::string text); + void showNotification(std::string text1 = "", std::string text2 = ""); }; #endif diff --git a/source/director.cpp b/source/director.cpp index 0741548..77d8b46 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -160,7 +160,7 @@ void Director::initOptions() options->notifications.posV = pos_top; options->notifications.posH = pos_left; options->notifications.sound = true; - options->notifications.color = {64, 64, 64}; + options->notifications.color = {48, 48, 48}; } // Comprueba los parametros del programa diff --git a/source/game.cpp b/source/game.cpp index 1ba13bc..9d5c436 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -161,7 +161,7 @@ void Game::checkEventHandler() break; case SDL_SCANCODE_F6: - screen->showNotification("MAMA MIRA! SIN MANOS!"); + screen->showNotification("1234567890"); break; #endif