brackeys-12/ui/building_menu.gd

61 lines
1.2 KiB
GDScript3
Raw Normal View History

2024-09-12 02:04:24 +00:00
extends Control
@onready var tabs = [
$HBoxContainer/BuildingTab, $HBoxContainer/BuildingTab2, $HBoxContainer/BuildingTab3
]
@onready var building_data = Data.data.buildings.values()
@onready var v_box_container: HBoxContainer = $Buildings/VBoxContainer
@onready var icons = [
$Buildings/VBoxContainer/BuildingIcon,
$Buildings/VBoxContainer/BuildingIcon2,
$Buildings/VBoxContainer/BuildingIcon3,
$Buildings/VBoxContainer/BuildingIcon4
]
@onready var spacers = [
$Buildings/VBoxContainer/Spacer,
$Buildings/VBoxContainer/Spacer2,
$Buildings/VBoxContainer/Spacer3
]
func _ready() -> void:
swap_to_tab(0)
func swap_to_tab(index):
for i in range(0, tabs.size()):
if i == index:
tabs[i].select()
else:
tabs[i].unselect()
var buildings = building_data.filter(func(a): return a.type == tabs[index].key)
for i in range(0, icons.size()):
if i < buildings.size():
icons[i].visible = true
if i > 0:
spacers[i - 1].visible = true
else:
icons[i].visible = false
if i > 0:
spacers[i - 1].visible = false
func _on_building_tab_clicked() -> void:
swap_to_tab(0)
func _on_building_tab_2_clicked() -> void:
swap_to_tab(1)
func _on_building_tab_3_clicked() -> void:
swap_to_tab(2)