106 lines
3.2 KiB
GDScript
106 lines
3.2 KiB
GDScript
class_name ComboWindowHud
|
|
extends HBoxContainer
|
|
|
|
@export var slot_count := 4
|
|
|
|
var panels: Array[PanelContainer] = []
|
|
var labels: Array[Label] = []
|
|
var clear_tween: Tween
|
|
|
|
|
|
func _ready() -> void:
|
|
_build_slots()
|
|
var bus := _event_bus()
|
|
bus.connect("combo_updated", refresh)
|
|
bus.connect("combo_cleared", _on_combo_cleared)
|
|
|
|
|
|
func refresh(inputs: Array) -> void:
|
|
if labels.is_empty():
|
|
_build_slots()
|
|
for index: int in range(labels.size()):
|
|
var filled := index < inputs.size()
|
|
labels[index].text = str(inputs[index]) if filled else "."
|
|
labels[index].modulate = Color(1.0, 1.0, 1.0, 1.0 if filled else 0.35)
|
|
panels[index].modulate = Color(1.0, 1.0, 1.0, 1.0 if filled else 0.48)
|
|
if filled:
|
|
_pulse_slot(panels[index])
|
|
|
|
|
|
func _on_combo_cleared(_reason: StringName) -> void:
|
|
refresh([])
|
|
_flash_clear()
|
|
|
|
|
|
func _build_slots() -> void:
|
|
if not labels.is_empty():
|
|
return
|
|
for index: int in range(slot_count):
|
|
var panel := PanelContainer.new()
|
|
panel.custom_minimum_size = Vector2(64, 56)
|
|
panel.pivot_offset = Vector2(32, 28)
|
|
panel.modulate = Color(1.0, 1.0, 1.0, 0.48)
|
|
panel.add_theme_stylebox_override("panel", _make_slot_style())
|
|
var label := Label.new()
|
|
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
|
label.text = "."
|
|
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
label.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
label.add_theme_color_override("font_color", Color(0.94, 0.98, 1.0, 1.0))
|
|
label.add_theme_color_override("font_shadow_color", Color(0.0, 0.0, 0.0, 0.9))
|
|
label.add_theme_constant_override("shadow_offset_x", 2)
|
|
label.add_theme_constant_override("shadow_offset_y", 2)
|
|
label.add_theme_font_size_override("font_size", 26)
|
|
panel.add_child(label)
|
|
add_child(panel)
|
|
panels.append(panel)
|
|
labels.append(label)
|
|
|
|
|
|
func _pulse_slot(panel: PanelContainer) -> void:
|
|
var tween := create_tween()
|
|
panel.scale = Vector2(1.08, 1.08)
|
|
tween.tween_property(panel, "scale", Vector2.ONE, 0.09)
|
|
|
|
|
|
func _flash_clear() -> void:
|
|
if clear_tween != null and clear_tween.is_valid():
|
|
clear_tween.kill()
|
|
clear_tween = create_tween()
|
|
clear_tween.set_parallel(true)
|
|
for panel: PanelContainer in panels:
|
|
panel.scale = Vector2(1.16, 1.16)
|
|
panel.modulate = Color(1.0, 1.0, 1.0, 1.0)
|
|
clear_tween.tween_property(panel, "scale", Vector2.ONE, 0.20)
|
|
clear_tween.tween_property(panel, "modulate", Color(1.0, 1.0, 1.0, 0.48), 0.20)
|
|
|
|
|
|
func _make_slot_style() -> StyleBoxFlat:
|
|
var style := StyleBoxFlat.new()
|
|
style.content_margin_left = 6.0
|
|
style.content_margin_top = 4.0
|
|
style.content_margin_right = 6.0
|
|
style.content_margin_bottom = 4.0
|
|
style.bg_color = Color(0.04, 0.07, 0.09, 0.82)
|
|
style.border_width_left = 2
|
|
style.border_width_top = 2
|
|
style.border_width_right = 2
|
|
style.border_width_bottom = 2
|
|
style.border_color = Color(0.43, 0.78, 0.88, 0.95)
|
|
style.corner_radius_top_left = 6
|
|
style.corner_radius_top_right = 6
|
|
style.corner_radius_bottom_right = 6
|
|
style.corner_radius_bottom_left = 6
|
|
return style
|
|
|
|
|
|
func _event_bus() -> Node:
|
|
var root := get_tree().root
|
|
var bus := root.get_node_or_null("EventBus")
|
|
if bus == null:
|
|
bus = load("res://autoload/event_bus.gd").new()
|
|
bus.name = "EventBus"
|
|
root.add_child(bus)
|
|
return bus
|