diff --git a/source/on_screen_help.cpp b/source/on_screen_help.cpp index cadcdff..853fc09 100644 --- a/source/on_screen_help.cpp +++ b/source/on_screen_help.cpp @@ -6,7 +6,9 @@ #include "texture.h" #include "lang.h" #include "param.h" +#include "dbgtxt.h" #include // Para std::unique_ptr +#include "utils.h" // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado OnScreenHelp *OnScreenHelp::onScreenHelp = nullptr; @@ -51,7 +53,7 @@ OnScreenHelp *OnScreenHelp::get() } // Constructor -OnScreenHelp::OnScreenHelp() : state(OnScreenHelpStatus::hidden) +OnScreenHelp::OnScreenHelp() : state(OnScreenHelpStatus::hidden), index(0) { setSize(); @@ -59,6 +61,7 @@ OnScreenHelp::OnScreenHelp() : state(OnScreenHelpStatus::hidden) SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); fillTexture(); + precalculatePath(hiddenPos, showingPos, 60); } // Destructor @@ -157,7 +160,7 @@ void OnScreenHelp::toggleState() state = OnScreenHelpStatus::exitting; } - if (state == OnScreenHelpStatus::hidden || state == OnScreenHelpStatus::exitting) + else if (state == OnScreenHelpStatus::hidden || state == OnScreenHelpStatus::exitting) { state = OnScreenHelpStatus::entering; } @@ -193,17 +196,17 @@ void OnScreenHelp::updatePosition() switch (state) { case OnScreenHelpStatus::hidden: - dest.x = hiddenPos; + index = 0; break; case OnScreenHelpStatus::showing: - dest.x = showingPos; + index = path.size() - 1; break; case OnScreenHelpStatus::exitting: - if (dest.x > hiddenPos) + if (index > 0) { - dest.x -= 8; + index--; } else { @@ -212,9 +215,9 @@ void OnScreenHelp::updatePosition() break; case OnScreenHelpStatus::entering: - if (dest.x < showingPos) + if (index < (int)path.size() - 1) { - dest.x += 8; + index++; } else { @@ -226,6 +229,18 @@ void OnScreenHelp::updatePosition() break; } - dest.x = std::max(hiddenPos, dest.x); - dest.x = std::min(showingPos, dest.x); + 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 index 2ce1773..6a1ec99 100644 --- a/source/on_screen_help.h +++ b/source/on_screen_help.h @@ -2,6 +2,7 @@ #include #include "text.h" +#include class Screen; class Asset; class Input; @@ -28,6 +29,8 @@ private: 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 @@ -52,6 +55,9 @@ private: // 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();