libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
ControllerButton.h
Go to the documentation of this file.
1#pragma once
2
4#include <memory>
5#include <unordered_map>
6#include <string>
8
9namespace Ship {
10class ConsoleVariable;
11class ControlDeck;
12class Window;
13
27 public:
29 void SetControlDeck(std::shared_ptr<ControlDeck> controlDeck) {
30 mControlDeck = std::move(controlDeck);
31 }
38 ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask,
39 std::shared_ptr<ConsoleVariable> consoleVariable = nullptr,
40 std::shared_ptr<ControlDeck> controlDeck = nullptr, std::shared_ptr<Window> window = nullptr);
42
47 std::shared_ptr<ControllerButtonMapping> GetButtonMappingById(std::string id);
48
52 std::unordered_map<std::string, std::shared_ptr<ControllerButtonMapping>> GetAllButtonMappings();
53
58 void AddButtonMapping(std::shared_ptr<ControllerButtonMapping> mapping);
59
64 void ClearButtonMappingId(std::string id);
65
70 void ClearButtonMapping(std::string id);
71
76 void ClearButtonMapping(std::shared_ptr<ControllerButtonMapping> mapping);
77
82 void AddDefaultMappings(PhysicalDeviceType physicalDeviceType);
83
88 void LoadButtonMappingFromConfig(std::string id);
89
94
99
102
108
120
126
133 bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
134
141 bool ProcessMouseButtonEvent(bool isPressed, Ship::MouseBtn button);
142
148
149 private:
150 uint8_t mPortIndex;
151 CONTROLLERBUTTONS_T mBitmask;
152 std::unordered_map<std::string, std::shared_ptr<ControllerButtonMapping>> mButtonMappings;
153 std::string GetConfigNameFromBitmask(CONTROLLERBUTTONS_T bitmask);
154
155 bool mUseEventInputToCreateNewMapping;
156 KbScancode mKeyboardScancodeForNewMapping;
157 MouseBtn mMouseButtonForNewMapping;
158
159 std::shared_ptr<ConsoleVariable> mConsoleVariable;
160 std::shared_ptr<ControlDeck> mControlDeck;
161 std::shared_ptr<Window> mWindow;
162};
163} // namespace Ship
#define CONTROLLERBUTTONS_T
Definition ControllerButtonMapping.h:13
Aggregates all ControllerButtonMapping instances for a single logical button.
Definition ControllerButton.h:26
void UpdatePad(CONTROLLERBUTTONS_T &padButtons)
Evaluates all active mappings and sets the corresponding bits in padButtons.
void AddDefaultMappings(PhysicalDeviceType physicalDeviceType)
Applies the default mappings for the given physical device type.
void AddButtonMapping(std::shared_ptr< ControllerButtonMapping > mapping)
Adds a new mapping to this button's collection.
void ClearAllButtonMappingsForDeviceType(PhysicalDeviceType physicalDeviceType)
Removes all mappings that target the given physical device type.
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode)
Forwards a keyboard event to all mappings that handle keyboard input.
void ClearAllButtonMappings()
Removes every in-memory mapping (does not touch Config).
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 ReloadAllMappingsFromConfig()
Clears all in-memory mappings and reloads them from Config.
void LoadButtonMappingFromConfig(std::string id)
Loads the mapping identified by id from Config and adds it to the collection.
std::shared_ptr< ControllerButtonMapping > GetButtonMappingById(std::string id)
Returns the mapping with the given unique ID, or nullptr if not found.
void ClearButtonMapping(std::shared_ptr< ControllerButtonMapping > mapping)
Removes the given mapping instance from both the in-memory map and Config.
bool ProcessMouseButtonEvent(bool isPressed, Ship::MouseBtn button)
Forwards a mouse-button event to all mappings that handle mouse input.
std::unordered_map< std::string, std::shared_ptr< ControllerButtonMapping > > GetAllButtonMappings()
Returns a copy of the full id → mapping map.
bool AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bitmask, std::string id)
Listens for the next raw physical input and adds or replaces a mapping for it.
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.
void SetControlDeck(std::shared_ptr< ControlDeck > controlDeck)
Injects the owning ControlDeck.
Definition ControllerButton.h:29
bool HasMappingsForPhysicalDeviceType(PhysicalDeviceType physicalDeviceType)
Returns true if any mapping targets the given physical device type.
void SaveButtonMappingIdsToConfig()
Writes the current set of mapping IDs to Config so they can be reloaded later.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
PhysicalDeviceType
Identifies the category of a physical input device.
Definition PhysicalDeviceType.h:11
KbScancode
Platform-independent keyboard scan codes used by the input mapping system.
Definition KeyboardScancodes.h:26
KbEventType
Identifies the type of a keyboard event delivered to the input mapping system.
Definition KeyboardScancodes.h:12
MouseBtn
Identifies a mouse button delivered to the input mapping system.
Definition KeyboardScancodes.h:136