libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::ControllerButton Class Reference

Aggregates all ControllerButtonMapping instances for a single logical button. More...

#include <ControllerButton.h>

Public Member Functions

void SetControlDeck (std::shared_ptr< ControlDeck > controlDeck)
 Injects the owning ControlDeck.
 
 ControllerButton (uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, std::shared_ptr< ConsoleVariable > consoleVariable=nullptr, std::shared_ptr< ControlDeck > controlDeck=nullptr, std::shared_ptr< Window > window=nullptr)
 Constructs a ControllerButton for a specific port and bitmask.
 
 ~ControllerButton ()
 
std::shared_ptr< ControllerButtonMappingGetButtonMappingById (std::string id)
 Returns the mapping with the given unique ID, or nullptr if not found.
 
std::unordered_map< std::string, std::shared_ptr< ControllerButtonMapping > > GetAllButtonMappings ()
 Returns a copy of the full id → mapping map.
 
void AddButtonMapping (std::shared_ptr< ControllerButtonMapping > mapping)
 Adds a new mapping to this button's collection.
 
void ClearButtonMappingId (std::string id)
 Removes the ID from Config without destroying the in-memory mapping object.
 
void ClearButtonMapping (std::string id)
 Removes the mapping with the given ID from both the in-memory map and Config.
 
void ClearButtonMapping (std::shared_ptr< ControllerButtonMapping > mapping)
 Removes the given mapping instance from both the in-memory map and Config.
 
void AddDefaultMappings (PhysicalDeviceType physicalDeviceType)
 Applies the default mappings for the given physical device type.
 
void LoadButtonMappingFromConfig (std::string id)
 Loads the mapping identified by id from Config and adds it to the collection.
 
void SaveButtonMappingIdsToConfig ()
 Writes the current set of mapping IDs to Config so they can be reloaded later.
 
void ReloadAllMappingsFromConfig ()
 Clears all in-memory mappings and reloads them from Config.
 
void ClearAllButtonMappings ()
 Removes every in-memory mapping (does not touch Config).
 
void ClearAllButtonMappingsForDeviceType (PhysicalDeviceType physicalDeviceType)
 Removes all mappings that target the given physical device type.
 
bool AddOrEditButtonMappingFromRawPress (CONTROLLERBUTTONS_T bitmask, std::string id)
 Listens for the next raw physical input and adds or replaces a mapping for it.
 
void UpdatePad (CONTROLLERBUTTONS_T &padButtons)
 Evaluates all active mappings and sets the corresponding bits in padButtons.
 
bool ProcessKeyboardEvent (KbEventType eventType, KbScancode scancode)
 Forwards a keyboard event to all mappings that handle keyboard input.
 
bool ProcessMouseButtonEvent (bool isPressed, Ship::MouseBtn button)
 Forwards a mouse-button event to all mappings that handle mouse input.
 
bool HasMappingsForPhysicalDeviceType (PhysicalDeviceType physicalDeviceType)
 Returns true if any mapping targets the given physical device type.
 

Detailed Description

Aggregates all ControllerButtonMapping instances for a single logical button.

ControllerButton represents one digital button bitmask on a Controller (e.g. the A button). It can hold multiple ControllerButtonMapping instances simultaneously, allowing the same logical button to be triggered by a keyboard key, a gamepad face button, or a mouse click all at the same time.

Mappings are persisted in Config and can be loaded/saved via the Config methods. The class also supports "listen for raw press" mode, where the next physical input received is automatically captured as a new mapping.

Constructor & Destructor Documentation

◆ ControllerButton()

Ship::ControllerButton::ControllerButton ( uint8_t  portIndex,
CONTROLLERBUTTONS_T  bitmask,
std::shared_ptr< ConsoleVariable consoleVariable = nullptr,
std::shared_ptr< ControlDeck controlDeck = nullptr,
std::shared_ptr< Window window = nullptr 
)

Constructs a ControllerButton for a specific port and bitmask.

Parameters
portIndexZero-based port index.
bitmaskSingle-bit bitmask representing this button (e.g. 0x0001 for A).
consoleVariableOptional ConsoleVariable dependency; falls back to Context lookup if nullptr.

◆ ~ControllerButton()

Ship::ControllerButton::~ControllerButton ( )

Member Function Documentation

◆ AddButtonMapping()

void Ship::ControllerButton::AddButtonMapping ( std::shared_ptr< ControllerButtonMapping mapping)

Adds a new mapping to this button's collection.

Parameters
mappingMapping to add. Its ID must be unique within this button.

◆ AddDefaultMappings()

void Ship::ControllerButton::AddDefaultMappings ( PhysicalDeviceType  physicalDeviceType)

Applies the default mappings for the given physical device type.

Parameters
physicalDeviceTypeType of device (keyboard, SDL gamepad, etc.).

◆ AddOrEditButtonMappingFromRawPress()

bool Ship::ControllerButton::AddOrEditButtonMappingFromRawPress ( CONTROLLERBUTTONS_T  bitmask,
std::string  id 
)

Listens for the next raw physical input and adds or replaces a mapping for it.

If id is non-empty, the existing mapping with that ID is replaced; otherwise a new mapping is created.

Parameters
bitmaskButton bitmask to associate with the captured input.
idOptional UUID of an existing mapping to replace.
Returns
true if a new mapping was captured and added.

◆ ClearAllButtonMappings()

void Ship::ControllerButton::ClearAllButtonMappings ( )

Removes every in-memory mapping (does not touch Config).

◆ ClearAllButtonMappingsForDeviceType()

void Ship::ControllerButton::ClearAllButtonMappingsForDeviceType ( PhysicalDeviceType  physicalDeviceType)

Removes all mappings that target the given physical device type.

Parameters
physicalDeviceTypeDevice type whose mappings should be cleared.

◆ ClearButtonMapping() [1/2]

void Ship::ControllerButton::ClearButtonMapping ( std::shared_ptr< ControllerButtonMapping mapping)

Removes the given mapping instance from both the in-memory map and Config.

Parameters
mappingMapping to remove.

◆ ClearButtonMapping() [2/2]

void Ship::ControllerButton::ClearButtonMapping ( std::string  id)

Removes the mapping with the given ID from both the in-memory map and Config.

Parameters
idMapping UUID to remove.

◆ ClearButtonMappingId()

void Ship::ControllerButton::ClearButtonMappingId ( std::string  id)

Removes the ID from Config without destroying the in-memory mapping object.

Parameters
idMapping UUID to unregister.

◆ GetAllButtonMappings()

std::unordered_map< std::string, std::shared_ptr< ControllerButtonMapping > > Ship::ControllerButton::GetAllButtonMappings ( )

Returns a copy of the full id → mapping map.

◆ GetButtonMappingById()

std::shared_ptr< ControllerButtonMapping > Ship::ControllerButton::GetButtonMappingById ( std::string  id)

Returns the mapping with the given unique ID, or nullptr if not found.

Parameters
idMapping UUID.

◆ HasMappingsForPhysicalDeviceType()

bool Ship::ControllerButton::HasMappingsForPhysicalDeviceType ( PhysicalDeviceType  physicalDeviceType)

Returns true if any mapping targets the given physical device type.

Parameters
physicalDeviceTypeDevice type to query.

◆ LoadButtonMappingFromConfig()

void Ship::ControllerButton::LoadButtonMappingFromConfig ( std::string  id)

Loads the mapping identified by id from Config and adds it to the collection.

Parameters
idMapping UUID stored in Config.

◆ ProcessKeyboardEvent()

bool Ship::ControllerButton::ProcessKeyboardEvent ( KbEventType  eventType,
KbScancode  scancode 
)

Forwards a keyboard event to all mappings that handle keyboard input.

Parameters
eventTypeKey-down or key-up.
scancodePlatform-independent scan code.
Returns
true if any mapping consumed the event.

◆ ProcessMouseButtonEvent()

bool Ship::ControllerButton::ProcessMouseButtonEvent ( bool  isPressed,
Ship::MouseBtn  button 
)

Forwards a mouse-button event to all mappings that handle mouse input.

Parameters
isPressedtrue for button-down, false for button-up.
buttonMouse button identifier.
Returns
true if any mapping consumed the event.

◆ ReloadAllMappingsFromConfig()

void Ship::ControllerButton::ReloadAllMappingsFromConfig ( )

Clears all in-memory mappings and reloads them from Config.

◆ SaveButtonMappingIdsToConfig()

void Ship::ControllerButton::SaveButtonMappingIdsToConfig ( )

Writes the current set of mapping IDs to Config so they can be reloaded later.

◆ SetControlDeck()

void Ship::ControllerButton::SetControlDeck ( std::shared_ptr< ControlDeck controlDeck)
inline

Injects the owning ControlDeck.

◆ UpdatePad()

void Ship::ControllerButton::UpdatePad ( CONTROLLERBUTTONS_T padButtons)

Evaluates all active mappings and sets the corresponding bits in padButtons.

Parameters
padButtonsReference to the pad button bitfield to update.

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