feat : mobile input controller
This commit is contained in:
@@ -23,6 +23,7 @@ var tekton_grab_button: Button
|
||||
const CONFIG_PATH = "user://touch_controls_settings.cfg"
|
||||
var button_size: float = 70.0
|
||||
var button_opacity: float = 0.7
|
||||
var joystick_size: float = 60.0
|
||||
var joystick_enabled: bool = true
|
||||
var touch_buttons_enabled: bool = true # Master toggle for action buttons
|
||||
var joystick_position: Vector2 = Vector2(120, -120) # Relative to bottom-left
|
||||
@@ -45,20 +46,30 @@ func initialize(p_main: Node):
|
||||
_load_settings()
|
||||
|
||||
# Connect to remapping signals
|
||||
if SettingsManager and not SettingsManager.control_remapped.is_connected(_on_control_remapped):
|
||||
SettingsManager.control_remapped.connect(_on_control_remapped)
|
||||
if SettingsManager:
|
||||
if not SettingsManager.control_remapped.is_connected(_on_control_remapped):
|
||||
SettingsManager.control_remapped.connect(_on_control_remapped)
|
||||
# Also refresh when settings_applied fires (e.g. use_controller toggle)
|
||||
if not SettingsManager.settings_applied.is_connected(_on_settings_applied_refresh):
|
||||
SettingsManager.settings_applied.connect(_on_settings_applied_refresh)
|
||||
|
||||
func _on_control_remapped(_action: String, _key: int):
|
||||
print("[TouchControls] Control remapped: %s. Refreshing labels." % _action)
|
||||
|
||||
# Refresh primary assigned buttons
|
||||
_refresh_all_shortcut_labels()
|
||||
|
||||
func _on_settings_applied_refresh():
|
||||
"""Called when SettingsManager.settings_applied fires (e.g. use_controller toggled)."""
|
||||
_refresh_all_shortcut_labels()
|
||||
|
||||
func _refresh_all_shortcut_labels():
|
||||
"""Re-run _ensure_shortcut_label on all known buttons to reflect current binding mode."""
|
||||
if grab_button: _ensure_shortcut_label(grab_button, "Grab")
|
||||
if put_button: _ensure_shortcut_label(put_button, "Put")
|
||||
if attack_mode_button: _ensure_shortcut_label(attack_mode_button, "AttackMode")
|
||||
if spawn_boost_button: _ensure_shortcut_label(spawn_boost_button, "SpawnBoost")
|
||||
if tekton_grab_button: _ensure_shortcut_label(tekton_grab_button, "TektonGrab")
|
||||
|
||||
# Also check all direct children of containers just in case
|
||||
# Also walk containers for any dynamically added buttons
|
||||
if power_bar_container:
|
||||
for child in power_bar_container.get_children():
|
||||
if child is Button:
|
||||
@@ -106,35 +117,13 @@ func _create_touch_ui():
|
||||
# Check if container already exists (added in scene)
|
||||
var container = self
|
||||
|
||||
# Helper to find or create control
|
||||
var find_or_create_joystick = func():
|
||||
var joy = container.get_node_or_null("VirtualJoystick")
|
||||
if joy:
|
||||
print("[TouchControls] Found existing VirtualJoystick")
|
||||
return joy
|
||||
|
||||
var joystick_script = load("res://scripts/ui/virtual_joystick.gd")
|
||||
joy = Control.new()
|
||||
joy.set_script(joystick_script)
|
||||
joy.name = "VirtualJoystick"
|
||||
joy.set_anchors_preset(Control.PRESET_BOTTOM_LEFT)
|
||||
|
||||
# Use standard size from joystick script defaults (radius 60 -> size 160)
|
||||
var joy_size = Vector2(160, 160)
|
||||
joy.custom_minimum_size = joy_size
|
||||
joy.size = joy_size
|
||||
|
||||
joy.offset_left = 120
|
||||
joy.offset_top = -280
|
||||
joy.offset_right = 280
|
||||
joy.offset_bottom = -120
|
||||
|
||||
container.add_child(joy)
|
||||
return joy
|
||||
|
||||
virtual_joystick = find_or_create_joystick.call()
|
||||
if not virtual_joystick.direction_changed.is_connected(_on_joystick_direction):
|
||||
virtual_joystick.direction_changed.connect(_on_joystick_direction)
|
||||
virtual_joystick = container.get_node_or_null("VirtualJoystick")
|
||||
if virtual_joystick:
|
||||
print("[TouchControls] Found local VirtualJoystick node")
|
||||
if not virtual_joystick.direction_changed.is_connected(_on_joystick_direction):
|
||||
virtual_joystick.direction_changed.connect(_on_joystick_direction)
|
||||
else:
|
||||
push_error("[TouchControls] VirtualJoystick node missing!")
|
||||
|
||||
# --- Actions Containers ---
|
||||
power_bar_container = container.get_node_or_null("PowerBarBtn")
|
||||
@@ -298,10 +287,10 @@ func _ensure_shortcut_label(btn: Button, button_name: String):
|
||||
if not SettingsManager: return
|
||||
|
||||
match button_name:
|
||||
"Grab": existing_lbl.text = SettingsManager.get_control_text("grab")
|
||||
"Put": existing_lbl.text = SettingsManager.get_control_text("put")
|
||||
"AttackMode": existing_lbl.text = SettingsManager.get_control_text("attack_mode")
|
||||
"TektonGrab": existing_lbl.text = SettingsManager.get_control_text("tekton_grab")
|
||||
"Grab": existing_lbl.text = SettingsManager.get_action_display("grab")
|
||||
"Put": existing_lbl.text = SettingsManager.get_action_display("put")
|
||||
"AttackMode": existing_lbl.text = SettingsManager.get_action_display("attack_mode")
|
||||
"TektonGrab": existing_lbl.text = SettingsManager.get_action_display("tekton_grab")
|
||||
|
||||
|
||||
print("[TouchControls] Updated %s shortcut label to: %s" % [button_name, existing_lbl.text])
|
||||
@@ -330,10 +319,10 @@ func _ensure_shortcut_label(btn: Button, button_name: String):
|
||||
shortcut_lbl.add_theme_constant_override("outline_size", 4)
|
||||
|
||||
match button_name:
|
||||
"Grab": shortcut_lbl.text = SettingsManager.get_control_text("grab") if SettingsManager else "Space"
|
||||
"Put": shortcut_lbl.text = SettingsManager.get_control_text("put") if SettingsManager else "R"
|
||||
"AttackMode": shortcut_lbl.text = SettingsManager.get_control_text("attack_mode") if SettingsManager else "Q"
|
||||
"TektonGrab": shortcut_lbl.text = SettingsManager.get_control_text("tekton_grab") if SettingsManager else "G"
|
||||
"Grab": shortcut_lbl.text = SettingsManager.get_action_display("grab") if SettingsManager else "Space"
|
||||
"Put": shortcut_lbl.text = SettingsManager.get_action_display("put") if SettingsManager else "R"
|
||||
"AttackMode": shortcut_lbl.text = SettingsManager.get_action_display("attack_mode") if SettingsManager else "Q"
|
||||
"TektonGrab": shortcut_lbl.text = SettingsManager.get_action_display("tekton_grab") if SettingsManager else "G"
|
||||
|
||||
|
||||
btn.add_child(shortcut_lbl)
|
||||
@@ -434,6 +423,7 @@ func _load_settings():
|
||||
button_opacity = config.get_value("touch_controls", "button_opacity", 0.7)
|
||||
button_scale = config.get_value("touch_controls", "button_scale", 1.0)
|
||||
joystick_enabled = config.get_value("touch_controls", "joystick_enabled", true)
|
||||
joystick_size = config.get_value("touch_controls", "joystick_size", 60.0)
|
||||
touch_buttons_enabled = config.get_value("touch_controls", "touch_buttons_enabled", true)
|
||||
|
||||
# Load button positions
|
||||
@@ -463,6 +453,7 @@ func _save_settings():
|
||||
config.set_value("touch_controls", "button_opacity", button_opacity)
|
||||
config.set_value("touch_controls", "button_scale", button_scale)
|
||||
config.set_value("touch_controls", "joystick_enabled", joystick_enabled)
|
||||
config.set_value("touch_controls", "joystick_size", joystick_size)
|
||||
config.set_value("touch_controls", "touch_buttons_enabled", touch_buttons_enabled)
|
||||
config.set_value("touch_controls", "grab_position", button_positions.grab)
|
||||
config.set_value("touch_controls", "put_position", button_positions.put)
|
||||
@@ -480,6 +471,8 @@ func _apply_settings():
|
||||
# Apply joystick visibility
|
||||
if virtual_joystick:
|
||||
virtual_joystick.visible = joystick_enabled and _is_touch_device()
|
||||
if virtual_joystick.has_method("set_radius"):
|
||||
virtual_joystick.set_radius(joystick_size)
|
||||
|
||||
# Apply touch buttons visibility - FORCED ON per request to "just show them"
|
||||
# Apply touch buttons visibility
|
||||
|
||||
Reference in New Issue
Block a user