update text2.cpp
This commit is contained in:
@@ -1,121 +1,107 @@
|
|||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "text2.h"
|
#include "text2.h"
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Text2::Text2()
|
Text2::Text2()
|
||||||
{
|
{
|
||||||
init(nullptr, nullptr, 0, 0);
|
init(nullptr, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Text2::~Text2()
|
Text2::~Text2()
|
||||||
{
|
{
|
||||||
init(nullptr, nullptr, 0, 0);
|
init(nullptr, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializador
|
void Text2::init(LTexture *texture, SDL_Renderer *renderer, Uint8 height)
|
||||||
void Text2::init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size)
|
|
||||||
{
|
{
|
||||||
Text::init(texture, renderer, type, size);
|
Text::init(texture, renderer, height);
|
||||||
mPosX = 0;
|
mPosX = 0;
|
||||||
mPosY = 0;
|
mPosY = 0;
|
||||||
mKerning = 0;
|
mKerning = 0;
|
||||||
mCaption = "";
|
mCaption = "";
|
||||||
mWrittingSpeed = 0;
|
mSpeed = 0;
|
||||||
mWrittingTimer = 0;
|
mCounter = 0;
|
||||||
mIndex = 0;
|
mIndex = 0;
|
||||||
mLenght = 0;
|
mLenght = 0;
|
||||||
mWrittingCompleted = false;
|
mCompleted = false;
|
||||||
mEnabled = false;
|
mEnabled = false;
|
||||||
mEnabledTimer = 0;
|
mEnabledCounter = 0;
|
||||||
mId = -1;
|
mId = -1;
|
||||||
mIntroEvents = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Text2::setPosX(int value)
|
void Text2::setPosX(int value)
|
||||||
{
|
{
|
||||||
mPosX = value;
|
mPosX = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Text2::setPosY(int value)
|
void Text2::setPosY(int value)
|
||||||
{
|
{
|
||||||
mPosY = value;
|
mPosY = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Text2::setKerning(int value)
|
void Text2::setKerning(int value)
|
||||||
{
|
{
|
||||||
mKerning = value;
|
mKerning = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Text2::setCaption(std::string text)
|
void Text2::setCaption(std::string text)
|
||||||
{
|
{
|
||||||
mCaption = text;
|
mCaption = text;
|
||||||
mLenght = text.length();
|
mLenght = text.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
void Text2::setSpeed(Uint16 value)
|
||||||
void Text2::setWrittingSpeed(Uint16 value)
|
|
||||||
{
|
{
|
||||||
mWrittingSpeed = value;
|
mSpeed = value;
|
||||||
mWrittingTimer = value;
|
mCounter = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Text2::setEnabled(bool value)
|
void Text2::setEnabled(bool value)
|
||||||
{
|
{
|
||||||
mEnabled = value;
|
mEnabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool Text2::IsEnabled()
|
bool Text2::IsEnabled()
|
||||||
{
|
{
|
||||||
return mEnabled;
|
return mEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
void Text2::setEnabledCounter(Uint16 value)
|
||||||
void Text2::setEnabledTimer(Uint16 value)
|
|
||||||
{
|
{
|
||||||
mEnabledTimer = value;
|
mEnabledCounter = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
Uint16 Text2::getEnabledCounter()
|
||||||
Uint16 Text2::getEnabledTimer()
|
|
||||||
{
|
{
|
||||||
return mEnabledTimer;
|
return mEnabledCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el objeto
|
|
||||||
void Text2::update()
|
void Text2::update()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (mEnabled)
|
||||||
{
|
{
|
||||||
if (mWrittingCompleted == false)
|
if (mCompleted == false)
|
||||||
{
|
{
|
||||||
if (mWrittingTimer > 0)
|
if (mCounter > 0)
|
||||||
{
|
{
|
||||||
--mWrittingTimer;
|
--mCounter;
|
||||||
}
|
}
|
||||||
if (mWrittingTimer == 0)
|
if (mCounter == 0)
|
||||||
{
|
{
|
||||||
++mIndex;
|
++mIndex;
|
||||||
mWrittingTimer = mWrittingSpeed;
|
mCounter = mSpeed;
|
||||||
}
|
}
|
||||||
if (mIndex == mLenght)
|
if (mIndex == mLenght)
|
||||||
{
|
{
|
||||||
mWrittingCompleted = true;
|
mCompleted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mWrittingCompleted)
|
if (mCompleted)
|
||||||
{
|
{
|
||||||
if (mEnabledTimer > 0)
|
if (mEnabledCounter > 0)
|
||||||
{
|
{
|
||||||
--mEnabledTimer;
|
--mEnabledCounter;
|
||||||
}
|
}
|
||||||
else if (mEnabledTimer == 0)
|
else if (mEnabledCounter == 0)
|
||||||
{
|
{
|
||||||
if (mId < 0)
|
if (mId < 0)
|
||||||
{
|
{
|
||||||
@@ -123,14 +109,13 @@ void Text2::update()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mIntroEvents[mId] = EVENT_COMPLETED;
|
//mIntroEvents[mId] = EVENT_COMPLETED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el objeto en pantalla
|
|
||||||
void Text2::render()
|
void Text2::render()
|
||||||
{
|
{
|
||||||
if (mEnabled)
|
if (mEnabled)
|
||||||
@@ -139,20 +124,12 @@ void Text2::render()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Centra la cadena de texto a un punto X
|
|
||||||
void Text2::center(int x)
|
void Text2::center(int x)
|
||||||
{
|
{
|
||||||
setPosX(x - (lenght(mCaption, mKerning) / 2));
|
setPosX(x - (lenght(mCaption, mKerning) / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Text2::setId(int id)
|
void Text2::setId(int id)
|
||||||
{
|
{
|
||||||
mId = id;
|
mId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Text2::setIntroEvents(Uint8 *value)
|
|
||||||
{
|
|
||||||
mIntroEvents = value;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public:
|
|||||||
~Text2();
|
~Text2();
|
||||||
|
|
||||||
// Inicializador
|
// Inicializador
|
||||||
void init(LTexture *texture, SDL_Renderer *renderer, Uint8 type, Uint8 size);
|
void init(LTexture *texture, SDL_Renderer *renderer, Uint8 height);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setPosX(int value);
|
void setPosX(int value);
|
||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
void setCaption(std::string text);
|
void setCaption(std::string text);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setWrittingSpeed(Uint16 value);
|
void setSpeed(Uint16 value);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setEnabled(bool value);
|
void setEnabled(bool value);
|
||||||
@@ -40,63 +40,36 @@ public:
|
|||||||
bool IsEnabled();
|
bool IsEnabled();
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setEnabledTimer(Uint16 value);
|
void setEnabledCounter(Uint16 value);
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
Uint16 getEnabledTimer();
|
Uint16 getEnabledCounter();
|
||||||
|
|
||||||
// Actualiza el objeto
|
// Actualiza todas las variables del objeto
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
// Dibuja el objeto en pantalla
|
// Dibuja el objeto en pantalla
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Centra la cadena de texto a un punto X
|
// Centra la cadena de texto respecto a un punto X
|
||||||
void center(int x);
|
void center(int x);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable mId
|
||||||
void setId(int id);
|
void setId(int id);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setIntroEvents(Uint8 *value);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Posicion X/Y donde empezar a escribir el texto
|
bool mCompleted; // Indica si se ha escrito todo el texto
|
||||||
int mPosX;
|
bool mEnabled; // Indica si el objeto está habilitado
|
||||||
int mPosY;
|
int mId; // Identificador
|
||||||
|
int mKerning; // Espacio entre caracteres
|
||||||
// Kerning del texto
|
int mPosX; // Posicion en el eje X donde empezar a escribir el texto
|
||||||
int mKerning;
|
int mPosY; // Posicion en el eje Y donde empezar a escribir el texto
|
||||||
|
std::string mCaption; // Texto para escribir
|
||||||
// Texto para escribir
|
Uint16 mCounter; // Temporizador de escritura para cada caracter
|
||||||
std::string mCaption;
|
Uint16 mEnabledCounter; // Contador para deshabilitar el objeto
|
||||||
|
Uint16 mIndex; // Indice a la posición dentro de la cadena de texto que se está escribiendo
|
||||||
// Velocidad de escritura
|
Uint16 mLenght; // Longitud de la cadena a escribir
|
||||||
Uint16 mWrittingSpeed;
|
Uint16 mSpeed; // Velocidad de escritura
|
||||||
|
|
||||||
// Temporizador de escritura para cada caracter
|
|
||||||
Uint16 mWrittingTimer;
|
|
||||||
|
|
||||||
// Posición del texto que se está escribiendo
|
|
||||||
Uint16 mIndex;
|
|
||||||
|
|
||||||
// Longitud de la cadena a escribir
|
|
||||||
Uint16 mLenght;
|
|
||||||
|
|
||||||
// Indica si se ha escrito todo el texto
|
|
||||||
bool mWrittingCompleted;
|
|
||||||
|
|
||||||
// Indica si el objeto está habilitado
|
|
||||||
bool mEnabled;
|
|
||||||
|
|
||||||
// Temporizador para deshabilitar el objeto
|
|
||||||
Uint16 mEnabledTimer;
|
|
||||||
|
|
||||||
// Identificador
|
|
||||||
int mId;
|
|
||||||
|
|
||||||
// Dirección del array de eventos donde notificar el estado
|
|
||||||
Uint8 *mIntroEvents;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user