La tarjeta d'ajuda ja entra i ix amb animacions suavitzades
This commit is contained in:
@@ -6,7 +6,9 @@
|
|||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
|
#include "dbgtxt.h"
|
||||||
#include <memory> // Para std::unique_ptr
|
#include <memory> // Para std::unique_ptr
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
OnScreenHelp *OnScreenHelp::onScreenHelp = nullptr;
|
OnScreenHelp *OnScreenHelp::onScreenHelp = nullptr;
|
||||||
@@ -51,7 +53,7 @@ OnScreenHelp *OnScreenHelp::get()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
OnScreenHelp::OnScreenHelp() : state(OnScreenHelpStatus::hidden)
|
OnScreenHelp::OnScreenHelp() : state(OnScreenHelpStatus::hidden), index(0)
|
||||||
{
|
{
|
||||||
setSize();
|
setSize();
|
||||||
|
|
||||||
@@ -59,6 +61,7 @@ OnScreenHelp::OnScreenHelp() : state(OnScreenHelpStatus::hidden)
|
|||||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
fillTexture();
|
fillTexture();
|
||||||
|
precalculatePath(hiddenPos, showingPos, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -157,7 +160,7 @@ void OnScreenHelp::toggleState()
|
|||||||
state = OnScreenHelpStatus::exitting;
|
state = OnScreenHelpStatus::exitting;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == OnScreenHelpStatus::hidden || state == OnScreenHelpStatus::exitting)
|
else if (state == OnScreenHelpStatus::hidden || state == OnScreenHelpStatus::exitting)
|
||||||
{
|
{
|
||||||
state = OnScreenHelpStatus::entering;
|
state = OnScreenHelpStatus::entering;
|
||||||
}
|
}
|
||||||
@@ -193,17 +196,17 @@ void OnScreenHelp::updatePosition()
|
|||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case OnScreenHelpStatus::hidden:
|
case OnScreenHelpStatus::hidden:
|
||||||
dest.x = hiddenPos;
|
index = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OnScreenHelpStatus::showing:
|
case OnScreenHelpStatus::showing:
|
||||||
dest.x = showingPos;
|
index = path.size() - 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OnScreenHelpStatus::exitting:
|
case OnScreenHelpStatus::exitting:
|
||||||
if (dest.x > hiddenPos)
|
if (index > 0)
|
||||||
{
|
{
|
||||||
dest.x -= 8;
|
index--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -212,9 +215,9 @@ void OnScreenHelp::updatePosition()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OnScreenHelpStatus::entering:
|
case OnScreenHelpStatus::entering:
|
||||||
if (dest.x < showingPos)
|
if (index < (int)path.size() - 1)
|
||||||
{
|
{
|
||||||
dest.x += 8;
|
index++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -226,6 +229,18 @@ void OnScreenHelp::updatePosition()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dest.x = std::max(hiddenPos, dest.x);
|
dest.x = path[index];
|
||||||
dest.x = std::min(showingPos, dest.x);
|
}
|
||||||
|
|
||||||
|
// 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<double>(i) / steps;
|
||||||
|
double value = start + (end - start) * easeInOutSine(t);
|
||||||
|
path.push_back(static_cast<int>(value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
#include <vector>
|
||||||
class Screen;
|
class Screen;
|
||||||
class Asset;
|
class Asset;
|
||||||
class Input;
|
class Input;
|
||||||
@@ -28,6 +29,8 @@ private:
|
|||||||
int hiddenPos, showingPos; // Las dos posiciones donde colocar la textura
|
int hiddenPos, showingPos; // Las dos posiciones donde colocar la textura
|
||||||
|
|
||||||
OnScreenHelpStatus state; // Estado del objeto
|
OnScreenHelpStatus state; // Estado del objeto
|
||||||
|
std::vector<int> 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
|
// [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
|
// Actualiza la posición
|
||||||
void updatePosition();
|
void updatePosition();
|
||||||
|
|
||||||
|
// Rellena los puntos por donde pasa la animación
|
||||||
|
void precalculatePath(double start, double end, int steps);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
// [SINGLETON] Crearemos el objeto screen con esta función estática
|
||||||
static void init();
|
static void init();
|
||||||
|
|||||||
Reference in New Issue
Block a user