HoverRace
2.0
|
Translates input events into actions. More...
#include <Controller.h>
Classes | |
struct | actions_t |
Public Types | |
using | ActionMap = std::map< int, ControlActionPtr > |
enum | ActionMapId : size_t { ActionMapId::CAMERA = 0x01, ActionMapId::CONSOLE = 0x02, ActionMapId::CONSOLE_TOGGLE = 0x04, ActionMapId::MENU = 0x08, ActionMapId::PLAYER = 0x10 } |
enum | axis_t { AXIS_X = 1, AXIS_Y, AXIS_Z, AXIS_WHEEL_X, AXIS_WHEEL_Y } |
using | MouseClickActionPtr = std::shared_ptr< Action< mouseClickSignal_t, const Mouse::Click & >> |
using | MouseScrollActionPtr = std::shared_ptr< Action< mouseScrollSignal_t, const Mouse::Scroll & >> |
using | StringActionPtr = std::shared_ptr< Action< stringSignal_t, const std::string & >> |
using | TextControlActionPtr = std::shared_ptr< Action< textControlSignal_t, TextControl::key_t >> |
using | ValueActionPtr = std::shared_ptr< Action< valueSignal_t >> |
using | Vec2ActionPtr = std::shared_ptr< Action< vec2Signal_t, const Vec2 & >> |
using | VoidActionPtr = std::shared_ptr< Action< voidSignal_t >> |
Public Member Functions | |
InputEventController () | |
~InputEventController () | |
bool | AddActionMap (const std::string &mapname, ActionMapId mapId) |
Add an action map into the current action map. More... | |
void | AddCameraMaps () |
Enable camera controls. More... | |
void | AddConsoleMaps () |
Enable console scroll controls. More... | |
void | AddConsoleToggleMaps () |
Enable console toggle. More... | |
void | AddMenuMaps () |
Enable menu controls. More... | |
void | AddPlayerMaps (int numPlayers, MainCharacter::MainCharacter **mcs) |
Update player mappings to point to correct MainCharacter objects, then add them to the active action map. More... | |
void | CaptureNextInput (int oldhash, std::string mapname) |
Capture the next user input event and reassign hash. More... | |
void | ClearActionMap () |
Clears all of the active control bindings. More... | |
void | DisableCaptureInput () |
Assign the next disabled hash to the current capture control. More... | |
ActionMap & | GetActionMap (std::string key) |
Return the map with the given key. More... | |
std::vector< std::string > | GetAvailableMaps () |
Return a vector containing the names of all the available maps. More... | |
void | HandleEvent (int hash, int value) |
VoidActionPtr | Hotkey (const std::string &key) |
Assign an action to a hotkey. More... | |
bool | IsCapturing () |
Check if the controller is currently capturing input. More... | |
bool | IsMapActive (ActionMapId id) |
Check if a control map is active. More... | |
void | LoadCameraMap () |
Set up camera controls. More... | |
void | LoadConfig () |
Load the configuration from the Config object. More... | |
void | LoadConsoleMap () |
Set up the console navigation controls. More... | |
void | LoadConsoleToggleMap () |
Set up the console toggle control. More... | |
void | LoadMenuMap () |
Set up menu controls. More... | |
bool | OnKeyPressed (const SDL_KeyboardEvent &arg) |
bool | OnKeyReleased (const SDL_KeyboardEvent &arg) |
bool | OnMouseMoved (const SDL_MouseMotionEvent &evt) |
bool | OnMousePressed (const SDL_MouseButtonEvent &evt) |
bool | OnMouseReleased (const SDL_MouseButtonEvent &evt) |
bool | OnMouseWheel (const SDL_MouseWheelEvent &evt) |
bool | OnTextInput (const SDL_TextInputEvent &evt) |
void | ProcessInputEvent (const SDL_Event &evt) |
void | ReloadConfig () |
Clear and reload entire configuration. More... | |
void | SaveConfig () |
Save the controller configuration to the Config object. More... | |
void | StopCapture () |
Exit capture mode. More... | |
SDL_Keycode | StringToKey (const std::string &s) |
Convert a canonical key name into a keycode. More... | |
Static Public Member Functions | |
static int | HashKeyboardEvent (const SDL_Keycode &arg) |
static int | HashMouseAxisEvent (axis_t axis, int direction) |
static int | HashMouseButtonEvent (const SDL_MouseButtonEvent &arg) |
static std::string | HashToString (int hash) |
Convert a hash into an internationalized string. More... | |
Public Attributes | |
struct HoverRace::Control::InputEventController::actions_t | actions |
Private Member Functions | |
int | GetNextAvailableDisabledHash () |
void | RebindKey (std::string mapname, int oldhash, int newhash) |
Private Attributes | |
ActionMap | actionMap |
We store several different action maps which we can choose from. More... | |
size_t | activeMaps |
std::map< std::string, ActionMap > | allActionMaps |
std::string | captureMap |
name of the map we are capturing for More... | |
bool | captureNextInput |
int | captureOldHash |
stores the value of the hash we will be replacing when capturing input More... | |
std::unordered_map< SDL_Keycode, VoidActionPtr > | hotkeys |
Vec2 | mousePos |
Track most-recent mouse position for lookup later. More... | |
int | nextAvailableDisabledHash |
Translates input events into actions.
The app class (the one running the SDL event loop), passes along input events to this class, which then fires the mapped action. Listeners can subscribe to the actions via the InputEventController::actions struct.
[Util::Config] | | [app] --(SDL_Event)--> [InputEventController] --(actions)--> [listeners]
Typically, to listen to an action, the listener must call the appropriate Add* function to enable the group of actions then call Action::Connect on the desired action to bind a function to the action. In subclasses of Client::Scene this is done in Client::Scene::AttachController.
Example:
controller.AddCameraMaps(); cameraZoomInConn = controller.actions.camera.zoomIn->Connect( std::bind(&GameScene::OnCameraZoom, this, 1));
Action::Connect returns a boost::signals2::connection. Be sure to call disconnect() on this connection to clean up. In subclasses of Client::Scene this is done in Client::Scene::DetachController.
using HoverRace::Control::InputEventController::MouseClickActionPtr = std::shared_ptr<Action<mouseClickSignal_t, const Mouse::Click&>> |
using HoverRace::Control::InputEventController::MouseScrollActionPtr = std::shared_ptr<Action<mouseScrollSignal_t, const Mouse::Scroll&>> |
using HoverRace::Control::InputEventController::StringActionPtr = std::shared_ptr<Action<stringSignal_t, const std::string&>> |
using HoverRace::Control::InputEventController::TextControlActionPtr = std::shared_ptr<Action<textControlSignal_t, TextControl::key_t>> |
using HoverRace::Control::InputEventController::ValueActionPtr = std::shared_ptr<Action<valueSignal_t>> |
using HoverRace::Control::InputEventController::Vec2ActionPtr = std::shared_ptr<Action<vec2Signal_t, const Vec2&>> |
using HoverRace::Control::InputEventController::VoidActionPtr = std::shared_ptr<Action<voidSignal_t>> |
|
strong |
HoverRace::Control::InputEventController::InputEventController | ( | ) |
HoverRace::Control::InputEventController::~InputEventController | ( | ) |
bool HoverRace::Control::InputEventController::AddActionMap | ( | const std::string & | mapname, |
ActionMapId | mapId | ||
) |
Add an action map into the current action map.
The available maps are referenced by string. Maps include:
"player1" ... "player4"
mapname | The action map name. |
mapId | The action map ID. |
false
if the map is not found void HoverRace::Control::InputEventController::AddCameraMaps | ( | ) |
Enable camera controls.
void HoverRace::Control::InputEventController::AddConsoleMaps | ( | ) |
Enable console scroll controls.
void HoverRace::Control::InputEventController::AddConsoleToggleMaps | ( | ) |
Enable console toggle.
void HoverRace::Control::InputEventController::AddMenuMaps | ( | ) |
Enable menu controls.
void HoverRace::Control::InputEventController::AddPlayerMaps | ( | int | numPlayers, |
MainCharacter::MainCharacter ** | mcs | ||
) |
Update player mappings to point to correct MainCharacter objects, then add them to the active action map.
If nullptr
is passed as any of the pointers that map will not be added. The "console-toggle" map will also be added.
numPlayers | The number of players to update. |
mcs | A pointer to the list of MainCharacter objects. |
void HoverRace::Control::InputEventController::CaptureNextInput | ( | int | oldhash, |
std::string | mapname | ||
) |
Capture the next user input event and reassign hash.
This function tells the InputEventController to capture the next user input event and assign the action currently residing at 'oldhash' to the hash of the new input. Behavior is undefined if there is no action assigned to the old hash, so don't screw it up! This is meant to be called by the control assignment dialog box.
oldhash | Old hash. |
mapname | String representing the name of the map. |
void HoverRace::Control::InputEventController::ClearActionMap | ( | ) |
Clears all of the active control bindings.
Does not delete the bindings but simply removes them from the active action map.
void HoverRace::Control::InputEventController::DisableCaptureInput | ( | ) |
Assign the next disabled hash to the current capture control.
Nothing will be done if the InputEventController is not in capture mode. This function will also disable capture mode.
InputEventController::ActionMap & HoverRace::Control::InputEventController::GetActionMap | ( | std::string | key | ) |
Return the map with the given key.
vector< string > HoverRace::Control::InputEventController::GetAvailableMaps | ( | ) |
Return a vector containing the names of all the available maps.
|
private |
void HoverRace::Control::InputEventController::HandleEvent | ( | int | hash, |
int | value | ||
) |
|
static |
|
static |
|
static |
|
static |
Convert a hash into an internationalized string.
hash | The control hash, from one of the hash functions, e.g. HashKeyboardEvent. |
InputEventController::VoidActionPtr HoverRace::Control::InputEventController::Hotkey | ( | const std::string & | key | ) |
Assign an action to a hotkey.
Hotkey actions are activated in *addition* to any normal action assigned to the key.
key | The string representation of the key. |
nullptr
if the key is an invalid key for a hotkey. bool HoverRace::Control::InputEventController::IsCapturing | ( | ) |
Check if the controller is currently capturing input.
It can be used to check whether or not an input has been captured.
true
if in capture mode, false
otherwise.
|
inline |
Check if a control map is active.
id | The map to look up. |
true
if active, false
if inactive. void HoverRace::Control::InputEventController::LoadCameraMap | ( | ) |
Set up camera controls.
void HoverRace::Control::InputEventController::LoadConfig | ( | ) |
Load the configuration from the Config object.
void HoverRace::Control::InputEventController::LoadConsoleMap | ( | ) |
Set up the console navigation controls.
void HoverRace::Control::InputEventController::LoadConsoleToggleMap | ( | ) |
Set up the console toggle control.
void HoverRace::Control::InputEventController::LoadMenuMap | ( | ) |
Set up menu controls.
bool HoverRace::Control::InputEventController::OnKeyPressed | ( | const SDL_KeyboardEvent & | arg | ) |
bool HoverRace::Control::InputEventController::OnKeyReleased | ( | const SDL_KeyboardEvent & | arg | ) |
bool HoverRace::Control::InputEventController::OnMouseMoved | ( | const SDL_MouseMotionEvent & | evt | ) |
bool HoverRace::Control::InputEventController::OnMousePressed | ( | const SDL_MouseButtonEvent & | evt | ) |
bool HoverRace::Control::InputEventController::OnMouseReleased | ( | const SDL_MouseButtonEvent & | evt | ) |
bool HoverRace::Control::InputEventController::OnMouseWheel | ( | const SDL_MouseWheelEvent & | evt | ) |
bool HoverRace::Control::InputEventController::OnTextInput | ( | const SDL_TextInputEvent & | evt | ) |
void HoverRace::Control::InputEventController::ProcessInputEvent | ( | const SDL_Event & | evt | ) |
|
private |
void HoverRace::Control::InputEventController::ReloadConfig | ( | ) |
Clear and reload entire configuration.
void HoverRace::Control::InputEventController::SaveConfig | ( | ) |
Save the controller configuration to the Config object.
void HoverRace::Control::InputEventController::StopCapture | ( | ) |
Exit capture mode.
SDL_Keycode HoverRace::Control::InputEventController::StringToKey | ( | const std::string & | s | ) |
Convert a canonical key name into a keycode.
The canonical key name is used in scripts and isn't translated.
s | The key name. |
SDLK_UNKNOWN
if the key name is unknown.
|
private |
We store several different action maps which we can choose from.
They are referenced by string. See ClearActionMap(), AddActionMap().
struct HoverRace::Control::InputEventController::actions_t HoverRace::Control::InputEventController::actions |
|
private |
|
private |
name of the map we are capturing for
|
private |
|
private |
stores the value of the hash we will be replacing when capturing input
|
private |
|
private |
Track most-recent mouse position for lookup later.
|
private |