From a3cd1b98872b7325f198d8ed777b575d376e950c Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 22 May 2025 09:07:07 +0200 Subject: [PATCH] eliminat OnScreenHelp --- source/credits.cpp | 1 - source/director.cpp | 3 - source/game.cpp | 1 - source/global_inputs.cpp | 21 ---- source/global_inputs.h | 6 - source/hiscore_table.cpp | 1 - source/instructions.cpp | 3 - source/intro.cpp | 3 - source/logo.cpp | 5 +- source/on_screen_help.cpp | 254 -------------------------------------- source/on_screen_help.h | 76 ------------ source/screen.cpp | 3 - source/title.cpp | 3 - 13 files changed, 1 insertion(+), 379 deletions(-) delete mode 100644 source/on_screen_help.cpp delete mode 100644 source/on_screen_help.h diff --git a/source/credits.cpp b/source/credits.cpp index aefbaf8..07afab2 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -109,7 +109,6 @@ void Credits::update() } Screen::get()->update(); - globalInputs::update(); fillCanvas(); } diff --git a/source/director.cpp b/source/director.cpp index 9f5f315..21ee3a7 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -29,7 +29,6 @@ #include "logo.h" // Para Logo #include "manage_hiscore_table.h" // Para ManageHiScoreTable #include "notifier.h" // Para Notifier -#include "on_screen_help.h" // Para OnScreenHelp #include "options.h" // Para GamepadOptions, Options, options #include "param.h" // Para loadParamsFromFile #include "resource.h" // Para Resource @@ -98,7 +97,6 @@ void Director::init() Input::init(Asset::get()->get("gamecontrollerdb.txt")); bindInputs(); Notifier::init(std::string(), Resource::get()->getText("8bithud")); - OnScreenHelp::init(); #ifdef DEBUG Screen::get()->initDebugInfo(); Screen::get()->setDebugInfoEnabled(true); @@ -110,7 +108,6 @@ void Director::close() { saveOptionsFile(Asset::get()->get("config.txt")); - OnScreenHelp::destroy(); Notifier::destroy(); Input::destroy(); Resource::destroy(); diff --git a/source/game.cpp b/source/game.cpp index 08b249b..375dfbf 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -996,7 +996,6 @@ void Game::update() } screen_->update(); - globalInputs::update(); fillCanvas(); } } diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 7c754b3..0916f64 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -7,7 +7,6 @@ #include "audio.h" // Para JA_SetMusicVolume, JA_SetSoundVolume #include "lang.h" // Para getText, Code, getNextLangCode, loadFro... #include "notifier.h" // Para Notifier -#include "on_screen_help.h" // Para OnScreenHelp #include "options.h" // Para Options, options, VideoOptions, GameOpt... #include "param.h" // Para Param, ParamGame, param #include "screen.h" // Para Screen @@ -333,24 +332,4 @@ namespace globalInputs } } } - - // Actualiza variables - void update() - { - if (service_pressed) - { - ++service_pressed_counter; - if (service_pressed_counter >= 200) - { - OnScreenHelp::get()->toggleState(); - service_pressed_counter = 0; - } - } - else - { - service_pressed_counter = 0; - } - - service_pressed = false; - } } \ No newline at end of file diff --git a/source/global_inputs.h b/source/global_inputs.h index 14fdff3..4bf63fb 100644 --- a/source/global_inputs.h +++ b/source/global_inputs.h @@ -2,12 +2,6 @@ namespace globalInputs { - extern int service_pressed_counter; - extern bool service_pressed; - // Comprueba los inputs que se pueden introducir en cualquier sección del juego void check(); - - // Actualiza variables - void update(); } \ No newline at end of file diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 78b4d94..3410f62 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -81,7 +81,6 @@ void HiScoreTable::update() Screen::get()->update(); // Actualiza las variables de globalInputs - globalInputs::update(); } } diff --git a/source/instructions.cpp b/source/instructions.cpp index ab31172..0833d4a 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -209,9 +209,6 @@ void Instructions::update() // Actualiza el objeto screen Screen::get()->update(); - // Actualiza las variables de globalInputs - globalInputs::update(); - // Incrementa el contador counter_++; diff --git a/source/intro.cpp b/source/intro.cpp index 36eaba0..e8bfb1c 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -247,9 +247,6 @@ void Intro::update() // Actualiza el objeto screen Screen::get()->update(); - - // Actualiza las variables de globalInputs - globalInputs::update(); } } diff --git a/source/logo.cpp b/source/logo.cpp index fd84f40..5fbe87e 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -163,10 +163,7 @@ void Logo::update() updateTextureColors(); // Gestiona el contador - counter_++; - - // Actualiza las variables de globalInputs - globalInputs::update(); + ++counter_; } } diff --git a/source/on_screen_help.cpp b/source/on_screen_help.cpp deleted file mode 100644 index e5b9c4f..0000000 --- a/source/on_screen_help.cpp +++ /dev/null @@ -1,254 +0,0 @@ -#include "on_screen_help.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para make_unique, unique_ptr -#include "lang.h" // Para getText -#include "param.h" // Para Param, ParamGame, param -#include "resource.h" // Para Resource -#include "screen.h" // Para Screen -#include "sprite.h" // Para Sprite -#include "text.h" // Para Text -#include "utils.h" // Para easeInOutSine - -// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado -OnScreenHelp *OnScreenHelp::onScreenHelp = nullptr; - -// Constantes evaluables en tiempo de compilación -constexpr int ICONSIZE = 16; -constexpr SDL_FPoint PADDING = {8, 8}; -constexpr SDL_FPoint DESP = {ICONSIZE + 4, 5}; - -constexpr SDL_FRect CONTROLLER_UP = {16, 0, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect CONTROLLER_DOWN = {48, 0, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect CONTROLLER_LEFT = {64, 0, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect LEFT_BUTTON = {112, 0, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect TOP_BUTTON = {80, 0, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect RIGHT_BUTTON = {96, 0, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect START_BUTTON = {0, 0, ICONSIZE, ICONSIZE}; - -constexpr SDL_FRect CONTROLLER_UP_POS = {PADDING.x, PADDING.y + 18 * 0, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect CONTROLLER_DOWN_POS = {PADDING.x, PADDING.y + 18 * 1, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect CONTROLLER_LEFT_POS = {PADDING.x, PADDING.y + 18 * 2, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect LEFT_BUTTON_POS = {PADDING.x, PADDING.y + 18 * 3, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect TOP_BUTTON_POS = {PADDING.x, PADDING.y + 18 * 4, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect RIGHT_BUTTON_POS = {PADDING.x, PADDING.y + 18 * 5, ICONSIZE, ICONSIZE}; -constexpr SDL_FRect START_BUTTON_POS = {PADDING.x, PADDING.y + 18 * 6, ICONSIZE, ICONSIZE}; - -// [SINGLETON] Crearemos el objeto onScreenHelp con esta función estática -void OnScreenHelp::init() -{ - OnScreenHelp::onScreenHelp = new OnScreenHelp(); -} - -// [SINGLETON] Destruiremos el objeto onScreenHelp con esta función estática -void OnScreenHelp::destroy() -{ - delete OnScreenHelp::onScreenHelp; -} - -// [SINGLETON] Con este método obtenemos el objeto onScreenHelp y podemos trabajar con él -OnScreenHelp *OnScreenHelp::get() -{ - return OnScreenHelp::onScreenHelp; -} - -// Constructor -OnScreenHelp::OnScreenHelp() : state(OnScreenHelpStatus::hidden), index(0) -{ - setSize(); - - texture = SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, dest.w, dest.h); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); - - fillTexture(); - precalculatePath(hiddenPos, showingPos, 60); -} - -// Destructor -OnScreenHelp::~OnScreenHelp() -{ - SDL_DestroyTexture(texture); -} - -// Actualiza la lógica interna -void OnScreenHelp::update() -{ - // Actualiza la posición - updatePosition(); -} - -// Muestra el objeto en pantalla -void OnScreenHelp::render() -{ - if (state != OnScreenHelpStatus::hidden) - { - SDL_RenderTexture(Screen::get()->getRenderer(), texture, nullptr, &dest); - } -} - -// Rellena la textura con los gráficos y texto -void OnScreenHelp::fillTexture() -{ - // Cambia el renderizador a la textura - auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer()); - SDL_SetRenderTarget(Screen::get()->getRenderer(), texture); - - // Crea el objeto para el texto - auto text = Resource::get()->getText("8bithud"); - - // Crea la textura con los gráficos - auto controllersTexture = Resource::get()->getTexture("controllers.png"); - - // Crea el sprite para dibujar los gráficos - auto sprite = std::make_unique(controllersTexture, (SDL_FRect){0, 0, 16, 16}); - - // Borra la textura - SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0); - SDL_RenderClear(Screen::get()->getRenderer()); - - // Pon el color de fondo con el bisel - SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0x55, 0x5D, 0x77, 255); - SDL_FRect rect; - rect = {4, 0, dest.w - (4 * 2), dest.h}; - SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); - - rect = {4 / 2, 1, dest.w - 4, dest.h - 2}; - SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); - - rect = {1, 4 / 2, dest.w - 2, dest.h - 4}; - SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); - - rect = {0, 4, dest.w, dest.h - (4 * 2)}; - SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); - - rect = {0, 0, dest.w / 2, dest.h}; - SDL_RenderFillRect(Screen::get()->getRenderer(), &rect); - - // Renderiza los botones y el texto - renderButton(sprite.get(), text.get(), CONTROLLER_UP, CONTROLLER_UP_POS, 107); - renderButton(sprite.get(), text.get(), CONTROLLER_DOWN, CONTROLLER_DOWN_POS, 108); - renderButton(sprite.get(), text.get(), CONTROLLER_LEFT, CONTROLLER_LEFT_POS, 109); - renderButton(sprite.get(), text.get(), LEFT_BUTTON, LEFT_BUTTON_POS, 110); - renderButton(sprite.get(), text.get(), TOP_BUTTON, TOP_BUTTON_POS, 111); - renderButton(sprite.get(), text.get(), RIGHT_BUTTON, RIGHT_BUTTON_POS, 112); - renderButton(sprite.get(), text.get(), START_BUTTON, START_BUTTON_POS, 113); - - // Restaura el destino de renderizado - SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); -} - -// Define el ancho y alto de la textura -void OnScreenHelp::setSize() -{ - const auto textSize = getLargestStringSize(); - const auto width = PADDING.x + DESP.x + textSize + PADDING.x; - const auto height = PADDING.y + (7 * 18) + PADDING.y; - const auto x = 0; - const auto y = (param.game.height - height) / 2; - - dest = (SDL_FRect){x, y, width, height}; - - hiddenPos = -width; - showingPos = 0; -} - -// Activa o desactiva el objeto -void OnScreenHelp::toggleState() -{ - if (state == OnScreenHelpStatus::showing || state == OnScreenHelpStatus::entering) - { - state = OnScreenHelpStatus::exitting; - } - - else if (state == OnScreenHelpStatus::hidden || state == OnScreenHelpStatus::exitting) - { - state = OnScreenHelpStatus::entering; - } -} - -// Calcula la longitud en pixels del texto más largo -auto OnScreenHelp::getLargestStringSize() -> int const -{ - auto text = Resource::get()->getText("8bithud"); - auto size = 0; - - for (int i = 107; i <= 113; ++i) - { - const auto textSize = text->lenght(lang::getText(i)); - size = textSize > size ? textSize : size; - } - - return size; -} - -// Renderizara el boton y el texto -void OnScreenHelp::renderButton(Sprite *sprite, Text *text, const SDL_FRect &buttonClip, const SDL_FRect &buttonPos, int textId) -{ - sprite->setSpriteClip(buttonClip); - sprite->setPosition(buttonPos); - sprite->render(); - text->write(buttonPos.x + DESP.x, buttonPos.y + DESP.y, lang::getText(textId)); -} - -// Actualiza la posición -void OnScreenHelp::updatePosition() -{ - switch (state) - { - case OnScreenHelpStatus::hidden: - { - index = 0; - break; - } - - case OnScreenHelpStatus::showing: - { - index = path.size() - 1; - break; - } - - case OnScreenHelpStatus::exitting: - { - if (index > 0) - { - index--; - } - else - { - state = OnScreenHelpStatus::hidden; - } - break; - } - - case OnScreenHelpStatus::entering: - { - if (index < (int)path.size() - 1) - { - index++; - } - else - { - state = OnScreenHelpStatus::showing; - } - break; - } - - default: - break; - } - - dest.x = path[index]; -} - -// Rellena los puntos por donde pasa la animación -void OnScreenHelp::precalculatePath(double start, double end, int steps) -{ - path.reserve(steps); - - for (int i = 0; i <= steps; ++i) - { - double t = static_cast(i) / steps; - double value = start + (end - start) * easeInOutSine(t); - path.push_back(static_cast(value)); - } -} \ No newline at end of file diff --git a/source/on_screen_help.h b/source/on_screen_help.h deleted file mode 100644 index 879ae9b..0000000 --- a/source/on_screen_help.h +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once - -#include // Para SDL_FRect -#include // Para SDL_Texture -#include // Para vector -class Sprite; -class Text; - -enum class OnScreenHelpStatus -{ - hidden, - showing, - entering, - exitting, -}; - -// Classe on_screen_help -class OnScreenHelp -{ -private: - // [SINGLETON] Objeto screen privado - static OnScreenHelp *onScreenHelp; - - SDL_Texture *texture; // Textura donde dibujar - SDL_FRect dest; // Posición donde dibujar la textura; - int hiddenPos, showingPos; // Las dos posiciones donde colocar la textura - - OnScreenHelpStatus state; // Estado del objeto - std::vector path; // Puntos por donde pasa la animación de la tarjeta - int index; // Indice para recorrer la animación - - // [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos screen desde fuera - - // Constructor - OnScreenHelp(); - - // Destructor - ~OnScreenHelp(); - - // Rellena la textura con los gráficos y texto - void fillTexture(); - - // Define el ancho y alto de la textura - void setSize(); - - // Calcula la longitud en pixels del texto más largo - auto getLargestStringSize() -> int const; - - // Renderizara el boton y el texto - void renderButton(Sprite *sprite, Text *text, const SDL_FRect &buttonClip, const SDL_FRect &buttonPos, int textId); - - // Actualiza la posición - void updatePosition(); - - // Rellena los puntos por donde pasa la animación - void precalculatePath(double start, double end, int steps); - -public: - // [SINGLETON] Crearemos el objeto screen con esta función estática - static void init(); - - // [SINGLETON] Destruiremos el objeto screen con esta función estática - static void destroy(); - - // [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él - static OnScreenHelp *get(); - - // Actualiza la lógica interna - void update(); - - // Muestra el objeto en pantalla - void render(); - - // Activa o desactiva el objeto - void toggleState(); -}; \ No newline at end of file diff --git a/source/screen.cpp b/source/screen.cpp index 122b5c0..e990011 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -16,7 +16,6 @@ #include "jail_shader.h" // Para init, render #include "mouse.h" // Para updateCursorVisibility #include "notifier.h" // Para Notifier -#include "on_screen_help.h" // Para OnScreenHelp #include "options.h" // Para Options, options, WindowOptions, Vid... #include "resource.h" // Para Resource #include "text.h" // Para Text @@ -174,7 +173,6 @@ void Screen::update() shake_effect_.update(src_rect_, dst_rect_); flash_effect_.update(); Notifier::get()->update(); - OnScreenHelp::get()->update(); Mouse::updateCursorVisibility(); } @@ -279,7 +277,6 @@ void Screen::renderOverlays() renderShake(); renderFlash(); renderAttenuate(); - OnScreenHelp::get()->render(); Notifier::get()->render(); #ifdef DEBUG renderInfo(); diff --git a/source/title.cpp b/source/title.cpp index 46f4b38..dea174f 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -74,9 +74,6 @@ void Title::update() // Actualiza el objeto screen Screen::get()->update(); - - // Actualiza las variables de globalInputs - globalInputs::update(); } }