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

QOL: Add keypad shortcuts so users can type with keyboard #85

Merged
merged 5 commits into from
Feb 26, 2024

Conversation

FailSpy
Copy link
Contributor

@FailSpy FailSpy commented Feb 23, 2024

Added shortcuts to the keypad buttons so now when users type numbers on their keyboard or numpad, it will press the corresponding UI button.

Enter serves as 'E' on the keypad
Backspace or Joypad action right button serves as 'C' on the keypad

@Phazorknight
Copy link
Owner

Thanks for this.
Unfortunately, these inputs overlap with default input_map_actions, causing the player to trigger these actions in addition to the keypad operations.

Examples:

  • Pressing 1,2,3,4 are default shortcuts for using the items in the inventory hotbar.
  • Pressing E overlaps with interact2. If the keypad is set to be opened with interact2 it closes it.

@FailSpy
Copy link
Contributor Author

FailSpy commented Feb 23, 2024

Just to clarify, 'E' is in reference to the 'E' button on the Keypad UI. There is no usage of the 'E' keyboard button in this change. I'm using keyboard 'Enter' to press the keypad UI's 'E' button, which it doesn't look like there's any inputs currently using.

But very good point on those default number shortcuts.
Considering that currently the keypad UI captures and prevents inputs such as moving and firing your gun, would it be okay for me to add a change that does similarly for the number shortcuts? With respect to Godot's default input consumption methods.

@FailSpy
Copy link
Contributor Author

FailSpy commented Feb 23, 2024

I've just added a change that keeps track of focus and consumes the input if the keypad is visible and in focus.

@Phazorknight
Copy link
Owner

Just to clarify, 'E' is in reference to the 'E' button on the Keypad UI. There is no usage of the 'E' keyboard button in this change. I'm using keyboard 'Enter' to press the keypad UI's 'E' button

Oops, yeah you're right. I kinda confused myself.

I did notice tho that when navigating the number buttons with the keyboard arrow keys and then "pressing" those buttons with the enter key, it adds the number to the keypad (as expected) but also triggers the keypad UI 'E' button (as inteded by your change). I think this is a pretty minor thing and potentially easily fixable, but wanted to mention it.

Everything else works great otherwise!

@FailSpy
Copy link
Contributor Author

FailSpy commented Feb 25, 2024

@Phazorknight Give it a shot now. Provided I've done things right:
If you've been using your keyboard to type the code, then Enter will work to press the 'E' key on the keypad and nothing else.
If you've been manually navigating the buttons and pressing Enter on each, it will not trigger the 'E' key on the keypad.

It's also now using Godot's default 'ui_accept' action input mapping.

CogitoButton nodes now have an optional switch to 'accept contextual enter' which will provide this functionality to any UI panel that might want it, and the "context" can be set by using Control's shortcut_context

Copy link
Owner

@Phazorknight Phazorknight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Amazing work!

@Phazorknight Phazorknight merged commit c3e68de into Phazorknight:main Feb 26, 2024
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.

2 participants