feat: Add TouchControlsManager for mobile virtual joystick and action buttons with settings persistence.

This commit is contained in:
Yogi Wiguna
2026-02-04 16:16:47 +08:00
parent 34867feb86
commit 4ccf789421
+40
View File
@@ -40,6 +40,28 @@ func initialize(p_main: Node3D):
func set_player(p_player: Node3D):
local_player = p_player
# Connect to PowerUpManager if it exists (for boost updates)
var powerup_mgr = local_player.get_node_or_null("PowerUpManager")
if powerup_mgr:
if not powerup_mgr.points_changed.is_connected(_on_boost_points_changed):
powerup_mgr.points_changed.connect(_on_boost_points_changed)
# Initialize state
_on_boost_points_changed(powerup_mgr.current_boost, powerup_mgr.MAX_BOOST)
else:
# Retry connection if manager appears later?
if not local_player.child_entered_tree.is_connected(_on_player_child_to_find_powerup):
local_player.child_entered_tree.connect(_on_player_child_to_find_powerup)
func _on_player_child_to_find_powerup(node):
if node.name == "PowerUpManager":
var powerup_mgr = node
if not powerup_mgr.points_changed.is_connected(_on_boost_points_changed):
powerup_mgr.points_changed.connect(_on_boost_points_changed)
_on_boost_points_changed(powerup_mgr.current_boost, powerup_mgr.MAX_BOOST)
if local_player.child_entered_tree.is_connected(_on_player_child_to_find_powerup):
local_player.child_entered_tree.disconnect(_on_player_child_to_find_powerup)
func _create_touch_ui():
print("[TouchControls] Creating/Finding touch UI...")
@@ -471,3 +493,21 @@ func show_controls():
func hide_controls():
visible = false
func _on_boost_points_changed(current_points: int, max_points: int):
# User Request: Disable Special & SpawnBoost if < 100%
var is_full = current_points >= (max_points - 1) # Tolerance
_update_boost_button_state(special_button, is_full)
_update_boost_button_state(spawn_boost_button, is_full)
func _update_boost_button_state(btn: Button, is_enabled: bool):
if not btn: return
btn.disabled = !is_enabled
# Visual feedback
if is_enabled:
btn.modulate = Color.WHITE
# Optional: Pulse effect?
else:
btn.modulate = Color(0.5, 0.5, 0.5, 0.5) # Dimmed