generated from krampus/template-godot4
PromptMap includes modifiers
This commit is contained in:
parent
ce2996a703
commit
01df07eb11
|
@ -1,6 +1,7 @@
|
||||||
class_name PromptMap
|
class_name PromptMap
|
||||||
## Tools for mapping input events to PromptFont glyphs.
|
## Tools for mapping input events to PromptFont glyphs.
|
||||||
|
|
||||||
|
const COMPOSE_FMT := "{0}+{1}"
|
||||||
const UNKNOWN_INPUT_SYMBOL := PromptFont.ICON_QUESTION
|
const UNKNOWN_INPUT_SYMBOL := PromptFont.ICON_QUESTION
|
||||||
|
|
||||||
## Keyboard key map
|
## Keyboard key map
|
||||||
|
@ -12,6 +13,7 @@ const KEYBOARD := {
|
||||||
KEY_CTRL: PromptFont.KEYBOARD_CONTROL,
|
KEY_CTRL: PromptFont.KEYBOARD_CONTROL,
|
||||||
KEY_ALT: PromptFont.KEYBOARD_ALT,
|
KEY_ALT: PromptFont.KEYBOARD_ALT,
|
||||||
KEY_SHIFT: PromptFont.KEYBOARD_SHIFT,
|
KEY_SHIFT: PromptFont.KEYBOARD_SHIFT,
|
||||||
|
KEY_META: PromptFont.KEYBOARD_SUPER,
|
||||||
KEY_TAB: PromptFont.KEYBOARD_TAB,
|
KEY_TAB: PromptFont.KEYBOARD_TAB,
|
||||||
KEY_CAPSLOCK: PromptFont.KEYBOARD_CAPS,
|
KEY_CAPSLOCK: PromptFont.KEYBOARD_CAPS,
|
||||||
KEY_BACKSPACE: PromptFont.KEYBOARD_BACKSPACE,
|
KEY_BACKSPACE: PromptFont.KEYBOARD_BACKSPACE,
|
||||||
|
@ -203,6 +205,20 @@ const NINTENDO_AXIS := {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static func _compose_modifiers(event: InputEventWithModifiers, base: String) -> String:
|
||||||
|
# Control -> Alt -> Shift -> Super/Meta
|
||||||
|
var composed := base
|
||||||
|
if event.meta_pressed:
|
||||||
|
composed = COMPOSE_FMT.format([PromptFont.KEYBOARD_SUPER, composed])
|
||||||
|
if event.shift_pressed:
|
||||||
|
composed = COMPOSE_FMT.format([PromptFont.KEYBOARD_SHIFT, composed])
|
||||||
|
if event.alt_pressed:
|
||||||
|
composed = COMPOSE_FMT.format([PromptFont.KEYBOARD_ALT, composed])
|
||||||
|
if event.ctrl_pressed:
|
||||||
|
composed = COMPOSE_FMT.format([PromptFont.KEYBOARD_CONTROL, composed])
|
||||||
|
return composed
|
||||||
|
|
||||||
|
|
||||||
## Get the symbol representing the given keyboard input event.
|
## Get the symbol representing the given keyboard input event.
|
||||||
##
|
##
|
||||||
## If there is no such symbol available, returns the key label.
|
## If there is no such symbol available, returns the key label.
|
||||||
|
@ -211,12 +227,12 @@ static func key(event: InputEventKey) -> String:
|
||||||
return OS.get_keycode_string(
|
return OS.get_keycode_string(
|
||||||
DisplayServer.keyboard_get_keycode_from_physical(event.physical_keycode)
|
DisplayServer.keyboard_get_keycode_from_physical(event.physical_keycode)
|
||||||
)
|
)
|
||||||
return KEYBOARD[event.physical_keycode]
|
return _compose_modifiers(event, KEYBOARD[event.physical_keycode] as String)
|
||||||
|
|
||||||
|
|
||||||
## Get the symbol representing the given mouse button event.
|
## Get the symbol representing the given mouse button event.
|
||||||
static func mouse_button(event: InputEventMouseButton) -> String:
|
static func mouse_button(event: InputEventMouseButton) -> String:
|
||||||
return MOUSE.get(event.button_index, UNKNOWN_INPUT_SYMBOL)
|
return _compose_modifiers(event, MOUSE.get(event.button_index, UNKNOWN_INPUT_SYMBOL) as String)
|
||||||
|
|
||||||
|
|
||||||
## Get the symbol representing the given gamepad button event.
|
## Get the symbol representing the given gamepad button event.
|
||||||
|
|
Loading…
Reference in New Issue