From 64b86c7ac17bd7695942bcc948beb97c7d6b30a4 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 4 Jun 2025 09:44:53 +0200 Subject: [PATCH] modificacions en el flujo de globalInputs afegida font aseprite canvis estetics en la info de debug moviment del cursor del ServiceMenu --- data/font/aseprite.png | Bin 0 -> 678 bytes data/font/aseprite.txt | 194 +++++++++++++++++++++++++++++++++++++++ source/director.cpp | 2 + source/game.cpp | 39 +++++--- source/game.h | 13 +-- source/global_inputs.cpp | 94 ++++++++++++++----- source/resource.cpp | 1 + source/screen.cpp | 14 +-- source/screen.h | 2 +- source/service_menu.cpp | 53 ++++++++--- source/service_menu.h | 11 ++- source/utils.cpp | 1 + source/utils.h | 1 + 13 files changed, 362 insertions(+), 63 deletions(-) create mode 100644 data/font/aseprite.png create mode 100644 data/font/aseprite.txt diff --git a/data/font/aseprite.png b/data/font/aseprite.png new file mode 100644 index 0000000000000000000000000000000000000000..69ac7fc58c2fca3bba55d972c5c5abeb5b1177d2 GIT binary patch literal 678 zcmV;X0$KfuP)Px#22e~?MgRZ*|NsA0eD!Pq0007XQchC<|67qFwEzGDKuJVFR9J=WSkZFBFbISH z|LHx{#vp`oy35kL&Rgp^0R#f#q#|Re&GQJaB*8GF*6}ETRrNK!WE7B0IvF^0h3IKG zZ)*kl>fj=%F)WDy(Dh8 zx%f=DkiQDt?a$B+P7b<6;HUwv43YKL(FEM~OtD$G8U62oOPt^J@BU5Z!Es*HXLhbA z#NrqnlNWID2Wt8NQRw(52C9A~`WaX>o@WNmfE{If;27HVh!fQj8G%=X z_**3WbWj0r`ZF-*iv*~MlwYkw1b%yb+w=Sy55CL% +4 +# 63 ? +4 +# 64 @ +7 +# 65 A +4 +# 66 B +4 +# 67 C +4 +# 68 D +4 +# 69 E +4 +# 70 F +4 +# 71 G +4 +# 72 H +4 +# 73 I +2 +# 74 J +2 +# 75 K +4 +# 76 L +4 +# 77 M +5 +# 78 N +4 +# 79 O +5 +# 80 P +4 +# 81 Q +5 +# 82 R +4 +# 83 S +4 +# 84 T +5 +# 85 U +4 +# 86 V +5 +# 87 W +7 +# 88 X +5 +# 89 Y +5 +# 90 Z +4 +# 91 [ +2 +# 92 \ +3 +# 93 ] +2 +# 94 ^ +5 +# 95 _ +5 +# 96 ` +3 +# 97 a +4 +# 98 b +4 +# 99 c +4 +# 100 d +4 +# 101 e +4 +# 102 f +2 +# 103 g +4 +# 104 h +4 +# 105 i +1 +# 106 j +2 +# 107 k +4 +# 108 l +1 +# 109 m +7 +# 110 n +4 +# 111 o +4 +# 112 p +4 +# 113 q +4 +# 114 r +3 +# 115 s +3 +# 116 t +2 +# 117 u +4 +# 118 v +4 +# 119 w +5 +# 120 x +5 +# 121 y +4 +# 122 z +4 +# 123 { +3 +# 124 | +3 +# 125 } +3 +# 126 ~ +5 \ No newline at end of file diff --git a/source/director.cpp b/source/director.cpp index 647119e..f3916c7 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -442,6 +442,8 @@ void Director::setFileList() // Fuentes de texto Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/aseprite.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/font/aseprite.txt", AssetType::FONT); Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::BITMAP); Asset::get()->add(prefix + "/data/font/smb2_palette1.pal", AssetType::PALETTE); Asset::get()->add(prefix + "/data/font/smb2.txt", AssetType::FONT); diff --git a/source/game.cpp b/source/game.cpp index 0d768dc..dff8d77 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -28,6 +28,7 @@ #include "scoreboard.h" // Para Scoreboard, ScoreboardMode, SCOREB... #include "screen.h" // Para Screen #include "section.h" // Para Name, name, AttractMode, Options +#include "service_menu.h" // Para ServiceMenu #include "smart_sprite.h" // Para SmartSprite #include "stage.h" // Para number, get, Stage, total_power #include "tabe.h" // Para Tabe, TabeState @@ -1334,10 +1335,18 @@ int Game::getController(int player_id) // Gestiona la entrada durante el juego void Game::checkInput() { - // Verifica si se debe pausar el juego. - checkPauseInput(); + // Comprueba las entradas si no está el menú de servicio activo + if (!ServiceMenu::get()->isEnabled()) + { + checkPauseInput(); + demo_.enabled ? DEMO_handlePassInput() : handlePlayersInput(); + } - demo_.enabled ? handleDemoMode() : handlePlayersInput(); + // Mueve los jugadores en el modo demo + if (demo_.enabled) + { + DEMO_handleInput(); + } // Verifica los inputs globales. globalInputs::check(); @@ -1365,8 +1374,19 @@ void Game::checkPauseInput() } } +// Gestiona las entradas de los jugadores en el modo demo para saltarse la demo. +void Game::DEMO_handlePassInput() +{ + if (input_->checkAnyButtonPressed()) + { + section::name = section::Name::TITLE; // Salir del modo demo y regresar al menú principal. + section::attract_mode = section::AttractMode::TITLE_TO_DEMO; // El juego volverá a mostrar la demo + return; + } +} + // Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos. -void Game::handleDemoMode() +void Game::DEMO_handleInput() { int index = 0; for (const auto &player : players_) @@ -1374,21 +1394,14 @@ void Game::handleDemoMode() if (player->isPlaying()) { // Maneja el input específico del jugador en modo demo. - handleDemoPlayerInput(player, index); - } - - if (input_->checkAnyButtonPressed()) - { - section::name = section::Name::TITLE; // Salir del modo demo y regresar al menú principal. - section::attract_mode = section::AttractMode::TITLE_TO_DEMO; // El juego volverá a mostrar la demo - return; + DEMO_handlePlayerInput(player, index); } ++index; } } // Procesa las entradas para un jugador específico durante el modo demo. -void Game::handleDemoPlayerInput(const std::shared_ptr &player, int index) +void Game::DEMO_handlePlayerInput(const std::shared_ptr &player, int index) { const auto &demoData = demo_.data[index][demo_.counter]; diff --git a/source/game.h b/source/game.h index d884db9..88b5706 100644 --- a/source/game.h +++ b/source/game.h @@ -103,10 +103,10 @@ private: }; // --- Objetos y punteros --- - SDL_Renderer *renderer_; // El renderizador de la ventana - Screen *screen_; // Objeto encargado de dibujar en pantalla - Input *input_; // Manejador de entrada - Scoreboard *scoreboard_; // Objeto para dibujar el marcador + SDL_Renderer *renderer_; // El renderizador de la ventana + Screen *screen_; // Objeto encargado de dibujar en pantalla + Input *input_; // Manejador de entrada + Scoreboard *scoreboard_; // Objeto para dibujar el marcador std::unique_ptr background_; // Objeto para dibujar el fondo del juego @@ -215,8 +215,9 @@ private: int getController(int playerId); // Obtiene un controlador a partir del "id" del jugador void checkInput(); // Gestiona la entrada durante el juego void checkPauseInput(); // Verifica si alguno de los controladores ha solicitado una pausa y actualiza el estado de pausa del juego. - void handleDemoMode(); // Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos. - void handleDemoPlayerInput(const std::shared_ptr &player, int index); // Procesa las entradas para un jugador específico durante el modo demo. + void DEMO_handleInput(); // Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos. + void DEMO_handlePassInput(); // Gestiona las entradas de los jugadores en el modo demo para saltarse la demo. + void DEMO_handlePlayerInput(const std::shared_ptr &player, int index); // Procesa las entradas para un jugador específico durante el modo demo. void handleFireInput(const std::shared_ptr &player, BulletType bulletType); // Maneja el disparo de un jugador, incluyendo la creación de balas y la gestión del tiempo de espera entre disparos. void handlePlayersInput(); // Gestiona las entradas de todos los jugadores en el modo normal (fuera del modo demo). void handleNormalPlayerInput(const std::shared_ptr &player); // Maneja las entradas de movimiento y disparo para un jugador en modo normal. diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 0b33ddb..7840a36 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -170,8 +170,72 @@ namespace globalInputs ServiceMenu::get()->toggle(); } - // Comprueba los inputs que se pueden introducir en cualquier sección del juego - void check() + // Comprueba el boton de servicio + void checkServiceButton() + { + // Teclado + if (Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + { + toggleServiceMenu(); + return; + } + + // Mandos + { + for (int i = 0; i < Input::get()->getNumControllers(); ++i) + { + if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + { + toggleServiceMenu(); + return; + } + } + } + } + + // Comprueba las entradas del menú de servicio + void checkServiceInputs() + { + // Teclado + { + // Arriba + if (Input::get()->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + { + ServiceMenu::get()->setSelectorUp(); + return; + } + + // Abajo + if (Input::get()->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) + { + ServiceMenu::get()->setSelectorDown(); + return; + } + } + + // Mandos + { + for (int i = 0; i < Input::get()->getNumControllers(); ++i) + { + // Arriba + if (Input::get()->checkInput(InputAction::UP, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + { + ServiceMenu::get()->setSelectorUp(); + return; + } + + // Abajo + if (Input::get()->checkInput(InputAction::DOWN, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) + { + ServiceMenu::get()->setSelectorDown(); + return; + } + } + } + } + + // Comprueba las entradas fuera del menú de servicio + void checkInputs() { // Teclado { @@ -267,13 +331,6 @@ namespace globalInputs return; } - // Service Menu - if (Input::get()->checkInput(InputAction::SERVICE, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) - { - toggleServiceMenu(); - return; - } - #ifdef DEBUG // Debug info if (Input::get()->checkInput(InputAction::SHOW_INFO, INPUT_DO_NOT_ALLOW_REPEAT, InputDeviceToUse::KEYBOARD)) @@ -283,18 +340,13 @@ namespace globalInputs } #endif } + } - // Mandos - { - for (int i = 0; i < Input::get()->getNumControllers(); ++i) - { - // Salir - if (Input::get()->checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::CONTROLLER, i)) - { - toggleServiceMenu(); - return; - } - } - } + // Comprueba los inputs que se pueden introducir en cualquier sección del juego + void check() + { + checkServiceButton(); + checkServiceInputs(); + checkInputs(); } } \ No newline at end of file diff --git a/source/resource.cpp b/source/resource.cpp index e46d157..985e319 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -334,6 +334,7 @@ void Resource::createText() {"04b_25_flat_2x", "04b_25_flat_2x.png", "04b_25_2x.txt"}, {"04b_25_reversed_2x", "04b_25_reversed_2x.png", "04b_25_2x.txt"}, {"8bithud", "8bithud.png", "8bithud.txt"}, + {"aseprite", "aseprite.png", "aseprite.txt"}, {"smb2", "smb2.gif", "smb2.txt"}}; for (const auto &resource : resources) diff --git a/source/screen.cpp b/source/screen.cpp index fc384a2..a492e2f 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -220,12 +220,12 @@ void Screen::renderInfo() { if (debug_info_.show) { + // Resolution + debug_info_.text->writeDX(TEXT_COLOR | TEXT_SHADOW, param.game.width - debug_info_.text->lenght(options.video.info) - 2, 1, options.video.info, 1, DEBUG_COLOR, 1, DEBUG_COLOR.darken(150)); + // FPS const std::string FPS_TEXT = std::to_string(fps_.lastValue) + " FPS"; - debug_info_.text->writeDX(TEXT_COLOR | TEXT_SHADOW, param.game.width - debug_info_.text->lenght(FPS_TEXT), 0, FPS_TEXT, 1, ORANGE_SOFT_COLOR, 1, ORANGE_SHADOW_COLOR); - - // Resolution - debug_info_.text->writeDX(TEXT_COLOR | TEXT_SHADOW, 0, 0, options.video.info, 1, ORANGE_SOFT_COLOR, 1, ORANGE_SHADOW_COLOR); + debug_info_.text->writeDX(TEXT_COLOR | TEXT_SHADOW, param.game.width - debug_info_.text->lenght(FPS_TEXT) - 2, 1 + debug_info_.text->getCharacterSize(), FPS_TEXT, 1, DEBUG_COLOR, 1, DEBUG_COLOR.darken(150)); } } #endif @@ -378,9 +378,9 @@ void Screen::getDisplayInfo() SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d", static_cast(param.game.width), static_cast(param.game.height), options.window.zoom); - options.video.info = std::to_string(static_cast(DM->w)) + " X " + - std::to_string(static_cast(DM->h)) + " AT " + - std::to_string(static_cast(DM->refresh_rate)) + " HZ"; + options.video.info = std::to_string(static_cast(DM->w)) + "x" + + std::to_string(static_cast(DM->h)) + " @ " + + std::to_string(static_cast(DM->refresh_rate)) + " Hz"; // Calcula el máximo factor de zoom que se puede aplicar a la pantalla const int MAX_ZOOM = std::min(DM->w / param.game.width, (DM->h - WINDOWS_DECORATIONS_) / param.game.height); diff --git a/source/screen.h b/source/screen.h index 6c163bf..958b605 100644 --- a/source/screen.h +++ b/source/screen.h @@ -170,7 +170,7 @@ private: { if (Resource::get()) { - text = Resource::get()->getText("smb2"); + text = Resource::get()->getText("aseprite"); if (!text) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to retrieve debug_.text object!"); diff --git a/source/service_menu.cpp b/source/service_menu.cpp index 7880308..b8b7915 100644 --- a/source/service_menu.cpp +++ b/source/service_menu.cpp @@ -99,7 +99,7 @@ void ServiceMenu::render() { y += lineHeight_; elementText_->writeColored(rect_.x + H_PADDING, y, VIDEO_LIST.at(i), i == selected_ ? selectedColor_ : textColor_, -2); - elementText_->writeColored(rect_.x + H_PADDING + 100, y, ": " + std::string(OPTIONS_LIST.at(i)), i == selected_ ? selectedColor_ : textColor_, -2); + elementText_->writeColored(rect_.x + H_PADDING + 100, y, "" + std::string(OPTIONS_LIST.at(i)), i == selected_ ? selectedColor_ : textColor_, -2); } } } @@ -139,21 +139,46 @@ void ServiceMenu::updateCounter() Color ServiceMenu::getSelectedColor() { static std::array colors = { - Color(0xFF, 0xFF, 0x00), // Amarillo brillante - Color(0xFF, 0xD7, 0x00), // Dorado claro - Color(0xFF, 0xEF, 0x7C), // Amarillo pastel - Color(0xFF, 0xCC, 0x00), // Amarillo anaranjado - Color(0xFF, 0xF7, 0x00), // Amarillo limón - Color(0xCC, 0x99, 0x00), // Mostaza - Color(0xFF, 0xF7, 0x00), // Amarillo limón (regreso) - Color(0xFF, 0xCC, 0x00), // Amarillo anaranjado (regreso) - Color(0xFF, 0xEF, 0x7C), // Amarillo pastel (regreso) - Color(0xFF, 0xD7, 0x00), // Dorado claro (regreso) - Color(0xFF, 0xFF, 0x00), // Amarillo brillante (regreso) - Color(0xCC, 0x99, 0x00) // Mostaza (regreso, cierre) + Color(0xFF, 0xFB, 0x8A), // Amarillo suave + Color(0xFF, 0xE4, 0x5D), // Dorado medio + Color(0xFF, 0xD1, 0x3C), // Amarillo pastel intenso + Color(0xFF, 0xBF, 0x23), // Amarillo anaranjado + Color(0xFF, 0xAA, 0x12), // Amarillo cálido + Color(0xE6, 0x9A, 0x08), // Mostaza oscuro + Color(0xE6, 0x9A, 0x08), // Mostaza oscuro (regreso, cierre) + Color(0xFF, 0xAA, 0x12), // Amarillo cálido (regreso) + Color(0xFF, 0xBF, 0x23), // Amarillo anaranjado (regreso) + Color(0xFF, 0xD1, 0x3C), // Amarillo pastel intenso (regreso) + Color(0xFF, 0xE4, 0x5D), // Dorado medio (regreso) + Color(0xFF, 0xFB, 0x8A) // Amarillo suave (regreso) }; const size_t index = counter_ % colors.size(); return colors.at(index); -} \ No newline at end of file +} + +void ServiceMenu::setSelectorUp() +{ + if (selected_ > 0) + { + --selected_; + } + else + { + selected_ = 4; + } +} + +void ServiceMenu::setSelectorDown() +{ + selected_ = (selected_ + 1) % 5; +} + +void ServiceMenu::acceptSelection() +{ +} + +void ServiceMenu::cancelSelection() +{ +} diff --git a/source/service_menu.h b/source/service_menu.h index 076e2a4..75e12dc 100644 --- a/source/service_menu.h +++ b/source/service_menu.h @@ -21,13 +21,22 @@ public: void render(); void update(); + // --- Métodos de control --- + void setSelectorUp(); + void setSelectorDown(); + void acceptSelection(); + void cancelSelection(); + + // --- Getters --- + bool isEnabled() const { return enabled_; } + private: // -- Variables internas --- bool enabled_ = false; // Indica si el menú de servicio está activo SDL_FRect rect_; // Rectangulo para definir el area del menú de servicio std::shared_ptr elementText_; // Objeto para escribir texto; std::shared_ptr titleText_; // Objeto para escribir texto; - size_t selected_ = 2; // Elemento del menú seleccionado + size_t selected_ = 2; // Elemento del menú seleccionado Uint32 counter_ = 0; // Contador interno // -- Aspecto -- diff --git a/source/utils.cpp b/source/utils.cpp index 58aa68f..7155ecc 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -36,6 +36,7 @@ const Color SERV_MENU_TITLE_COLOR = Color(0XFF, 0XFF, 0XFF); const Color SERV_MENU_TEXT_COLOR = Color(0XFF, 0XFF, 0XFF); const Color SERV_MENU_SELECTED_COLOR = Color(0XFF, 0XFF, 0X00);; const Color SERV_MENU_BG_COLOR = Color(0x1E, 0x1E, 0x1E); +const Color DEBUG_COLOR = Color(0xFF, 0xFF, 0x00); // Obtiene un color del vector de colores imitando al Coche Fantástico Color getColorLikeKnightRider(const std::vector &colors, int counter_) diff --git a/source/utils.h b/source/utils.h index 844ce7c..95cee43 100644 --- a/source/utils.h +++ b/source/utils.h @@ -131,6 +131,7 @@ extern const Color SERV_MENU_TITLE_COLOR; extern const Color SERV_MENU_TEXT_COLOR; extern const Color SERV_MENU_SELECTED_COLOR; extern const Color SERV_MENU_BG_COLOR; +extern const Color DEBUG_COLOR; // Colores y gráficos Color getColorLikeKnightRider(const std::vector &colors, int counter_);