Gamepad A und B auf ui_accept und ui_cancel gemappt
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QPgKvy5W9WRNFHjkm5QsHx
This commit is contained in:
@@ -9,6 +9,7 @@ var net: Net
|
|||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
_map_gamepad()
|
||||||
theme = Style.make_theme()
|
theme = Style.make_theme()
|
||||||
var bg := Style.Backdrop.new()
|
var bg := Style.Backdrop.new()
|
||||||
bg.set_anchors_preset(Control.PRESET_FULL_RECT)
|
bg.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||||
@@ -73,6 +74,18 @@ func _input(event: InputEvent) -> void:
|
|||||||
get_viewport().gui_release_focus()
|
get_viewport().gui_release_focus()
|
||||||
|
|
||||||
|
|
||||||
|
## Gamepad-Tasten für die Menünavigation: A bestätigt, B bricht ab (falls nicht schon zugeordnet).
|
||||||
|
func _map_gamepad() -> void:
|
||||||
|
for pair in [["ui_accept", JOY_BUTTON_A], ["ui_cancel", JOY_BUTTON_B]]:
|
||||||
|
var action: String = pair[0]
|
||||||
|
if not InputMap.has_action(action):
|
||||||
|
InputMap.add_action(action)
|
||||||
|
if not InputMap.action_get_events(action).any(func(e): return e is InputEventJoypadButton):
|
||||||
|
var ev := InputEventJoypadButton.new()
|
||||||
|
ev.button_index = pair[1]
|
||||||
|
InputMap.action_add_event(action, ev)
|
||||||
|
|
||||||
|
|
||||||
func focus_first_button() -> void:
|
func focus_first_button() -> void:
|
||||||
if screen == null or screen is BattleScreen:
|
if screen == null or screen is BattleScreen:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -526,6 +526,7 @@ func test_gamepad_menue() -> void:
|
|||||||
var f2 := get_viewport().gui_get_focus_owner()
|
var f2 := get_viewport().gui_get_focus_owner()
|
||||||
check(f2 is Button and f2 != f, "Steuerkreuz wechselt den Knopf")
|
check(f2 is Button and f2 != f, "Steuerkreuz wechselt den Knopf")
|
||||||
var target_text: String = f2.text
|
var target_text: String = f2.text
|
||||||
|
check(InputMap.action_get_events("ui_accept").any(func(e): return e is InputEventJoypadButton), "A ist auf ui_accept gemappt")
|
||||||
var accept := InputEventJoypadButton.new()
|
var accept := InputEventJoypadButton.new()
|
||||||
accept.button_index = JOY_BUTTON_A
|
accept.button_index = JOY_BUTTON_A
|
||||||
accept.pressed = true
|
accept.pressed = true
|
||||||
|
|||||||
Reference in New Issue
Block a user