Trabajando en el menu del titulo
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -3,189 +3,189 @@
|
||||
# box height
|
||||
8
|
||||
# 32 espacio ( )
|
||||
8
|
||||
7
|
||||
# 33 !
|
||||
8
|
||||
1
|
||||
# 34 "
|
||||
8
|
||||
4
|
||||
# 35 #
|
||||
8
|
||||
6
|
||||
# 36 $
|
||||
8
|
||||
5
|
||||
# 37 %
|
||||
8
|
||||
7
|
||||
# 38 &
|
||||
8
|
||||
6
|
||||
# 39 '
|
||||
8
|
||||
2
|
||||
# 40 (
|
||||
8
|
||||
2
|
||||
# 41 )
|
||||
8
|
||||
2
|
||||
# 42 *
|
||||
8
|
||||
5
|
||||
# 43 +
|
||||
8
|
||||
5
|
||||
# 44 ,
|
||||
8
|
||||
2
|
||||
# 45 -
|
||||
8
|
||||
4
|
||||
# 46 .
|
||||
8
|
||||
1
|
||||
# 47 /
|
||||
8
|
||||
4
|
||||
# 48 0
|
||||
8
|
||||
5
|
||||
# 49 1
|
||||
8
|
||||
5
|
||||
# 50 2
|
||||
8
|
||||
5
|
||||
# 51 3
|
||||
8
|
||||
5
|
||||
# 52 4
|
||||
8
|
||||
5
|
||||
# 53 5
|
||||
8
|
||||
5
|
||||
# 54 6
|
||||
8
|
||||
5
|
||||
# 55 7
|
||||
8
|
||||
5
|
||||
# 56 8
|
||||
8
|
||||
5
|
||||
# 57 9
|
||||
8
|
||||
5
|
||||
# 58 :
|
||||
8
|
||||
1
|
||||
# 59 ;
|
||||
8
|
||||
2
|
||||
# 60 <
|
||||
8
|
||||
3
|
||||
# 61 =
|
||||
8
|
||||
6
|
||||
# 62 >
|
||||
8
|
||||
3
|
||||
# 63 ?
|
||||
8
|
||||
5
|
||||
# 64 @
|
||||
8
|
||||
7
|
||||
# 65 A
|
||||
8
|
||||
5
|
||||
# 66 B
|
||||
8
|
||||
5
|
||||
# 67 C
|
||||
8
|
||||
5
|
||||
# 68 D
|
||||
8
|
||||
6
|
||||
# 69 E
|
||||
8
|
||||
5
|
||||
# 70 F
|
||||
8
|
||||
5
|
||||
# 71 G
|
||||
8
|
||||
5
|
||||
# 72 H
|
||||
8
|
||||
5
|
||||
# 73 I
|
||||
8
|
||||
3
|
||||
# 74 J
|
||||
8
|
||||
4
|
||||
# 75 K
|
||||
8
|
||||
5
|
||||
# 76 L
|
||||
8
|
||||
4
|
||||
# 77 M
|
||||
8
|
||||
6
|
||||
# 78 N
|
||||
8
|
||||
5
|
||||
# 79 O
|
||||
8
|
||||
5
|
||||
# 80 P
|
||||
8
|
||||
5
|
||||
# 81 Q
|
||||
8
|
||||
5
|
||||
# 82 R
|
||||
8
|
||||
5
|
||||
# 83 S
|
||||
8
|
||||
5
|
||||
# 84 T
|
||||
8
|
||||
5
|
||||
# 85 U
|
||||
8
|
||||
5
|
||||
# 86 V
|
||||
8
|
||||
5
|
||||
# 87 W
|
||||
8
|
||||
7
|
||||
# 88 X
|
||||
8
|
||||
5
|
||||
# 89 Y
|
||||
8
|
||||
5
|
||||
# 90 Z
|
||||
8
|
||||
5
|
||||
# 91 [
|
||||
8
|
||||
2
|
||||
# 92 \
|
||||
8
|
||||
4
|
||||
# 93 ]
|
||||
8
|
||||
2
|
||||
# 94 ^
|
||||
8
|
||||
4
|
||||
# 95 _
|
||||
8
|
||||
6
|
||||
# 96 `
|
||||
8
|
||||
2
|
||||
# 97 a
|
||||
8
|
||||
5
|
||||
# 98 b
|
||||
8
|
||||
5
|
||||
# 99 c
|
||||
8
|
||||
5
|
||||
# 100 d
|
||||
8
|
||||
5
|
||||
# 101 e
|
||||
8
|
||||
5
|
||||
# 102 f
|
||||
8
|
||||
5
|
||||
# 103 g
|
||||
8
|
||||
5
|
||||
# 104 h
|
||||
8
|
||||
5
|
||||
# 105 i
|
||||
8
|
||||
3
|
||||
# 106 j
|
||||
8
|
||||
3
|
||||
# 107 k
|
||||
8
|
||||
5
|
||||
# 108 l
|
||||
8
|
||||
3
|
||||
# 109 m
|
||||
8
|
||||
7
|
||||
# 110 n
|
||||
8
|
||||
5
|
||||
# 111 o
|
||||
8
|
||||
5
|
||||
# 112 p
|
||||
8
|
||||
5
|
||||
# 113 q
|
||||
8
|
||||
5
|
||||
# 114 r
|
||||
8
|
||||
4
|
||||
# 115 s
|
||||
8
|
||||
5
|
||||
# 116 t
|
||||
8
|
||||
4
|
||||
# 117 u
|
||||
8
|
||||
5
|
||||
# 118 v
|
||||
8
|
||||
5
|
||||
# 119 w
|
||||
8
|
||||
6
|
||||
# 120 x
|
||||
8
|
||||
5
|
||||
# 121 y
|
||||
8
|
||||
4
|
||||
# 122 z
|
||||
8
|
||||
4
|
||||
# 123 {
|
||||
8
|
||||
5
|
||||
# 124 |
|
||||
8
|
||||
# 125 }
|
||||
|
||||
@@ -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();
|
||||
@@ -46,6 +47,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