Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input action system and re-designed UI event handling #219

Merged
merged 67 commits into from
Aug 9, 2021
Merged

Conversation

afritz1
Copy link
Owner

@afritz1 afritz1 commented Aug 8, 2021

Previously, all UI panels listened to hardcoded SDL keycodes and mouse button presses, and each panel manually implemented the means of clicking a button.

Now, panels register various types of input listeners and all SDL events are handled by the InputManager. Some of the input listeners are for input actions (inspired by Unity's input actions) which allow panels to register a callback with a string that points to an input action definition for a physical input event (key down, key up, mouse button down, etc.). This should make key rebinding much easier to implement, although that has not been started yet.

There are a couple weird places where a fullscreen button is used to implement a panel's interactivity. Not sure if that needs to change, but it's just a little weird.

Not completely set on the idea of held keys and mouse buttons being broadcast as events; might make them public getters on the input manager in the future instead.

afritz1 added 30 commits July 9, 2021 22:01
Thinking that input actions will strictly be hotkey-like data and pointer input will involve mouse position and selecting UI buttons.
The input manager will register them all at application start and then various UI situations will enable/disable them.
Needed a more convenient function than std::strcmp() for const char*.
Input action maps are disabled by default and need to be turned on for UI contexts that need them.
Each Panel gets a unique input listener ID on construction so the input manager can add and remove listeners without ambiguity.
The places where these events are currently handled in Game::handleEvents() will be changed over to use these callbacks soon.
Needed to add support for tracking freed input listeners so the add listener functions can return an ID instead of require one. This way things are much closer to texture allocation than their own pattern. Panel intentionally does not store application exit or window resized listener IDs because it is not allowed to; the game loop will listen to those exclusively.
The first key I tested with was PrintScreen and at first I thought it was a bug that its key down was firing the same time as the key up, but that seems to be exclusively a behavior with that key for some reason.
Resetting the callbacks to just their default constructor does not make them callable, have to assign a dummy callable.
Need to implement mouse button held handling in InputManager.
Allowing hotkeys like Escape and Enter to work during text entry so we can get out of things like the name screen in character creation or note writing in the automap.
This was interfering with the automap hotkey while in the automap because the automap input action map is not allowed in text entry mode, and text entry mode is on by default at application start?
Need to allow panel changes to happen for each processed event in case two events on the same frame attempt to change the current panel, which is not allowed.
Trying to mitigate the cost of applying the input system changes across all the game's panels.
Input listeners for panels need to be disabled but kept alive when pop-ups are displayed over them.
The input manager should take care of checking if the mouse clicks a button, instead of each panel implementing that itself. The ButtonProxy has a parameter-less callback that wraps the button's variadic template callback.
This did not have a physical on-screen button and was treated exclusively as a hotkey, which is now superseded by input actions. Going to apply this change to the other panels.
Also changed ButtonProxy Rect to a function to support moving buttons like ListBox items since their positions are global in UI space.
Also changed the SDL_Keycode hotkey to an input action string. It doesn't do anything fancy like change depending on what text character is the highlighted one, but it should be configurable in a key bindings file in theory.
Also re-organized some world map mask ID functions.
Need to see why the input manager is still double-firing some events; thought that would've been fixed by removing this.
Still not perfect; need to revise how panel changes are handled so that when a panel and sub-panel are pushed on the same frame, the panel gets paused correctly.
Fixes the problem with pressing Escape when a panel and sub-panel were added on the same frame.
For pressing Tab to escape.
For pressing Tab to go back to the character sheet.
The Cinematic map was getting turned off when transitioning between panels that use it, so decided this would be easier.
@afritz1 afritz1 added this to the 0.14.0 milestone Aug 8, 2021
@afritz1
Copy link
Owner Author

afritz1 commented Aug 9, 2021

Tested on Windows and Raspberry Pi and seems fine.

@afritz1 afritz1 merged commit 38d2fe7 into main Aug 9, 2021
@afritz1 afritz1 deleted the input-actions branch August 9, 2021 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant