-
Notifications
You must be signed in to change notification settings - Fork 68
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Tested on Windows and Raspberry Pi and seems fine. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.