Add configurable keyboard rebinding via controls.txt#1543
Open
Lisiowen wants to merge 4 commits intoMCLCE:mainfrom
Open
Add configurable keyboard rebinding via controls.txt#1543Lisiowen wants to merge 4 commits intoMCLCE:mainfrom
Lisiowen wants to merge 4 commits intoMCLCE:mainfrom
Conversation
Added user control loading functionality from a configuration file.
Corrected function name.
This file contains hidden or 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
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.
Description
This PR adds a keyboard keybind configuration system via a
controls.txtfile in the game directory (similar tousername.txt).controls.txtfile is optional, it only overrides the defaults rather than replacing the current implementation.Changes
Previous Behavior
Keyboard inputs were defined as hardcoded constants in the
KeyboardMouseInput.hfile, so there was no method to change these bindings without modifying the source code and recompiling.Root Cause
The input system used a static, read-only implementation. There was also no system in place to bridge an external config file to the KeyboardMouseInput variables.
New Behavior
On launch, the game attempts to load the
controls.txtfile. Users can override a keybind using standard characters or modifier keys using decimal Windows Virtual-Key codes.KEY_INVENTORY=I-> Standard character for "I"KEY_SPRINT=160-> VK code forLeft ShiftKEY_SNEAK=162-> VK code forLeft ControlIf the file doesn't exist or the specific action isn't included in the file, the game defaults to the standard LCE keybinds.
Fix Implementation
KeyboardMouseInput.hwith mutable static variables to allow the values to be reassigned at runtime during theKeyboardMouseInput::Init()sequence without changing their global state.INPUT_BINDING_TABLEmacro as the source of truth for all the configurable inputs toKeyboardMouseInput.cpp, this defines the default values as well as generating the lookup map for any user configured overrides.LoadUserControlsfunction, this usesstd::mapfor efficient lookups andisdigit()to differentiate between VK codes and standard character inputs. It's also used to check if thecontrols.txtfile exists and for skipping over any empty lines in the file.KeyboardMouseInput::Init()to ensure controls are ready before running.Cross-Platform + Wine Support
controls.txtfiles created on unix-based systems (Linux/macOS) or Windows don't cause parsing errorsAI Use Disclosure
No AI used.
Related Issues
Fixes #128
Closes #749
Documentation + Templates
Thanks for looking over my PR, I'm happy to update the project
READMEwith a section on how to usecontrols.txtand I can make a template file as a starting point for users as well as listing common VK codes.