feat: Implement touch controls and a settings menu.

This commit is contained in:
Yogi Wiguna
2026-03-24 11:11:14 +08:00
parent 878e331b6e
commit 82fdbf91d1
10 changed files with 121 additions and 145 deletions
+5 -8
View File
@@ -92,15 +92,12 @@ func handle_unhandled_input(event):
player.enter_attack_mode()
get_viewport().set_input_as_handled()
elif event.is_action_pressed("spawn_boost"):
if player.is_carrying_tekton and player.powerup_manager:
if player.powerup_manager.has_method("spawn_boost_reward"):
player.powerup_manager.spawn_boost_reward()
get_viewport().set_input_as_handled()
elif event.is_action_pressed("action_grab_tekton"):
if not player.is_carrying_tekton and player.powerup_manager:
if player.powerup_manager.has_method("can_use_special"): # Corrected method name
if player.is_carrying_tekton:
if player.powerup_manager and player.powerup_manager.has_method("spawn_boost_reward"):
player.powerup_manager.spawn_boost_reward()
else:
if player.powerup_manager and player.powerup_manager.has_method("can_use_special"):
player.grab_tekton()
get_viewport().set_input_as_handled()
+2 -5
View File
@@ -55,9 +55,7 @@ var settings = {
# Power Bar Controls / Special
"attack_mode": KEY_Q,
"attack_mode_alt": KEY_U,
"spawn_boost": KEY_E,
"spawn_boost_alt": KEY_I
"attack_mode_alt": KEY_U
}
}
@@ -171,8 +169,7 @@ func apply_control_settings():
"put": "action_put",
"use_powerup": "use_powerup",
"tekton_grab": "action_grab_tekton",
"attack_mode": "action_knock_tekton",
"spawn_boost": "spawn_boost"
"attack_mode": "action_knock_tekton"
}
for setting_key in mapping.keys():
+65 -59
View File
@@ -8,7 +8,8 @@ signal attack_mode_pressed
# Touch control nodes
var virtual_joystick: Control
var actions_container: Control # New container
var power_bar_container: Control # Renamed from actions_container
var interaction_container: Control # New container for Interaction
var grab_button: Button
var put_button: Button
var attack_mode_button: Button # Renamed from special_button
@@ -57,9 +58,14 @@ func _on_control_remapped(_action: String, _key: int):
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 actions_container just in case
if actions_container:
for child in actions_container.get_children():
# Also check all direct children of containers just in case
if power_bar_container:
for child in power_bar_container.get_children():
if child is Button:
var b_name = child.name.replace("Btn", "")
_ensure_shortcut_label(child, b_name)
if interaction_container:
for child in interaction_container.get_children():
if child is Button:
var b_name = child.name.replace("Btn", "")
_ensure_shortcut_label(child, b_name)
@@ -141,73 +147,74 @@ func _create_touch_ui():
if not virtual_joystick.direction_changed.is_connected(_on_joystick_direction):
virtual_joystick.direction_changed.connect(_on_joystick_direction)
# --- Actions Container ---
actions_container = container.get_node_or_null("ActionsBtn")
if not actions_container:
actions_container = Control.new()
actions_container.name = "ActionsBtn"
actions_container.set_anchors_preset(Control.PRESET_FULL_RECT) # Or appropriate preset
actions_container.mouse_filter = Control.MOUSE_FILTER_PASS
container.add_child(actions_container)
# --- Actions Containers ---
power_bar_container = container.get_node_or_null("PowerBarBtn")
if not power_bar_container:
power_bar_container = container.get_node_or_null("ActionsBtn") # Fallback
interaction_container = container.get_node_or_null("InteractionBtn")
# Create containers if missing (runtime dynamic creation)
if not power_bar_container:
power_bar_container = Control.new()
power_bar_container.name = "PowerBarBtn"
power_bar_container.set_anchors_preset(Control.PRESET_FULL_RECT)
power_bar_container.mouse_filter = Control.MOUSE_FILTER_PASS
container.add_child(power_bar_container)
else:
print("[TouchControls] Found existing ActionsBtn container")
print("[TouchControls] Found existing PowerBarBtn container")
# Center buttons in the container instead of spreading them out
if actions_container is BoxContainer:
actions_container.alignment = BoxContainer.ALIGNMENT_CENTER
if not interaction_container:
interaction_container = Control.new()
interaction_container.name = "InteractionBtn"
interaction_container.set_anchors_preset(Control.PRESET_FULL_RECT)
interaction_container.mouse_filter = Control.MOUSE_FILTER_PASS
container.add_child(interaction_container)
else:
print("[TouchControls] Found existing InteractionBtn container")
# Create action buttons (parented to actions_container if possible, or use logic)
# User Request: "move those button to ActionsBtn children"
attack_mode_button = _find_or_create_action_button(actions_container, "AttackMode", "", button_positions.attack_mode) # Renamed
# spawn_boost_button = _find_or_create_action_button(actions_container, "SpawnBoost", "🚀", button_positions.spawn_boost)
grab_button = _find_or_create_action_button(actions_container, "Grab", "👋", button_positions.grab)
put_button = _find_or_create_action_button(actions_container, "Put", "📦", button_positions.put)
tekton_grab_button = _find_or_create_action_button(actions_container, "TektonGrab", "👋", Vector2(-280, -80))
# Style/Align Containers
if power_bar_container is BoxContainer:
power_bar_container.alignment = BoxContainer.ALIGNMENT_CENTER
if interaction_container is BoxContainer:
interaction_container.alignment = BoxContainer.ALIGNMENT_CENTER
# Create action buttons
attack_mode_button = _find_or_create_action_button(power_bar_container, "AttackMode", "", button_positions.attack_mode)
tekton_grab_button = _find_or_create_action_button(power_bar_container, "TektonGrab", "👋", Vector2(-280, -80))
grab_button = _find_or_create_action_button(interaction_container, "Grab", "👋", button_positions.grab)
put_button = _find_or_create_action_button(interaction_container, "Put", "📦", button_positions.put)
# Order: AttackMode, SpawnBoost, Grab, TektonGrab
# Order / Icons
if attack_mode_button:
actions_container.move_child(attack_mode_button, 0)
attack_mode_button.icon = load("res://assets/graphics/touch_control/attack_mode.png")
attack_mode_button.expand_icon = true
# if spawn_boost_button:
# actions_container.move_child(spawn_boost_button, 1)
# spawn_boost_button.icon = load("res://assets/graphics/touch_control/spawn_tile.png")
# spawn_boost_button.expand_icon = true
if grab_button:
actions_container.move_child(grab_button, 2)
grab_button.icon = load("res://assets/graphics/touch_control/take_tile.png")
grab_button.expand_icon = true
if tekton_grab_button:
actions_container.move_child(tekton_grab_button, 3)
tekton_grab_button.icon = load("res://assets/graphics/touch_control/grab_tekton.png")
tekton_grab_button.expand_icon = true
# Hide Put Button
if put_button:
put_button.visible = false
put_button.visible = true
# Create settings button (top-right corner)
settings_button = container.get_node_or_null("SettingsBtn")
# Use existing settings button (child of Main node)
settings_button = main_scene.get_node_or_null("SettingsBtn")
if not settings_button:
settings_button = Button.new()
settings_button.name = "SettingsBtn"
settings_button.text = ""
settings_button.set_anchors_preset(Control.PRESET_TOP_RIGHT)
settings_button.offset_left = -70
settings_button.offset_right = -20
settings_button.offset_top = 70
settings_button.offset_bottom = 120
settings_button.custom_minimum_size = Vector2(50, 50)
settings_button.mouse_filter = Control.MOUSE_FILTER_STOP
_style_button(settings_button, 0.5)
container.add_child(settings_button)
# Fallback to local search just in case
settings_button = container.get_node_or_null("SettingsBtn")
if settings_button:
print("[TouchControls] Found existing SettingsBtn on main scene")
# Ensure it's not hidden by mistake
settings_button.visible = true
if not settings_button.pressed.is_connected(_on_settings_pressed):
settings_button.pressed.connect(_on_settings_pressed)
@@ -306,9 +313,8 @@ func _ensure_shortcut_label(btn: Button, button_name: String):
match button_name:
"Grab": existing_lbl.text = SettingsManager.get_control_text("grab")
"Put": existing_lbl.text = ""
"Put": existing_lbl.text = SettingsManager.get_control_text("put")
"AttackMode": existing_lbl.text = SettingsManager.get_control_text("attack_mode")
# "SpawnBoost": existing_lbl.text = SettingsManager.get_control_text("spawn_boost")
"TektonGrab": existing_lbl.text = SettingsManager.get_control_text("tekton_grab")
@@ -339,9 +345,8 @@ func _ensure_shortcut_label(btn: Button, button_name: String):
match button_name:
"Grab": shortcut_lbl.text = SettingsManager.get_control_text("grab") if SettingsManager else "Space"
"Put": shortcut_lbl.text = "" # Disabled shortcut
"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"
# "SpawnBoost": shortcut_lbl.text = SettingsManager.get_control_text("spawn_boost") if SettingsManager else "E"
"TektonGrab": shortcut_lbl.text = SettingsManager.get_control_text("tekton_grab") if SettingsManager else "G"
@@ -495,17 +500,18 @@ func _apply_settings():
virtual_joystick.visible = joystick_enabled
# Apply touch buttons visibility - FORCED ON per request to "just show them"
if actions_container:
actions_container.visible = true
actions_container.set_anchors_preset(Control.PRESET_FULL_RECT)
actions_container.mouse_filter = Control.MOUSE_FILTER_PASS
# Apply touch buttons visibility
if power_bar_container:
power_bar_container.visible = true
if interaction_container:
interaction_container.visible = true
var buttons_visible = true
print("[TouchControls] Applying settings: ButtonsVisible=", buttons_visible)
if grab_button:
grab_button.visible = false
grab_button.visible = true
grab_button.scale = Vector2(button_scale, button_scale)
grab_button.set_anchors_preset(Control.PRESET_BOTTOM_RIGHT)
grab_button.offset_left = button_positions.grab.x
@@ -514,7 +520,7 @@ func _apply_settings():
grab_button.offset_bottom = button_positions.grab.y + button_size
if put_button:
put_button.visible = false # Always INTENTIONALLY HIDDEN per request
put_button.visible = true
if attack_mode_button:
attack_mode_button.visible = true
@@ -617,7 +623,7 @@ func _on_tekton_carried_changed(_is_carrying: bool):
# Swapping to Spawn function (Hotkey E)
tekton_grab_button.icon = load("res://assets/graphics/touch_control/spawn_tile.png")
if SettingsManager:
_ensure_shortcut_label(tekton_grab_button, "SpawnBoost")
_ensure_shortcut_label(tekton_grab_button, "TektonGrab")
else:
# Swapping back to Grab function (Hotkey G)
tekton_grab_button.icon = load("res://assets/graphics/touch_control/grab_tekton.png")