From f03e258cb03f1fc5a078173bef25deb8cad543b3 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Wed, 10 Jan 2024 11:40:27 +0300 Subject: [PATCH] modules: configure option items in the enter tree hook --- .../building_option/building_option.gd | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/modules/building/building_option/building_option.gd b/src/modules/building/building_option/building_option.gd index 5c4e822..d6e812c 100644 --- a/src/modules/building/building_option/building_option.gd +++ b/src/modules/building/building_option/building_option.gd @@ -1,16 +1,16 @@ class_name BuildingOption extends Control -const buildings_json = preload("res://src/modules/building/building_option/buildings.tres") - signal selected(item: BuildingOptionItem) @export var selected_id: int -@onready var option_button: OptionButton = $OptionButton; + +const buildings_json = preload("res://src/modules/building/building_option/buildings.tres") + +var option_button: OptionButton; var selected_option: BuildingOptionItem = null - var options: Array[BuildingOptionItem] = [] func select(selected_id: int): @@ -20,16 +20,18 @@ func select(selected_id: int): selected_option = option selected.emit(option) -func _ready(): +func _enter_tree(): + option_button = $OptionButton; + for building_group in buildings_json.data: option_button.add_separator(building_group.group) for building in building_group.children: options.append(BuildingOptionItem.new(building)) option_button.add_item("{label} ({energy} ⚡)".format(building), building.id) - - option_button.selected = -1 - + + +func _ready(): if selected_id != null: select(selected_id)