menu class improved
This commit is contained in:
@@ -64,7 +64,7 @@ void Menu::init(std::string name, int x, int y, int backgroundType)
|
||||
mSelector.moving = false;
|
||||
|
||||
// Elementos del menu
|
||||
for (int i = 0; i < MAX_ITEMS; i++)
|
||||
for (int i = 0; i < MENU_MAX_ITEMS; i++)
|
||||
{
|
||||
mItem[i].label = "";
|
||||
mItem[i].w = 0;
|
||||
@@ -218,6 +218,7 @@ bool Menu::increaseSelectorIndex()
|
||||
mSelector.target = mItem[mSelector.index].y;
|
||||
mSelector.despY = (mSelector.target - mSelector.origin) / mSelector.numJumps;
|
||||
mSelector.moving = true;
|
||||
updateSelectorHeight();
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -238,6 +239,7 @@ bool Menu::decreaseSelectorIndex()
|
||||
mSelector.target = mItem[mSelector.index].y;
|
||||
mSelector.despY = (mSelector.target - mSelector.origin) / mSelector.numJumps;
|
||||
mSelector.moving = true;
|
||||
updateSelectorHeight();
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -284,11 +286,18 @@ void Menu::render()
|
||||
{
|
||||
mText->writeColored(mItem[i].x, mItem[i].y, mItem[i].label, mColorGreyed);
|
||||
}
|
||||
//else // no selectable
|
||||
//{
|
||||
// const color_t color = {mSelector.itemR, mSelector.itemG, mSelector.itemB};
|
||||
// mText->writeColored(mItem[i].x, mItem[i].y, mItem[i].label, color);
|
||||
//}
|
||||
else // No seleccionable
|
||||
{
|
||||
if ((mItem[i].linkedUp) && (i == mSelector.index + 1))
|
||||
{
|
||||
const color_t color = {mSelector.itemR, mSelector.itemG, mSelector.itemB};
|
||||
mText->writeColored(mItem[i].x, mItem[i].y, mItem[i].label, color);
|
||||
}
|
||||
else // No enlazado con el de arriba
|
||||
{
|
||||
mText->write(mItem[i].x, mItem[i].y, mItem[i].label);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,13 +319,15 @@ void Menu::setRectSize()
|
||||
mSelector.rect.h = (mText->getCharacterWidth() * 1) + 1;
|
||||
mSelector.rect.w = mRectBG.rect.w;
|
||||
mSelector.rect.x = mRectBG.rect.x;
|
||||
updateSelectorHeight();
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Menu::setTotalItems(int num)
|
||||
{
|
||||
mTotalItems = num;
|
||||
mTotalItems > MAX_ITEMS ? MAX_ITEMS : mTotalItems;
|
||||
if (mTotalItems > MENU_MAX_ITEMS)
|
||||
mTotalItems = MENU_MAX_ITEMS;
|
||||
}
|
||||
|
||||
// Establece el color del rectangulo de fondo
|
||||
@@ -361,7 +372,7 @@ void Menu::centerMenuOnX(int value)
|
||||
mPosX = (value) - (mWidestItem / 2);
|
||||
|
||||
// Reposiciona los elementos del menu
|
||||
for (int i = 0; i < MAX_ITEMS; i++)
|
||||
for (int i = 0; i < MENU_MAX_ITEMS; i++)
|
||||
{
|
||||
mItem[i].x = mPosX;
|
||||
}
|
||||
@@ -410,7 +421,7 @@ void Menu::centerMenuElementsOnX()
|
||||
}
|
||||
|
||||
// Añade un item al menu
|
||||
void Menu::addItem(std::string text, const Uint8 hPaddingUp, const Uint8 hPaddingDown, bool selectable, bool greyed)
|
||||
void Menu::addItem(std::string text, const Uint8 hPaddingUp, const Uint8 hPaddingDown, bool selectable, bool greyed, bool linkedDown)
|
||||
{
|
||||
// Si es el primer item coge la posición en el eje Y del propio menu
|
||||
if (mTotalItems == 0)
|
||||
@@ -427,6 +438,8 @@ void Menu::addItem(std::string text, const Uint8 hPaddingUp, const Uint8 hPaddin
|
||||
mItem[mTotalItems].hPaddingDown = hPaddingDown;
|
||||
mItem[mTotalItems].selectable = selectable;
|
||||
mItem[mTotalItems].greyed = greyed;
|
||||
mItem[mTotalItems].linkedDown = linkedDown;
|
||||
mItem[mTotalItems + 1].linkedUp = linkedDown;
|
||||
|
||||
setTotalItems(mTotalItems + 1);
|
||||
reorganize();
|
||||
@@ -524,3 +537,22 @@ void Menu::setGreyed(Uint8 index, bool value)
|
||||
{
|
||||
mItem[index].greyed = value;
|
||||
}
|
||||
|
||||
// Establece el estado de enlace de un item
|
||||
void Menu::setLinkedDown(Uint8 index, bool value)
|
||||
{
|
||||
mItem[index].linkedDown = value;
|
||||
}
|
||||
|
||||
// Calcula la altura del selector
|
||||
void Menu::updateSelectorHeight()
|
||||
{
|
||||
if (mItem[mSelector.index].linkedDown)
|
||||
{
|
||||
mSelector.rect.h = mItem[mSelector.index + 1].y + mItem[mSelector.index + 1].h - mItem[mSelector.index].y - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
mSelector.rect.h = mItem[mSelector.index].h - 1;
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@ private:
|
||||
Uint8 hPaddingDown; // Espaciado bajo el elemento
|
||||
bool selectable; // Indica si se puede seleccionar
|
||||
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 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
|
||||
|
||||
@@ -175,7 +177,7 @@ public:
|
||||
void centerMenuElementsOnX();
|
||||
|
||||
// Añade un item al menu
|
||||
void addItem(std::string text, const Uint8 hPaddingUp = 0, const Uint8 hPaddingDown = 0, bool selectable = true, bool greyed = false);
|
||||
void addItem(std::string text, const Uint8 hPaddingUp = 0, const Uint8 hPaddingDown = 0, bool selectable = true, bool greyed = false, bool linkedDown = false);
|
||||
|
||||
// Cambia el texto de un item
|
||||
void setItemCaption(Uint8 index, std::string text);
|
||||
@@ -191,6 +193,12 @@ public:
|
||||
|
||||
// Establece el estado agrisado de un item
|
||||
void setGreyed(Uint8 index, bool value);
|
||||
|
||||
// Establece el estado de enlace de un item
|
||||
void setLinkedDown(Uint8 index, bool value);
|
||||
|
||||
// Calcula la altura del selector
|
||||
void updateSelectorHeight();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -264,12 +264,12 @@ void Title::init(bool demo, Uint8 subsection)
|
||||
|
||||
mMenu.options->init("OPTIONS", 0, BLOCK, MENU_BACKGROUND_TRANSPARENT);
|
||||
mMenu.options->addItem(mLang->getText(59), 0, 5); // (0) DIFFICULTY
|
||||
mMenu.options->addItem(mLang->getText(62)); // (1) PLAYER 1 CONTROLS
|
||||
mMenu.options->addItem(mLang->getText(62), 0, 0, true, false, true); // (1) PLAYER 1 CONTROLS
|
||||
mMenu.options->addItem(mLang->getText(69), 0, 0, false, false); // (2) KEYBOARD
|
||||
mMenu.options->addItem(mLang->getText(63)); // (3) PLAYER 2 CONTROLS
|
||||
mMenu.options->addItem(mLang->getText(63), 0, 0, true, false, true); // (3) PLAYER 2 CONTROLS
|
||||
mMenu.options->addItem(mLang->getText(70), 0, 5, false, false); // (4) GAME CONTROLLER
|
||||
mMenu.options->addItem(mLang->getText(8), 0, 5); // (5) LANGUAGE
|
||||
mMenu.options->addItem(mLang->getText(58)); // (6) DISPLAY MODE
|
||||
mMenu.options->addItem(mLang->getText(58), 0, 0, true, false, true); // (6) DISPLAY MODE
|
||||
mMenu.options->addItem(mLang->getText(4), 0, 0, false, false); // (7) WINDOWED
|
||||
mMenu.options->addItem(mLang->getText(7)); // (8) WINDOW SIZE
|
||||
mMenu.options->addItem(mLang->getText(60)); // (9) FILTER
|
||||
|
||||
Reference in New Issue
Block a user