feat: Initialize main game scene and add player input and touch control managers.

This commit is contained in:
Yogi Wiguna
2026-02-05 11:57:04 +08:00
parent e2675d782a
commit 597e6d0a56
3 changed files with 119 additions and 139 deletions
+36 -69
View File
@@ -9518,14 +9518,10 @@ text = "seconds"
horizontal_alignment = 1 horizontal_alignment = 1
[node name="GlobalMatchTimer" type="PanelContainer" parent="." unique_id=1714357974] [node name="GlobalMatchTimer" type="PanelContainer" parent="." unique_id=1714357974]
anchors_preset = 5 offset_left = 48.0
anchor_left = 0.5 offset_top = 64.0
anchor_right = 0.5 offset_right = 208.0
offset_left = -80.0 offset_bottom = 114.0
offset_top = 24.0
offset_right = 80.0
offset_bottom = 74.0
grow_horizontal = 2
[node name="VBox" type="VBoxContainer" parent="GlobalMatchTimer" unique_id=24429117] [node name="VBox" type="VBoxContainer" parent="GlobalMatchTimer" unique_id=24429117]
layout_mode = 2 layout_mode = 2
@@ -9712,7 +9708,6 @@ layout_mode = 2
text = "Back" text = "Back"
[node name="TouchControls" type="CanvasLayer" parent="." unique_id=1390485948] [node name="TouchControls" type="CanvasLayer" parent="." unique_id=1390485948]
layer = 10
script = ExtResource("touch_manager") script = ExtResource("touch_manager")
[node name="TouchControls" type="Control" parent="TouchControls" unique_id=1539594058] [node name="TouchControls" type="Control" parent="TouchControls" unique_id=1539594058]
@@ -9726,6 +9721,7 @@ grow_vertical = 2
mouse_filter = 2 mouse_filter = 2
[node name="VirtualJoystick" type="Control" parent="TouchControls/TouchControls" unique_id=1983608919] [node name="VirtualJoystick" type="Control" parent="TouchControls/TouchControls" unique_id=1983608919]
visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = 2 anchors_preset = 2
anchor_top = 1.0 anchor_top = 1.0
@@ -9737,79 +9733,50 @@ offset_bottom = -120.0
grow_vertical = 0 grow_vertical = 0
script = ExtResource("virtual_joystick") script = ExtResource("virtual_joystick")
[node name="GrabBtn" type="Button" parent="TouchControls/TouchControls" unique_id=914810452] [node name="ActionsBtn" type="HBoxContainer" parent="TouchControls/TouchControls" unique_id=1921269452]
layout_mode = 1 layout_mode = 0
anchors_preset = 3 offset_left = 24.0
anchor_left = 1.0 offset_top = 58.0
anchor_top = 1.0 offset_right = 231.0
anchor_right = 1.0 offset_bottom = 123.25
anchor_bottom = 1.0 theme_override_constants/separation = 15
offset_left = -303.0
offset_top = -249.0
offset_right = -233.0
offset_bottom = -179.0
grow_horizontal = 0
grow_vertical = 0
focus_mode = 0
icon = ExtResource("25_qkpxi")
flat = true
expand_icon = true
[node name="PutBtn" type="Button" parent="TouchControls/TouchControls" unique_id=1027790362] [node name="PutBtn" type="Button" parent="TouchControls/TouchControls/ActionsBtn" unique_id=1027790362]
visible = false visible = false
layout_mode = 1 layout_mode = 2
anchors_preset = 3 size_flags_horizontal = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -223.0
offset_top = -169.0
offset_right = -153.0
offset_bottom = -99.0
grow_horizontal = 0
grow_vertical = 0
focus_mode = 0 focus_mode = 0
icon = ExtResource("26_5q0nq") icon = ExtResource("26_5q0nq")
flat = true flat = true
icon_alignment = 1
expand_icon = true expand_icon = true
[node name="SpecialBtn" type="Button" parent="TouchControls/TouchControls" unique_id=1380511463] [node name="AttackModeBtn" type="Button" parent="TouchControls/TouchControls/ActionsBtn" unique_id=1380511463]
layout_mode = 1 layout_mode = 2
anchors_preset = 3 size_flags_horizontal = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -223.0
offset_top = -323.0
offset_right = -153.0
offset_bottom = -253.0
grow_horizontal = 0
grow_vertical = 0
focus_mode = 0 focus_mode = 0
icon = ExtResource("27_dgi5k") icon = ExtResource("27_dgi5k")
flat = true flat = true
icon_alignment = 1
expand_icon = true expand_icon = true
[node name="SpawnBoostBtn" type="Button" parent="TouchControls/TouchControls" unique_id=1566173505] [node name="SpawnBoostBtn" type="Button" parent="TouchControls/TouchControls/ActionsBtn" unique_id=1566173505]
layout_mode = 1 layout_mode = 2
anchors_preset = 3 size_flags_horizontal = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -143.0
offset_top = -241.0
offset_right = -73.0
offset_bottom = -171.0
grow_horizontal = 0
grow_vertical = 0
icon = ExtResource("28_j8jky") icon = ExtResource("28_j8jky")
flat = true flat = true
icon_alignment = 1 icon_alignment = 1
expand_icon = true expand_icon = true
[node name="GrabBtn" type="Button" parent="TouchControls/TouchControls/ActionsBtn" unique_id=914810452]
layout_mode = 2
size_flags_horizontal = 3
focus_mode = 0
icon = ExtResource("25_qkpxi")
flat = true
icon_alignment = 1
expand_icon = true
[node name="SettingsBtn" type="Button" parent="TouchControls/TouchControls" unique_id=1964422444] [node name="SettingsBtn" type="Button" parent="TouchControls/TouchControls" unique_id=1964422444]
layout_mode = 1 layout_mode = 1
anchors_preset = 3 anchors_preset = 3
@@ -9817,10 +9784,10 @@ anchor_left = 1.0
anchor_top = 1.0 anchor_top = 1.0
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_left = -1337.0 offset_left = -70.0
offset_top = -83.0 offset_top = -80.0
offset_right = -1287.0 offset_right = -22.0
offset_bottom = -33.0 offset_bottom = -32.0
grow_horizontal = 0 grow_horizontal = 0
grow_vertical = 0 grow_vertical = 0
text = "⚙" text = "⚙"
+4 -1
View File
@@ -102,12 +102,15 @@ func handle_unhandled_input(event):
# player.auto_put_item() # player.auto_put_item()
KEY_Q: KEY_Q:
if player.powerup_manager: if player.powerup_manager:
# Attack Mode (formerly Special)
player.powerup_manager.use_special_effect() player.powerup_manager.use_special_effect()
KEY_E: # Swapped to E per request KEY_E:
if player.powerup_manager: if player.powerup_manager:
# Spawn Boost
if player.powerup_manager.has_method("spawn_boost_reward"): if player.powerup_manager.has_method("spawn_boost_reward"):
player.powerup_manager.spawn_boost_reward() player.powerup_manager.spawn_boost_reward()
else: else:
# Fallback if method missing
player.powerup_manager.use_special_effect() player.powerup_manager.use_special_effect()
# Handle spawn point selection if not yet selected # Handle spawn point selection if not yet selected
+79 -69
View File
@@ -4,13 +4,14 @@ extends CanvasLayer
signal grab_pressed signal grab_pressed
signal put_pressed signal put_pressed
signal special_pressed signal attack_mode_pressed
# Touch control nodes # Touch control nodes
var virtual_joystick: Control var virtual_joystick: Control
var actions_container: Control # New container
var grab_button: Button var grab_button: Button
var put_button: Button var put_button: Button
var special_button: Button var attack_mode_button: Button # Renamed from special_button
var spawn_boost_button: Button var spawn_boost_button: Button
var settings_button: Button var settings_button: Button
@@ -19,12 +20,12 @@ const CONFIG_PATH = "user://touch_controls_settings.cfg"
var button_size: float = 70.0 var button_size: float = 70.0
var button_opacity: float = 0.7 var button_opacity: float = 0.7
var joystick_enabled: bool = true var joystick_enabled: bool = true
var touch_buttons_enabled: bool = true # Master toggle for action buttons (grab, put, special) var touch_buttons_enabled: bool = true # Master toggle for action buttons
var joystick_position: Vector2 = Vector2(120, -120) # Relative to bottom-left var joystick_position: Vector2 = Vector2(120, -120) # Relative to bottom-left
var button_positions: Dictionary = { var button_positions: Dictionary = {
"grab": Vector2(-200, -240), # Relative to bottom-right "grab": Vector2(-200, -240), # Relative to bottom-right
"put": Vector2(-120, -160), "put": Vector2(-120, -160),
"special": Vector2(-200, -80), "attack_mode": Vector2(-200, -80), # Renamed
"spawn_boost": Vector2(-120, -80) "spawn_boost": Vector2(-120, -80)
} }
var button_scale: float = 1.0 var button_scale: float = 1.0
@@ -111,13 +112,33 @@ func _create_touch_ui():
if not virtual_joystick.direction_changed.is_connected(_on_joystick_direction): if not virtual_joystick.direction_changed.is_connected(_on_joystick_direction):
virtual_joystick.direction_changed.connect(_on_joystick_direction) virtual_joystick.direction_changed.connect(_on_joystick_direction)
# Helper to find or create button logic moved to function _find_or_create_action_button # --- 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)
else:
print("[TouchControls] Found existing ActionsBtn container")
# Create action buttons (parented to actions_container if possible, or use logic)
# User Request: "move those button to ActionsBtn children"
# Create action buttons (bottom-right) attack_mode_button = _find_or_create_action_button(actions_container, "AttackMode", "", button_positions.attack_mode) # Renamed
grab_button = _find_or_create_action_button(container, "Grab", "👋", button_positions.grab) spawn_boost_button = _find_or_create_action_button(actions_container, "SpawnBoost", "🚀", button_positions.spawn_boost)
put_button = _find_or_create_action_button(container, "Put", "📦", button_positions.put) grab_button = _find_or_create_action_button(actions_container, "Grab", "👋", button_positions.grab)
special_button = _find_or_create_action_button(container, "Special", "", button_positions.special) put_button = _find_or_create_action_button(actions_container, "Put", "📦", button_positions.put)
spawn_boost_button = _find_or_create_action_button(container, "SpawnBoost", "🚀", button_positions.spawn_boost)
# Order: AttackMode, SpawnBoost, Grab
if attack_mode_button: actions_container.move_child(attack_mode_button, 0)
if spawn_boost_button: actions_container.move_child(spawn_boost_button, 1)
if grab_button: actions_container.move_child(grab_button, 2)
# Hide Put Button
if put_button:
put_button.visible = false
# Create settings button (top-right corner) # Create settings button (top-right corner)
settings_button = container.get_node_or_null("SettingsBtn") settings_button = container.get_node_or_null("SettingsBtn")
@@ -222,6 +243,13 @@ func _style_button(btn: Button, opacity: float):
func _ensure_shortcut_label(btn: Button, button_name: String): func _ensure_shortcut_label(btn: Button, button_name: String):
if btn.has_node("ShortcutLabel"): if btn.has_node("ShortcutLabel"):
# Update Label content if it exists to match potential remapping
var existing_lbl = btn.get_node("ShortcutLabel")
match button_name:
"Grab": existing_lbl.text = "Space"
"Put": existing_lbl.text = ""
"AttackMode": existing_lbl.text = "Q"
"SpawnBoost": existing_lbl.text = "E"
return return
# Add Keyboard Shortcut Label # Add Keyboard Shortcut Label
@@ -238,7 +266,7 @@ func _ensure_shortcut_label(btn: Button, button_name: String):
match button_name: match button_name:
"Grab": shortcut_lbl.text = "Space" "Grab": shortcut_lbl.text = "Space"
"Put": shortcut_lbl.text = "" # Disabled shortcut "Put": shortcut_lbl.text = "" # Disabled shortcut
"Special": shortcut_lbl.text = "Q" "AttackMode": shortcut_lbl.text = "Q"
"SpawnBoost": shortcut_lbl.text = "E" "SpawnBoost": shortcut_lbl.text = "E"
btn.add_child(shortcut_lbl) btn.add_child(shortcut_lbl)
@@ -257,7 +285,7 @@ func _on_button_pressed(button_name: String):
match button_name: match button_name:
"Grab": btn = grab_button "Grab": btn = grab_button
"Put": btn = put_button "Put": btn = put_button
"Special": btn = special_button "AttackMode": btn = attack_mode_button
"SpawnBoost": btn = spawn_boost_button "SpawnBoost": btn = spawn_boost_button
if btn: if btn:
@@ -274,17 +302,18 @@ func _on_button_pressed(button_name: String):
emit_signal("put_pressed") emit_signal("put_pressed")
if local_player.has_method("auto_put_item"): if local_player.has_method("auto_put_item"):
local_player.auto_put_item() local_player.auto_put_item()
"Special": "AttackMode":
emit_signal("special_pressed") emit_signal("attack_mode_pressed") # Also special?
# emit_signal("special_pressed") # Keep legacy signal?
var powerup_mgr = local_player.get_node_or_null("PowerUpManager") var powerup_mgr = local_player.get_node_or_null("PowerUpManager")
if powerup_mgr: if powerup_mgr:
# Require Full Boost to Activate (User Request: "Connect to boost bar") # Require Full Boost to Activate (User Request: "Connect to boost bar")
var can_use = powerup_mgr.can_use_special() var can_use = powerup_mgr.can_use_special()
var boost_val = powerup_mgr.current_boost var boost_val = powerup_mgr.current_boost
print("[TouchControls] Special Pressed. Boost: %s, CanUse: %s" % [boost_val, can_use]) print("[TouchControls] AttackMode Pressed. Boost: %s, CanUse: %s" % [boost_val, can_use])
if can_use: if can_use:
powerup_mgr.use_special_effect() # Sets is_attack_mode=true, Does NOT consume boost yet powerup_mgr.use_special_effect() # Sets is_attack_mode=true
else: else:
# Optional feedback for not ready? # Optional feedback for not ready?
pass pass
@@ -298,9 +327,10 @@ func _on_button_pressed(button_name: String):
print("[TouchControls] SpawnBoost Pressed. Boost: %s, CanUse: %s" % [boost_val, can_use]) print("[TouchControls] SpawnBoost Pressed. Boost: %s, CanUse: %s" % [boost_val, can_use])
if can_use: # Check if boost is full if can_use: # Check if boost is full
# Same usage logic, but specific action
if local_player.special_tiles_manager and local_player.special_tiles_manager.has_method("spawn_powerups_around"): if local_player.special_tiles_manager and local_player.special_tiles_manager.has_method("spawn_powerups_around"):
local_player.special_tiles_manager.spawn_powerups_around(local_player.current_position) local_player.special_tiles_manager.spawn_powerups_around(local_player.current_position)
powerup_mgr.reset_boost() # Consume the boost manually since we bypassed use_special_effect powerup_mgr.reset_boost() # Consume the boost manually
else: else:
print("[TouchControls] PowerUpManager missing on player") print("[TouchControls] PowerUpManager missing on player")
@@ -309,7 +339,7 @@ func _on_button_released(button_name: String):
match button_name: match button_name:
"Grab": btn = grab_button "Grab": btn = grab_button
"Put": btn = put_button "Put": btn = put_button
"Special": btn = special_button "AttackMode": btn = attack_mode_button
"SpawnBoost": btn = spawn_boost_button "SpawnBoost": btn = spawn_boost_button
if btn: if btn:
@@ -348,9 +378,12 @@ func _load_settings():
# Load button positions # Load button positions
var grab_pos = config.get_value("touch_controls", "grab_position", Vector2(-200, -240)) var grab_pos = config.get_value("touch_controls", "grab_position", Vector2(-200, -240))
var put_pos = config.get_value("touch_controls", "put_position", Vector2(-120, -160)) var put_pos = config.get_value("touch_controls", "put_position", Vector2(-120, -160))
var special_pos = config.get_value("touch_controls", "special_position", Vector2(-200, -80)) var attack_mode_pos = config.get_value("touch_controls", "attack_mode_position", Vector2(-200, -80)) # Changed key from special
if config.has_section_key("touch_controls", "special_position"): # Migrate legacy
attack_mode_pos = config.get_value("touch_controls", "special_position", Vector2(-200, -80))
var spawn_boost_pos = config.get_value("touch_controls", "spawn_boost_position", Vector2(-120, -80)) var spawn_boost_pos = config.get_value("touch_controls", "spawn_boost_position", Vector2(-120, -80))
button_positions = {"grab": grab_pos, "put": put_pos, "special": special_pos, "spawn_boost": spawn_boost_pos} button_positions = {"grab": grab_pos, "put": put_pos, "attack_mode": attack_mode_pos, "spawn_boost": spawn_boost_pos}
# Apply loaded settings # Apply loaded settings
_apply_settings() _apply_settings()
@@ -367,7 +400,7 @@ func _save_settings():
config.set_value("touch_controls", "touch_buttons_enabled", touch_buttons_enabled) 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", "grab_position", button_positions.grab)
config.set_value("touch_controls", "put_position", button_positions.put) config.set_value("touch_controls", "put_position", button_positions.put)
config.set_value("touch_controls", "special_position", button_positions.special) config.set_value("touch_controls", "attack_mode_position", button_positions.attack_mode) # Renamed
config.set_value("touch_controls", "spawn_boost_position", button_positions.spawn_boost) config.set_value("touch_controls", "spawn_boost_position", button_positions.spawn_boost)
var err = config.save(CONFIG_PATH) var err = config.save(CONFIG_PATH)
@@ -393,34 +426,34 @@ func _apply_settings():
grab_button.visible = buttons_visible grab_button.visible = buttons_visible
grab_button.scale = Vector2(button_scale, button_scale) grab_button.scale = Vector2(button_scale, button_scale)
# Use offsets for anchored controls, not position # Use offsets for anchored controls, not position
grab_button.offset_left = button_positions.grab.x # grab_button.offset_left = button_positions.grab.x
grab_button.offset_top = button_positions.grab.y # grab_button.offset_top = button_positions.grab.y
grab_button.offset_right = button_positions.grab.x + button_size # grab_button.offset_right = button_positions.grab.x + button_size
grab_button.offset_bottom = button_positions.grab.y + button_size # grab_button.offset_bottom = button_positions.grab.y + button_size
if put_button: if put_button:
put_button.visible = buttons_visible put_button.visible = false # Always INTENTIONALLY HIDDEN per request
put_button.scale = Vector2(button_scale, button_scale) # put_button.scale = Vector2(button_scale, button_scale)
put_button.offset_left = button_positions.put.x # put_button.offset_left = button_positions.put.x
put_button.offset_top = button_positions.put.y # put_button.offset_top = button_positions.put.y
put_button.offset_right = button_positions.put.x + button_size # put_button.offset_right = button_positions.put.x + button_size
put_button.offset_bottom = button_positions.put.y + button_size # put_button.offset_bottom = button_positions.put.y + button_size
if special_button: if attack_mode_button:
special_button.visible = buttons_visible attack_mode_button.visible = buttons_visible
special_button.scale = Vector2(button_scale, button_scale) attack_mode_button.scale = Vector2(button_scale, button_scale)
special_button.offset_left = button_positions.special.x # attack_mode_button.offset_left = button_positions.attack_mode.x
special_button.offset_top = button_positions.special.y # attack_mode_button.offset_top = button_positions.attack_mode.y
special_button.offset_right = button_positions.special.x + button_size # attack_mode_button.offset_right = button_positions.attack_mode.x + button_size
special_button.offset_bottom = button_positions.special.y + button_size # attack_mode_button.offset_bottom = button_positions.attack_mode.y + button_size
if spawn_boost_button: if spawn_boost_button:
spawn_boost_button.visible = buttons_visible spawn_boost_button.visible = buttons_visible
spawn_boost_button.scale = Vector2(button_scale, button_scale) spawn_boost_button.scale = Vector2(button_scale, button_scale)
spawn_boost_button.offset_left = button_positions.spawn_boost.x # spawn_boost_button.offset_left = button_positions.spawn_boost.x
spawn_boost_button.offset_top = button_positions.spawn_boost.y # spawn_boost_button.offset_top = button_positions.spawn_boost.y
spawn_boost_button.offset_right = button_positions.spawn_boost.x + button_size # spawn_boost_button.offset_right = button_positions.spawn_boost.x + button_size
spawn_boost_button.offset_bottom = button_positions.spawn_boost.y + button_size # spawn_boost_button.offset_bottom = button_positions.spawn_boost.y + button_size
# Force layer update # Force layer update
visible = true visible = true
@@ -430,7 +463,7 @@ func _apply_settings():
# ============================================================================= # =============================================================================
func set_touch_buttons_enabled(enabled: bool): func set_touch_buttons_enabled(enabled: bool):
"""Enable or disable all action buttons (grab, put, special).""" """Enable or disable all action buttons (grab, put, attack_mode)."""
touch_buttons_enabled = enabled touch_buttons_enabled = enabled
_apply_settings() _apply_settings()
@@ -447,31 +480,8 @@ func set_button_scale(p_scale: float):
func set_button_position(button_name: String, new_position: Vector2): func set_button_position(button_name: String, new_position: Vector2):
"""Update position of a specific button.""" """Update position of a specific button."""
button_positions[button_name] = new_position button_positions[button_name] = new_position
match button_name: # Logic to update offsets removed per request (Scene Controlled)
"grab": # Only saving the data for persistence if user eventually wants it back
if grab_button:
grab_button.offset_left = new_position.x
grab_button.offset_top = new_position.y
grab_button.offset_right = new_position.x + button_size
grab_button.offset_bottom = new_position.y + button_size
"put":
if put_button:
put_button.offset_left = new_position.x
put_button.offset_top = new_position.y
put_button.offset_right = new_position.x + button_size
put_button.offset_bottom = new_position.y + button_size
"special":
if special_button:
special_button.offset_left = new_position.x
special_button.offset_top = new_position.y
special_button.offset_right = new_position.x + button_size
special_button.offset_bottom = new_position.y + button_size
"spawn_boost":
if spawn_boost_button:
spawn_boost_button.offset_left = new_position.x
spawn_boost_button.offset_top = new_position.y
spawn_boost_button.offset_right = new_position.x + button_size
spawn_boost_button.offset_bottom = new_position.y + button_size
func get_button_positions() -> Dictionary: func get_button_positions() -> Dictionary:
"""Get current button positions for settings UI.""" """Get current button positions for settings UI."""
@@ -498,7 +508,7 @@ func _on_boost_points_changed(current_points: int, max_points: int):
# User Request: Disable Special & SpawnBoost if < 100% # User Request: Disable Special & SpawnBoost if < 100%
var is_full = current_points >= (max_points - 1) # Tolerance var is_full = current_points >= (max_points - 1) # Tolerance
_update_boost_button_state(special_button, is_full) _update_boost_button_state(attack_mode_button, is_full)
_update_boost_button_state(spawn_boost_button, is_full) _update_boost_button_state(spawn_boost_button, is_full)
func _update_boost_button_state(btn: Button, is_enabled: bool): func _update_boost_button_state(btn: Button, is_enabled: bool):