|
Player12
An open source football management simulator
|
Registry of every action. One instance per run (registry()). More...
#include <input_actions.h>
Classes | |
| struct | StringHash |
Public Member Functions | |
| ActionRegistry () | |
| ActionId | registerAction (const ActionDef &def) |
| Registers an action (or returns the existing one). | |
| std::optional< ActionId > | find (std::string_view id) const |
| Handle of an action by id. | |
| const Action & | action (ActionId id) const |
| std::size_t | size () const |
| ImGuiKeyChord | chord (ActionId id, std::size_t slot=0) const |
| Current chord in a slot (ImGuiKey_None when unbound). | |
| std::string | label (ActionId id) const |
| Label of the primary chord, or of the alternate one. | |
| bool | pressed (ActionId id, ImGuiInputFlags flags=ImGuiInputFlags_RouteGlobal) const |
| Pressed this frame through ImGui's shortcut router (any slot). Pass ImGuiInputFlags_Repeat for held keys. A chord is matched exactly: "S" does not fire while Shift is held. | |
| bool | pressed (std::string_view id, ImGuiInputFlags flags=ImGuiInputFlags_RouteGlobal) const |
| pressed() by id; false for unknown ids. | |
| bool | matches (ActionId id, const SDL_KeyboardEvent &event) const |
| True when an SDL key-down event is one of the action's chords. | |
| bool | matches (std::string_view id, const SDL_KeyboardEvent &event) const |
| bool | matchesKey (ActionId id, const SDL_KeyboardEvent &event) const |
| Like matches() but ignoring the modifiers held (key down or up): for held game controls, so a pass key still works while Shift sprints. | |
| bool | matchesKey (std::string_view id, const SDL_KeyboardEvent &event) const |
| std::optional< std::pair< ActionId, std::size_t > > | conflictFor (ActionId id, ImGuiKeyChord chord, std::size_t slot) const |
Another action that would clash with chord in slot of id (same chord, overlapping context). | |
| RebindResult | rebind (ActionId id, std::size_t slot, ImGuiKeyChord chord, bool replace=false) |
Binds a chord (ImGuiKey_None clears the slot). A clash is refused unless replace is true, which clears the other action's slot. Fixed actions and unbindable keys are refused. The settings are updated (not saved to disk). | |
| void | resetToDefault (ActionId id) |
| Restores one action's default chords. | |
| void | resetAll () |
| Restores every action's default chords. | |
| bool | isDefault (ActionId id) const |
| True when an action uses its default chords. | |
| void | reloadFromSettings () |
| Re-applies the bindings stored in the settings. | |
| std::uint32_t | revision () const |
| Bumped by every binding change (for cached labels). | |
| void | forEach (Category category, const std::function< void(ActionId, const Action &)> &visit) const |
Calls visit for each action of a category, in order. | |
Private Member Functions | |
| void | applyStored (ActionId id) |
| void | store (ActionId id) const |
Private Attributes | |
| std::vector< Action > | actions |
| std::uint32_t | revision_ = 0 |
| std::unordered_map< std::string, ActionId, StringHash, std::equal_to<> > | by_id |
Registry of every action. One instance per run (registry()).
Registration is idempotent: registering an id again returns the existing handle, so screens may register their own actions when constructed. Bindings stored in the settings are applied at registration and on reloadFromSettings().
|
default |
|
private |
| ImGuiKeyChord Input::ActionRegistry::chord | ( | ActionId | id, |
| std::size_t | slot = 0 |
||
| ) | const |
Current chord in a slot (ImGuiKey_None when unbound).
| std::optional< std::pair< ActionId, std::size_t > > Input::ActionRegistry::conflictFor | ( | ActionId | id, |
| ImGuiKeyChord | chord, | ||
| std::size_t | slot | ||
| ) | const |
Another action that would clash with chord in slot of id (same chord, overlapping context).
| std::optional< ActionId > Input::ActionRegistry::find | ( | std::string_view | id | ) | const |
Handle of an action by id.
| void Input::ActionRegistry::forEach | ( | Category | category, |
| const std::function< void(ActionId, const Action &)> & | visit | ||
| ) | const |
Calls visit for each action of a category, in order.
| bool Input::ActionRegistry::isDefault | ( | ActionId | id | ) | const |
True when an action uses its default chords.
| std::string Input::ActionRegistry::label | ( | ActionId | id | ) | const |
Label of the primary chord, or of the alternate one.
| bool Input::ActionRegistry::matches | ( | ActionId | id, |
| const SDL_KeyboardEvent & | event | ||
| ) | const |
True when an SDL key-down event is one of the action's chords.
| bool Input::ActionRegistry::matches | ( | std::string_view | id, |
| const SDL_KeyboardEvent & | event | ||
| ) | const |
| bool Input::ActionRegistry::matchesKey | ( | ActionId | id, |
| const SDL_KeyboardEvent & | event | ||
| ) | const |
Like matches() but ignoring the modifiers held (key down or up): for held game controls, so a pass key still works while Shift sprints.
| bool Input::ActionRegistry::matchesKey | ( | std::string_view | id, |
| const SDL_KeyboardEvent & | event | ||
| ) | const |
| bool Input::ActionRegistry::pressed | ( | ActionId | id, |
| ImGuiInputFlags | flags = ImGuiInputFlags_RouteGlobal |
||
| ) | const |
Pressed this frame through ImGui's shortcut router (any slot). Pass ImGuiInputFlags_Repeat for held keys. A chord is matched exactly: "S" does not fire while Shift is held.
| bool Input::ActionRegistry::pressed | ( | std::string_view | id, |
| ImGuiInputFlags | flags = ImGuiInputFlags_RouteGlobal |
||
| ) | const |
pressed() by id; false for unknown ids.
| RebindResult Input::ActionRegistry::rebind | ( | ActionId | id, |
| std::size_t | slot, | ||
| ImGuiKeyChord | chord, | ||
| bool | replace = false |
||
| ) |
Binds a chord (ImGuiKey_None clears the slot). A clash is refused unless replace is true, which clears the other action's slot. Fixed actions and unbindable keys are refused. The settings are updated (not saved to disk).
Registers an action (or returns the existing one).
| void Input::ActionRegistry::reloadFromSettings | ( | ) |
Re-applies the bindings stored in the settings.
| void Input::ActionRegistry::resetAll | ( | ) |
Restores every action's default chords.
| void Input::ActionRegistry::resetToDefault | ( | ActionId | id | ) |
Restores one action's default chords.
|
inline |
Bumped by every binding change (for cached labels).
|
inline |
|
private |
|
private |
|
private |
|
private |