modules: configure option items in the enter tree hook
This commit is contained in:
parent
0405c159ac
commit
f03e258cb0
1 changed files with 10 additions and 8 deletions
|
@ -1,16 +1,16 @@
|
||||||
class_name BuildingOption
|
class_name BuildingOption
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
const buildings_json = preload("res://src/modules/building/building_option/buildings.tres")
|
|
||||||
|
|
||||||
|
|
||||||
signal selected(item: BuildingOptionItem)
|
signal selected(item: BuildingOptionItem)
|
||||||
|
|
||||||
@export var selected_id: int
|
@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 selected_option: BuildingOptionItem = null
|
||||||
|
|
||||||
var options: Array[BuildingOptionItem] = []
|
var options: Array[BuildingOptionItem] = []
|
||||||
|
|
||||||
func select(selected_id: int):
|
func select(selected_id: int):
|
||||||
|
@ -20,7 +20,9 @@ func select(selected_id: int):
|
||||||
selected_option = option
|
selected_option = option
|
||||||
selected.emit(option)
|
selected.emit(option)
|
||||||
|
|
||||||
func _ready():
|
func _enter_tree():
|
||||||
|
option_button = $OptionButton;
|
||||||
|
|
||||||
for building_group in buildings_json.data:
|
for building_group in buildings_json.data:
|
||||||
option_button.add_separator(building_group.group)
|
option_button.add_separator(building_group.group)
|
||||||
|
|
||||||
|
@ -28,8 +30,8 @@ func _ready():
|
||||||
options.append(BuildingOptionItem.new(building))
|
options.append(BuildingOptionItem.new(building))
|
||||||
option_button.add_item("{label} ({energy} ⚡)".format(building), building.id)
|
option_button.add_item("{label} ({energy} ⚡)".format(building), building.id)
|
||||||
|
|
||||||
option_button.selected = -1
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
if selected_id != null:
|
if selected_id != null:
|
||||||
select(selected_id)
|
select(selected_id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue