feat: Add powerup inventory UI and mobile touch controls including a virtual joystick and action buttons.
This commit is contained in:
@@ -138,6 +138,8 @@ func _find_or_create_action_button(container: Control, button_name: String, icon
|
||||
|
||||
btn.button_down.connect(func(): _on_button_pressed(button_name))
|
||||
btn.button_up.connect(func(): _on_button_released(button_name))
|
||||
|
||||
_ensure_shortcut_label(btn, button_name)
|
||||
return btn
|
||||
|
||||
# Create new
|
||||
@@ -164,7 +166,9 @@ func _create_action_button(button_name: String, icon: String, pos: Vector2) -> B
|
||||
btn.button_down.connect(func(): _on_button_pressed(button_name))
|
||||
btn.button_up.connect(func(): _on_button_released(button_name))
|
||||
|
||||
_style_button(btn, button_opacity)
|
||||
# Helper to ensure label exists
|
||||
_ensure_shortcut_label(btn, button_name)
|
||||
|
||||
return btn
|
||||
|
||||
func _style_button(btn: Button, opacity: float):
|
||||
@@ -194,6 +198,29 @@ func _style_button(btn: Button, opacity: float):
|
||||
# Prevent buttons from stealing focus (fixes Spacebar activation)
|
||||
btn.focus_mode = Control.FOCUS_NONE
|
||||
|
||||
func _ensure_shortcut_label(btn: Button, button_name: String):
|
||||
if btn.has_node("ShortcutLabel"):
|
||||
return
|
||||
|
||||
# Add Keyboard Shortcut Label
|
||||
var shortcut_lbl = Label.new()
|
||||
shortcut_lbl.name = "ShortcutLabel"
|
||||
shortcut_lbl.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
shortcut_lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
shortcut_lbl.vertical_alignment = VERTICAL_ALIGNMENT_BOTTOM
|
||||
shortcut_lbl.offset_bottom = 20 # Below button
|
||||
shortcut_lbl.add_theme_font_size_override("font_size", 16)
|
||||
shortcut_lbl.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
shortcut_lbl.add_theme_constant_override("outline_size", 4)
|
||||
|
||||
match button_name:
|
||||
"Grab": shortcut_lbl.text = "Space"
|
||||
"Put": shortcut_lbl.text = "R"
|
||||
"Special": shortcut_lbl.text = "C"
|
||||
"SpawnBoost": shortcut_lbl.text = "V"
|
||||
|
||||
btn.add_child(shortcut_lbl)
|
||||
|
||||
func _on_joystick_direction(direction: Vector2i):
|
||||
if local_player and local_player.has_method("simple_move_to"):
|
||||
var target_pos = local_player.current_position + direction
|
||||
|
||||
@@ -74,6 +74,35 @@ func _setup_btn(effect_id: int, btn: Button):
|
||||
cd_lbl.text = ""
|
||||
btn.add_child(cd_lbl)
|
||||
|
||||
# Add Keyboard Shortcut Label
|
||||
if not btn.has_node("ShortcutLabel"):
|
||||
var sc_lbl = Label.new()
|
||||
sc_lbl.name = "ShortcutLabel"
|
||||
sc_lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
sc_lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
sc_lbl.vertical_alignment = VERTICAL_ALIGNMENT_BOTTOM
|
||||
sc_lbl.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
# Offset slightly below or at bottom edge
|
||||
sc_lbl.offset_bottom = 20
|
||||
sc_lbl.add_theme_font_size_override("font_size", 14)
|
||||
sc_lbl.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
sc_lbl.add_theme_constant_override("outline_size", 4)
|
||||
|
||||
# Determine Label Text based on Effect ID
|
||||
# 0: Speed -> 1
|
||||
# 2: Wall -> 2
|
||||
# 1: Freeze -> 3
|
||||
# 3: Ghost -> 4
|
||||
var key_text = ""
|
||||
match effect_id:
|
||||
0: key_text = "1"
|
||||
2: key_text = "2"
|
||||
1: key_text = "3"
|
||||
3: key_text = "4"
|
||||
|
||||
sc_lbl.text = key_text
|
||||
btn.add_child(sc_lbl)
|
||||
|
||||
# Connect click
|
||||
if not btn.pressed.is_connected(_on_btn_pressed):
|
||||
btn.pressed.connect(_on_btn_pressed.bind(effect_id))
|
||||
|
||||
Reference in New Issue
Block a user