42 lines
973 B
GDScript
42 lines
973 B
GDScript
|
|
extends Node2D
|
||
|
|
class_name SelectionManager
|
||
|
|
|
||
|
|
const SIGNAL_SELECTION_CHANGED = "selection-changed"
|
||
|
|
|
||
|
|
@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[Positional] = []
|
||
|
|
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 = []
|
||
|
|
emit_signal(SIGNAL_SELECTION_CHANGED)
|
||
|
|
print("clear selection ", len(selection))
|
||
|
|
|
||
|
|
func append_array(items: Array[Positional]):
|
||
|
|
selection.append_array(items)
|
||
|
|
emit_signal(SIGNAL_SELECTION_CHANGED)
|
||
|
|
|
||
|
|
func select_array(items: Array[Positional]):
|
||
|
|
clear()
|
||
|
|
if items.is_empty():
|
||
|
|
return
|
||
|
|
append_array(items)
|
||
|
|
print("selected ", len(selection))
|
||
|
|
|
||
|
|
func _draw():
|
||
|
|
if selection.is_empty():
|
||
|
|
return
|
||
|
|
for tile in selection:
|
||
|
|
draw_rect(
|
||
|
|
tile.worldbox.grow(lerp(-16, 0, anim_t)),
|
||
|
|
lerp(selected_box_hidden_color, selected_box_color, anim_t ** 1.3),
|
||
|
|
false, 3
|
||
|
|
)
|