From 8dcf473f314deb94b27280da7afe09c1300a4657 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 30 Mar 2026 22:50:56 +0200 Subject: [PATCH] autocompletar amb armadura de lagarto --- source/game/ui/console.cpp | 75 ++++++++++++++++++++++++++++++-------- source/game/ui/console.hpp | 3 +- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/source/game/ui/console.cpp b/source/game/ui/console.cpp index 1fe7da14d..c71feedae 100644 --- a/source/game/ui/console.cpp +++ b/source/game/ui/console.cpp @@ -202,7 +202,7 @@ static const std::vector COMMANDS = { {.keyword = "SHADER", .execute = [](const std::vector& args) -> std::string { if (args.empty()) { Screen::get()->toggleShaders(); - return std::string("Shaders ") + (Options::video.postfx ? "ON" : "OFF"); + return std::string("Shader ") + (Options::video.postfx ? "ON" : "OFF"); } if (args[0] == "ON") { if (Options::video.postfx) { return "Shader already ON"; } @@ -1133,26 +1133,71 @@ void Console::handleEvent(const SDL_Event& event) { } break; case SDL_SCANCODE_TAB: { - // Calcular prefijo (input actual en mayúsculas) - std::string prefix; - for (unsigned char c : input_line_) { prefix += static_cast(std::toupper(c)); } - // Regenerar lista si el prefijo ha cambiado o la lista está vacía - if (tab_matches_.empty() || tab_prefix_ != prefix) { - tab_matches_.clear(); - tab_prefix_ = prefix; - for (const auto& cmd : COMMANDS) { - if (cmd.hidden) { continue; } - if (prefix.empty() || cmd.keyword.starts_with(prefix)) { - tab_matches_.push_back(std::string(cmd.keyword)); + if (tab_matches_.empty()) { + // Calcular el input actual en mayúsculas + std::string upper; + for (unsigned char c : input_line_) { upper += static_cast(std::toupper(c)); } + + const size_t space_pos = upper.rfind(' '); + if (space_pos == std::string::npos) { + // Modo comando: ciclar keywords que empiecen por el prefijo + for (const auto& cmd : COMMANDS) { + if (cmd.hidden) { continue; } + if (upper.empty() || cmd.keyword.starts_with(upper)) { + tab_matches_.emplace_back(cmd.keyword); + } + } + } else { + // Modo sub-argumento: completar primer arg del comando base + using SubArgs = std::vector; + using Entry = std::pair; + static const std::vector SUB_ARGS = { + {"SS", {"ON", "OFF", "SIZE", "UPSCALE", "DOWNSCALE"}}, + {"SHADER", {"ON", "OFF", "NEXT", "POSTFX", "CRTPI"}}, + {"BORDER", {"ON", "OFF"}}, + {"FULLSCREEN", {"ON", "OFF"}}, + {"ZOOM", {"UP", "DOWN"}}, + {"INTSCALE", {"ON", "OFF"}}, + {"VSYNC", {"ON", "OFF"}}, + {"DRIVER", {"LIST", "AUTO", "NONE"}}, + {"PALETTE", {"NEXT", "PREV"}}, + {"AUDIO", {"ON", "OFF", "VOL"}}, + {"MUSIC", {"ON", "OFF", "VOL"}}, + {"SOUND", {"ON", "OFF", "VOL"}}, +#ifdef _DEBUG + {"SHOW", {"INFO", "NOTIFICATION", "CHEEVO"}}, + {"SET", {"PLAYER", "INITIAL", "ITEMS"}}, + {"DEBUG", {"ON", "OFF"}}, + {"ROOM", {"NEXT", "PREV"}}, + {"SCENE", {"LOGO", "LOADING", "TITLE", "CREDITS", "GAME", "ENDING", "ENDING2", "RESTART"}}, +#else + {"SHOW", {"INFO"}}, + {"SET", {"PLAYER"}}, +#endif + {"HIDE", {"INFO"}}, + {"KIOSK", {"ON"}}, + {"CHEAT", {"INFINITE", "INVINCIBILITY", "OPEN", "CLOSE"}}, + }; + const std::string base_cmd = upper.substr(0, space_pos); + const std::string sub_prefix = upper.substr(space_pos + 1); + for (const auto& [keyword, args] : SUB_ARGS) { + if (keyword == base_cmd) { + for (const auto& arg : args) { + if (sub_prefix.empty() || std::string_view{arg}.starts_with(sub_prefix)) { + tab_matches_.emplace_back(std::string(base_cmd) + " " + std::string(arg)); + } + } + break; + } } } tab_index_ = -1; } if (tab_matches_.empty()) { break; } tab_index_ = (tab_index_ + 1) % static_cast(tab_matches_.size()); - std::string lower = tab_matches_[static_cast(tab_index_)]; - for (char& c : lower) { c = static_cast(std::tolower(static_cast(c))); } - input_line_ = lower; + std::string result = tab_matches_[static_cast(tab_index_)]; + for (char& c : result) { c = static_cast(std::tolower(static_cast(c))); } + input_line_ = result; break; } default: diff --git a/source/game/ui/console.hpp b/source/game/ui/console.hpp index a491781b7..e3623226e 100644 --- a/source/game/ui/console.hpp +++ b/source/game/ui/console.hpp @@ -49,7 +49,7 @@ class Console { // Constantes de consola static constexpr std::string_view CONSOLE_NAME = "JDD Console"; - static constexpr std::string_view CONSOLE_VERSION = "v2.0"; + static constexpr std::string_view CONSOLE_VERSION = "v2.1"; static constexpr int MAX_LINE_CHARS = 32; static constexpr int MAX_HISTORY_SIZE = 20; static constexpr float CURSOR_ON_TIME = 0.5F; @@ -101,5 +101,4 @@ class Console { // Estado de autocompletado (TAB) std::vector tab_matches_; // Comandos que coinciden con el prefijo actual int tab_index_{-1}; // Índice actual en tab_matches_ - std::string tab_prefix_; // Prefijo usado en la última búsqueda TAB };