update
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
extends Control
|
||||
|
||||
# PowerUpInventoryUI - Displays stored powerups and handles selection
|
||||
|
||||
# UI References
|
||||
var icon_containers: Dictionary = {} # { EffectEnum: TextureRect }
|
||||
var selection_indicators: Dictionary = {} # { EffectEnum: Control }
|
||||
|
||||
# Local State
|
||||
var selected_effect: int = -1
|
||||
|
||||
signal effect_selected(effect: int)
|
||||
|
||||
func _ready():
|
||||
# Wait for children to be ready
|
||||
await get_tree().process_frame
|
||||
|
||||
# Map Effect Enum to UI Nodes (Assumes specific names in main.tscn)
|
||||
# Default structure: HBoxContainer > CoinIcon, HeartIcon, etc.
|
||||
var container = get_node_or_null("HBoxContainer")
|
||||
if not container:
|
||||
print("PowerUpUI: Container not found")
|
||||
return
|
||||
|
||||
# SpecialEffect.BURN_TILES (0) -> Coin
|
||||
_setup_icon(0, container.get_node_or_null("CoinIcon"))
|
||||
# SpecialEffect.BLOCK_FLOOR (3) -> Heart
|
||||
_setup_icon(3, container.get_node_or_null("HeartIcon"))
|
||||
# SpecialEffect.FREEZE_PLAYER (2) -> Diamond
|
||||
_setup_icon(2, container.get_node_or_null("DiamondIcon"))
|
||||
# SpecialEffect.INVISIBLE_MODE (4) -> Star
|
||||
_setup_icon(4, container.get_node_or_null("StarIcon"))
|
||||
|
||||
# Note: SpecialEffect enum values from SpecialTilesManager:
|
||||
# BURN_TILES = 0
|
||||
# SPAWN_TILES = 1 (we map Coin to 0, merged)
|
||||
# FREEZE_PLAYER = 2
|
||||
# BLOCK_FLOOR = 3
|
||||
# INVISIBLE_MODE = 4
|
||||
|
||||
func _setup_icon(effect_id: int, node: Control):
|
||||
if not node: return
|
||||
|
||||
icon_containers[effect_id] = node
|
||||
|
||||
# Assume node has specific children for selection state?
|
||||
# "SelectRect" child?
|
||||
var select_rect = node.get_node_or_null("SelectRect")
|
||||
if select_rect:
|
||||
selection_indicators[effect_id] = select_rect
|
||||
select_rect.visible = false
|
||||
|
||||
# Connect click event
|
||||
if not node.gui_input.is_connected(_on_icon_input):
|
||||
node.gui_input.connect(_on_icon_input.bind(effect_id))
|
||||
|
||||
func _on_icon_input(event, effect_id: int):
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
if selected_effect == effect_id:
|
||||
deselect()
|
||||
else:
|
||||
select_effect(effect_id)
|
||||
|
||||
func setup(player_node):
|
||||
var special_manager = player_node.get_node_or_null("SpecialTilesManager")
|
||||
if special_manager:
|
||||
if not special_manager.is_connected("inventory_updated", _on_inventory_updated):
|
||||
special_manager.connect("inventory_updated", _on_inventory_updated)
|
||||
_on_inventory_updated(special_manager.inventory)
|
||||
|
||||
func _on_inventory_updated(inventory: Dictionary):
|
||||
# Update UI icons (Dimmed vs Lit)
|
||||
for effect in icon_containers:
|
||||
if inventory.has(effect):
|
||||
var has_item = inventory[effect]
|
||||
icon_containers[effect].modulate = Color.WHITE if has_item else Color(0.3, 0.3, 0.3, 0.5)
|
||||
|
||||
if not has_item and selected_effect == effect:
|
||||
deselect()
|
||||
|
||||
func select_effect(effect: int):
|
||||
# Check if we own it first? The UI click handler should check.
|
||||
selected_effect = effect
|
||||
emit_signal("effect_selected", effect)
|
||||
_update_selection_visuals()
|
||||
|
||||
func deselect():
|
||||
selected_effect = -1
|
||||
emit_signal("effect_selected", -1)
|
||||
_update_selection_visuals()
|
||||
|
||||
func _update_selection_visuals():
|
||||
for effect in selection_indicators:
|
||||
selection_indicators[effect].visible = (effect == selected_effect)
|
||||
Reference in New Issue
Block a user