Trabajando en el menu del titulo
This commit is contained in:
@@ -18,7 +18,7 @@ AnimatedSprite::AnimatedSprite(LTexture *texture, SDL_Renderer *renderer, std::s
|
||||
// Destructor
|
||||
AnimatedSprite::~AnimatedSprite()
|
||||
{
|
||||
for (auto a : animation)
|
||||
for (auto &a : animation)
|
||||
{
|
||||
a.frames.clear();
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ int Menu::getWidestItem()
|
||||
int result = 0;
|
||||
|
||||
// Obtenemos la anchura del item mas ancho
|
||||
for (auto i : item)
|
||||
for (auto &i : item)
|
||||
{
|
||||
result = std::max(result, i.rect.w);
|
||||
}
|
||||
@@ -416,7 +416,7 @@ void Menu::centerMenuOnX(int value)
|
||||
x = (value) - (findWidth() / 2);
|
||||
|
||||
// Reposiciona los elementos del menu
|
||||
for (auto i : item)
|
||||
for (auto &i : item)
|
||||
{
|
||||
i.rect.x = x;
|
||||
}
|
||||
@@ -446,7 +446,7 @@ void Menu::centerMenuElementsOnX()
|
||||
{
|
||||
areElementsCenteredOnX = true;
|
||||
|
||||
for (auto i : item)
|
||||
for (auto &i : item)
|
||||
{
|
||||
i.rect.x = (centerX - (i.rect.w / 2));
|
||||
}
|
||||
@@ -495,6 +495,9 @@ void Menu::setItemCaption(int index, std::string text)
|
||||
item[index].rect.w = this->text->lenght(item[index].label);
|
||||
item[index].rect.h = this->text->getCharacterWidth();
|
||||
reorganize();
|
||||
|
||||
const std::string texto = item[index].label + ":" + std::to_string(item[index].rect.w);
|
||||
printf("Adding menu item -> %s\n", texto.c_str());
|
||||
}
|
||||
|
||||
// Establece el indice del itemm que se usará por defecto al cancelar el menu
|
||||
@@ -559,7 +562,7 @@ int Menu::findHeight()
|
||||
int height = 0;
|
||||
|
||||
// Obtenemos la altura de la suma de alturas de los items
|
||||
for (auto i : item)
|
||||
for (auto &i : item)
|
||||
{
|
||||
height += i.rect.h + i.hPaddingDown;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ Prog::Prog(std::string executablePath)
|
||||
}
|
||||
else
|
||||
{
|
||||
section.name = SECTION_PROG_LOGO;
|
||||
section.name = SECTION_PROG_TITLE;
|
||||
}
|
||||
input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||
screen = new Screen(window, renderer, options);
|
||||
|
||||
@@ -56,12 +56,16 @@ void Text::init()
|
||||
mOffset[i].x = ((i - 32) % 15) * mBoxWidth;
|
||||
mOffset[i].y = ((i - 32) / 15) * mBoxHeight;
|
||||
}
|
||||
|
||||
printf("Cargando %s\n", mFile.c_str());
|
||||
const std::string texto = "w = "+ std::to_string(mBoxWidth) + ", h = " + std::to_string(mBoxHeight);
|
||||
printf("%s\n",texto.c_str());
|
||||
}
|
||||
|
||||
// Escribe texto en pantalla
|
||||
void Text::write(int x, int y, std::string text, int kerning, int lenght)
|
||||
{
|
||||
Uint16 shift = 0;
|
||||
int shift = 0;
|
||||
|
||||
if (lenght == -1)
|
||||
lenght = text.length();
|
||||
@@ -134,14 +138,15 @@ void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, col
|
||||
}
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
Uint16 Text::lenght(std::string text, int kerning)
|
||||
int Text::lenght(std::string text, int kerning)
|
||||
{
|
||||
Uint16 shift = 0;
|
||||
int shift = 0;
|
||||
|
||||
for (int i = 0; i < (int)text.length(); ++i)
|
||||
for (int i = 0; i < (int)text.length(); i++)
|
||||
shift += (mOffset[int(text[i])].w + kerning);
|
||||
|
||||
return shift;
|
||||
// Descuenta el kerning del último caracter
|
||||
return shift - kerning;
|
||||
}
|
||||
|
||||
// Inicializa el vector de offsets desde un fichero
|
||||
@@ -178,7 +183,7 @@ void Text::initOffsetFromFile()
|
||||
}
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
Uint8 Text::getCharacterWidth()
|
||||
int Text::getCharacterWidth()
|
||||
{
|
||||
return mBoxWidth;
|
||||
}
|
||||
@@ -21,12 +21,12 @@ private:
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
Uint8 w;
|
||||
int w;
|
||||
};
|
||||
Offset mOffset[128]; // Vector con las posiciones y ancho de cada letra
|
||||
|
||||
Uint8 mBoxWidth; // Anchura de la caja de cada caracter en el png
|
||||
Uint8 mBoxHeight; // Altura de la caja de cada caracter en el png
|
||||
int mBoxWidth; // Anchura de la caja de cada caracter en el png
|
||||
int mBoxHeight; // Altura de la caja de cada caracter en el png
|
||||
std::string mFile; // Fichero con los descriptores de la fuente
|
||||
LTexture *texture; // Textura con los bitmaps del texto
|
||||
|
||||
@@ -59,10 +59,10 @@ public:
|
||||
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1);
|
||||
|
||||
// Obtiene la longitud en pixels de una cadena
|
||||
Uint16 lenght(std::string text, int kerning = 1);
|
||||
int lenght(std::string text, int kerning = 1);
|
||||
|
||||
// Devuelve el valor de la variable
|
||||
Uint8 getCharacterWidth();
|
||||
int getCharacterWidth();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input)
|
||||
sprite = new AnimatedSprite(texture, renderer, asset->get("intro.ani"));
|
||||
sprite->setCurrentAnimation("menu");
|
||||
text = new Text(asset->get("dogica.png"), asset->get("dogica.txt"), renderer);
|
||||
text2 = new Text(asset->get("debug.png"), asset->get("debug.txt"), renderer);
|
||||
music = JA_LoadMusic(asset->get("music_title.ogg").c_str());
|
||||
menu = new Menu(renderer, text, input);
|
||||
initMenu();
|
||||
@@ -45,6 +46,9 @@ Title::~Title()
|
||||
|
||||
delete text;
|
||||
text = nullptr;
|
||||
|
||||
delete text2;
|
||||
text2 = nullptr;
|
||||
|
||||
delete menu;
|
||||
menu = nullptr;
|
||||
@@ -59,7 +63,7 @@ void Title::initMenu()
|
||||
menu->loadAudioFile(asset->get("sound_menu_select.wav"), SOUND_ACCEPT);
|
||||
menu->loadAudioFile(asset->get("sound_menu_move.wav"), SOUND_MOVE);
|
||||
|
||||
menu->init("TITLE", 0, 0, MENU_BACKGROUND_SOLID);
|
||||
menu->init("TITLE", 0, 150, MENU_BACKGROUND_TRANSPARENT);
|
||||
menu->addItem("START",2);
|
||||
menu->addItem("OPTIONS", 5);
|
||||
menu->addItem("EXIT");
|
||||
@@ -91,11 +95,11 @@ void Title::update()
|
||||
}
|
||||
|
||||
// Cualquier tecla pulsada
|
||||
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
/*if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
||||
{
|
||||
section.name = SECTION_PROG_GAME;
|
||||
section.subsection = 0;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
sprite->animate();
|
||||
menu->update();
|
||||
@@ -113,7 +117,7 @@ void Title::render()
|
||||
|
||||
// Dibuja los objetos
|
||||
sprite->render();
|
||||
text->writeDX(TXT_CENTER | TXT_COLOR, 160, 200, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", -1, {255, 93, 4});
|
||||
text2->writeDX(TXT_CENTER | TXT_COLOR, 160, 205, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", 0, {255, 93, 4});
|
||||
menu->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
|
||||
@@ -25,6 +25,7 @@ private:
|
||||
Asset *asset; // Objeto con los ficheros de recurso
|
||||
Input *input; // Objeto para gestionar las entradas
|
||||
Text *text; // Objeto para escribir texto en pantalla
|
||||
Text *text2; // Objeto para escribir texto en pantalla
|
||||
Menu *menu; // Objeto para gestionar el menu del titulo
|
||||
AnimatedSprite *sprite; // Sprite para dibujar los graficos de la intro
|
||||
JA_Music music; // Musica del titulo del juego
|
||||
|
||||
Reference in New Issue
Block a user