From a0613ddd8df9123d24fa57492529fc813f099f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Wed, 24 Aug 2022 22:39:36 +0200 Subject: [PATCH] Trabajando en el menu del titulo --- data/font/dogica.png | Bin 1198 -> 1194 bytes data/font/dogica.txt | 184 +++++++++++++++++++------------------- source/animatedsprite.cpp | 2 +- source/menu.cpp | 11 ++- source/prog.cpp | 2 +- source/text.cpp | 17 ++-- source/text.h | 10 +-- source/title.cpp | 12 ++- source/title.h | 1 + 9 files changed, 126 insertions(+), 113 deletions(-) diff --git a/data/font/dogica.png b/data/font/dogica.png index c035348e59991a02af54de5787a0b75a58b19777..4bf77af50fcee76e6e6339ee08879a1a8dcdd0dc 100644 GIT binary patch delta 1161 zcmV;41a|wb391Q@F@I!9L_t(|ob6lNw&NfOHC_4tUv^$5t;Y&`b1|`P_RE}9ZUO?P z(^3FxtrgMCMsLIDS+f)EA;SCdU^aNrNVM(eBbwR($<~6c@gv)3(_ED(kJ$>^z>I=a zYpvV1ZKag5ZQGXZh(q=)pz5+b*vw?hoa7LOU#k#a$7Y^RRDYc!c1}ZvL6H(Yk|W7u zl0~!4LxWm~MUTX{Y;u$`&R{9X?Z0SUqPIFB;{-D_Op;uJ*(ca~0;E&iCQfFM&v1T3 z$C9VI2P#3)Q@S!{@8!>gS?g<}m5h+4Qi&Jw_Z!rv-jR-xgEX3KerA0cXuVN;&OCjZ z9L7GY{@Kr2@PEqPTLIS7Q_3r2B?B@t`q0fJ5z^PMpK(u)>R_v5i-Ue2EzW|c1t148 z^lSo*c>Bac>&QMpQwl@i( zxux9rc0{i^$7j+MT{}oNoW+m!6MgPK&ybJomux77{5Gjp{@acbt@Xt~CVyl=Spm$z zs_pC1Gf4upELjOx1`+u#nq(gSKlkANZ^=-PVSlZhOn!C-4V3CojU*cy=talFxeNyzYKXrh-kpWaP&^_yFWZM=QBt5=j=p%cCC7S6QZHe_5 zfqzQO%qcvB-(tVVhO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nguf; zpbd`vNFEwcq5;fQvC#%;Pxk6Zf8oChOmI;ER)e{^Wqh~N?{EEO!#85Zhc6yH1FU7@ znZ~u|8}bf%#P2DAh@U~G0*x&oa?+Pyn18hmebdF9nsgJgzsZ;7IJ<&n@rYatB*sxb zGVW_v6uHLmYxYO=BY6GC`ZFSLDjN}a`rquebX?XUk!NcU%>GaURy;F4Li%Ux^bf!@ zIJ-wM*Bp!X3ie0i^ZdW)db2(Uo)1bQvJaUn4$+vPGuivNu<{gVV4bk+J+pGptA7p( zN)Xcr%n)GpF{THz@|hlo!07Yn_pDp`EIUTtNDu$$3Y-n_w_{0Zx_Zg~CQu*4Sv_zT zM62oFI1x+_jP#fr7eF>}%%E}O{doSep`x6g{nglw-*|X~ivoD}-D~03Ct2u&ggbzL f9Cr!+Ec^p^YMXAqeQK5f0000 -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 } diff --git a/source/animatedsprite.cpp b/source/animatedsprite.cpp index 342f4a6..ed7ca1c 100644 --- a/source/animatedsprite.cpp +++ b/source/animatedsprite.cpp @@ -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(); } diff --git a/source/menu.cpp b/source/menu.cpp index 717fd87..4deb7cb 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -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; } diff --git a/source/prog.cpp b/source/prog.cpp index 1789c64..4db8ab0 100644 --- a/source/prog.cpp +++ b/source/prog.cpp @@ -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); diff --git a/source/text.cpp b/source/text.cpp index 3152d7d..a3f80ee 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -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; } \ No newline at end of file diff --git a/source/text.h b/source/text.h index 4462a24..16991a0 100644 --- a/source/text.h +++ b/source/text.h @@ -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 diff --git a/source/title.cpp b/source/title.cpp index 7025f31..d8c35c1 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -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 diff --git a/source/title.h b/source/title.h index d477c76..b0f67f3 100644 --- a/source/title.h +++ b/source/title.h @@ -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