Actualizados los menus para el modo de consola portatil de videojuegos

This commit is contained in:
2023-02-13 11:25:36 +01:00
parent e7b1af237a
commit abe48d5995
6 changed files with 229 additions and 26 deletions

110
data/menu/options_gc.men Normal file
View File

@@ -0,0 +1,110 @@
font_png=smb2.png
font_txt=smb2.txt
sound_move=menu_move.wav
sound_accept=menu_select.wav
name=OPTIONS
x=0
y=116
backgroundType=0
backgroundColor=48,48,64,192
areElementsCenteredOnX=true
isCenteredOnX=true
centerX=128
isCenteredOnY=true
centerY=96
selector_color=229,28,35,255
selector_text_color=255,241,118
defaultActionWhenCancel=13
[item]
text=DIFFICULTY
hPaddingDown=7
[/item]
[item]
text=PLAYER 1 CONTROLS
hPaddingDown=2
selectable=false
greyed=true
linkedDown=true
[/item]
[item]
text=KEYBOARD
hPaddingDown=7
selectable=false
greyed=true
[/item]
[item]
text=PLAYER 2 CONTROLS
hPaddingDown=2
selectable=false
greyed=true
linkedDown=true
[/item]
[item]
text=GAME CONTROLLER
hPaddingDown=7
selectable=false
greyed=false
[/item]
[item]
text=LANGUAGE
hPaddingDown=7
[/item]
[item]
text=DISPLAY MODE
hPaddingDown=2
selectable=false
greyed=true
linkedDown=true
[/item]
[item]
text=WINDOW
hPaddingDown=7
selectable=false
greyed=true
[/item]
[item]
text=WINDOW SIZE
hPaddingDown=2
selectable=false
greyed=true
[/item]
[item]
text=FILTER
hPaddingDown=2
[/item]
[item]
text=VSYNC
hPaddingDown=7
[/item]
[item]
text=HOW TO PLAY
hPaddingDown=7
[/item]
[item]
text=ACCEPT
hPaddingDown=2
[/item]
[item]
text=CANCEL
[/item]

41
data/menu/title_gc.men Normal file
View File

@@ -0,0 +1,41 @@
font_png=smb2.png
font_txt=smb2.txt
sound_move=menu_move.wav
sound_accept=menu_select.wav
name=TITLE
x=0
y=116
backgroundType=0
backgroundColor=48,48,64,192
areElementsCenteredOnX=true
isCenteredOnX=true
centerX=128
selector_color=229,28,35,0
selector_text_color=255,180,0
defaultActionWhenCancel=3
[item]
text=PLAY
hPaddingDown=2
[/item]
[item]
text=2 PLAYERS
hPaddingDown=7
visible=false
selectable=false
[/item]
[item]
text=OPTIONS
hPaddingDown=7
[/item]
[item]
text=QUIT
[/item]

View File

@@ -119,6 +119,7 @@ bool Menu::load(std::string file_path)
item.selectable = true;
item.greyed = false;
item.linkedDown = false;
item.visible = true;
do
{
@@ -137,7 +138,7 @@ bool Menu::load(std::string file_path)
} while (line != "[/item]");
addItem(item.label, item.hPaddingDown, item.selectable, item.greyed, item.linkedDown);
addItem(item.label, item.hPaddingDown, item.selectable, item.greyed, item.linkedDown, item.visible);
}
// En caso contrario se parsea el fichero para buscar las variables y los valores
@@ -206,6 +207,11 @@ bool Menu::setItem(item_t *item, std::string var, std::string value)
item->linkedDown = value == "true" ? true : false;
}
else if (var == "visible")
{
item->visible = value == "true" ? true : false;
}
else if ((var == "") || (var == "[/item]"))
{
}
@@ -628,33 +634,36 @@ void Menu::render()
// Renderiza el texto
for (int i = 0; i < (int)item.size(); ++i)
{
if (i == selector.index)
if (item[i].visible)
{
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
}
else if (item[i].selectable)
{
text->write(item[i].rect.x, item[i].rect.y, item[i].label);
}
else if (item[i].greyed)
{
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, colorGreyed);
}
else
{ // No seleccionable
if ((item[i].linkedUp) && (i == selector.index + 1))
if (i == selector.index)
{
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
}
else // No enlazado con el de arriba
else if (item[i].selectable)
{
text->write(item[i].rect.x, item[i].rect.y, item[i].label);
}
else if (item[i].greyed)
{
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, colorGreyed);
}
else
{ // No seleccionable
if ((item[i].linkedUp) && (i == selector.index + 1))
{
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
}
else // No enlazado con el de arriba
{
text->write(item[i].rect.x, item[i].rect.y, item[i].label);
}
}
}
}
}
@@ -798,7 +807,7 @@ void Menu::centerMenuElementsOnX()
}
// Añade un item al menu
void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown)
void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown, bool visible)
{
item_t temp;
@@ -816,6 +825,7 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre
temp.selectable = selectable;
temp.greyed = greyed;
temp.linkedDown = linkedDown;
temp.visible = visible;
item.push_back(temp);
@@ -833,6 +843,12 @@ void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool gre
reorganize();
}
// Elimina un item del menu
void Menu::removeItem(int index)
{
/* POR HACER */
}
// Cambia el texto de un item
void Menu::setItemCaption(int index, std::string text)
{
@@ -941,6 +957,12 @@ void Menu::setLinkedDown(int index, bool value)
item[index].linkedDown = value;
}
// Establece el estado de visibilidad de un item
void Menu::setVisible(int index, bool value)
{
item[index].visible = value;
}
// Calcula la altura del selector
int Menu::getSelectorHeight(int value)
{

View File

@@ -46,6 +46,7 @@ private:
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
bool visible; // Indica si el elemento es visible
};
struct selector_t
@@ -89,9 +90,9 @@ private:
bool isCenteredOnY; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y
bool areElementsCenteredOnX; // Variable para saber si los elementos van centrados en el eje X
int widestItem; // Anchura del elemento más ancho
JA_Sound_t* soundAccept; // Sonido al aceptar o elegir una opción del menu
JA_Sound_t* soundCancel; // Sonido al cancelar el menu
JA_Sound_t* soundMove; // Sonido al mover el selector
JA_Sound_t *soundAccept; // Sonido al aceptar o elegir una opción del menu
JA_Sound_t *soundCancel; // Sonido al cancelar el menu
JA_Sound_t *soundMove; // Sonido al mover el selector
color_t colorGreyed; // Color para los elementos agrisados
rectangle_t rectBG; // Rectangulo de fondo del menu
std::vector<item_t> item; // Estructura para cada elemento del menu
@@ -185,7 +186,10 @@ public:
void centerMenuElementsOnX();
// 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(std::string text, int hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false, bool visible = true);
// Elimina un item del menu
void removeItem(int index);
// Cambia el texto de un item
void setItemCaption(int index, std::string text);
@@ -205,6 +209,9 @@ public:
// Establece el estado de enlace de un item
void setLinkedDown(int index, bool value);
// Establece el estado de visibilidad de un item
void setVisible(int index, bool value);
// Establece el nombre del menu
void setName(std::string name);

View File

@@ -347,7 +347,9 @@ bool Director::setFileList()
// Menus
asset->add(prefix + "/data/menu/title.men", t_data);
asset->add(prefix + "/data/menu/title_gc.men", t_data);
asset->add(prefix + "/data/menu/options.men", t_data);
asset->add(prefix + "/data/menu/options_gc.men", t_data);
asset->add(prefix + "/data/menu/pause.men", t_data);
asset->add(prefix + "/data/menu/gameover.men", t_data);
asset->add(prefix + "/data/menu/player_select.men", t_data);

View File

@@ -32,8 +32,13 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
text1 = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
text2 = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
#ifdef GAME_CONSOLE
menu.title = new Menu(renderer, asset, input, asset->get("title_gc.men"));
menu.options = new Menu(renderer, asset, input, asset->get("options_gc.men"));
#else
menu.title = new Menu(renderer, asset, input, asset->get("title.men"));
menu.options = new Menu(renderer, asset, input, asset->get("options.men"));
#endif
menu.playerSelect = new Menu(renderer, asset, input, asset->get("player_select.men"));
// Sonidos
@@ -920,8 +925,12 @@ void Title::updateMenuLabels()
menu.options->centerMenuOnY(GAMECANVAS_CENTER_Y);
menu.options->centerMenuElementsOnX();
// Establece las etiquetas del menu de titulo
// Establece las etiquetas del menu de titulo
#ifdef GAME_CONSOLE
menu.title->setItemCaption(0, lang->getText(0)); // PLAY
#else
menu.title->setItemCaption(0, lang->getText(51)); // 1 PLAYER
#endif
menu.title->setItemCaption(1, lang->getText(52)); // 2 PLAYERS
menu.title->setItemCaption(2, lang->getText(1)); // OPTIONS
menu.title->setItemCaption(3, lang->getText(3)); // QUIT
@@ -937,6 +946,17 @@ void Title::updateMenuLabels()
// Recoloca el menu de selección de jugador
menu.playerSelect->centerMenuOnX(GAMECANVAS_CENTER_X);
menu.playerSelect->centerMenuElementsOnX();
#ifdef GAME_CONSOLE
menu.options->setGreyed(1, true);
menu.options->setSelectable(1, false);
menu.options->setGreyed(2, true);
menu.options->setSelectable(2, false);
menu.options->setGreyed(3, true);
menu.options->setSelectable(3, false);
menu.options->setGreyed(4, true);
menu.options->setSelectable(4, false);
#endif
}
// Aplica las opciones de menu seleccionadas
@@ -1155,4 +1175,5 @@ void Title::reLoadTextures()
// Deshabilita ciertas opciones de los menus
void Title::disableMenuEntries()
{
// Quita opciones no válidas para jugar en una consola portatil
}