|
R-Type
Distributed multiplayer game engine in C++
|
Centralized key binding manager (Singleton) More...
#include <KeyBindings.hpp>

Classes | |
| struct | KeyBinding |
Public Member Functions | |
| KeyBindings (const KeyBindings &)=delete | |
| KeyBindings & | operator= (const KeyBindings &)=delete |
| KeyBindings (KeyBindings &&)=delete | |
| KeyBindings & | operator= (KeyBindings &&)=delete |
| void | ResetToDefaults () |
| Reset all bindings to defaults. | |
| int | GetPrimaryKey (GameAction action) const |
| Get the primary key for an action. | |
| int | GetSecondaryKey (GameAction action) const |
| Get the secondary key for an action. | |
| void | SetPrimaryKey (GameAction action, int key) |
| Set the primary key for an action. | |
| void | SetSecondaryKey (GameAction action, int key) |
| Set the secondary key for an action. | |
| void | ClearSecondaryKey (GameAction action) |
| Clear the secondary key for an action. | |
| bool | IsKeyBoundToAction (GameAction action, int key) const |
| Check if a key is bound to an action (primary or secondary) | |
| void | SetOnBindingsChanged (std::function< void()> callback) |
| Set callback for when bindings change. | |
| bool | SaveToFile (const std::string &filepath) const |
| Save bindings to a file. | |
| bool | LoadFromFile (const std::string &filepath) |
| Load bindings from a file. | |
Static Public Member Functions | |
| static KeyBindings & | getInstance () |
| Get the singleton instance. | |
| static std::string | GetKeyName (int key) |
| Get human-readable name of a key. | |
| static std::string | GetGamepadButtonName (int button) |
| Get human-readable name of a gamepad button. | |
| static std::string | GetBindingName (int binding) |
| Get human-readable name of a binding (keyboard key or gamepad button) | |
| static std::string | GetActionName (GameAction action) |
| Get human-readable name of an action. | |
Private Member Functions | |
| KeyBindings () | |
| ~KeyBindings ()=default | |
| void | NotifyBindingsChanged () |
Private Attributes | |
| std::unordered_map< GameAction, KeyBinding > | _bindings |
| std::function< void()> | _onBindingsChanged |
Centralized key binding manager (Singleton)
Manages all game key bindings with support for:
Definition at line 79 of file KeyBindings.hpp.
|
delete |
|
delete |
|
private |
Definition at line 20 of file KeyBindings.cpp.
References ResetToDefaults().

|
privatedefault |
| void Input::KeyBindings::ClearSecondaryKey | ( | GameAction | action | ) |
Clear the secondary key for an action.
| action | The game action |
Definition at line 77 of file KeyBindings.cpp.
References _bindings, and NotifyBindingsChanged().
Referenced by Game::KeyBindingsMenu::CreateBindingRow().

|
static |
Get human-readable name of an action.
| action | The game action |
Definition at line 238 of file KeyBindings.cpp.
References Input::CHAT_OPEN, Input::MENU_BACK, Input::MENU_CONFIRM, Input::MENU_NEXT, Input::MENU_PREVIOUS, Input::MOVE_DOWN, Input::MOVE_LEFT, Input::MOVE_RIGHT, Input::MOVE_UP, Input::PAUSE_MENU, and Input::SHOOT.
Referenced by Game::KeyBindingsMenu::CreateBindingRow(), Game::KeyBindingsMenu::HandleCapturedKey(), Game::KeyBindingsMenu::Render(), and Game::KeyBindingsMenu::StartKeyCapture().
|
static |
Get human-readable name of a binding (keyboard key or gamepad button)
| binding | The binding value (may be key or GAMEPAD_BUTTON_OFFSET + button) |
Definition at line 228 of file KeyBindings.cpp.
References Input::BindingToGamepadButton(), GetGamepadButtonName(), GetKeyName(), and Input::IsGamepadBinding().
Referenced by Game::KeyBindingsMenu::CreateBindingRow(), and Game::KeyBindingsMenu::UpdateBindingButtonText().

|
static |
Get human-readable name of a gamepad button.
| button | The button code (GAMEPAD_BUTTON_* constant) |
Definition at line 199 of file KeyBindings.cpp.
Referenced by GetBindingName().
|
static |
Get the singleton instance.
Definition at line 15 of file KeyBindings.cpp.
Referenced by Game::KeyBindingsMenu::CreateBindingRow(), Game::KeyBindingsMenu::HandleCapturedKey(), Rendering::HandleEscapeKeyInput(), UI::RaylibMenu::HandleKeyboardNavigation(), Rendering::InitializeKeyBindingsMenu(), Rendering::InitializeMenus(), GameLoop::processInput(), and Game::KeyBindingsMenu::UpdateBindingButtonText().
|
static |
Get human-readable name of a key.
| key | The key code |
Definition at line 90 of file KeyBindings.cpp.
Referenced by GetBindingName(), and Game::KeyBindingsMenu::HandleCapturedKey().
| int Input::KeyBindings::GetPrimaryKey | ( | GameAction | action | ) | const |
Get the primary key for an action.
| action | The game action |
Definition at line 51 of file KeyBindings.cpp.
References _bindings.
| int Input::KeyBindings::GetSecondaryKey | ( | GameAction | action | ) | const |
Get the secondary key for an action.
| action | The game action |
Definition at line 59 of file KeyBindings.cpp.
References _bindings.
| bool Input::KeyBindings::IsKeyBoundToAction | ( | GameAction | action, |
| int | key | ||
| ) | const |
Check if a key is bound to an action (primary or secondary)
| action | The game action to check |
| key | The key code to check |
Definition at line 82 of file KeyBindings.cpp.
References _bindings.
| bool Input::KeyBindings::LoadFromFile | ( | const std::string & | filepath | ) |
Load bindings from a file.
| filepath | Path to load file |
Definition at line 285 of file KeyBindings.cpp.
References _bindings, LOG_INFO, LOG_WARNING, and NotifyBindingsChanged().
Referenced by Rendering::InitializeMenus().

|
private |
Definition at line 264 of file KeyBindings.cpp.
References _onBindingsChanged.
Referenced by ClearSecondaryKey(), LoadFromFile(), ResetToDefaults(), SetPrimaryKey(), and SetSecondaryKey().
|
delete |
|
delete |
| void Input::KeyBindings::ResetToDefaults | ( | ) |
Reset all bindings to defaults.
Definition at line 24 of file KeyBindings.cpp.
References _bindings, Input::CHAT_OPEN, Input::GamepadButtonToBinding(), Input::MENU_BACK, Input::MENU_CONFIRM, Input::MENU_NEXT, Input::MENU_PREVIOUS, Input::MOVE_DOWN, Input::MOVE_LEFT, Input::MOVE_RIGHT, Input::MOVE_UP, NotifyBindingsChanged(), Input::PAUSE_MENU, and Input::SHOOT.
Referenced by KeyBindings().

| bool Input::KeyBindings::SaveToFile | ( | const std::string & | filepath | ) | const |
Save bindings to a file.
| filepath | Path to save file |
Definition at line 270 of file KeyBindings.cpp.
References _bindings, LOG_ERROR, and LOG_INFO.
Referenced by Rendering::InitializeKeyBindingsMenu().
| void Input::KeyBindings::SetOnBindingsChanged | ( | std::function< void()> | callback | ) |
Set callback for when bindings change.
| callback | Function to call when any binding changes |
Definition at line 260 of file KeyBindings.cpp.
References _onBindingsChanged.
| void Input::KeyBindings::SetPrimaryKey | ( | GameAction | action, |
| int | key | ||
| ) |
Set the primary key for an action.
| action | The game action |
| key | The key code to bind |
Definition at line 67 of file KeyBindings.cpp.
References _bindings, and NotifyBindingsChanged().

| void Input::KeyBindings::SetSecondaryKey | ( | GameAction | action, |
| int | key | ||
| ) |
Set the secondary key for an action.
| action | The game action |
| key | The key code to bind |
Definition at line 72 of file KeyBindings.cpp.
References _bindings, and NotifyBindingsChanged().

|
private |
Definition at line 197 of file KeyBindings.hpp.
Referenced by ClearSecondaryKey(), GetPrimaryKey(), GetSecondaryKey(), IsKeyBoundToAction(), LoadFromFile(), ResetToDefaults(), SaveToFile(), SetPrimaryKey(), and SetSecondaryKey().
|
private |
Definition at line 198 of file KeyBindings.hpp.
Referenced by NotifyBindingsChanged(), and SetOnBindingsChanged().