40 lines
858 B
GDScript
40 lines
858 B
GDScript
extends Node2D
|
|
class_name SelectionManager
|
|
|
|
signal selection_updated
|
|
|
|
@export var selected_box_hidden_color = Color(1, 1, 1, 0)
|
|
@export var selected_box_color = Color(1, 1, 1, 0.6)
|
|
@onready var selection: Array[Building] = []
|
|
var anim_t: float = 0.0
|
|
|
|
func _process(delta):
|
|
anim_t += delta * 8
|
|
anim_t = clamp(anim_t, 0, 1)
|
|
queue_redraw()
|
|
|
|
func clear():
|
|
anim_t = 0
|
|
selection = []
|
|
selection_updated.emit(selection)
|
|
|
|
func append_array(items: Array[Building]):
|
|
selection.append_array(items)
|
|
selection_updated.emit(selection)
|
|
|
|
func select_array(items: Array[Building]):
|
|
clear()
|
|
if items.is_empty():
|
|
return
|
|
append_array(items)
|
|
|
|
func _draw():
|
|
if selection.is_empty():
|
|
return
|
|
for tile in selection:
|
|
draw_rect(
|
|
tile.get_worldbox().grow(lerp(-16, 0, anim_t)),
|
|
lerp(selected_box_hidden_color, selected_box_color, anim_t ** 1.3),
|
|
false, 3
|
|
)
|