Player12
An open source football management simulator
Loading...
Searching...
No Matches
Input::ActionRegistry Class Reference

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
 

Detailed Description

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().

Constructor & Destructor Documentation

◆ ActionRegistry()

Input::ActionRegistry::ActionRegistry ( )
default

Member Function Documentation

◆ action()

const Action & Input::ActionRegistry::action ( ActionId  id) const

◆ applyStored()

void Input::ActionRegistry::applyStored ( ActionId  id)
private

◆ chord()

ImGuiKeyChord Input::ActionRegistry::chord ( ActionId  id,
std::size_t  slot = 0 
) const

Current chord in a slot (ImGuiKey_None when unbound).

◆ conflictFor()

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).

◆ find()

std::optional< ActionId > Input::ActionRegistry::find ( std::string_view  id) const

Handle of an action by id.

◆ forEach()

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.

◆ isDefault()

bool Input::ActionRegistry::isDefault ( ActionId  id) const

True when an action uses its default chords.

◆ label()

std::string Input::ActionRegistry::label ( ActionId  id) const

Label of the primary chord, or of the alternate one.

◆ matches() [1/2]

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.

◆ matches() [2/2]

bool Input::ActionRegistry::matches ( std::string_view  id,
const SDL_KeyboardEvent &  event 
) const

◆ matchesKey() [1/2]

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.

◆ matchesKey() [2/2]

bool Input::ActionRegistry::matchesKey ( std::string_view  id,
const SDL_KeyboardEvent &  event 
) const

◆ pressed() [1/2]

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.

◆ pressed() [2/2]

bool Input::ActionRegistry::pressed ( std::string_view  id,
ImGuiInputFlags  flags = ImGuiInputFlags_RouteGlobal 
) const

pressed() by id; false for unknown ids.

◆ rebind()

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).

◆ registerAction()

ActionId Input::ActionRegistry::registerAction ( const ActionDef &  def)

Registers an action (or returns the existing one).

◆ reloadFromSettings()

void Input::ActionRegistry::reloadFromSettings ( )

Re-applies the bindings stored in the settings.

◆ resetAll()

void Input::ActionRegistry::resetAll ( )

Restores every action's default chords.

◆ resetToDefault()

void Input::ActionRegistry::resetToDefault ( ActionId  id)

Restores one action's default chords.

◆ revision()

std::uint32_t Input::ActionRegistry::revision ( ) const
inline

Bumped by every binding change (for cached labels).

◆ size()

std::size_t Input::ActionRegistry::size ( ) const
inline

◆ store()

void Input::ActionRegistry::store ( ActionId  id) const
private

Member Data Documentation

◆ actions

std::vector<Action> Input::ActionRegistry::actions
private

◆ by_id

std::unordered_map<std::string, ActionId, StringHash, std::equal_to<> > Input::ActionRegistry::by_id
private

◆ revision_

std::uint32_t Input::ActionRegistry::revision_ = 0
private

The documentation for this class was generated from the following files: