Retocados los nombres de las variables de la clase menu

This commit is contained in:
2022-08-23 20:08:28 +02:00
parent f2ea31a564
commit bca15cd29e
7 changed files with 349 additions and 362 deletions

View File

@@ -33,8 +33,8 @@ width=16
height=16 height=16
x=20 x=20
y=8 y=8
vx=0 vx=0.7
vy=0.7 vy=0
x1=5 x1=5
y1=8 y1=8
x2=33 x2=33

View File

@@ -22,8 +22,8 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,239,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,70,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,239,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,70,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,257,258,257,258,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,101,102,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,257,258,257,258,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,101,102,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,289,290,289,290,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,327,328,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,289,290,289,290,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,583,584,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,359,360,69,70,0,0,0,93,94,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,615,616,69,70,0,0,0,93,94,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,189,190,101,102,0,0,0,125,126,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,189,190,101,102,0,0,0,125,126,0,0,0,0,0,0,
263,264,0,0,0,0,0,193,194,0,0,0,0,189,190,0,0,0,0,0,0,0,281,282,277,278,279,274,280,0,0,0,157,158,0,0,0,0,0,0, 263,264,0,0,0,0,0,193,194,0,0,0,0,189,190,0,0,0,0,0,0,0,281,282,277,278,279,274,280,0,0,0,157,158,0,0,0,0,0,0,
295,296,0,0,0,0,0,225,226,0,0,0,0,189,190,0,0,281,275,275,275,275,313,314,309,310,311,312,304,0,0,0,189,190,0,0,0,0,0,0, 295,296,0,0,0,0,0,225,226,0,0,0,0,189,190,0,0,281,275,275,275,275,313,314,309,310,311,312,304,0,0,0,189,190,0,0,0,0,0,0,

View File

@@ -60,12 +60,14 @@ void Enemy::update()
// Comprueba si ha llegado al limite del recorrido para darse media vuelta // Comprueba si ha llegado al limite del recorrido para darse media vuelta
void Enemy::checkPath() void Enemy::checkPath()
{ {
// Comprueba los límites horizontales
if (sprite->getPosX() > p2.x || sprite->getPosX() < p1.x) if (sprite->getPosX() > p2.x || sprite->getPosX() < p1.x)
{ {
sprite->setVelX(sprite->getVelX() * (-1)); sprite->setVelX(sprite->getVelX() * (-1));
sprite->flip(); sprite->flip();
} }
// Comprueba los límites verticales
if (sprite->getPosY() > p2.y || sprite->getPosY() < p1.y) if (sprite->getPosY() > p2.y || sprite->getPosY() < p1.y)
{ {
sprite->setVelY(sprite->getVelY() * (-1)); sprite->setVelY(sprite->getVelY() * (-1));

View File

@@ -5,16 +5,16 @@
Input::Input(std::string file) Input::Input(std::string file)
{ {
// Fichero gamecontrollerdb.txt // Fichero gamecontrollerdb.txt
mDBpath = file; dbPath = file;
// Inicializa las variables // Inicializa las variables
for (int i = 0; i < 17; i++) for (int i = 0; i < 17; i++)
{ {
mKeyBindings[i].scancode = 0; keyBindings[i].scancode = 0;
mKeyBindings[i].active = false; keyBindings[i].active = false;
mGameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID; gameControllerBindings[i].button = SDL_CONTROLLER_BUTTON_INVALID;
mGameControllerBindings[i].active = false; gameControllerBindings[i].active = false;
} }
discoverGameController(); discoverGameController();
@@ -23,20 +23,20 @@ Input::Input(std::string file)
// Destructor // Destructor
Input::~Input() Input::~Input()
{ {
for (int i = 0; i < mNumGamepads; i++) for (int i = 0; i < numGamepads; i++)
mConnectedControllers[i] = nullptr; connectedControllers[i] = nullptr;
} }
// Asigna uno de los posibles inputs a una tecla del teclado // Asigna uno de los posibles inputs a una tecla del teclado
void Input::bindKey(Uint8 input, SDL_Scancode code) void Input::bindKey(Uint8 input, SDL_Scancode code)
{ {
mKeyBindings[input].scancode = code; keyBindings[input].scancode = code;
} }
// Asigna uno de los posibles inputs a un botón del mando // Asigna uno de los posibles inputs a un botón del mando
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button) void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
{ {
mGameControllerBindings[input].button = button; gameControllerBindings[input].button = button;
} }
// Comprueba si un input esta activo // Comprueba si un input esta activo
@@ -54,18 +54,18 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
if (repeat) if (repeat)
{ {
if (mKeystates[mKeyBindings[input].scancode] != 0) if (mKeystates[keyBindings[input].scancode] != 0)
successKeyboard = true; successKeyboard = true;
else else
successKeyboard = false; successKeyboard = false;
} }
else else
{ {
if (!mKeyBindings[input].active) if (!keyBindings[input].active)
{ {
if (mKeystates[mKeyBindings[input].scancode] != 0) if (mKeystates[keyBindings[input].scancode] != 0)
{ {
mKeyBindings[input].active = true; keyBindings[input].active = true;
successKeyboard = true; successKeyboard = true;
} }
else else
@@ -75,9 +75,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
} }
else else
{ {
if (mKeystates[mKeyBindings[input].scancode] == 0) if (mKeystates[keyBindings[input].scancode] == 0)
{ {
mKeyBindings[input].active = false; keyBindings[input].active = false;
successKeyboard = false; successKeyboard = false;
} }
else else
@@ -93,18 +93,18 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
{ {
if (repeat) if (repeat)
{ {
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0) if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
successGameController = true; successGameController = true;
else else
successGameController = false; successGameController = false;
} }
else else
{ {
if (!mGameControllerBindings[input].active) if (!gameControllerBindings[input].active)
{ {
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) != 0) if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
{ {
mGameControllerBindings[input].active = true; gameControllerBindings[input].active = true;
successGameController = true; successGameController = true;
} }
else else
@@ -114,9 +114,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
} }
else else
{ {
if (SDL_GameControllerGetButton(mConnectedControllers[index], mGameControllerBindings[input].button) == 0) if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) == 0)
{ {
mGameControllerBindings[input].active = false; gameControllerBindings[input].active = false;
successGameController = false; successGameController = false;
} }
else else
@@ -138,43 +138,43 @@ bool Input::discoverGameController()
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1) if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
if (SDL_GameControllerAddMappingsFromFile(mDBpath.c_str()) < 0) if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
printf("Error, could not load %s file: %s\n", mDBpath.c_str(), SDL_GetError()); printf("Error, could not load %s file: %s\n", dbPath.c_str(), SDL_GetError());
int nJoysticks = SDL_NumJoysticks(); int nJoysticks = SDL_NumJoysticks();
mNumGamepads = 0; numGamepads = 0;
// Cuenta el numero de mandos // Cuenta el numero de mandos
for (int i = 0; i < nJoysticks; i++) for (int i = 0; i < nJoysticks; i++)
if (SDL_IsGameController(i)) if (SDL_IsGameController(i))
mNumGamepads++; numGamepads++;
printf("\nChecking for game controllers...\n"); printf("\nChecking for game controllers...\n");
printf("%i joysticks found, %i are gamepads\n", nJoysticks, mNumGamepads); printf("%i joysticks found, %i are gamepads\n", nJoysticks, numGamepads);
if (mNumGamepads > 0) if (numGamepads > 0)
{ {
found = true; found = true;
for (int i = 0; i < mNumGamepads; i++) for (int i = 0; i < numGamepads; i++)
{ {
// Abre el mando y lo añade a la lista // Abre el mando y lo añade a la lista
SDL_GameController *pad = SDL_GameControllerOpen(i); SDL_GameController *pad = SDL_GameControllerOpen(i);
if (SDL_GameControllerGetAttached(pad) == 1) if (SDL_GameControllerGetAttached(pad) == 1)
{ {
mConnectedControllers.push_back(pad); connectedControllers.push_back(pad);
std::string separator(" #"); std::string separator(" #");
std::string name = SDL_GameControllerNameForIndex(i); std::string name = SDL_GameControllerNameForIndex(i);
name.resize(25); name.resize(25);
name = name + separator + std::to_string(i); name = name + separator + std::to_string(i);
std::cout << name << std::endl; std::cout << name << std::endl;
mControllerNames.push_back(name); controllerNames.push_back(name);
} }
else else
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl; std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
} }
//mGameController = mConnectedControllers[0]; //mGameController = connectedControllers[0];
SDL_GameControllerEventState(SDL_ENABLE); SDL_GameControllerEventState(SDL_ENABLE);
} }
@@ -184,7 +184,7 @@ bool Input::discoverGameController()
// Comprueba si hay algun mando conectado // Comprueba si hay algun mando conectado
bool Input::gameControllerFound() bool Input::gameControllerFound()
{ {
if (mNumGamepads > 0) if (numGamepads > 0)
return true; return true;
else else
return false; return false;
@@ -193,8 +193,8 @@ 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) std::string Input::getControllerName(int index)
{ {
if (mNumGamepads > 0) if (numGamepads > 0)
return mControllerNames[index]; return controllerNames[index];
else else
return ""; return "";
} }
@@ -202,5 +202,5 @@ std::string Input::getControllerName(int index)
// Obten el numero de mandos conectados // Obten el numero de mandos conectados
int Input::getNumControllers() int Input::getNumControllers()
{ {
return mNumGamepads; return numGamepads;
} }

View File

@@ -41,19 +41,19 @@ private:
Uint8 scancode; // Scancode asociado Uint8 scancode; // Scancode asociado
bool active; // Indica si está activo bool active; // Indica si está activo
}; };
keyBindings_t mKeyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos keyBindings_t keyBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
struct GameControllerBindings_t struct GameControllerBindings_t
{ {
SDL_GameControllerButton button; // GameControllerButton asociado SDL_GameControllerButton button; // GameControllerButton asociado
bool active; // Indica si está activo bool active; // Indica si está activo
}; };
GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos GameControllerBindings_t gameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos
std::vector<SDL_GameController *> mConnectedControllers; // Vector con todos los mandos conectados std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
std::vector<std::string> mControllerNames; // Vector con los nombres de los mandos std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
int mNumGamepads; // Numero de mandos conectados int numGamepads; // Numero de mandos conectados
std::string mDBpath; // Ruta al archivo gamecontrollerdb.txt std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
// Comprueba si hay un mando conectado // Comprueba si hay un mando conectado
bool discoverGameController(); bool discoverGameController();

View File

@@ -2,20 +2,20 @@
#include "menu.h" #include "menu.h"
// Constructor // Constructor
Menu::Menu(SDL_Renderer *renderer, Text *text, Input *input, std::string *fileList) Menu::Menu(SDL_Renderer *renderer, Text *text, Input *input, Asset *asset)
{ {
mRenderer = renderer; this->renderer = renderer;
mText = text; this->text = text;
mInput = input; this->input = input;
mFileList = fileList; this->asset = asset;
} }
Menu::~Menu() Menu::~Menu()
{ {
mRenderer = nullptr; renderer = nullptr;
mText = nullptr; text = nullptr;
mInput = nullptr; input = nullptr;
mFileList = nullptr; asset = nullptr;
} }
// Inicializador // Inicializador
@@ -24,56 +24,51 @@ void Menu::init(std::string name, int x, int y, int backgroundType)
loadMedia(); loadMedia();
// Inicia variables // Inicia variables
mName = name; this->name = name;
mSelector.index = 0; selector.index = 0;
mTotalItems = 0; totalItems = 0;
mItemSelected = MENU_NO_OPTION; itemSelected = MENU_NO_OPTION;
mPosX = x; this->x = x;
mPosY = y; this->y = y;
mRectBG.rect.x = 0; rectBG.rect = {0,0,0,0};
mRectBG.rect.y = 0; rectBG.color = {0,0,0};
mRectBG.rect.w = 0; rectBG.a = 0;
mRectBG.rect.h = 0; this->backgroundType = backgroundType;
mRectBG.r = 0; isCenteredOnX = false;
mRectBG.g = 0; isCenteredOnY = false;
mRectBG.b = 0; areElementsCenteredOnX = false;
mBackgroundType = backgroundType; centerX = 0;
mIsCenteredOnX = false; centerY = 0;
mIsCenteredOnY = false; widestItem = 0;
mAreElementsCenteredOnX = false; colorGreyed = {128, 128, 128};
mCenterX = 0;
mCenterY = 0;
mWidestItem = 0;
mColorGreyed = {128, 128, 128};
// Selector // Selector
mSelector.originY = 0; selector.originY = 0;
mSelector.targetY = 0; selector.targetY = 0;
mSelector.despY = 0; selector.despY = 0;
mSelector.originH = 0; selector.originH = 0;
mSelector.targetH = 0; selector.targetH = 0;
mSelector.incH = 0; selector.incH = 0;
mSelector.y = 0.0f; selector.y = 0.0f;
mSelector.h = 0.0f; selector.h = 0.0f;
mSelector.numJumps = 8; selector.numJumps = 8;
mSelector.moving = false; selector.moving = false;
mSelector.resizing = false; selector.resizing = false;
mSelector.rect = {0, 0, 0, 0}; selector.rect = {0, 0, 0, 0};
mSelector.r = 0; selector.color = {0,0,0};
mSelector.g = 0; selector.itemColor = {0,0,0};
mSelector.b = 0; selector.a = 255;
mSelector.a = 255;
// Elementos del menu // Elementos del menu
for (int i = 0; i < MENU_MAX_ITEMS; i++) for (int i = 0; i < MENU_MAX_ITEMS; i++)
{ {
mItem[i].label = ""; item[i].label = "";
mItem[i].rect = {0, 0, 0, 0}; item[i].rect = {0, 0, 0, 0};
mItem[i].hPaddingDown = 0; item[i].hPaddingDown = 0;
mItem[i].selectable = false; item[i].selectable = false;
mItem[i].greyed = false; item[i].greyed = false;
mItem[i].linkedDown = false; item[i].linkedDown = false;
mItem[i].linkedUp = false; item[i].linkedUp = false;
} }
} }
@@ -84,9 +79,9 @@ bool Menu::loadMedia()
bool success = true; bool success = true;
// Sonidos // Sonidos
mSoundMove = JA_LoadSound(mFileList[17].c_str()); soundMove = JA_LoadSound(asset->get("").c_str());
mSoundAccept = JA_LoadSound(mFileList[18].c_str()); soundAccept = JA_LoadSound(asset->get("").c_str());
mSoundCancel = JA_LoadSound(mFileList[16].c_str()); soundCancel = JA_LoadSound(asset->get("").c_str());
return success; return success;
} }
@@ -94,102 +89,102 @@ bool Menu::loadMedia()
// Obtiene el nombre del menu // Obtiene el nombre del menu
std::string Menu::getName() std::string Menu::getName()
{ {
return mName; return name;
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable
Uint8 Menu::getItemSelected() int Menu::getItemSelected()
{ {
// Al llamar a esta funcion, se obtiene el valor y se borra // Al llamar a esta funcion, se obtiene el valor y se borra
const int temp = mItemSelected; const int temp = itemSelected;
mItemSelected = MENU_NO_OPTION; itemSelected = MENU_NO_OPTION;
return temp; return temp;
} }
// Actualiza la posicion y el estado del selector // Actualiza la posicion y el estado del selector
void Menu::updateSelector() void Menu::updateSelector()
{ {
if (mSelector.moving) if (selector.moving)
{ {
// Calcula el desplazamiento en Y // Calcula el desplazamiento en Y
mSelector.y += mSelector.despY; selector.y += selector.despY;
if (mSelector.despY > 0) // Va hacia abajo if (selector.despY > 0) // Va hacia abajo
{ {
if (mSelector.y > mSelector.targetY) // Ha llegado al destino if (selector.y > selector.targetY) // Ha llegado al destino
{ {
mSelector.originY = mSelector.y = mSelector.targetY; selector.originY = selector.y = selector.targetY;
mSelector.moving = false; selector.moving = false;
} }
} }
if (mSelector.despY < 0) // Va hacia arriba if (selector.despY < 0) // Va hacia arriba
{ {
if (mSelector.y < mSelector.targetY) // Ha llegado al destino if (selector.y < selector.targetY) // Ha llegado al destino
{ {
mSelector.originY = mSelector.y = mSelector.targetY; selector.originY = selector.y = selector.targetY;
mSelector.moving = false; selector.moving = false;
} }
} }
mSelector.rect.y = int(mSelector.y); selector.rect.y = int(selector.y);
} }
else else
{ {
mSelector.rect.y = int(mSelector.y); selector.rect.y = int(selector.y);
} }
if (mSelector.resizing) if (selector.resizing)
{ {
// Calcula el incremento en H // Calcula el incremento en H
mSelector.h += mSelector.incH; selector.h += selector.incH;
if (mSelector.incH > 0) // Crece if (selector.incH > 0) // Crece
{ {
if (mSelector.h > mSelector.targetH) // Ha llegado al destino if (selector.h > selector.targetH) // Ha llegado al destino
{ {
//mSelector.originH = mSelector.targetH = mSelector.rect.h = getSelectorHeight(mSelector.index); //selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index);
mSelector.originH = mSelector.h = mSelector.targetH; selector.originH = selector.h = selector.targetH;
mSelector.resizing = false; selector.resizing = false;
} }
} }
if (mSelector.incH < 0) // Decrece if (selector.incH < 0) // Decrece
{ {
if (mSelector.h < mSelector.targetH) // Ha llegado al destino if (selector.h < selector.targetH) // Ha llegado al destino
{ {
//mSelector.originH = mSelector.targetH = mSelector.rect.h = getSelectorHeight(mSelector.index); //selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index);
mSelector.originH = mSelector.h = mSelector.targetH; selector.originH = selector.h = selector.targetH;
mSelector.resizing = false; selector.resizing = false;
} }
} }
mSelector.rect.h = int(mSelector.h); selector.rect.h = int(selector.h);
} }
else else
{ {
mSelector.rect.h = getSelectorHeight(mSelector.index); selector.rect.h = getSelectorHeight(selector.index);
} }
} }
// Coloca el selector en una posición específica // Coloca el selector en una posición específica
void Menu::setSelectorPos(Uint8 index) void Menu::setSelectorPos(int index)
{ {
if (index < mTotalItems) if (index < totalItems)
{ {
mSelector.index = index; selector.index = index;
mSelector.rect.y = mSelector.y = mSelector.originY = mSelector.targetY = mItem[mSelector.index].rect.y; selector.rect.y = selector.y = selector.originY = selector.targetY = item[selector.index].rect.y;
mSelector.rect.w = mRectBG.rect.w; selector.rect.w = rectBG.rect.w;
mSelector.rect.x = mRectBG.rect.x; selector.rect.x = rectBG.rect.x;
mSelector.originH = mSelector.targetH = mSelector.rect.h = getSelectorHeight(mSelector.index); selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index);
mSelector.moving = false; selector.moving = false;
mSelector.resizing = false; selector.resizing = false;
} }
} }
// Obtiene la anchura del elemento más ancho del menu // Obtiene la anchura del elemento más ancho del menu
Uint16 Menu::getWidestItem() int Menu::getWidestItem()
{ {
Uint16 result = 0; int result = 0;
// Obtenemos la anchura del item mas ancho // Obtenemos la anchura del item mas ancho
for (int i = 0; i < mTotalItems; i++) for (int i = 0; i < totalItems; i++)
if (mItem[i].rect.w > result) if (item[i].rect.w > result)
result = mItem[i].rect.w; result = item[i].rect.w;
return result; return result;
} }
@@ -197,23 +192,23 @@ Uint16 Menu::getWidestItem()
// Deja el menu apuntando al primer elemento // Deja el menu apuntando al primer elemento
void Menu::reset() void Menu::reset()
{ {
mItemSelected = MENU_NO_OPTION; itemSelected = MENU_NO_OPTION;
mSelector.index = 0; selector.index = 0;
mSelector.originY = mSelector.targetY = mSelector.y = mItem[0].rect.y; selector.originY = selector.targetY = selector.y = item[0].rect.y;
mSelector.originH = mSelector.targetH = mItem[0].rect.h; selector.originH = selector.targetH = item[0].rect.h;
mSelector.moving = false; selector.moving = false;
mSelector.resizing = false; selector.resizing = false;
} }
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño // Actualiza el menu para recolocarlo correctamente y establecer el tamaño
void Menu::reorganize() void Menu::reorganize()
{ {
setRectSize(); setRectSize();
if (mIsCenteredOnX) if (isCenteredOnX)
centerMenuOnX(mCenterX); centerMenuOnX(centerX);
if (mIsCenteredOnY) if (isCenteredOnY)
centerMenuOnY(mCenterY); centerMenuOnY(centerY);
if (mAreElementsCenteredOnX) if (areElementsCenteredOnX)
centerMenuElementsOnX(); centerMenuElementsOnX();
} }
@@ -223,28 +218,28 @@ bool Menu::increaseSelectorIndex()
bool success = false; bool success = false;
// Obten las coordenadas del elemento actual // Obten las coordenadas del elemento actual
mSelector.y = mSelector.originY = mItem[mSelector.index].rect.y; selector.y = selector.originY = item[selector.index].rect.y;
mSelector.h = mSelector.originH = getSelectorHeight(mSelector.index); selector.h = selector.originH = getSelectorHeight(selector.index);
// Calcula cual es el siguiente elemento // Calcula cual es el siguiente elemento
++mSelector.index %= mTotalItems; ++selector.index %= totalItems;
while (!mItem[mSelector.index].selectable) while (!item[selector.index].selectable)
//mSelector.index++; //selector.index++;
++mSelector.index %= mTotalItems; ++selector.index %= totalItems;
success = true; success = true;
// Establece las coordenadas y altura de destino // Establece las coordenadas y altura de destino
if (success) if (success)
{ {
mSelector.targetY = mItem[mSelector.index].rect.y; selector.targetY = item[selector.index].rect.y;
mSelector.despY = (mSelector.targetY - mSelector.originY) / mSelector.numJumps; selector.despY = (selector.targetY - selector.originY) / selector.numJumps;
mSelector.targetH = getSelectorHeight(mSelector.index); selector.targetH = getSelectorHeight(selector.index);
mSelector.incH = (mSelector.targetH - mSelector.originH) / mSelector.numJumps; selector.incH = (selector.targetH - selector.originH) / selector.numJumps;
mSelector.moving = true; selector.moving = true;
if (mSelector.incH != 0) if (selector.incH != 0)
mSelector.resizing = true; selector.resizing = true;
} }
return success; return success;
@@ -256,35 +251,35 @@ bool Menu::decreaseSelectorIndex()
bool success = false; bool success = false;
// Obten las coordenadas del elemento actual // Obten las coordenadas del elemento actual
mSelector.y = mSelector.originY = mItem[mSelector.index].rect.y; selector.y = selector.originY = item[selector.index].rect.y;
mSelector.h = mSelector.originH = getSelectorHeight(mSelector.index); selector.h = selector.originH = getSelectorHeight(selector.index);
// Calcula cual es el siguiente elemento // Calcula cual es el siguiente elemento
if (mSelector.index == 0) if (selector.index == 0)
mSelector.index = mTotalItems; selector.index = totalItems;
else else
mSelector.index--; selector.index--;
while (!mItem[mSelector.index].selectable) while (!item[selector.index].selectable)
{ {
if (mSelector.index == 0) if (selector.index == 0)
mSelector.index = mTotalItems; selector.index = totalItems;
else else
mSelector.index--; selector.index--;
} }
success = true; success = true;
// Establece las coordenadas y altura de destino // Establece las coordenadas y altura de destino
if (success) if (success)
{ {
mSelector.targetY = mItem[mSelector.index].rect.y; selector.targetY = item[selector.index].rect.y;
mSelector.despY = (mSelector.targetY - mSelector.originY) / mSelector.numJumps; selector.despY = (selector.targetY - selector.originY) / selector.numJumps;
mSelector.targetH = getSelectorHeight(mSelector.index); selector.targetH = getSelectorHeight(selector.index);
mSelector.incH = (mSelector.targetH - mSelector.originH) / mSelector.numJumps; selector.incH = (selector.targetH - selector.originH) / selector.numJumps;
mSelector.moving = true; selector.moving = true;
if (mSelector.incH != 0) if (selector.incH != 0)
mSelector.resizing = true; selector.resizing = true;
} }
return success; return success;
@@ -300,52 +295,52 @@ void Menu::update()
void Menu::render() void Menu::render()
{ {
// Rendereritza el fondo del menu // Rendereritza el fondo del menu
if (mBackgroundType == MENU_BACKGROUND_SOLID) if (backgroundType == MENU_BACKGROUND_SOLID)
{ {
SDL_SetRenderDrawColor(mRenderer, mRectBG.r, mRectBG.g, mRectBG.b, mRectBG.a); SDL_SetRenderDrawColor(renderer, rectBG.color.r, rectBG.color.g, rectBG.color.b, rectBG.a);
SDL_RenderFillRect(mRenderer, &mRectBG.rect); SDL_RenderFillRect(renderer, &rectBG.rect);
} }
// Renderiza el rectangulo del selector // Renderiza el rectangulo del selector
SDL_Rect temp = mSelector.rect; SDL_Rect temp = selector.rect;
temp.y--; temp.y--;
temp.h++; temp.h++;
SDL_SetRenderDrawColor(mRenderer, mSelector.r, mSelector.g, mSelector.b, mSelector.a); SDL_SetRenderDrawColor(renderer, selector.color.r, selector.color.g, selector.color.b, selector.a);
SDL_RenderFillRect(mRenderer, &temp); SDL_RenderFillRect(renderer, &temp);
// Renderiza el borde del fondo // Renderiza el borde del fondo
if (mBackgroundType == MENU_BACKGROUND_SOLID) if (backgroundType == MENU_BACKGROUND_SOLID)
{ {
SDL_SetRenderDrawColor(mRenderer, mRectBG.r, mRectBG.g, mRectBG.b, 255); SDL_SetRenderDrawColor(renderer, rectBG.color.r, rectBG.color.g, rectBG.color.b, 255);
SDL_RenderDrawRect(mRenderer, &mRectBG.rect); SDL_RenderDrawRect(renderer, &rectBG.rect);
} }
// Renderitza el texto // Renderitza el texto
for (int i = 0; i < mTotalItems; i++) for (int i = 0; i < totalItems; i++)
{ {
if (i == mSelector.index) if (i == selector.index)
{ {
const color_t color = {mSelector.itemR, mSelector.itemG, mSelector.itemB}; const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
mText->writeColored(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label, color); text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
} }
else if (mItem[i].selectable) else if (item[i].selectable)
{ {
mText->write(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label); text->write(item[i].rect.x, item[i].rect.y, item[i].label);
} }
else if (mItem[i].greyed) else if (item[i].greyed)
{ {
mText->writeColored(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label, mColorGreyed); text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, colorGreyed);
} }
else // No seleccionable else // No seleccionable
{ {
if ((mItem[i].linkedUp) && (i == mSelector.index + 1)) if ((item[i].linkedUp) && (i == selector.index + 1))
{ {
const color_t color = {mSelector.itemR, mSelector.itemG, mSelector.itemB}; const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
mText->writeColored(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label, color); text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
} }
else // No enlazado con el de arriba else // No enlazado con el de arriba
{ {
mText->write(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label); text->write(item[i].rect.x, item[i].rect.y, item[i].label);
} }
} }
} }
@@ -354,65 +349,59 @@ void Menu::render()
// Establece el rectangulo de fondo del menu y el selector // Establece el rectangulo de fondo del menu y el selector
void Menu::setRectSize() void Menu::setRectSize()
{ {
mRectBG.rect.w = findWidth() + mText->getCharacterWidth(); rectBG.rect.w = findWidth() + text->getCharacterWidth();
mRectBG.rect.h = findHeight() + mText->getCharacterWidth(); rectBG.rect.h = findHeight() + text->getCharacterWidth();
// La posición X es la del menú menos medio caracter // La posición X es la del menú menos medio caracter
mRectBG.rect.x = mPosX - (mText->getCharacterWidth() / 2); rectBG.rect.x = x - (text->getCharacterWidth() / 2);
// La posición Y es la del menu menos la altura de medio caracter // La posición Y es la del menu menos la altura de medio caracter
mRectBG.rect.y = mPosY - (mText->getCharacterWidth() / 2); rectBG.rect.y = y - (text->getCharacterWidth() / 2);
// Establecemos los valores del rectangulo del selector a partir de los valores del rectangulo de fondo // Establecemos los valores del rectangulo del selector a partir de los valores del rectangulo de fondo
setSelectorPos(mSelector.index); setSelectorPos(selector.index);
} }
// Establece el valor de la variable // Establece el valor de la variable
void Menu::setTotalItems(int num) void Menu::setTotalItems(int num)
{ {
mTotalItems = num; totalItems = num;
if (mTotalItems > MENU_MAX_ITEMS) if (totalItems > MENU_MAX_ITEMS)
mTotalItems = MENU_MAX_ITEMS; totalItems = MENU_MAX_ITEMS;
} }
// Establece el color del rectangulo de fondo // Establece el color del rectangulo de fondo
void Menu::setBackgroundColor(int r, int g, int b, int alpha) void Menu::setBackgroundColor(color_t color, int alpha)
{ {
mRectBG.r = r; rectBG.color = color;
mRectBG.g = g; rectBG.a = alpha;
mRectBG.b = b;
mRectBG.a = alpha;
} }
// Establece el color del rectangulo del selector // Establece el color del rectangulo del selector
void Menu::setSelectorColor(int r, int g, int b, int alpha) void Menu::setSelectorColor(color_t color, int alpha)
{ {
mSelector.r = r; selector.color = color;
mSelector.g = g; selector.a = alpha;
mSelector.b = b;
mSelector.a = alpha;
} }
// Establece el color del texto del selector // Establece el color del texto del selector
void Menu::setSelectorTextColor(int r, int g, int b) void Menu::setSelectorTextColor(color_t color)
{ {
mSelector.itemR = r; selector.itemColor = color;
mSelector.itemG = g;
mSelector.itemB = b;
} }
// Centra el menu respecto un punto en el eje X // Centra el menu respecto un punto en el eje X
void Menu::centerMenuOnX(int value) void Menu::centerMenuOnX(int value)
{ {
mIsCenteredOnX = true; isCenteredOnX = true;
mCenterX = value; centerX = value;
// Establece la nueva posición centrada en funcion del elemento más ancho // Establece la nueva posición centrada en funcion del elemento más ancho
mPosX = (value) - (findWidth() / 2); x = (value) - (findWidth() / 2);
// Reposiciona los elementos del menu // Reposiciona los elementos del menu
for (int i = 0; i < MENU_MAX_ITEMS; i++) for (int i = 0; i < MENU_MAX_ITEMS; i++)
mItem[i].rect.x = mPosX; item[i].rect.x = x;
// Recalcula el rectangulo de fondo // Recalcula el rectangulo de fondo
setRectSize(); setRectSize();
@@ -421,11 +410,11 @@ void Menu::centerMenuOnX(int value)
// Centra el menu respecto un punto en el eje Y // Centra el menu respecto un punto en el eje Y
void Menu::centerMenuOnY(int value) void Menu::centerMenuOnY(int value)
{ {
mIsCenteredOnY = true; isCenteredOnY = true;
mCenterY = value; centerY = value;
// Establece la nueva posición centrada en funcion del elemento más ancho // Establece la nueva posición centrada en funcion del elemento más ancho
mPosY = (value) - (findHeight() / 2); y = (value) - (findHeight() / 2);
// Reposiciona los elementos del menu // Reposiciona los elementos del menu
replaceElementsOnY(); replaceElementsOnY();
@@ -437,126 +426,126 @@ void Menu::centerMenuOnY(int value)
// Centra los elementos del menu en el eje X // Centra los elementos del menu en el eje X
void Menu::centerMenuElementsOnX() void Menu::centerMenuElementsOnX()
{ {
mAreElementsCenteredOnX = true; areElementsCenteredOnX = true;
for (int i = 0; i < mTotalItems; i++) for (int i = 0; i < totalItems; i++)
mItem[i].rect.x = (mCenterX - (mItem[i].rect.w / 2)); item[i].rect.x = (centerX - (item[i].rect.w / 2));
} }
// Añade un item al menu // Añade un item al menu
void Menu::addItem(std::string text, Uint8 hPaddingDown, bool selectable, bool greyed, bool linkedDown) void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown)
{ {
// Si es el primer item coge la posición en el eje Y del propio menu // Si es el primer item coge la posición en el eje Y del propio menu
if (mTotalItems == 0) if (totalItems == 0)
mItem[mTotalItems].rect.y = mPosY; item[totalItems].rect.y = y;
else else
// En caso contrario, coge la posición en el eje Y a partir del elemento anterior // En caso contrario, coge la posición en el eje Y a partir del elemento anterior
mItem[mTotalItems].rect.y = mItem[mTotalItems - 1].rect.y + mItem[mTotalItems - 1].rect.h + mItem[mTotalItems - 1].hPaddingDown; item[totalItems].rect.y = item[totalItems - 1].rect.y + item[totalItems - 1].rect.h + item[totalItems - 1].hPaddingDown;
setItemCaption(mTotalItems, text); setItemCaption(totalItems, text);
mItem[mTotalItems].rect.x = mPosX; item[totalItems].rect.x = x;
mItem[mTotalItems].hPaddingDown = hPaddingDown; item[totalItems].hPaddingDown = hPaddingDown;
mItem[mTotalItems].selectable = selectable; item[totalItems].selectable = selectable;
mItem[mTotalItems].greyed = greyed; item[totalItems].greyed = greyed;
mItem[mTotalItems].linkedDown = linkedDown; item[totalItems].linkedDown = linkedDown;
if (mTotalItems > 0) if (totalItems > 0)
if (mItem[mTotalItems - 1].linkedDown) if (item[totalItems - 1].linkedDown)
mItem[mTotalItems].linkedUp = true; item[totalItems].linkedUp = true;
setTotalItems(mTotalItems + 1); setTotalItems(totalItems + 1);
mCenterX = mPosX + (findWidth() / 2); centerX = x + (findWidth() / 2);
reorganize(); reorganize();
} }
// Cambia el texto de un item // Cambia el texto de un item
void Menu::setItemCaption(Uint8 index, std::string text) void Menu::setItemCaption(int index, std::string text)
{ {
mItem[index].label = text; item[index].label = text;
mItem[index].rect.w = mText->lenght(mItem[index].label); item[index].rect.w = this->text->lenght(item[index].label);
mItem[index].rect.h = mText->getCharacterWidth(); item[index].rect.h = this->text->getCharacterWidth();
reorganize(); reorganize();
} }
// Establece el indice del itemm que se usará por defecto al cancelar el menu // Establece el indice del itemm que se usará por defecto al cancelar el menu
void Menu::setDefaultActionWhenCancel(Uint8 item) void Menu::setDefaultActionWhenCancel(int item)
{ {
mDefaultActionWhenCancel = item; defaultActionWhenCancel = item;
} }
// Gestiona la entrada de teclado y mando durante el menu // Gestiona la entrada de teclado y mando durante el menu
void Menu::checkInput() void Menu::checkInput()
{ {
if (mInput->checkInput(INPUT_UP, REPEAT_FALSE)) if (input->checkInput(INPUT_UP, REPEAT_FALSE))
if (decreaseSelectorIndex()) if (decreaseSelectorIndex())
JA_PlaySound(mSoundMove); JA_PlaySound(soundMove);
if (mInput->checkInput(INPUT_DOWN, REPEAT_FALSE)) if (input->checkInput(INPUT_DOWN, REPEAT_FALSE))
if (increaseSelectorIndex()) if (increaseSelectorIndex())
JA_PlaySound(mSoundMove); JA_PlaySound(soundMove);
if (mInput->checkInput(INPUT_ACCEPT, REPEAT_FALSE)) if (input->checkInput(INPUT_ACCEPT, REPEAT_FALSE))
{ {
mItemSelected = mSelector.index; itemSelected = selector.index;
JA_PlaySound(mSoundAccept); JA_PlaySound(soundAccept);
} }
if (mInput->checkInput(INPUT_CANCEL, REPEAT_FALSE)) if (input->checkInput(INPUT_CANCEL, REPEAT_FALSE))
{ {
mItemSelected = mDefaultActionWhenCancel; itemSelected = defaultActionWhenCancel;
JA_PlaySound(mSoundCancel); JA_PlaySound(soundCancel);
} }
} }
// Calcula el ancho del menu // Calcula el ancho del menu
Uint16 Menu::findWidth() int Menu::findWidth()
{ {
return getWidestItem(); return getWidestItem();
} }
// Calcula el alto del menu // Calcula el alto del menu
Uint16 Menu::findHeight() int Menu::findHeight()
{ {
Uint16 height = 0; int height = 0;
// Obtenemos la altura de la suma de alturas de los items // Obtenemos la altura de la suma de alturas de los items
for (int i = 0; i < mTotalItems; i++) for (int i = 0; i < totalItems; i++)
height += mItem[i].rect.h + mItem[i].hPaddingDown; height += item[i].rect.h + item[i].hPaddingDown;
return height - mItem[mTotalItems - 1].hPaddingDown; return height - item[totalItems - 1].hPaddingDown;
} }
// Recoloca los elementos del menu en el eje Y // Recoloca los elementos del menu en el eje Y
void Menu::replaceElementsOnY() void Menu::replaceElementsOnY()
{ {
mItem[0].rect.y = mPosY; item[0].rect.y = y;
for (int i = 1; i < mTotalItems; i++) for (int i = 1; i < totalItems; i++)
mItem[i].rect.y = mItem[i - 1].rect.y + mItem[i - 1].rect.h + mItem[i - 1].hPaddingDown; item[i].rect.y = item[i - 1].rect.y + item[i - 1].rect.h + item[i - 1].hPaddingDown;
} }
// Establece el estado seleccionable de un item // Establece el estado seleccionable de un item
void Menu::setSelectable(Uint8 index, bool value) void Menu::setSelectable(int index, bool value)
{ {
mItem[index].selectable = value; item[index].selectable = value;
} }
// Establece el estado agrisado de un item // Establece el estado agrisado de un item
void Menu::setGreyed(Uint8 index, bool value) void Menu::setGreyed(int index, bool value)
{ {
mItem[index].greyed = value; item[index].greyed = value;
} }
// Establece el estado de enlace de un item // Establece el estado de enlace de un item
void Menu::setLinkedDown(Uint8 index, bool value) void Menu::setLinkedDown(int index, bool value)
{ {
mItem[index].linkedDown = value; item[index].linkedDown = value;
} }
// Calcula la altura del selector // Calcula la altura del selector
int Menu::getSelectorHeight(int value) int Menu::getSelectorHeight(int value)
{ {
if (mItem[value].linkedDown) if (item[value].linkedDown)
return mItem[value].rect.h + mItem[value].hPaddingDown + mItem[value + 1].rect.h; return item[value].rect.h + item[value].hPaddingDown + item[value + 1].rect.h;
else else
return mItem[value].rect.h; return item[value].rect.h;
} }

View File

@@ -4,6 +4,8 @@
#include "sprite.h" #include "sprite.h"
#include "text.h" #include "text.h"
#include "input.h" #include "input.h"
#include "asset.h"
#include "utils.h"
#include "jail_audio.h" #include "jail_audio.h"
#ifndef MENU_H #ifndef MENU_H
@@ -23,76 +25,70 @@
class Menu class Menu
{ {
private: private:
std::string mName; // Nombre del menu std::string name; // Nombre del menu
int mPosX; // 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 mPosY; // 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
Uint16 mHeight; // Altura del menu int h; // Altura del menu
Uint16 mWidth; // Anchura del menu int w; // Anchura del menu
Uint8 mTotalItems; // Numero total de items del menu int totalItems; // Numero total de items del menu
int mItemSelected; // Índice del item del menu que ha sido seleccionado int itemSelected; // Índice del item del menu que ha sido seleccionado
Uint8 mDefaultActionWhenCancel; // Indice del item del menu que se selecciona cuando se cancela el menu int defaultActionWhenCancel; // Indice del item del menu que se selecciona cuando se cancela el menu
Uint8 mBackgroundType; // Tipo de fondo para el menu int backgroundType; // Tipo de fondo para el menu
bool mIsCenteredOnX; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje X int centerX; // Centro del menu en el eje X
bool mIsCenteredOnY; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y int centerY; // Centro del menu en el eje Y
int mCenterX; // Centro del menu en el eje X bool isCenteredOnX; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje X
int mCenterY; // Centro del menu en el eje Y bool isCenteredOnY; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y
bool mAreElementsCenteredOnX; // Variable para saber si los elementos van centrados en el eje X bool areElementsCenteredOnX; // Variable para saber si los elementos van centrados en el eje X
Uint16 mWidestItem; // Anchura del elemento más ancho int widestItem; // Anchura del elemento más ancho
JA_Sound mSoundAccept; // Sonido al aceptar o elegir una opción del menu JA_Sound soundAccept; // Sonido al aceptar o elegir una opción del menu
JA_Sound mSoundCancel; // Sonido al cancelar el menu JA_Sound soundCancel; // Sonido al cancelar el menu
JA_Sound mSoundMove; // Sonido al mover el selector JA_Sound soundMove; // Sonido al mover el selector
SDL_Renderer *mRenderer; // Puntero al renderizador de la ventana SDL_Renderer *renderer; // Puntero al renderizador de la ventana
std::string *mFileList; // Lista de ficheros Asset *asset; // Objeto encargado de gestionar los ficheros de recursos
Text *mText; // Texto para poder escribir los items del menu Text *text; // Texto para poder escribir los items del menu
Input *mInput; // Gestor de eventos de entrada de teclado o gamepad Input *input; // Gestor de eventos de entrada de teclado o gamepad
color_t mColorGreyed; // Color para los elementos agrisados color_t colorGreyed; // Color para los elementos agrisados
struct rectangle struct rectangle_t
{ {
SDL_Rect rect; // Rectangulo SDL_Rect rect; // Rectangulo
Uint8 r; // Rojo color_t color; // Color
Uint8 g; // Verde int a; // Transparencia
Uint8 b; // Azul
Uint8 a; // Transparencia
}; };
rectangle mRectBG; // Rectangulo de fondo del menu rectangle_t rectBG; // Rectangulo de fondo del menu
struct item struct item_t
{ {
std::string label; // Texto std::string label; // Texto
SDL_Rect rect; // Rectangulo que delimita el elemento SDL_Rect rect; // Rectangulo que delimita el elemento
Uint8 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
bool greyed; // Indica si ha de aparecer con otro color mas oscuro bool greyed; // Indica si ha de aparecer con otro color mas oscuro
bool linkedDown; // Indica si el elemento actual y el siguiente se tratan como uno solo. Afecta al selector bool linkedDown; // Indica si el elemento actual y el siguiente se tratan como uno solo. Afecta al selector
bool linkedUp; // Indica si el elemento actual y el anterior se tratan como uno solo. Afecta al selector bool linkedUp; // Indica si el elemento actual y el anterior se tratan como uno solo. Afecta al selector
}; };
item mItem[MENU_MAX_ITEMS]; // Estructura para cada elemento del menu item_t item[MENU_MAX_ITEMS]; // Estructura para cada elemento del menu
struct selector struct selector_t
{ {
float originY; // Coordenada de origen float originY; // Coordenada de origen
float targetY; // Coordenada de destino float targetY; // Coordenada de destino
float despY; // Cantidad de pixeles que se desplaza el selector en cada salto: (target - origin) / numJumps float despY; // Cantidad de pixeles que se desplaza el selector en cada salto: (target - origin) / numJumps
bool moving; // Indica si el selector está avanzando hacia el destino bool moving; // Indica si el selector está avanzando hacia el destino
float originH; // Altura de origen float originH; // Altura de origen
float targetH; // Altura de destino float targetH; // Altura de destino
float incH; // Cantidad de pixels que debe incrementar o decrementar el selector en cada salto float incH; // Cantidad de pixels que debe incrementar o decrementar el selector en cada salto
bool resizing; // Indica si el selector está cambiando de tamaño bool resizing; // Indica si el selector está cambiando de tamaño
float y; // Coordenada actual, usado para el desplazamiento float y; // Coordenada actual, usado para el desplazamiento
float h; // Altura actual, usado para el cambio de tamaño float h; // Altura actual, usado para el cambio de tamaño
Uint8 numJumps; // Numero de pasos preestablecido para llegar al destino int numJumps; // Numero de pasos preestablecido para llegar al destino
Uint8 index; // Elemento del menu que tiene el foco int index; // Elemento del menu que tiene el foco
SDL_Rect rect; // Rectangulo del selector SDL_Rect rect; // Rectangulo del selector
Uint8 r; // Cantidad de color rojo para el rectangulo del selector color_t color; // Color del selector
Uint8 g; // Cantidad de color verde para el rectangulo del selector color_t itemColor; // Color del item
Uint8 b; // Cantidad de color azul para el rectangulo del selector int a; // Cantidad de transparencia para el rectangulo del selector
Uint8 a; // Cantidad de transparencia para el rectangulo del selector
Uint8 itemR; // Cantidad de color rojo para el texto del elemento seleccionado
Uint8 itemG; // Cantidad de color verde para el texto del elemento seleccionado
Uint8 itemB; // Cantidad de color azul para el texto del elemento seleccionado
}; };
selector mSelector; // Variables para pintar el selector del menu selector_t selector; // Variables para pintar el selector del menu
// Carga los recursos necesarios para la sección 'Title' // Carga los recursos necesarios para la sección 'Title'
bool loadMedia(); bool loadMedia();
@@ -116,16 +112,16 @@ private:
void updateSelector(); void updateSelector();
// Obtiene la anchura del elemento más ancho del menu // Obtiene la anchura del elemento más ancho del menu
Uint16 getWidestItem(); int getWidestItem();
// Gestiona la entrada de teclado y mando durante el menu // Gestiona la entrada de teclado y mando durante el menu
void checkMenuInput(Menu *menu); void checkMenuInput(Menu *menu);
// Calcula el ancho del menu // Calcula el ancho del menu
Uint16 findWidth(); int findWidth();
// Calcula el alto del menu // Calcula el alto del menu
Uint16 findHeight(); int findHeight();
// Recoloca los elementos del menu en el eje Y // Recoloca los elementos del menu en el eje Y
void replaceElementsOnY(); void replaceElementsOnY();
@@ -135,7 +131,7 @@ private:
public: public:
// Constructor // Constructor
Menu(SDL_Renderer *renderer, Text *text, Input *input, std::string *fileList); Menu(SDL_Renderer *renderer, Text *text, Input *input, Asset *asset);
// Destructor // Destructor
~Menu(); ~Menu();
@@ -147,7 +143,7 @@ public:
std::string getName(); std::string getName();
// Obtiene el valor de la variable // Obtiene el valor de la variable
Uint8 getItemSelected(); int getItemSelected();
// Deja el menu apuntando al primer elemento // Deja el menu apuntando al primer elemento
void reset(); void reset();
@@ -162,13 +158,13 @@ public:
void render(); void render();
// Establece el color del rectangulo de fondo // Establece el color del rectangulo de fondo
void setBackgroundColor(int r, int g, int b, int alpha); void setBackgroundColor(color_t color, int alpha);
// Establece el color del rectangulo del selector // Establece el color del rectangulo del selector
void setSelectorColor(int r, int g, int b, int alpha); void setSelectorColor(color_t color, int alpha);
// Establece el color del texto del selector // Establece el color del texto del selector
void setSelectorTextColor(int r, int g, int b); void setSelectorTextColor(color_t color);
// Centra el menu respecto a un punto en el eje X // Centra el menu respecto a un punto en el eje X
void centerMenuOnX(int value); void centerMenuOnX(int value);
@@ -180,25 +176,25 @@ public:
void centerMenuElementsOnX(); void centerMenuElementsOnX();
// Añade un item al menu // Añade un item al menu
void addItem(std::string text, Uint8 hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false); void addItem(std::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(Uint8 index, std::string text); void setItemCaption(int index, std::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(Uint8 item); void setDefaultActionWhenCancel(int item);
// Coloca el selector en una posición específica // Coloca el selector en una posición específica
void setSelectorPos(Uint8 index); void setSelectorPos(int index);
// Establece el estado seleccionable de un item // Establece el estado seleccionable de un item
void setSelectable(Uint8 index, bool value); void setSelectable(int index, bool value);
// Establece el estado agrisado de un item // Establece el estado agrisado de un item
void setGreyed(Uint8 index, bool value); void setGreyed(int index, bool value);
// Establece el estado de enlace de un item // Establece el estado de enlace de un item
void setLinkedDown(Uint8 index, bool value); void setLinkedDown(int index, bool value);
}; };
#endif #endif