Input hints: Display logical keys#2347
Conversation
|
Needs rebase; conflicts due to #2331. Also needs testing on the web platform. |
e6b4629 to
f59fb44
Compare
|
Play this branch at https://play.threadbare.game/branches/endlessm/wjt/rewrite-input-hud-again/. (This launches the game from the start, not directly at the change(s) in this pull request.) |
f59fb44 to
f26ff0e
Compare
| push_warning("Primary keyboard binding for %s not a key: %s" % [action_name, event]) | ||
| return | ||
|
|
||
| var logical_keycode := DisplayServer.keyboard_get_keycode_from_physical(event.physical_keycode) |
There was a problem hiding this comment.
TODO: keyboard_get_keycode_from_physical is not supported on the web platform
index.js:467 ERROR: Not supported by this display server.
onPrintError @ index.js:467
index.js:467 at: keyboard_get_keycode_from_physical (servers/display/display_server.cpp:1211)
There was a problem hiding this comment.
Physical bindings work on the web but that's because at the time the keyboard event is delivered, both the physical and logical codes are provided:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#instance_properties
There is an API to do the lookup, but only in Chromium:
https://developer.mozilla.org/en-US/docs/Web/API/Keyboard/getLayoutMap
I wonder if there is a widely used workaround.
There was a problem hiding this comment.
But in the worst case we can just make this call conditional on "is not the web", and fall back to the current behaviour.
Our keybindings are, correctly, configured to use the physical location of keys on the keyboard. This is because WASD are chosen to be the same shape as the arrow keys, not because "W" means up; and so other bindings such as Z and X must also be physical to avoid clashing. However this means the labels are wrong for QWERTZ and AZERTY keyboards: | Action | QWERTY | QWERTZ | AZERTY | | ------ | ------ | ------ | ------ | | Up | W | W | Z | | Left | A | A | Q | | Down | S | S | S | | Right | D | D | D | | Throw | X | X | X | | Repel | Z | Y | C | We don't actually show WASD in the UI, but we do show X for Throw and Z for Repel. Rather than hardcoding that the glyph for Repel is Z on a keyboard and L1 on a gamepad, instead look these up dynamically. Change the resources to be based on the Key / JoyButton / etc. enums. Rewrite the importer accordingly to generate just one resource per device type (which contains all the necessary AtlasTextures) rather than hundreds of separate AtlasTexture resources. (It was my idea to do the latter; I was wrong!) Update to Kenney Input Prompts 1.5; among other things this introduces a glyph for the "Pause" key on a keyboard, which we do actually have a binding for. But only check in the four sheets that we actually use. Then in the input hint controls, determine which key/button the event is bound to, and display that. There are some annoying edge cases to handle, including: - R2 is analogue so is represented in Godot as an axis that can never be negative, but we present it as a button; - The arrow keys want to be treated like a joystick in the UI; - We show mouse + keyboard controls for some actions; - Sony helpfully relabelled the Start/Select buttons from PS3 (and older) to something else in PS4 and something else again in PS5. Resolves #2185
f26ff0e to
694c8a5
Compare
Our keybindings are, correctly, configured to use the physical location
of keys on the keyboard. This is because WASD are chosen to be the same
shape as the arrow keys, not because "W" means up; and so other bindings
such as Z and X must also be physical to avoid clashing.
However this means the labels are wrong for QWERTZ and AZERTY keyboards:
We don't actually show WASD in the UI, but we do show X for Throw and Z
for Repel.
Rather than hardcoding that the glyph for Repel is Z on a keyboard and
L1 on a gamepad, instead look these up dynamically.
Change the resources to be based on the Key / JoyButton / etc. enums.
Rewrite the importer accordingly to generate just one resource per
device type (which contains all the necessary AtlasTextures) rather than
hundreds of separate AtlasTexture resources. (It was my idea to do the
latter; I was wrong!)
Update to Kenney Input Prompts 1.5; among other things this introduces a
glyph for the "Pause" key on a keyboard, which we do actually have a
binding for. But only check in the four sheets that we actually use.
Then in the input hint controls, determine which key/button the event is
bound to, and display that.
There are some annoying edge cases to handle, including:
negative, but we present it as a button;
older) to something else in PS4 and something else again in PS5.
Resolves #2185