feat : mobile input controller

This commit is contained in:
2026-04-13 18:15:49 +08:00
parent a478e3fc2e
commit a592eb1de0
25 changed files with 771 additions and 2058 deletions
+22 -10
View File
@@ -7,6 +7,10 @@ var movement_manager: Node
var race_manager: Node
@onready var SettingsManager = get_node_or_null("/root/SettingsManager")
# Analog stick repeat throttle (prevents firing a new move every frame while held)
var _analog_move_timer: float = 0.0
const ANALOG_MOVE_RATE: float = 0.18 # seconds between grid steps when holding stick
func initialize(p_player: Node3D, p_movement_manager: Node, p_race_manager: Node):
player = p_player
movement_manager = p_movement_manager
@@ -21,16 +25,21 @@ func _process(delta):
return
var move_vec = Vector2i.ZERO
# 1. Controller / Joystick Movement
if SettingsManager and SettingsManager.settings.controls.get("use_controller", false):
var joystick_vec = Input.get_vector("move_west", "move_east", "move_north", "move_south")
if joystick_vec.length() > 0.3: # Deadzone
# 1. Left Analog Stick — always active (controller plugged in, any mode)
var joystick_vec = Input.get_vector("move_west", "move_east", "move_north", "move_south", 0.25)
if joystick_vec.length() > 0.25:
_analog_move_timer -= delta
if _analog_move_timer <= 0.0:
if abs(joystick_vec.x) > abs(joystick_vec.y):
move_vec.x = 1 if joystick_vec.x > 0 else -1
else:
move_vec.y = 1 if joystick_vec.y > 0 else -1
_analog_move_timer = ANALOG_MOVE_RATE
else:
_analog_move_timer = 0.0 # Reset so next touch fires immediately
# 2. Keyboard Movement (Fallback)
# 2. Keyboard / D-pad Movement (fires via action pressed, handled by event)
if move_vec == Vector2i.ZERO:
if Input.is_action_pressed("move_north"): move_vec.y -= 1
if Input.is_action_pressed("move_south"): move_vec.y += 1
@@ -75,8 +84,11 @@ func handle_unhandled_input(event):
if not player.is_multiplayer_authority() or player.is_frozen or player.is_stop_frozen or (TurnManager.turn_based_mode and (not player.is_my_turn or movement_manager.is_moving)):
return
# --- Keyboard Shortcuts (Event-based) ---
if event is InputEventKey and event.pressed and not event.echo:
# --- Action Shortcuts (Keyboard OR Controller Button) ---
var is_action_event = (event is InputEventKey and event.pressed and not event.echo) \
or (event is InputEventJoypadButton and event.pressed)
if is_action_event:
# Safety check for SettingsManager
if not SettingsManager:
return
@@ -87,21 +99,21 @@ func handle_unhandled_input(event):
get_viewport().set_input_as_handled()
return
# 3. Action Buttons (Remappable via InputMap)
# 2. Action Buttons (Remappable via InputMap)
if event.is_action_pressed("action_knock_tekton"):
if player.powerup_manager:
player.powerup_manager.use_special_effect()
if player.is_attack_mode and player.has_method("enter_attack_mode"):
player.enter_attack_mode()
get_viewport().set_input_as_handled()
elif event.is_action_pressed("action_grab_tekton"):
if not player.is_carrying_tekton:
if player.powerup_manager and player.powerup_manager.has_method("can_use_special"):
player.grab_tekton()
get_viewport().set_input_as_handled()
# Handle spawn point selection if not yet selected
if not player.spawn_point_selected and player.highlighted_spawn_points.size() > 0:
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT: