feat: add TOGGLE_BAGS action and integrate inventory screen with keybinding manager

- Add TOGGLE_BAGS action to keybinding manager (B key default)
- Update inventory_screen.cpp to use keybinding manager for bag and character toggles
- Maintain consistent keybinding system across all UI windows
This commit is contained in:
Kelsi 2026-03-11 09:02:15 -07:00
parent 7220737d48
commit 332c2f6d3f
3 changed files with 18 additions and 9 deletions

View file

@ -17,6 +17,7 @@ public:
enum class Action { enum class Action {
TOGGLE_CHARACTER_SCREEN, TOGGLE_CHARACTER_SCREEN,
TOGGLE_INVENTORY, TOGGLE_INVENTORY,
TOGGLE_BAGS,
TOGGLE_SPELLBOOK, TOGGLE_SPELLBOOK,
TOGGLE_TALENTS, TOGGLE_TALENTS,
TOGGLE_QUESTS, TOGGLE_QUESTS,

View file

@ -1,4 +1,5 @@
#include "ui/inventory_screen.hpp" #include "ui/inventory_screen.hpp"
#include "ui/keybinding_manager.hpp"
#include "game/game_handler.hpp" #include "game/game_handler.hpp"
#include "core/application.hpp" #include "core/application.hpp"
#include "rendering/vk_context.hpp" #include "rendering/vk_context.hpp"
@ -709,18 +710,21 @@ bool InventoryScreen::bagHasAnyItems(const game::Inventory& inventory, int bagIn
} }
void InventoryScreen::render(game::Inventory& inventory, uint64_t moneyCopper) { void InventoryScreen::render(game::Inventory& inventory, uint64_t moneyCopper) {
// B key toggle (edge-triggered) // Bags toggle (B key, edge-triggered)
bool wantsTextInput = ImGui::GetIO().WantTextInput; bool bagsDown = KeybindingManager::getInstance().isActionPressed(
bool bDown = !wantsTextInput && core::Input::getInstance().isKeyPressed(SDL_SCANCODE_B); KeybindingManager::Action::TOGGLE_BAGS, false);
bool bToggled = bDown && !bKeyWasDown; bool bToggled = bagsDown && !bKeyWasDown;
bKeyWasDown = bDown; bKeyWasDown = bagsDown;
// C key toggle for character screen (edge-triggered) // Character screen toggle (C key, edge-triggered)
bool cDown = !wantsTextInput && core::Input::getInstance().isKeyPressed(SDL_SCANCODE_C); bool characterDown = KeybindingManager::getInstance().isActionPressed(
if (cDown && !cKeyWasDown) { KeybindingManager::Action::TOGGLE_CHARACTER_SCREEN, false);
if (characterDown && !cKeyWasDown) {
characterOpen = !characterOpen; characterOpen = !characterOpen;
} }
cKeyWasDown = cDown; cKeyWasDown = characterDown;
bool wantsTextInput = ImGui::GetIO().WantTextInput;
if (separateBags_) { if (separateBags_) {
if (bToggled) { if (bToggled) {

View file

@ -18,6 +18,7 @@ void KeybindingManager::initializeDefaults() {
// Set default keybindings // Set default keybindings
bindings_[static_cast<int>(Action::TOGGLE_CHARACTER_SCREEN)] = ImGuiKey_C; bindings_[static_cast<int>(Action::TOGGLE_CHARACTER_SCREEN)] = ImGuiKey_C;
bindings_[static_cast<int>(Action::TOGGLE_INVENTORY)] = ImGuiKey_I; bindings_[static_cast<int>(Action::TOGGLE_INVENTORY)] = ImGuiKey_I;
bindings_[static_cast<int>(Action::TOGGLE_BAGS)] = ImGuiKey_B;
bindings_[static_cast<int>(Action::TOGGLE_SPELLBOOK)] = ImGuiKey_P; // WoW standard key bindings_[static_cast<int>(Action::TOGGLE_SPELLBOOK)] = ImGuiKey_P; // WoW standard key
bindings_[static_cast<int>(Action::TOGGLE_TALENTS)] = ImGuiKey_N; // WoW standard key bindings_[static_cast<int>(Action::TOGGLE_TALENTS)] = ImGuiKey_N; // WoW standard key
bindings_[static_cast<int>(Action::TOGGLE_QUESTS)] = ImGuiKey_L; bindings_[static_cast<int>(Action::TOGGLE_QUESTS)] = ImGuiKey_L;
@ -57,6 +58,7 @@ const char* KeybindingManager::getActionName(Action action) {
switch (action) { switch (action) {
case Action::TOGGLE_CHARACTER_SCREEN: return "Character Screen"; case Action::TOGGLE_CHARACTER_SCREEN: return "Character Screen";
case Action::TOGGLE_INVENTORY: return "Inventory"; case Action::TOGGLE_INVENTORY: return "Inventory";
case Action::TOGGLE_BAGS: return "Bags";
case Action::TOGGLE_SPELLBOOK: return "Spellbook"; case Action::TOGGLE_SPELLBOOK: return "Spellbook";
case Action::TOGGLE_TALENTS: return "Talents"; case Action::TOGGLE_TALENTS: return "Talents";
case Action::TOGGLE_QUESTS: return "Quests"; case Action::TOGGLE_QUESTS: return "Quests";
@ -120,6 +122,7 @@ void KeybindingManager::loadFromConfigFile(const std::string& filePath) {
int actionIdx = -1; int actionIdx = -1;
if (action == "toggle_character_screen") actionIdx = static_cast<int>(Action::TOGGLE_CHARACTER_SCREEN); if (action == "toggle_character_screen") actionIdx = static_cast<int>(Action::TOGGLE_CHARACTER_SCREEN);
else if (action == "toggle_inventory") actionIdx = static_cast<int>(Action::TOGGLE_INVENTORY); else if (action == "toggle_inventory") actionIdx = static_cast<int>(Action::TOGGLE_INVENTORY);
else if (action == "toggle_bags") actionIdx = static_cast<int>(Action::TOGGLE_BAGS);
else if (action == "toggle_spellbook") actionIdx = static_cast<int>(Action::TOGGLE_SPELLBOOK); else if (action == "toggle_spellbook") actionIdx = static_cast<int>(Action::TOGGLE_SPELLBOOK);
else if (action == "toggle_talents") actionIdx = static_cast<int>(Action::TOGGLE_TALENTS); else if (action == "toggle_talents") actionIdx = static_cast<int>(Action::TOGGLE_TALENTS);
else if (action == "toggle_quests") actionIdx = static_cast<int>(Action::TOGGLE_QUESTS); else if (action == "toggle_quests") actionIdx = static_cast<int>(Action::TOGGLE_QUESTS);
@ -210,6 +213,7 @@ void KeybindingManager::saveToConfigFile(const std::string& filePath) const {
} actionMap[] = { } actionMap[] = {
{Action::TOGGLE_CHARACTER_SCREEN, "toggle_character_screen"}, {Action::TOGGLE_CHARACTER_SCREEN, "toggle_character_screen"},
{Action::TOGGLE_INVENTORY, "toggle_inventory"}, {Action::TOGGLE_INVENTORY, "toggle_inventory"},
{Action::TOGGLE_BAGS, "toggle_bags"},
{Action::TOGGLE_SPELLBOOK, "toggle_spellbook"}, {Action::TOGGLE_SPELLBOOK, "toggle_spellbook"},
{Action::TOGGLE_TALENTS, "toggle_talents"}, {Action::TOGGLE_TALENTS, "toggle_talents"},
{Action::TOGGLE_QUESTS, "toggle_quests"}, {Action::TOGGLE_QUESTS, "toggle_quests"},