Add gamepad support: stick look, trigger fire, pad menu confirm

- project.godot: joypad events on the ten existing actions (left stick move,
  A jump, right trigger/RB fire, X reload, B/LB grenade, Start pause, Back
  fullscreen), four new look_* actions on the right stick (deadzone 0.2) and
  ui_accept/ui_cancel redefined with the pad buttons A/B while keeping
  Enter/KP Enter/Space/Esc: the 4.7.1 engine maps no pad button on those.
- scripts/player.gd: gamepad_mode turns on by itself on the first pad input;
  _can_aim() replaces the "mouse captured" gate of shoot and grenade (the pad
  never captures the pointer, same trap already fixed for touch);
  _handle_gamepad_look() converts the right stick into equivalent relative
  mouse pixels (900 px/s at full deflection, m^1.8 response) and still goes
  through apply_look(); restart accepts A/X and the death text follows the
  device in use.
- scripts/start_screen.gd: pad hint shown only when a controller is connected,
  refreshed on Input.joy_connection_changed.
- tools/test_gamepad.gd: 33 checks on map structure, keyboard preservation,
  real event pipeline, gamepad_mode and analog look.
- docs/GAMEPAD.md: mapping, code map, verification, known limit (kiosk name
  entry still needs a keyboard: on-screen keyboard is the next step).

Verified: test_gamepad 33/33, test_fullscreen_shortcut 8/8, test_touch_controls
14/14 (--touch), test_grenade 24/24, test_boss 50/50, test_rebalance_branding
14/14, test_player_profile 30/30. test_start_screen keeps its 2 pre-existing
headless failures (identical on HEAD).
This commit is contained in:
Matteo Benedetto
2026-10-24 17:42:26 +02:00
parent b08ac8c6a1
commit 2c39d6235f
5 changed files with 406 additions and 8 deletions
+29
View File
@@ -16,6 +16,10 @@ var player: Node
var leaderboard: Node
var profile := {}
var name_field: LineEdit
var play_button: Button
## Riga di aiuto che compare solo quando c'e' un gamepad collegato: con mouse e
## tastiera la schermata resta identica a prima.
var pad_hint: Label
var rows_box: VBoxContainer
var status_label: Label
var me_label: Label
@@ -29,6 +33,9 @@ func _ready() -> void:
name_locked = Profile.is_name_locked(profile)
rows_shown = ROWS_TOUCH if (player != null and player.touch_mode) else ROWS_DESKTOP
_build_ui()
# Hotplug: la riga di aiuto del pad compare/scompare senza riavviare il gioco.
Input.joy_connection_changed.connect(_on_joy_connection_changed)
_refresh_pad_hint()
if leaderboard != null:
leaderboard.fetch()
@@ -75,6 +82,13 @@ func _build_ui() -> void:
play.custom_minimum_size = Vector2(0, 56)
play.pressed.connect(_start)
column.add_child(play)
play_button = play
# Aiuto per il pad: visibile solo se un controller e' collegato.
pad_hint = _label("", 13, DIM, HORIZONTAL_ALIGNMENT_CENTER)
pad_hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
pad_hint.visible = false
column.add_child(pad_hint)
var panel := PanelContainer.new()
var style := StyleBoxFlat.new()
@@ -140,6 +154,21 @@ func _label(text: String, size: int, color: Color, align: int) -> Label:
label.add_theme_font_size_override("font_size", size)
return label
func _on_joy_connection_changed(_device: int, _connected: bool) -> void:
_refresh_pad_hint()
## Testo e visibilita' dell'aiuto gamepad. Il nome resta da inserire: con il solo pad
## serve una tastiera su schermo (fase successiva), qui si documentano i comandi.
func _refresh_pad_hint() -> void:
if pad_hint == null:
return
var pads := Input.get_connected_joypads()
pad_hint.visible = not pads.is_empty()
if not pads.is_empty():
pad_hint.text = "PAD — stick sx muovi · stick dx visuale · RT spara · X ricarica · B/LB granata · A salta · Start pausa · Back schermo intero"
if play_button != null and not play_button.has_focus() and name_field != null and not name_field.has_focus():
play_button.grab_focus()
func _set_status(text: String) -> void:
if status_label != null:
status_label.text = text