From b30016bc28a28772c150cc5e24ea4f4bb0235e64 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 25 Dec 2021 02:52:21 +0100 Subject: [PATCH] Set up continent select dropdown. --- .../world_generator/ui/tabs/Continent.gd | 42 +++++++++++++++++-- .../world_generator/ui/tabs/Continent.tscn | 2 +- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/game/addons/world_generator/ui/tabs/Continent.gd b/game/addons/world_generator/ui/tabs/Continent.gd index 0268b685..670b4027 100644 --- a/game/addons/world_generator/ui/tabs/Continent.gd +++ b/game/addons/world_generator/ui/tabs/Continent.gd @@ -1,15 +1,51 @@ tool extends HBoxContainer -var edited_world +var edited_world : WorldGenWorld = null +var edited_continent : Continent = null -func refresh() -> void: - pass +func _ready(): + var option_button : OptionButton = $HSplitContainer/VBoxContainer/OptionButton + option_button.connect("item_selected", self, "on_item_selected") + +func refresh_continent() -> void: # $HSplitContainer/ResourcePropertyList.edit_resource(edited_world) # $VBoxContainer/DataList.set_edited_resource(edited_world) # $HSplitContainer/RectEditor.set_edited_resource(edited_world) + + if !edited_continent: + return + +func refresh() -> void: + var option_button : OptionButton = $HSplitContainer/VBoxContainer/OptionButton + option_button.clear() + + if !edited_world: + return + + var content : Array = edited_world.get_content() + + for c in content: + if c: + option_button.add_item(c.resource_name) + option_button.set_item_metadata(option_button.get_item_count() - 1, c) + + if !edited_continent: + edited_continent = c + + refresh_continent() func set_wgworld(wgw : WorldGenWorld) -> void: edited_world = wgw refresh() + +func set_continent(continent : Continent) -> void: + edited_continent = continent + + refresh_continent() + +func on_item_selected(idx : int) -> void: + var option_button : OptionButton = $HSplitContainer/VBoxContainer/OptionButton + + set_continent(option_button.get_item_metadata(idx)) diff --git a/game/addons/world_generator/ui/tabs/Continent.tscn b/game/addons/world_generator/ui/tabs/Continent.tscn index 2cd40db4..6040bdd1 100644 --- a/game/addons/world_generator/ui/tabs/Continent.tscn +++ b/game/addons/world_generator/ui/tabs/Continent.tscn @@ -32,7 +32,7 @@ margin_left = 747.0 margin_right = 1024.0 margin_bottom = 600.0 -[node name="MenuButton" type="OptionButton" parent="HSplitContainer/VBoxContainer"] +[node name="OptionButton" type="OptionButton" parent="HSplitContainer/VBoxContainer"] margin_right = 277.0 margin_bottom = 20.0 selected = 0