Provide ability to execute an action from the keybindings menu #36859
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.
Summary
SUMMARY: Interface "Option to execute an action from the keybindings menu"
Purpose of change
As a relatively new player who doesn't have all the possible actions or especially their keybindings committed to memory, I find myself frequently opening the keybinding menu both to see what's possible and then how to invoke it. But then I have to remember the keybinding, close keybindings menu, and then invoke the action. It would be much nicer if I could simply invoke the command while I was there.
Describe the solution
Primarily the solution was designed to be minimally disruptive both to players and in code. For this reason, seasoned players probably won't notice its presence - and their existing workflows definitely will not be affected. Since the keybinding menu already includes a system for filtering entries and then editing keybindings, this solution simply adds a discrete option to execute a chosen command as well. By default, the changed function in input.cpp does not present the option to execute an action. A
true
value to the function's optionalpermit_execute_action
parameter must be provided to enable the option. So, for example, from the game's main screen it makes no sense to execute an action when manipulating key bindings. In game, however, the option is visible.The edit keybinding keys are '-', '+', and '='. I added '.' for the execute option. Similarly, the letter prefix that the menuing system prefixes actions was color-coded. Keeping with this standard, I made the color of the prefixes for the execution action a basic white - distinct from the others.
When an action is chosen for execution, the keybinding menu automatically closes and the action is run. Importantly, the execution of this action still runs through the normal handle_action.cpp method. So any validity checks are still performed and messages still supplied to the player - in both success and failure cases.
Describe alternatives you've considered
While the keybinding menu is a logical place to locate this functionality for a couple reasons (it is already programmed to limit visibility of actions to what the player should see, and is a common place players already go to for action information), I initially created an entirely new menu devoted to finding other menus by name. After playing with that version for awhile, it seemed overkill and to duplicate existing systems.
Testing
In-game testing and unit tests. I did get a unit test failure but I don't see how my change could be related:
Additional context
Here is a screen shot of it in action:
![execute_in_keybindings](https://user-images.githubusercontent.com/67298/72116639-22833300-3308-11ea-9308-8c4696b30afa.png)