make layout swapping with numpad

This commit is contained in:
Teatov 2025-07-30 14:13:50 +10:00
parent 0e63b16900
commit 1a407859e3
2 changed files with 21 additions and 17 deletions

View File

@ -54,11 +54,6 @@ reset_animations={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194340,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
swap_layout={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194332,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
[physics]

View File

@ -48,20 +48,27 @@ func _unhandled_input(event: InputEvent) -> void:
_rot_sod = SecondOrderDynamics.new(_rot_sod_fzr, _default_position)
return
if event.is_action_pressed("swap_layout") and LayoutConfig.is_configuring:
_swap_layout()
return
if event is not InputEventKey:
return
var event_key := event as InputEventKey
if event_key.echo:
return
if (
event_key.is_pressed()
and LayoutConfig.is_configuring
and event_key.physical_keycode >= KEY_KP_0
and event_key.physical_keycode <= KEY_KP_9
):
_swap_layout(event_key.physical_keycode)
return
var keycode := event_key.get_physical_keycode_with_modifiers()
if (
event_key.is_pressed()
and not event_key.echo
and (keycode == KEY_SHIFT | KEY_MASK_ALT or keycode == KEY_ALT | KEY_MASK_SHIFT)
):
alt_layout = not alt_layout
@ -147,19 +154,21 @@ func _get_row_key_step(key_props: KeyProps) -> float:
#region layout swapping
func _swap_layout() -> void:
_play_sfx(_layout_swap_sfx)
if LayoutConfig.current_layout is LayoutANSI:
func _swap_layout(kp_key: Key) -> void:
if kp_key == KEY_KP_1:
LayoutConfig.swap_layout(LayoutANSI.name_static())
elif kp_key == KEY_KP_2:
LayoutConfig.swap_layout(LayoutANSIVariant.name_static())
elif LayoutConfig.current_layout is LayoutANSIVariant:
elif kp_key == KEY_KP_3:
LayoutConfig.swap_layout(LayoutISO.name_static())
elif LayoutConfig.current_layout is LayoutISO:
elif kp_key == KEY_KP_4:
LayoutConfig.swap_layout(LayoutJD40.name_static())
elif LayoutConfig.current_layout is LayoutJD40:
elif kp_key == KEY_KP_5:
LayoutConfig.swap_layout(LayoutPlanck.name_static())
else:
LayoutConfig.swap_layout(LayoutANSI.name_static())
return
_regenerate_keys(LayoutConfig.layout_rows)
_play_sfx(_layout_swap_sfx)
func _regenerate_keys(layout_rows: Array[Array]) -> void: