From 58042c5cd67cecf8104a32c7fe2abbd13f6de74e Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sat, 15 Feb 2025 18:50:43 +0100 Subject: [PATCH] Remove default focus from spellbook search, allow toggling focus via shortcut --- client/gui/Shortcut.h | 1 + client/gui/ShortcutHandler.cpp | 1 + client/windows/CSpellWindow.cpp | 13 ++++++++++++- client/windows/CSpellWindow.h | 1 + config/shortcutsConfig.json | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/client/gui/Shortcut.h b/client/gui/Shortcut.h index bd8c57a26..5124906f0 100644 --- a/client/gui/Shortcut.h +++ b/client/gui/Shortcut.h @@ -295,6 +295,7 @@ enum class EShortcut // Spellbook screen SPELLBOOK_TAB_ADVENTURE, SPELLBOOK_TAB_COMBAT, + SPELLBOOK_SEARCH_FOCUS, LIST_HERO_UP, LIST_HERO_DOWN, diff --git a/client/gui/ShortcutHandler.cpp b/client/gui/ShortcutHandler.cpp index 19c3cc728..07ae9db69 100644 --- a/client/gui/ShortcutHandler.cpp +++ b/client/gui/ShortcutHandler.cpp @@ -277,6 +277,7 @@ EShortcut ShortcutHandler::findShortcut(const std::string & identifier ) const {"heroCostumeLoad9", EShortcut::HERO_COSTUME_LOAD_9 }, {"spellbookTabAdventure", EShortcut::SPELLBOOK_TAB_ADVENTURE }, {"spellbookTabCombat", EShortcut::SPELLBOOK_TAB_COMBAT }, + {"spellbookSearchFocus", EShortcut::SPELLBOOK_SEARCH_FOCUS }, {"listHeroUp", EShortcut::LIST_HERO_UP }, {"listHeroDown", EShortcut::LIST_HERO_DOWN }, {"listHeroTop", EShortcut::LIST_HERO_TOP }, diff --git a/client/windows/CSpellWindow.cpp b/client/windows/CSpellWindow.cpp index f3033e864..8e752ba66 100644 --- a/client/windows/CSpellWindow.cpp +++ b/client/windows/CSpellWindow.cpp @@ -138,7 +138,7 @@ CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _m searchBoxRectangle = std::make_shared(r.resize(1), rectangleColor, borderColor); searchBoxDescription = std::make_shared(r.center().x, r.center().y, FONT_SMALL, ETextAlignment::CENTER, grayedColor, CGI->generaltexth->translate("vcmi.spellBook.search")); - searchBox = std::make_shared(r, FONT_SMALL, ETextAlignment::CENTER, true); + searchBox = std::make_shared(r, FONT_SMALL, ETextAlignment::CENTER, false); searchBox->setCallback(std::bind(&CSpellWindow::searchInput, this)); } @@ -354,6 +354,14 @@ void CSpellWindow::fbattleSpellsb() computeSpellsPerArea(); } +void CSpellWindow::toggleSearchBoxFocus() +{ + if(searchBox != nullptr) + { + searchBox->hasFocus() ? searchBox->removeFocus() : searchBox->giveFocus(); + } +} + void CSpellWindow::fmanaPtsb() { } @@ -546,6 +554,9 @@ void CSpellWindow::keyPressed(EShortcut key) case EShortcut::SPELLBOOK_TAB_ADVENTURE: fadvSpellsb(); break; + case EShortcut::SPELLBOOK_SEARCH_FOCUS: + toggleSearchBoxFocus(); + break; } } diff --git a/client/windows/CSpellWindow.h b/client/windows/CSpellWindow.h index 6f5eeb719..9f88e7fcd 100644 --- a/client/windows/CSpellWindow.h +++ b/client/windows/CSpellWindow.h @@ -129,6 +129,7 @@ public: void fexitb(); void fadvSpellsb(); void fbattleSpellsb(); + void toggleSearchBoxFocus(); void fmanaPtsb(); void fLcornerb(); diff --git a/config/shortcutsConfig.json b/config/shortcutsConfig.json index f8bbb522c..c305c5a5d 100644 --- a/config/shortcutsConfig.json +++ b/config/shortcutsConfig.json @@ -233,6 +233,7 @@ "spectateTrackHero": [], "spellbookTabAdventure": "A", "spellbookTabCombat": "C", + "spellbookSearchFocus": "Tab", "townOpenFort": "F", "townOpenGarrisonedHero": "Shift+H", "townOpenHall": "B",