49 lines
1.6 KiB
GDScript
49 lines
1.6 KiB
GDScript
|
|
extends VBoxContainer
|
||
|
|
|
||
|
|
@export var selection_manager: SelectionManager
|
||
|
|
@export var name_label: Label
|
||
|
|
@export var selection_panel: Control
|
||
|
|
@export var content_panel: Container
|
||
|
|
var grid: Grid
|
||
|
|
|
||
|
|
func _ready():
|
||
|
|
selection_manager.selection_updated.connect(_selection_updated)
|
||
|
|
grid = Util.find(Grid)
|
||
|
|
|
||
|
|
func deselect():
|
||
|
|
name_label.text = "Nothing Selected"
|
||
|
|
if !selection_panel.hidden: selection_panel.hide()
|
||
|
|
for child in content_panel.get_children(): child.queue_free()
|
||
|
|
|
||
|
|
func select_single(item: Building):
|
||
|
|
name_label.text = item.data.tile_name
|
||
|
|
selection_panel.show()
|
||
|
|
for child in content_panel.get_children(): child.queue_free()
|
||
|
|
|
||
|
|
for upgrade in item.data.upgrade_paths:
|
||
|
|
var container = FoldableContainer.new()
|
||
|
|
container.folded = false
|
||
|
|
container.title = upgrade.tile_name
|
||
|
|
content_panel.add_child(container)
|
||
|
|
for thing in upgrade.field_requirements:
|
||
|
|
match thing.get_script():
|
||
|
|
FieldMin:
|
||
|
|
var req = thing as FieldMin
|
||
|
|
var checkbox = CheckBox.new()
|
||
|
|
checkbox.text = str(Grid.Field.keys()[req.field])
|
||
|
|
checkbox.button_pressed = req.is_satisfied_at_position(grid, item.tile_pos)
|
||
|
|
checkbox.disabled = true
|
||
|
|
container.add_child(checkbox)
|
||
|
|
FieldMax:
|
||
|
|
var req = thing as FieldMax
|
||
|
|
var checkbox = CheckBox.new()
|
||
|
|
checkbox.text = str(Grid.Field.keys()[req.field])
|
||
|
|
checkbox.button_pressed = req.is_satisfied_at_position(grid, item.tile_pos)
|
||
|
|
checkbox.disabled = true
|
||
|
|
container.add_child(checkbox)
|
||
|
|
|
||
|
|
|
||
|
|
func _selection_updated(things: Array[Building]):
|
||
|
|
if things.size() == 0: deselect()
|
||
|
|
if things.size() == 1: select_single(things[0])
|