Kelsidavis-WoWee/include/ui/keybinding_manager.hpp
Kelsi e6741f815a feat: add keybinding manager for customizable action shortcuts
Implement KeybindingManager singleton class to support:
- Storing and loading keybinding configuration from ini files
- Querying whether an action's keybinding was pressed
- Runtime rebinding of actions to different keys
- Default keybinding set: C=Character, I=Inventory, S=Spellbook, K=Talents,
  L=Quests, M=Minimap, Esc=Settings, Enter=Chat

This is the foundation for user-customizable keybindings. Integration with
UI controls and replacement of hard-coded ImGui::IsKeyPressed calls will
follow in subsequent improvements.
2026-03-11 06:26:57 -07:00

82 lines
1.8 KiB
C++

#ifndef WOWEE_KEYBINDING_MANAGER_HPP
#define WOWEE_KEYBINDING_MANAGER_HPP
#include <imgui.h>
#include <string>
#include <unordered_map>
#include <memory>
namespace wowee::ui {
/**
* Manages keybinding configuration for in-game actions.
* Supports loading/saving from config files and runtime rebinding.
*/
class KeybindingManager {
public:
enum class Action {
TOGGLE_CHARACTER_SCREEN,
TOGGLE_INVENTORY,
TOGGLE_SPELLBOOK,
TOGGLE_TALENTS,
TOGGLE_QUESTS,
TOGGLE_MINIMAP,
TOGGLE_SETTINGS,
TOGGLE_CHAT,
ACTION_COUNT
};
static KeybindingManager& getInstance();
/**
* Check if an action's keybinding was just pressed.
* Uses ImGui::IsKeyPressed() internally with the bound key.
*/
bool isActionPressed(Action action, bool repeat = false);
/**
* Get the currently bound key for an action.
*/
ImGuiKey getKeyForAction(Action action) const;
/**
* Rebind an action to a different key.
*/
void setKeyForAction(Action action, ImGuiKey key);
/**
* Reset all keybindings to defaults.
*/
void resetToDefaults();
/**
* Load keybindings from config file.
*/
void loadFromConfigFile(const std::string& filePath);
/**
* Save keybindings to config file.
*/
void saveToConfigFile(const std::string& filePath) const;
/**
* Get human-readable name for an action.
*/
static const char* getActionName(Action action);
/**
* Get all actions for iteration.
*/
static constexpr int getActionCount() { return static_cast<int>(Action::ACTION_COUNT); }
private:
KeybindingManager();
std::unordered_map<int, ImGuiKey> bindings_; // action -> key
void initializeDefaults();
};
} // namespace wowee::ui
#endif // WOWEE_KEYBINDING_MANAGER_HPP