using namespace std en todos los ficheros
This commit is contained in:
7
main.cpp
7
main.cpp
@@ -97,6 +97,13 @@ int main(int argc, char *argv[])
|
|||||||
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
input->bindKey(INPUT_DOWN, SDL_SCANCODE_DOWN);
|
||||||
input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
input->bindKey(INPUT_LEFT, SDL_SCANCODE_LEFT);
|
||||||
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
input->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT);
|
||||||
|
string controllerName = "";
|
||||||
|
int numControllers= input->getNumControllers();
|
||||||
|
if (numControllers>0)
|
||||||
|
{
|
||||||
|
controllerName=getControllerName(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Inicializa el texto
|
// Inicializa el texto
|
||||||
Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer);
|
Text *text = new Text(asset->get("smb2.txt"), asset->get("smb2.png"), renderer);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
|
|
||||||
// Carga la animación desde un fichero
|
// Carga la animación desde un fichero
|
||||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose)
|
animatedSprite_t loadAnimationFromFile(Texture *texture, string filePath, bool verbose)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
animatedSprite_t as;
|
animatedSprite_t as;
|
||||||
@@ -11,9 +11,9 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
int frameHeight = 0;
|
int frameHeight = 0;
|
||||||
int maxTiles = 0;
|
int maxTiles = 0;
|
||||||
|
|
||||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
const string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||||
std::ifstream file(filePath);
|
ifstream file(filePath);
|
||||||
std::string line;
|
string line;
|
||||||
|
|
||||||
// El fichero se puede abrir
|
// El fichero se puede abrir
|
||||||
if (file.good())
|
if (file.good())
|
||||||
@@ -21,9 +21,9 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
// Procesa el fichero linea a linea
|
// Procesa el fichero linea a linea
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Animation loaded: " << filename << std::endl;
|
cout << "Animation loaded: " << filename << endl;
|
||||||
}
|
}
|
||||||
while (std::getline(file, line))
|
while (getline(file, line))
|
||||||
{
|
{
|
||||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||||
if (line == "[animation]")
|
if (line == "[animation]")
|
||||||
@@ -35,7 +35,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::getline(file, line);
|
getline(file, line);
|
||||||
|
|
||||||
// Encuentra la posición del caracter '='
|
// Encuentra la posición del caracter '='
|
||||||
int pos = line.find("=");
|
int pos = line.find("=");
|
||||||
@@ -50,24 +50,24 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
|
|
||||||
else if (line.substr(0, pos) == "speed")
|
else if (line.substr(0, pos) == "speed")
|
||||||
{
|
{
|
||||||
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
|
buffer.speed = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "loop")
|
else if (line.substr(0, pos) == "loop")
|
||||||
{
|
{
|
||||||
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
|
buffer.loop = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frames")
|
else if (line.substr(0, pos) == "frames")
|
||||||
{
|
{
|
||||||
// Se introducen los valores separados por comas en un vector
|
// Se introducen los valores separados por comas en un vector
|
||||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
stringstream ss(line.substr(pos + 1, line.length()));
|
||||||
std::string tmp;
|
string tmp;
|
||||||
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
||||||
while (getline(ss, tmp, ','))
|
while (getline(ss, tmp, ','))
|
||||||
{
|
{
|
||||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||||
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
const int numTile = stoi(tmp) > maxTiles ? 0 : stoi(tmp);
|
||||||
rect.x = (numTile % framesPerRow) * frameWidth;
|
rect.x = (numTile % framesPerRow) * frameWidth;
|
||||||
rect.y = (numTile / framesPerRow) * frameHeight;
|
rect.y = (numTile / framesPerRow) * frameHeight;
|
||||||
buffer.frames.push_back(rect);
|
buffer.frames.push_back(rect);
|
||||||
@@ -76,7 +76,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (line != "[/animation]");
|
} while (line != "[/animation]");
|
||||||
@@ -96,22 +96,22 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
{
|
{
|
||||||
if (line.substr(0, pos) == "framesPerRow")
|
if (line.substr(0, pos) == "framesPerRow")
|
||||||
{
|
{
|
||||||
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
|
framesPerRow = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frameWidth")
|
else if (line.substr(0, pos) == "frameWidth")
|
||||||
{
|
{
|
||||||
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
frameWidth = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frameHeight")
|
else if (line.substr(0, pos) == "frameHeight")
|
||||||
{
|
{
|
||||||
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
|
frameHeight = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normaliza valores
|
// Normaliza valores
|
||||||
@@ -138,7 +138,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
cout << "Warning: Unable to open " << filename.c_str() << " file" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,9 +146,9 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer)
|
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, string file, vector<string> *buffer)
|
||||||
{
|
{
|
||||||
//std::cout << "Creado AnimatedSprite" << std::endl;
|
//cout << "Creado AnimatedSprite" << endl;
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
setTexture(texture);
|
setTexture(texture);
|
||||||
setRenderer(renderer);
|
setRenderer(renderer);
|
||||||
@@ -177,7 +177,7 @@ AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::st
|
|||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation)
|
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation)
|
||||||
{
|
{
|
||||||
//std::cout << "Creado AnimatedSprite" << std::endl;
|
//cout << "Creado AnimatedSprite" << endl;
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
setTexture(animation->texture);
|
setTexture(animation->texture);
|
||||||
setRenderer(renderer);
|
setRenderer(renderer);
|
||||||
@@ -195,7 +195,7 @@ AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animati
|
|||||||
// Destructor
|
// Destructor
|
||||||
AnimatedSprite::~AnimatedSprite()
|
AnimatedSprite::~AnimatedSprite()
|
||||||
{
|
{
|
||||||
//std::cout << "Destruido AnimatedSprite" << std::endl;
|
//cout << "Destruido AnimatedSprite" << endl;
|
||||||
for (auto &a : animation)
|
for (auto &a : animation)
|
||||||
{
|
{
|
||||||
a.frames.clear();
|
a.frames.clear();
|
||||||
@@ -204,7 +204,7 @@ AnimatedSprite::~AnimatedSprite()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el indice de la animación a partir del nombre
|
// Obtiene el indice de la animación a partir del nombre
|
||||||
int AnimatedSprite::getIndex(std::string name)
|
int AnimatedSprite::getIndex(string name)
|
||||||
{
|
{
|
||||||
int index = -1;
|
int index = -1;
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ int AnimatedSprite::getIndex(std::string name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << std::endl;
|
cout << "** Warning: could not find \"" << name.c_str() << "\" animation" << endl;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -283,13 +283,13 @@ void AnimatedSprite::setCurrentFrame(int num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor del contador
|
// Establece el valor del contador
|
||||||
void AnimatedSprite::setAnimationCounter(std::string name, int num)
|
void AnimatedSprite::setAnimationCounter(string name, int num)
|
||||||
{
|
{
|
||||||
animation[getIndex(name)].counter = num;
|
animation[getIndex(name)].counter = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la velocidad de una animación
|
// Establece la velocidad de una animación
|
||||||
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
|
void AnimatedSprite::setAnimationSpeed(string name, int speed)
|
||||||
{
|
{
|
||||||
animation[getIndex(name)].counter = speed;
|
animation[getIndex(name)].counter = speed;
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,7 @@ void AnimatedSprite::setAnimationSpeed(int index, int speed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece si la animación se reproduce en bucle
|
// Establece si la animación se reproduce en bucle
|
||||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
|
void AnimatedSprite::setAnimationLoop(string name, int loop)
|
||||||
{
|
{
|
||||||
animation[getIndex(name)].loop = loop;
|
animation[getIndex(name)].loop = loop;
|
||||||
}
|
}
|
||||||
@@ -313,7 +313,7 @@ void AnimatedSprite::setAnimationLoop(int index, int loop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
|
void AnimatedSprite::setAnimationCompleted(string name, bool value)
|
||||||
{
|
{
|
||||||
animation[getIndex(name)].completed = value;
|
animation[getIndex(name)].completed = value;
|
||||||
}
|
}
|
||||||
@@ -331,7 +331,7 @@ bool AnimatedSprite::animationIsCompleted()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index)
|
SDL_Rect AnimatedSprite::getAnimationClip(string name, Uint8 index)
|
||||||
{
|
{
|
||||||
return animation[getIndex(name)].frames[index];
|
return animation[getIndex(name)].frames[index];
|
||||||
}
|
}
|
||||||
@@ -343,7 +343,7 @@ SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga la animación desde un vector
|
// Carga la animación desde un vector
|
||||||
bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
bool AnimatedSprite::loadFromVector(vector<string> *source)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
int framesPerRow = 0;
|
int framesPerRow = 0;
|
||||||
@@ -353,7 +353,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
|
|
||||||
// Indicador de éxito en el proceso
|
// Indicador de éxito en el proceso
|
||||||
bool success = true;
|
bool success = true;
|
||||||
std::string line;
|
string line;
|
||||||
|
|
||||||
// Recorre todo el vector
|
// Recorre todo el vector
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -389,24 +389,24 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
|
|
||||||
else if (line.substr(0, pos) == "speed")
|
else if (line.substr(0, pos) == "speed")
|
||||||
{
|
{
|
||||||
buffer.speed = std::stoi(line.substr(pos + 1, line.length()));
|
buffer.speed = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "loop")
|
else if (line.substr(0, pos) == "loop")
|
||||||
{
|
{
|
||||||
buffer.loop = std::stoi(line.substr(pos + 1, line.length()));
|
buffer.loop = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frames")
|
else if (line.substr(0, pos) == "frames")
|
||||||
{
|
{
|
||||||
// Se introducen los valores separados por comas en un vector
|
// Se introducen los valores separados por comas en un vector
|
||||||
std::stringstream ss(line.substr(pos + 1, line.length()));
|
stringstream ss(line.substr(pos + 1, line.length()));
|
||||||
std::string tmp;
|
string tmp;
|
||||||
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
SDL_Rect rect = {0, 0, frameWidth, frameHeight};
|
||||||
while (getline(ss, tmp, ','))
|
while (getline(ss, tmp, ','))
|
||||||
{
|
{
|
||||||
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
// Comprueba que el tile no sea mayor que el maximo indice permitido
|
||||||
const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp);
|
const int numTile = stoi(tmp) > maxTiles ? 0 : stoi(tmp);
|
||||||
rect.x = (numTile % framesPerRow) * frameWidth;
|
rect.x = (numTile % framesPerRow) * frameWidth;
|
||||||
rect.y = (numTile / framesPerRow) * frameHeight;
|
rect.y = (numTile / framesPerRow) * frameHeight;
|
||||||
buffer.frames.push_back(rect);
|
buffer.frames.push_back(rect);
|
||||||
@@ -415,7 +415,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << endl;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -436,22 +436,22 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
{
|
{
|
||||||
if (line.substr(0, pos) == "framesPerRow")
|
if (line.substr(0, pos) == "framesPerRow")
|
||||||
{
|
{
|
||||||
framesPerRow = std::stoi(line.substr(pos + 1, line.length()));
|
framesPerRow = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frameWidth")
|
else if (line.substr(0, pos) == "frameWidth")
|
||||||
{
|
{
|
||||||
frameWidth = std::stoi(line.substr(pos + 1, line.length()));
|
frameWidth = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (line.substr(0, pos) == "frameHeight")
|
else if (line.substr(0, pos) == "frameHeight")
|
||||||
{
|
{
|
||||||
frameHeight = std::stoi(line.substr(pos + 1, line.length()));
|
frameHeight = stoi(line.substr(pos + 1, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
cout << "Warning: unknown parameter " << line.substr(0, pos).c_str() << endl;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,7 +481,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece la animacion actual
|
// Establece la animacion actual
|
||||||
void AnimatedSprite::setCurrentAnimation(std::string name)
|
void AnimatedSprite::setCurrentAnimation(string name)
|
||||||
{
|
{
|
||||||
const int newAnimation = getIndex(name);
|
const int newAnimation = getIndex(name);
|
||||||
if (currentAnimation != newAnimation)
|
if (currentAnimation != newAnimation)
|
||||||
|
|||||||
@@ -11,10 +11,12 @@
|
|||||||
#ifndef ANIMATEDSPRITE_H
|
#ifndef ANIMATEDSPRITE_H
|
||||||
#define ANIMATEDSPRITE_H
|
#define ANIMATEDSPRITE_H
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
struct animation_t
|
struct animation_t
|
||||||
{
|
{
|
||||||
std::string name; // Nombre de la animacion
|
string name; // Nombre de la animacion
|
||||||
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
|
vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
|
||||||
int speed; // Velocidad de la animación
|
int speed; // Velocidad de la animación
|
||||||
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
|
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
|
||||||
bool completed; // Indica si ha finalizado la animación
|
bool completed; // Indica si ha finalizado la animación
|
||||||
@@ -24,23 +26,23 @@ struct animation_t
|
|||||||
|
|
||||||
struct animatedSprite_t
|
struct animatedSprite_t
|
||||||
{
|
{
|
||||||
std::vector<animation_t> animations; // Vector con las diferentes animaciones
|
vector<animation_t> animations; // Vector con las diferentes animaciones
|
||||||
Texture *texture; // Textura con los graficos para el sprite
|
Texture *texture; // Textura con los graficos para el sprite
|
||||||
};
|
};
|
||||||
|
|
||||||
// Carga la animación desde un fichero
|
// Carga la animación desde un fichero
|
||||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose = false);
|
animatedSprite_t loadAnimationFromFile(Texture *texture, string filePath, bool verbose = false);
|
||||||
|
|
||||||
class AnimatedSprite : public MovingSprite
|
class AnimatedSprite : public MovingSprite
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<animation_t> animation; // Vector con las diferentes animaciones
|
vector<animation_t> animation; // Vector con las diferentes animaciones
|
||||||
int currentAnimation; // Animacion activa
|
int currentAnimation; // Animacion activa
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
|
AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, string file = "", vector<string> *buffer = nullptr);
|
||||||
AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation);
|
AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -56,35 +58,35 @@ public:
|
|||||||
void setCurrentFrame(int num);
|
void setCurrentFrame(int num);
|
||||||
|
|
||||||
// Establece el valor del contador
|
// Establece el valor del contador
|
||||||
void setAnimationCounter(std::string name, int num);
|
void setAnimationCounter(string name, int num);
|
||||||
|
|
||||||
// Establece la velocidad de una animación
|
// Establece la velocidad de una animación
|
||||||
void setAnimationSpeed(std::string name, int speed);
|
void setAnimationSpeed(string name, int speed);
|
||||||
void setAnimationSpeed(int index, int speed);
|
void setAnimationSpeed(int index, int speed);
|
||||||
|
|
||||||
// Establece el frame al que vuelve la animación al finalizar
|
// Establece el frame al que vuelve la animación al finalizar
|
||||||
void setAnimationLoop(std::string name, int loop);
|
void setAnimationLoop(string name, int loop);
|
||||||
void setAnimationLoop(int index, int loop);
|
void setAnimationLoop(int index, int loop);
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void setAnimationCompleted(std::string name, bool value);
|
void setAnimationCompleted(string name, bool value);
|
||||||
void setAnimationCompleted(int index, bool value);
|
void setAnimationCompleted(int index, bool value);
|
||||||
|
|
||||||
// Comprueba si ha terminado la animación
|
// Comprueba si ha terminado la animación
|
||||||
bool animationIsCompleted();
|
bool animationIsCompleted();
|
||||||
|
|
||||||
// Devuelve el rectangulo de una animación y frame concreto
|
// Devuelve el rectangulo de una animación y frame concreto
|
||||||
SDL_Rect getAnimationClip(std::string name = "default", Uint8 index = 0);
|
SDL_Rect getAnimationClip(string name = "default", Uint8 index = 0);
|
||||||
SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0);
|
SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0);
|
||||||
|
|
||||||
// Obtiene el indice de la animación a partir del nombre
|
// Obtiene el indice de la animación a partir del nombre
|
||||||
int getIndex(std::string name);
|
int getIndex(string name);
|
||||||
|
|
||||||
// Carga la animación desde un vector
|
// Carga la animación desde un vector
|
||||||
bool loadFromVector(std::vector<std::string> *source);
|
bool loadFromVector(vector<string> *source);
|
||||||
|
|
||||||
// Establece la animacion actual
|
// Establece la animacion actual
|
||||||
void setCurrentAnimation(std::string name = "default");
|
void setCurrentAnimation(string name = "default");
|
||||||
void setCurrentAnimation(int index = 0);
|
void setCurrentAnimation(int index = 0);
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Asset::Asset(std::string executablePath)
|
Asset::Asset(string executablePath)
|
||||||
{
|
{
|
||||||
//std::cout << "Construido Asset" << std::endl;
|
//cout << "Construido Asset" << endl;
|
||||||
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
|
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
|
||||||
longestName = 0;
|
longestName = 0;
|
||||||
verbose = true;
|
verbose = true;
|
||||||
@@ -13,11 +13,11 @@ Asset::Asset(std::string executablePath)
|
|||||||
// Destructot
|
// Destructot
|
||||||
Asset::~Asset()
|
Asset::~Asset()
|
||||||
{
|
{
|
||||||
//std::cout << "Destruido Asset" << std::endl;
|
//cout << "Destruido Asset" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
|
void Asset::add(string file, enum assetType type, bool required, bool absolute)
|
||||||
{
|
{
|
||||||
item_t temp;
|
item_t temp;
|
||||||
temp.file = absolute ? file : executablePath + file;
|
temp.file = absolute ? file : executablePath + file;
|
||||||
@@ -25,17 +25,17 @@ void Asset::add(std::string file, enum assetType type, bool required, bool absol
|
|||||||
temp.required = required;
|
temp.required = required;
|
||||||
fileList.push_back(temp);
|
fileList.push_back(temp);
|
||||||
|
|
||||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
const string filename = file.substr(file.find_last_of("\\/") + 1);
|
||||||
longestName = SDL_max(longestName, filename.size());
|
longestName = SDL_max(longestName, filename.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
||||||
std::string Asset::get(std::string text)
|
string Asset::get(string text)
|
||||||
{
|
{
|
||||||
for (auto f : fileList)
|
for (auto f : fileList)
|
||||||
{
|
{
|
||||||
const size_t lastIndex = f.file.find_last_of("/") + 1;
|
const size_t lastIndex = f.file.find_last_of("/") + 1;
|
||||||
const std::string file = f.file.substr(lastIndex, std::string::npos);
|
const string file = f.file.substr(lastIndex, string::npos);
|
||||||
|
|
||||||
if (file == text)
|
if (file == text)
|
||||||
{
|
{
|
||||||
@@ -45,7 +45,7 @@ std::string Asset::get(std::string text)
|
|||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
cout << "Warning: file " << text.c_str() << " not found" << endl;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -57,10 +57,10 @@ bool Asset::check()
|
|||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "\n** Checking files" << std::endl;
|
cout << "\n** Checking files" << endl;
|
||||||
|
|
||||||
std::cout << "Executable path is: " << executablePath << std::endl;
|
cout << "Executable path is: " << executablePath << endl;
|
||||||
std::cout << "Sample filepath: " << fileList.back().file << std::endl;
|
cout << "Sample filepath: " << fileList.back().file << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||||
@@ -82,7 +82,7 @@ bool Asset::check()
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl;
|
cout << "\n>> " << getTypeName(type).c_str() << " FILES" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto f : fileList)
|
for (auto f : fileList)
|
||||||
@@ -100,13 +100,13 @@ bool Asset::check()
|
|||||||
{
|
{
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
std::cout << "\n** All files OK.\n"
|
cout << "\n** All files OK.\n"
|
||||||
<< std::endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "\n** A file is missing. Exiting.\n"
|
cout << "\n** A file is missing. Exiting.\n"
|
||||||
<< std::endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,13 +114,13 @@ bool Asset::check()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba que existe un fichero
|
// Comprueba que existe un fichero
|
||||||
bool Asset::checkFile(std::string path)
|
bool Asset::checkFile(string path)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
std::string result = "ERROR";
|
string result = "ERROR";
|
||||||
|
|
||||||
// Comprueba si existe el fichero
|
// Comprueba si existe el fichero
|
||||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
const string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||||
SDL_RWops *file = SDL_RWFromFile(path.c_str(), "rb");
|
SDL_RWops *file = SDL_RWFromFile(path.c_str(), "rb");
|
||||||
|
|
||||||
if (file != nullptr)
|
if (file != nullptr)
|
||||||
@@ -132,19 +132,19 @@ bool Asset::checkFile(std::string path)
|
|||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
cout.setf(ios::left, ios::adjustfield);
|
||||||
std::cout << "Checking file: ";
|
cout << "Checking file: ";
|
||||||
std::cout.width(longestName + 2);
|
cout.width(longestName + 2);
|
||||||
std::cout.fill('.');
|
cout.fill('.');
|
||||||
std::cout << filename + " ";
|
cout << filename + " ";
|
||||||
std::cout << " [" + result + "]" << std::endl;
|
cout << " [" + result + "]" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el nombre del tipo de recurso
|
// Devuelve el nombre del tipo de recurso
|
||||||
std::string Asset::getTypeName(int type)
|
string Asset::getTypeName(int type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#ifndef ASSET_H
|
#ifndef ASSET_H
|
||||||
#define ASSET_H
|
#define ASSET_H
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
enum assetType
|
enum assetType
|
||||||
{
|
{
|
||||||
t_bitmap,
|
t_bitmap,
|
||||||
@@ -28,7 +30,7 @@ private:
|
|||||||
// Estructura para definir un item
|
// Estructura para definir un item
|
||||||
struct item_t
|
struct item_t
|
||||||
{
|
{
|
||||||
std::string file; // Ruta del fichero desde la raiz del directorio
|
string file; // Ruta del fichero desde la raiz del directorio
|
||||||
enum assetType type; // Indica el tipo de recurso
|
enum assetType type; // Indica el tipo de recurso
|
||||||
bool required; // Indica si es un fichero que debe de existir
|
bool required; // Indica si es un fichero que debe de existir
|
||||||
//bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta
|
//bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta
|
||||||
@@ -36,28 +38,28 @@ private:
|
|||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int longestName; // Contiene la longitud del nombre de fichero mas largo
|
int longestName; // Contiene la longitud del nombre de fichero mas largo
|
||||||
std::vector<item_t> fileList; // Listado con todas las rutas a los ficheros
|
vector<item_t> fileList; // Listado con todas las rutas a los ficheros
|
||||||
std::string executablePath; // Ruta al ejecutable
|
string executablePath; // Ruta al ejecutable
|
||||||
bool verbose; // Indica si ha de mostrar información por pantalla
|
bool verbose; // Indica si ha de mostrar información por pantalla
|
||||||
|
|
||||||
// Comprueba que existe un fichero
|
// Comprueba que existe un fichero
|
||||||
bool checkFile(std::string executablePath);
|
bool checkFile(string executablePath);
|
||||||
|
|
||||||
// Devuelve el nombre del tipo de recurso
|
// Devuelve el nombre del tipo de recurso
|
||||||
std::string getTypeName(int type);
|
string getTypeName(int type);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Asset(std::string path);
|
Asset(string path);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Asset();
|
~Asset();
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
|
void add(string file, enum assetType type, bool required = true, bool absolute = false);
|
||||||
|
|
||||||
// Devuelve un elemento de la lista a partir de una cadena
|
// Devuelve un elemento de la lista a partir de una cadena
|
||||||
std::string get(std::string text);
|
string get(string text);
|
||||||
|
|
||||||
// Comprueba que existen todos los elementos
|
// Comprueba que existen todos los elementos
|
||||||
bool check();
|
bool check();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ void Debug::render()
|
|||||||
for (auto s : slot)
|
for (auto s : slot)
|
||||||
{
|
{
|
||||||
text->write(x, y, s);
|
text->write(x, y, s);
|
||||||
w = (std::max(w, (int)s.length()));
|
w = (max(w, (int)s.length()));
|
||||||
y += text->getCharacterSize() + 1;
|
y += text->getCharacterSize() + 1;
|
||||||
if (y > 192 - text->getCharacterSize())
|
if (y > 192 - text->getCharacterSize())
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ void Debug::setPos(SDL_Point p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Añade un texto para mostrar
|
// Añade un texto para mostrar
|
||||||
void Debug::add(std::string text)
|
void Debug::add(string text)
|
||||||
{
|
{
|
||||||
slot.push_back(text);
|
slot.push_back(text);
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ void Debug::clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Añade un texto para mostrar en el apartado log
|
// Añade un texto para mostrar en el apartado log
|
||||||
void Debug::addToLog(std::string text)
|
void Debug::addToLog(string text)
|
||||||
{
|
{
|
||||||
log.push_back(text);
|
log.push_back(text);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
#ifndef DEBUG_H
|
#ifndef DEBUG_H
|
||||||
#define DEBUG_H
|
#define DEBUG_H
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
// Clase Debug
|
// Clase Debug
|
||||||
class Debug
|
class Debug
|
||||||
{
|
{
|
||||||
@@ -24,8 +26,8 @@ private:
|
|||||||
Texture *texture; // Textura para el texto
|
Texture *texture; // Textura para el texto
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<std::string> slot; // Vector con los textos a escribir
|
vector<string> slot; // Vector con los textos a escribir
|
||||||
std::vector<std::string> log; // Vector con los textos a escribir
|
vector<string> log; // Vector con los textos a escribir
|
||||||
int x; // Posicion donde escribir el texto de debug
|
int x; // Posicion donde escribir el texto de debug
|
||||||
int y; // Posición donde escribir el texto de debug
|
int y; // Posición donde escribir el texto de debug
|
||||||
bool enabled; // Indica si esta activo el modo debug
|
bool enabled; // Indica si esta activo el modo debug
|
||||||
@@ -47,13 +49,13 @@ public:
|
|||||||
void setPos(SDL_Point p);
|
void setPos(SDL_Point p);
|
||||||
|
|
||||||
// Añade un texto para mostrar
|
// Añade un texto para mostrar
|
||||||
void add(std::string text);
|
void add(string text);
|
||||||
|
|
||||||
// Borra la información de debug
|
// Borra la información de debug
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
// Añade un texto para mostrar en el apartado log
|
// Añade un texto para mostrar en el apartado log
|
||||||
void addToLog(std::string text);
|
void addToLog(string text);
|
||||||
|
|
||||||
// Borra la información de debug del apartado log
|
// Borra la información de debug del apartado log
|
||||||
void clearLog();
|
void clearLog();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input::Input(std::string file)
|
Input::Input(string file)
|
||||||
{
|
{
|
||||||
// Fichero gamecontrollerdb.txt
|
// Fichero gamecontrollerdb.txt
|
||||||
dbPath = file;
|
dbPath = file;
|
||||||
@@ -201,7 +201,7 @@ bool Input::discoverGameController()
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl;
|
cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,8 +219,8 @@ bool Input::discoverGameController()
|
|||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "\nChecking for game controllers...\n";
|
cout << "\nChecking for game controllers...\n";
|
||||||
std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numGamepads > 0)
|
if (numGamepads > 0)
|
||||||
@@ -234,13 +234,13 @@ bool Input::discoverGameController()
|
|||||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||||
{
|
{
|
||||||
connectedControllers.push_back(pad);
|
connectedControllers.push_back(pad);
|
||||||
const std::string separator(" #");
|
const string separator(" #");
|
||||||
std::string name = SDL_GameControllerNameForIndex(i);
|
string name = SDL_GameControllerNameForIndex(i);
|
||||||
name.resize(25);
|
name.resize(25);
|
||||||
name = name + separator + std::to_string(i);
|
name = name + separator + to_string(i);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << name << std::endl;
|
cout << name << endl;
|
||||||
}
|
}
|
||||||
controllerNames.push_back(name);
|
controllerNames.push_back(name);
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ bool Input::discoverGameController()
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
cout << "SDL_GetError() = " << SDL_GetError() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,7 +273,7 @@ bool Input::gameControllerFound()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obten el nombre de un mando de juego
|
// Obten el nombre de un mando de juego
|
||||||
std::string Input::getControllerName(int index)
|
string Input::getControllerName(int index)
|
||||||
{
|
{
|
||||||
if (numGamepads > 0)
|
if (numGamepads > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#ifndef INPUT_H
|
#ifndef INPUT_H
|
||||||
#define INPUT_H
|
#define INPUT_H
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
// Tipos diferentes de eventos de entrada
|
// Tipos diferentes de eventos de entrada
|
||||||
#define INPUT_NULL 0
|
#define INPUT_NULL 0
|
||||||
#define INPUT_UP 1
|
#define INPUT_UP 1
|
||||||
@@ -72,21 +74,21 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
std::vector<GameControllerBindings_t> gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
vector<GameControllerBindings_t> gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
vector<string> controllerNames; // Vector con los nombres de los mandos
|
||||||
int numGamepads; // Numero de mandos conectados
|
int numGamepads; // Numero de mandos conectados
|
||||||
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
||||||
bool verbose; // Indica si ha de mostrar mensajes
|
bool verbose; // Indica si ha de mostrar mensajes
|
||||||
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
||||||
bool enabled; // Indica si está habilitado
|
bool enabled; // Indica si está habilitado
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Input(std::string file);
|
Input(string file);
|
||||||
|
|
||||||
// Actualiza el estado del objeto
|
// Actualiza el estado del objeto
|
||||||
void update();
|
void update();
|
||||||
@@ -113,7 +115,7 @@ public:
|
|||||||
int getNumControllers();
|
int getNumControllers();
|
||||||
|
|
||||||
// Obten el nombre de un mando de juego
|
// Obten el nombre de un mando de juego
|
||||||
std::string getControllerName(int index);
|
string getControllerName(int index);
|
||||||
|
|
||||||
// Establece si ha de mostrar mensajes
|
// Establece si ha de mostrar mensajes
|
||||||
void setVerbose(bool value);
|
void setVerbose(bool value);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
//Menu::Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, std::string file)
|
//Menu::Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, string file)
|
||||||
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file)
|
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, string file)
|
||||||
{
|
{
|
||||||
// Copia punteros
|
// Copia punteros
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
@@ -91,7 +91,7 @@ Menu::~Menu()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga la configuración del menu desde un archivo de texto
|
// Carga la configuración del menu desde un archivo de texto
|
||||||
bool Menu::load(std::string file_path)
|
bool Menu::load(string file_path)
|
||||||
{
|
{
|
||||||
// Indicador de éxito en la carga
|
// Indicador de éxito en la carga
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@@ -99,16 +99,16 @@ bool Menu::load(std::string file_path)
|
|||||||
// Indica si se ha creado ya el objeto de texto
|
// Indica si se ha creado ya el objeto de texto
|
||||||
bool textAllocated = false;
|
bool textAllocated = false;
|
||||||
|
|
||||||
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
const string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||||
std::string line;
|
string line;
|
||||||
std::ifstream file(file_path);
|
ifstream file(file_path);
|
||||||
|
|
||||||
// El fichero se puede abrir
|
// El fichero se puede abrir
|
||||||
if (file.good())
|
if (file.good())
|
||||||
{
|
{
|
||||||
// Procesa el fichero linea a linea
|
// Procesa el fichero linea a linea
|
||||||
std::cout << "Reading file " << filename.c_str() << std::endl;
|
cout << "Reading file " << filename.c_str() << endl;
|
||||||
while (std::getline(file, line))
|
while (getline(file, line))
|
||||||
{
|
{
|
||||||
if (line == "[item]")
|
if (line == "[item]")
|
||||||
{
|
{
|
||||||
@@ -122,7 +122,7 @@ bool Menu::load(std::string file_path)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Lee la siguiente linea
|
// Lee la siguiente linea
|
||||||
std::getline(file, line);
|
getline(file, line);
|
||||||
|
|
||||||
// Encuentra la posición del caracter '='
|
// Encuentra la posición del caracter '='
|
||||||
int pos = line.find("=");
|
int pos = line.find("=");
|
||||||
@@ -130,7 +130,7 @@ bool Menu::load(std::string file_path)
|
|||||||
// Procesa las dos subcadenas
|
// Procesa las dos subcadenas
|
||||||
if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << endl;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ bool Menu::load(std::string file_path)
|
|||||||
// Procesa las dos subcadenas
|
// Procesa las dos subcadenas
|
||||||
if (!setVars(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
if (!setVars(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << endl;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,13 +161,13 @@ bool Menu::load(std::string file_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cierra el fichero
|
// Cierra el fichero
|
||||||
std::cout << "Closing file " << filename.c_str() << std::endl;
|
cout << "Closing file " << filename.c_str() << endl;
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
// El fichero no se puede abrir
|
// El fichero no se puede abrir
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
cout << "Warning: Unable to open " << filename.c_str() << " file" << endl;
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ bool Menu::load(std::string file_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
// Asigna variables a partir de dos cadenas
|
||||||
bool Menu::setItem(item_t *item, std::string var, std::string value)
|
bool Menu::setItem(item_t *item, string var, string value)
|
||||||
{
|
{
|
||||||
// Indicador de éxito en la asignación
|
// Indicador de éxito en la asignación
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@@ -187,7 +187,7 @@ bool Menu::setItem(item_t *item, std::string var, std::string value)
|
|||||||
|
|
||||||
else if (var == "hPaddingDown")
|
else if (var == "hPaddingDown")
|
||||||
{
|
{
|
||||||
item->hPaddingDown = std::stoi(value);
|
item->hPaddingDown = stoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "selectable")
|
else if (var == "selectable")
|
||||||
@@ -218,7 +218,7 @@ bool Menu::setItem(item_t *item, std::string var, std::string value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
// Asigna variables a partir de dos cadenas
|
||||||
bool Menu::setVars(std::string var, std::string value)
|
bool Menu::setVars(string var, string value)
|
||||||
{
|
{
|
||||||
// Indicador de éxito en la asignación
|
// Indicador de éxito en la asignación
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@@ -255,70 +255,70 @@ bool Menu::setVars(std::string var, std::string value)
|
|||||||
|
|
||||||
else if (var == "x")
|
else if (var == "x")
|
||||||
{
|
{
|
||||||
x = std::stoi(value);
|
x = stoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "centerX")
|
else if (var == "centerX")
|
||||||
{
|
{
|
||||||
centerX = std::stoi(value);
|
centerX = stoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "centerY")
|
else if (var == "centerY")
|
||||||
{
|
{
|
||||||
centerY = std::stoi(value);
|
centerY = stoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "y")
|
else if (var == "y")
|
||||||
{
|
{
|
||||||
y = std::stoi(value);
|
y = stoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "backgroundType")
|
else if (var == "backgroundType")
|
||||||
{
|
{
|
||||||
backgroundType = std::stoi(value);
|
backgroundType = stoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "backgroundColor")
|
else if (var == "backgroundColor")
|
||||||
{
|
{
|
||||||
// Se introducen los valores separados por comas en un vector
|
// Se introducen los valores separados por comas en un vector
|
||||||
std::stringstream ss(value);
|
stringstream ss(value);
|
||||||
std::string tmp;
|
string tmp;
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
rectBG.color.r = std::stoi(tmp);
|
rectBG.color.r = stoi(tmp);
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
rectBG.color.g = std::stoi(tmp);
|
rectBG.color.g = stoi(tmp);
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
rectBG.color.b = std::stoi(tmp);
|
rectBG.color.b = stoi(tmp);
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
rectBG.a = std::stoi(tmp);
|
rectBG.a = stoi(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "selector_color")
|
else if (var == "selector_color")
|
||||||
{
|
{
|
||||||
// Se introducen los valores separados por comas en un vector
|
// Se introducen los valores separados por comas en un vector
|
||||||
std::stringstream ss(value);
|
stringstream ss(value);
|
||||||
std::string tmp;
|
string tmp;
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
selector.color.r = std::stoi(tmp);
|
selector.color.r = stoi(tmp);
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
selector.color.g = std::stoi(tmp);
|
selector.color.g = stoi(tmp);
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
selector.color.b = std::stoi(tmp);
|
selector.color.b = stoi(tmp);
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
selector.a = std::stoi(tmp);
|
selector.a = stoi(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "selector_text_color")
|
else if (var == "selector_text_color")
|
||||||
{
|
{
|
||||||
// Se introducen los valores separados por comas en un vector
|
// Se introducen los valores separados por comas en un vector
|
||||||
std::stringstream ss(value);
|
stringstream ss(value);
|
||||||
std::string tmp;
|
string tmp;
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
selector.itemColor.r = std::stoi(tmp);
|
selector.itemColor.r = stoi(tmp);
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
selector.itemColor.g = std::stoi(tmp);
|
selector.itemColor.g = stoi(tmp);
|
||||||
getline(ss, tmp, ',');
|
getline(ss, tmp, ',');
|
||||||
selector.itemColor.b = std::stoi(tmp);
|
selector.itemColor.b = stoi(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "areElementsCenteredOnX")
|
else if (var == "areElementsCenteredOnX")
|
||||||
@@ -338,7 +338,7 @@ bool Menu::setVars(std::string var, std::string value)
|
|||||||
|
|
||||||
else if (var == "defaultActionWhenCancel")
|
else if (var == "defaultActionWhenCancel")
|
||||||
{
|
{
|
||||||
defaultActionWhenCancel = std::stoi(value);
|
defaultActionWhenCancel = stoi(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "")
|
else if (var == "")
|
||||||
@@ -354,7 +354,7 @@ bool Menu::setVars(std::string var, std::string value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga los ficheros de audio
|
// Carga los ficheros de audio
|
||||||
void Menu::loadAudioFile(std::string file, int sound)
|
void Menu::loadAudioFile(string file, int sound)
|
||||||
{
|
{
|
||||||
switch (sound)
|
switch (sound)
|
||||||
{
|
{
|
||||||
@@ -376,7 +376,7 @@ void Menu::loadAudioFile(std::string file, int sound)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el nombre del menu
|
// Obtiene el nombre del menu
|
||||||
std::string Menu::getName()
|
string Menu::getName()
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -475,7 +475,7 @@ int Menu::getWidestItem()
|
|||||||
// Obtenemos la anchura del item mas ancho
|
// Obtenemos la anchura del item mas ancho
|
||||||
for (auto &i : item)
|
for (auto &i : item)
|
||||||
{
|
{
|
||||||
result = std::max(result, i.rect.w);
|
result = max(result, i.rect.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -797,7 +797,7 @@ void Menu::centerMenuElementsOnX()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Añade un item al menu
|
// Añade un item al menu
|
||||||
void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown)
|
void Menu::addItem(string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown)
|
||||||
{
|
{
|
||||||
item_t temp;
|
item_t temp;
|
||||||
|
|
||||||
@@ -833,7 +833,7 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el texto de un item
|
// Cambia el texto de un item
|
||||||
void Menu::setItemCaption(int index, std::string text)
|
void Menu::setItemCaption(int index, string text)
|
||||||
{
|
{
|
||||||
item[index].label = text;
|
item[index].label = text;
|
||||||
item[index].rect.w = this->text->lenght(item[index].label);
|
item[index].rect.w = this->text->lenght(item[index].label);
|
||||||
@@ -954,7 +954,7 @@ int Menu::getSelectorHeight(int value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece el nombre del menu
|
// Establece el nombre del menu
|
||||||
void Menu::setName(std::string name)
|
void Menu::setName(string name)
|
||||||
{
|
{
|
||||||
this->name = name;
|
this->name = name;
|
||||||
}
|
}
|
||||||
@@ -973,7 +973,7 @@ void Menu::setBackgroundType(int value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establece la fuente de texto que se utilizará
|
// Establece la fuente de texto que se utilizará
|
||||||
void Menu::setText(std::string font_png, std::string font_txt)
|
void Menu::setText(string font_png, string font_txt)
|
||||||
{
|
{
|
||||||
if (!text)
|
if (!text)
|
||||||
{
|
{
|
||||||
|
|||||||
34
units/menu.h
34
units/menu.h
@@ -15,6 +15,8 @@
|
|||||||
#ifndef MENU_H
|
#ifndef MENU_H
|
||||||
#define MENU_H
|
#define MENU_H
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
// Tipos de fondos para el menu
|
// Tipos de fondos para el menu
|
||||||
#define MENU_BACKGROUND_TRANSPARENT 0
|
#define MENU_BACKGROUND_TRANSPARENT 0
|
||||||
#define MENU_BACKGROUND_SOLID 1
|
#define MENU_BACKGROUND_SOLID 1
|
||||||
@@ -40,7 +42,7 @@ private:
|
|||||||
|
|
||||||
struct item_t
|
struct item_t
|
||||||
{
|
{
|
||||||
std::string label; // Texto
|
string label; // Texto
|
||||||
SDL_Rect rect; // Rectangulo que delimita el elemento
|
SDL_Rect rect; // Rectangulo que delimita el elemento
|
||||||
int hPaddingDown; // Espaciado bajo el elemento
|
int hPaddingDown; // Espaciado bajo el elemento
|
||||||
bool selectable; // Indica si se puede seleccionar
|
bool selectable; // Indica si se puede seleccionar
|
||||||
@@ -77,7 +79,7 @@ private:
|
|||||||
Input *input; // Gestor de eventos de entrada de teclado o gamepad
|
Input *input; // Gestor de eventos de entrada de teclado o gamepad
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::string name; // Nombre del menu
|
string name; // Nombre del menu
|
||||||
int x; // Posición en el eje X de la primera letra del primer elemento
|
int x; // Posición en el eje X de la primera letra del primer elemento
|
||||||
int y; // Posición en el eje Y de la primera letra del primer elemento
|
int y; // Posición en el eje Y de la primera letra del primer elemento
|
||||||
int h; // Altura del menu
|
int h; // Altura del menu
|
||||||
@@ -96,19 +98,19 @@ private:
|
|||||||
JA_Sound_t* soundMove; // Sonido al mover el selector
|
JA_Sound_t* soundMove; // Sonido al mover el selector
|
||||||
color_t colorGreyed; // Color para los elementos agrisados
|
color_t colorGreyed; // Color para los elementos agrisados
|
||||||
rectangle_t rectBG; // Rectangulo de fondo del menu
|
rectangle_t rectBG; // Rectangulo de fondo del menu
|
||||||
std::vector<item_t> item; // Estructura para cada elemento del menu
|
vector<item_t> item; // Estructura para cada elemento del menu
|
||||||
selector_t selector; // Variables para pintar el selector del menu
|
selector_t selector; // Variables para pintar el selector del menu
|
||||||
std::string font_png;
|
string font_png;
|
||||||
std::string font_txt;
|
string font_txt;
|
||||||
|
|
||||||
// Carga la configuración del menu desde un archivo de texto
|
// Carga la configuración del menu desde un archivo de texto
|
||||||
bool load(std::string file_path);
|
bool load(string file_path);
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
// Asigna variables a partir de dos cadenas
|
||||||
bool setVars(std::string var, std::string value);
|
bool setVars(string var, string value);
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
// Asigna variables a partir de dos cadenas
|
||||||
bool setItem(item_t *item, std::string var, std::string value);
|
bool setItem(item_t *item, string var, string value);
|
||||||
|
|
||||||
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
||||||
void reorganize();
|
void reorganize();
|
||||||
@@ -142,17 +144,17 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
//Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, std::string file = "");
|
//Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, string file = "");
|
||||||
Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file = "");
|
Menu(SDL_Renderer *renderer, Asset *asset, Input *input, string file = "");
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Menu();
|
~Menu();
|
||||||
|
|
||||||
// Carga los ficheros de audio
|
// Carga los ficheros de audio
|
||||||
void loadAudioFile(std::string file, int sound);
|
void loadAudioFile(string file, int sound);
|
||||||
|
|
||||||
// Obtiene el nombre del menu
|
// Obtiene el nombre del menu
|
||||||
std::string getName();
|
string getName();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
// Obtiene el valor de la variable
|
||||||
int getItemSelected();
|
int getItemSelected();
|
||||||
@@ -188,10 +190,10 @@ public:
|
|||||||
void centerMenuElementsOnX();
|
void centerMenuElementsOnX();
|
||||||
|
|
||||||
// Añade un item al menu
|
// Añade un item al menu
|
||||||
void addItem(std::string text, int hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false);
|
void addItem(string text, int hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false);
|
||||||
|
|
||||||
// Cambia el texto de un item
|
// Cambia el texto de un item
|
||||||
void setItemCaption(int index, std::string text);
|
void setItemCaption(int index, string text);
|
||||||
|
|
||||||
// Establece el indice del item que se usará por defecto al cancelar el menu
|
// Establece el indice del item que se usará por defecto al cancelar el menu
|
||||||
void setDefaultActionWhenCancel(int item);
|
void setDefaultActionWhenCancel(int item);
|
||||||
@@ -209,7 +211,7 @@ public:
|
|||||||
void setLinkedDown(int index, bool value);
|
void setLinkedDown(int index, bool value);
|
||||||
|
|
||||||
// Establece el nombre del menu
|
// Establece el nombre del menu
|
||||||
void setName(std::string name);
|
void setName(string name);
|
||||||
|
|
||||||
// Establece la posición del menu
|
// Establece la posición del menu
|
||||||
void setPos(int x, int y);
|
void setPos(int x, int y);
|
||||||
@@ -218,7 +220,7 @@ public:
|
|||||||
void setBackgroundType(int value);
|
void setBackgroundType(int value);
|
||||||
|
|
||||||
// Establece la fuente de texto que se utilizará
|
// Establece la fuente de texto que se utilizará
|
||||||
void setText(std::string font_png, std::string font_txt);
|
void setText(string font_png, string font_txt);
|
||||||
|
|
||||||
// Establece el rectangulo de fondo del menu
|
// Establece el rectangulo de fondo del menu
|
||||||
void setRectSize(int w = 0, int h = 0);
|
void setRectSize(int w = 0, int h = 0);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
||||||
{
|
{
|
||||||
//std::cout << "Construido Screen" << std::endl;
|
//cout << "Construido Screen" << endl;
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
this->window = window;
|
this->window = window;
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
@@ -26,7 +26,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
|||||||
{
|
{
|
||||||
if (options->console)
|
if (options->console)
|
||||||
{
|
{
|
||||||
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_SetTextureBlendMode(gameCanvas, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(gameCanvas, SDL_BLENDMODE_BLEND);
|
||||||
@@ -38,7 +38,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Screen::~Screen()
|
Screen::~Screen()
|
||||||
{
|
{
|
||||||
//std::cout << "Destruido Screen" << std::endl;
|
//cout << "Destruido Screen" << endl;
|
||||||
if (notify != nullptr)
|
if (notify != nullptr)
|
||||||
{
|
{
|
||||||
delete notify;
|
delete notify;
|
||||||
@@ -195,7 +195,7 @@ void Screen::setWindowSize(int size)
|
|||||||
void Screen::decWindowSize()
|
void Screen::decWindowSize()
|
||||||
{
|
{
|
||||||
--options->screen.windowZoom;
|
--options->screen.windowZoom;
|
||||||
options->screen.windowZoom = std::max(options->screen.windowZoom, 1);
|
options->screen.windowZoom = max(options->screen.windowZoom, 1);
|
||||||
setVideoMode(0);
|
setVideoMode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ void Screen::decWindowSize()
|
|||||||
void Screen::incWindowSize()
|
void Screen::incWindowSize()
|
||||||
{
|
{
|
||||||
++options->screen.windowZoom;
|
++options->screen.windowZoom;
|
||||||
options->screen.windowZoom = std::min(options->screen.windowZoom, 4);
|
options->screen.windowZoom = min(options->screen.windowZoom, 4);
|
||||||
setVideoMode(0);
|
setVideoMode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +327,7 @@ void Screen::iniSpectrumFade()
|
|||||||
spectrumColor.clear();
|
spectrumColor.clear();
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
const vector<string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
||||||
for (auto v : vColors)
|
for (auto v : vColors)
|
||||||
{
|
{
|
||||||
spectrumColor.push_back(stringToColor(options->palette, v));
|
spectrumColor.push_back(stringToColor(options->palette, v));
|
||||||
@@ -392,7 +392,7 @@ void Screen::updateNotifier()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void Screen::showNotification(std::string text1, std::string text2, int icon)
|
void Screen::showNotification(string text1, string text2, int icon)
|
||||||
{
|
{
|
||||||
notify->showText(text1, text2, icon);
|
notify->showText(text1, text2, icon);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#ifndef SCREEN_H
|
#ifndef SCREEN_H
|
||||||
#define SCREEN_H
|
#define SCREEN_H
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
#define FILTER_NEAREST 0
|
#define FILTER_NEAREST 0
|
||||||
#define FILTER_LINEAL 1
|
#define FILTER_LINEAL 1
|
||||||
|
|
||||||
@@ -38,7 +40,7 @@ private:
|
|||||||
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
||||||
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
||||||
int spectrumFadeLenght; // Duración del fade spectrum
|
int spectrumFadeLenght; // Duración del fade spectrum
|
||||||
std::vector<color_t> spectrumColor; // Colores para el fade spectrum
|
vector<color_t> spectrumColor; // Colores para el fade spectrum
|
||||||
|
|
||||||
// Inicializa las variables para el fade
|
// Inicializa las variables para el fade
|
||||||
void iniFade();
|
void iniFade();
|
||||||
@@ -133,7 +135,7 @@ public:
|
|||||||
void updateNotifier();
|
void updateNotifier();
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
// Muestra una notificación de texto por pantalla;
|
||||||
void showNotification(std::string text1 = "", std::string text2 = "", int icon = -1);
|
void showNotification(string text1 = "", string text2 = "", int icon = -1);
|
||||||
|
|
||||||
// Actualiza la lógica del objeto
|
// Actualiza la lógica del objeto
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
|
Texture::Texture(SDL_Renderer *renderer, string path, bool verbose)
|
||||||
{
|
{
|
||||||
//std::cout << "Construido Texture" << std::endl;
|
//cout << "Construido Texture" << endl;
|
||||||
// Copia punteros
|
// Copia punteros
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->path = path;
|
this->path = path;
|
||||||
@@ -27,16 +27,16 @@ Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Texture::~Texture()
|
Texture::~Texture()
|
||||||
{
|
{
|
||||||
//std::cout << "Destruido Texture" << std::endl;
|
//cout << "Destruido Texture" << endl;
|
||||||
|
|
||||||
// Libera memoria
|
// Libera memoria
|
||||||
unload();
|
unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga una imagen desde un fichero
|
// Carga una imagen desde un fichero
|
||||||
bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose)
|
bool Texture::loadFromFile(string path, SDL_Renderer *renderer, bool verbose)
|
||||||
{
|
{
|
||||||
const std::string filename = path.substr(path.find_last_of("\\/") + 1);
|
const string filename = path.substr(path.find_last_of("\\/") + 1);
|
||||||
int req_format = STBI_rgb_alpha;
|
int req_format = STBI_rgb_alpha;
|
||||||
int width, height, orig_format;
|
int width, height, orig_format;
|
||||||
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
unsigned char *data = stbi_load(path.c_str(), &width, &height, &orig_format, req_format);
|
||||||
@@ -49,7 +49,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Image loaded: " << filename.c_str() << std::endl;
|
cout << "Image loaded: " << filename.c_str() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Unable to load image " << path.c_str() << std::endl;
|
cout << "Unable to load image " << path.c_str() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -91,7 +91,7 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos
|
|||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << std::endl;
|
cout << "Unable to create texture from " << path.c_str() << "! SDL Error: " << SDL_GetError() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -118,7 +118,7 @@ bool Texture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Tex
|
|||||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||||
if (texture == nullptr)
|
if (texture == nullptr)
|
||||||
{
|
{
|
||||||
std::cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << std::endl;
|
cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#ifndef TEXTURE_H
|
#ifndef TEXTURE_H
|
||||||
#define TEXTURE_H
|
#define TEXTURE_H
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class Texture
|
class Texture
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -17,17 +19,17 @@ private:
|
|||||||
// Variables
|
// Variables
|
||||||
int width; // Ancho de la imagen
|
int width; // Ancho de la imagen
|
||||||
int height; // Alto de la imagen
|
int height; // Alto de la imagen
|
||||||
std::string path; // Ruta de la imagen de la textura
|
string path; // Ruta de la imagen de la textura
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Texture(SDL_Renderer *renderer, std::string path = "", bool verbose = false);
|
Texture(SDL_Renderer *renderer, string path = "", bool verbose = false);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
// Carga una imagen desde un fichero
|
// Carga una imagen desde un fichero
|
||||||
bool loadFromFile(std::string path, SDL_Renderer *renderer, bool verbose = false);
|
bool loadFromFile(string path, SDL_Renderer *renderer, bool verbose = false);
|
||||||
|
|
||||||
// Crea una textura en blanco
|
// Crea una textura en blanco
|
||||||
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
bool createBlank(SDL_Renderer *renderer, int width, int height, SDL_TextureAccess = SDL_TEXTUREACCESS_STREAMING);
|
||||||
|
|||||||
Reference in New Issue
Block a user