From 4d91e861782c343fb50100d6408db937ace51a7c Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 9 Jul 2024 06:52:05 +0200 Subject: [PATCH] =?UTF-8?q?-=20treballant=20en=20el=20menu=20de=20redefini?= =?UTF-8?q?ci=C3=B3=20de=20tecles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/m_menu_tecles.cpp | 32 ++++++++++++++++++++++++++++---- source/m_menu_tecles.h | 1 + source/main.cpp | 10 +++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/source/m_menu_tecles.cpp b/source/m_menu_tecles.cpp index e412dc9..6155df4 100644 --- a/source/m_menu_tecles.cpp +++ b/source/m_menu_tecles.cpp @@ -1,5 +1,8 @@ #include "m_menu_tecles.h" #include "jdraw.h" +#include "jinput.h" +#include "config.h" +#include namespace modules { @@ -14,21 +17,42 @@ namespace modules int loop() { + if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { + return MENU_TECLES_TORNAR; + } + if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN))) + { selected_option++; if (selected_option>6) selected_option=0; } + + if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP))) + { selected_option--; if (selected_option<0) selected_option=6; } + + if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || + input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { + //if (selected_option==MENU_AUDIO_MUSICA) config::toggleMusic(); + //if (selected_option==MENU_AUDIO_SO) config::toggleSound(); + if (selected_option==MENU_TECLES_TORNAR) return MENU_TECLES_TORNAR; + } + draw::cls(2); draw::color(1); draw::print2("REDEFINIR TECLES", 13, 3, YELLOW, FONT_ZOOM_VERTICAL); int pos = 10; - static char *textos[6] = { "AMUNT:", "AVALL:", "ESQUERRA:", "DRETA:", "BOTAR: ", "AGAFAR: " }; + static const char *textos[6] = { "AMUNT:", "AVALL:", "ESQUERRA:", "DRETA:", "BOTAR: ", "AGAFAR: " }; for (int i=0; i<6; ++i) { - draw::print2(i==selected_option?"fg":"de", 13, pos, i==selected_option?YELLOW:TEAL, i==selected_option?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); - draw::print2(textos[i], 18, pos, i==selected_option?YELLOW:TEAL, i==selected_option?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); - + const bool selected = (i==selected_option); + draw::print2(selected?"fg":"de", 13, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); + draw::print2(textos[i], 18, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); + pos += selected?3:2; } + const bool selected = (selected_option==MENU_TECLES_TORNAR); + draw::print2(selected?"fg":"de", 13, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); + draw::print2("TORNAR", 18, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); + draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE); draw::render(); diff --git a/source/m_menu_tecles.h b/source/m_menu_tecles.h index 2ccc891..852e1f0 100644 --- a/source/m_menu_tecles.h +++ b/source/m_menu_tecles.h @@ -11,6 +11,7 @@ namespace modules #define MENU_TECLES_DRETA 3 #define MENU_TECLES_BOTAR 4 #define MENU_TECLES_AGAFAR 5 + #define MENU_TECLES_TORNAR 6 void init(); int loop(); diff --git a/source/main.cpp b/source/main.cpp index af4c4e3..7023b06 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -12,13 +12,15 @@ #include "m_menu.h" #include "m_logo.h" #include "m_ingame.h" +#include "m_menu_tecles.h" #include "m_menu_audio.h" #define M_LOGO 0 #define M_MENU 1 #define M_GAME 2 #define M_INGAME 3 -#define M_MENU_AUDIO 4 +#define M_MENU_TECLES 4 +#define M_MENU_AUDIO 5 int current_module = M_LOGO; int zoom = 3; @@ -95,6 +97,7 @@ bool game::loop() if (option != OPTION_NONE) { if (option == OPTION_EIXIR) return false; if (option == OPTION_JUGAR) { modules::game::init(); current_module = M_GAME; } + if (option == OPTION_TECLES) { modules::menu_tecles::init(); current_module = M_MENU_TECLES; } if (option == OPTION_AUDIO) { modules::menu_audio::init(); current_module = M_MENU_AUDIO; } } break; @@ -108,6 +111,11 @@ bool game::loop() if (option == INGAME_CONTINUAR) { current_module = M_GAME; } } break; + case M_MENU_TECLES: + if (modules::menu_tecles::loop() == MENU_TECLES_TORNAR) { + modules::menu::init(); current_module = M_MENU; + } + break; case M_MENU_AUDIO: if (modules::menu_audio::loop() == MENU_AUDIO_TORNAR) { modules::menu::init(); current_module = M_MENU;