mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
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.
This commit is contained in:
parent
79c8d93c45
commit
e6741f815a
3 changed files with 338 additions and 0 deletions
82
include/ui/keybinding_manager.hpp
Normal file
82
include/ui/keybinding_manager.hpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
#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
|
||||
Loading…
Add table
Add a link
Reference in a new issue