From 1fa69031060830bf9e0a69fd7fcdb3f753d7786b Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 25 Dec 2021 23:09:56 +0100 Subject: [PATCH] Cleaned up the methods in the Zone editor. Also fixed a few smaller usability issues. --- .../world_generator/test/test_world.tres | 4 +- game/addons/world_generator/ui/tabs/Zone.gd | 73 ++++++++++--------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/game/addons/world_generator/test/test_world.tres b/game/addons/world_generator/test/test_world.tres index 4148d99c..70ee4ac3 100644 --- a/game/addons/world_generator/test/test_world.tres +++ b/game/addons/world_generator/test/test_world.tres @@ -8,13 +8,13 @@ [sub_resource type="Resource" id=14] resource_name = "qwe" script = ExtResource( 4 ) -rect = Rect2( 12, 17, 159.14, 87.78 ) +rect = Rect2( 21, 25, 150, 79 ) locked = false [sub_resource type="Resource" id=15] resource_name = "we" script = ExtResource( 4 ) -rect = Rect2( 0, 0, 19.14, 12.78 ) +rect = Rect2( 3, -1, 54.14, 32.78 ) locked = false [sub_resource type="Resource" id=8] diff --git a/game/addons/world_generator/ui/tabs/Zone.gd b/game/addons/world_generator/ui/tabs/Zone.gd index 15434690..93ff4ff7 100644 --- a/game/addons/world_generator/ui/tabs/Zone.gd +++ b/game/addons/world_generator/ui/tabs/Zone.gd @@ -12,31 +12,11 @@ func _ready(): var zoption_button : OptionButton = $HSplitContainer/VBoxContainer/ZoneOptionButton zoption_button.connect("item_selected", self, "on_zone_item_selected") -func refresh_continent() -> void: - var option_button : OptionButton = $HSplitContainer/VBoxContainer/ZoneOptionButton - option_button.clear() - - if !edited_continent: - return - - var content : Array = edited_continent.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_zone: - edited_zone = c - -func refresh_zone() -> void: - $HSplitContainer/VBoxContainer/HBoxContainer2/ResourcePropertyList.edit_resource(edited_zone) - $HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/DataList.set_edited_resource(edited_zone) - $HSplitContainer/RectEditor.set_edited_resource(edited_zone) - func refresh() -> void: var option_button : OptionButton = $HSplitContainer/VBoxContainer/ContinentOptionButton option_button.clear() + edited_continent = null + edited_zone = null if !edited_world: return @@ -51,8 +31,44 @@ func refresh() -> void: if !edited_continent: edited_continent = c - refresh_continent() + continent_changed() + +func continent_changed() -> void: + var option_button : OptionButton = $HSplitContainer/VBoxContainer/ZoneOptionButton + option_button.clear() + edited_zone = null + + if !edited_continent: + return + var content : Array = edited_continent.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_zone: + edited_zone = c + + zone_changed() + +func zone_changed() -> void: + $HSplitContainer/VBoxContainer/HBoxContainer2/ResourcePropertyList.edit_resource(edited_zone) + $HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/DataList.set_edited_resource(edited_zone) + $HSplitContainer/RectEditor.set_edited_resource(edited_zone) + +func set_continent(continent : Continent) -> void: + edited_continent = continent + edited_zone = null + + continent_changed() + +func set_zone(zone : Zone) -> void: + edited_zone = zone + + zone_changed() + func set_wgworld(wgw : WorldGenWorld) -> void: edited_world = wgw edited_continent = null @@ -60,17 +76,6 @@ func set_wgworld(wgw : WorldGenWorld) -> void: refresh() -func set_continent(continent : Continent) -> void: - edited_continent = continent - edited_zone = null - - refresh_continent() - -func set_zone(zone : Zone) -> void: - edited_zone = zone - - refresh_zone() - func on_continent_item_selected(idx : int) -> void: var option_button : OptionButton = $HSplitContainer/VBoxContainer/ContinentOptionButton