feat: Add powerup inventory UI and mobile touch controls including a virtual joystick and action buttons.

This commit is contained in:
Yogi Wiguna
2026-02-04 16:08:38 +08:00
parent d9cdd9068e
commit 34867feb86
2 changed files with 57 additions and 1 deletions
+28 -1
View File
@@ -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