From 8453518e8b32d92bc820664e023cc67f967bd2d7 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 26 Dec 2021 18:52:23 +0100 Subject: [PATCH] Added a class selector to the world editor on add. --- .../world_generator/test/test_world.tres | 76 +++++++++++++++++-- game/addons/world_generator/ui/DataList.gd | 61 ++++++++++++--- game/addons/world_generator/ui/DataList.tscn | 64 ++++++++++++++-- .../world_generator/ui/tabs/Continent.tscn | 1 + game/addons/world_generator/ui/tabs/Zone.tscn | 1 + 5 files changed, 183 insertions(+), 20 deletions(-) diff --git a/game/addons/world_generator/test/test_world.tres b/game/addons/world_generator/test/test_world.tres index b462d74c..c13212ee 100644 --- a/game/addons/world_generator/test/test_world.tres +++ b/game/addons/world_generator/test/test_world.tres @@ -1,9 +1,12 @@ -[gd_resource type="Resource" load_steps=28 format=2] +[gd_resource type="Resource" load_steps=40 format=2] [ext_resource path="res://addons/world_generator/resources/world_gen_world.gd" type="Script" id=1] [ext_resource path="res://addons/world_generator/resources/continent.gd" type="Script" id=2] [ext_resource path="res://addons/world_generator/resources/zone.gd" type="Script" id=3] [ext_resource path="res://addons/world_generator/resources/subzone.gd" type="Script" id=4] +[ext_resource path="res://world_generator/continents/test_continent.gd" type="Script" id=5] +[ext_resource path="res://world_generator/zones/test_zone.gd" type="Script" id=6] +[ext_resource path="res://world_generator/subzones/test_subzone.gd" type="Script" id=7] [sub_resource type="Resource" id=14] resource_name = "qwe" @@ -17,12 +20,18 @@ script = ExtResource( 4 ) rect = Rect2( 7, 9, 54, 34 ) locked = false +[sub_resource type="Resource" id=34] +resource_name = "yy" +script = ExtResource( 7 ) +rect = Rect2( 66, 11, 100, 91 ) +locked = false + [sub_resource type="Resource" id=8] resource_name = "asdasr" script = ExtResource( 3 ) rect = Rect2( 35, 21, 191.4, 127.8 ) locked = false -subzones = [ SubResource( 14 ), SubResource( 15 ) ] +subzones = [ SubResource( 14 ), SubResource( 15 ), SubResource( 34 ) ] [sub_resource type="Resource" id=13] resource_name = "qqq" @@ -86,12 +95,26 @@ rect = Rect2( 64, 6, 158.1, 39.8 ) locked = false subzones = [ ] +[sub_resource type="Resource" id=32] +resource_name = "tttte" +script = ExtResource( 3 ) +rect = Rect2( 103, 28, 100, 100 ) +locked = false +subzones = [ ] + +[sub_resource type="Resource" id=35] +resource_name = "yu" +script = ExtResource( 6 ) +rect = Rect2( 88, 21, 100, 100 ) +locked = false +subzones = [ ] + [sub_resource type="Resource" id=1] resource_name = "wwww" script = ExtResource( 2 ) rect = Rect2( 163, 35, 241, 158 ) locked = false -zones = [ SubResource( 8 ), SubResource( 13 ), SubResource( 24 ), SubResource( 26 ) ] +zones = [ SubResource( 8 ), SubResource( 13 ), SubResource( 24 ), SubResource( 26 ), SubResource( 32 ), SubResource( 35 ) ] [sub_resource type="Resource" id=2] resource_name = "efefef" @@ -184,7 +207,7 @@ func setup_property_inspector(inspector) -> void: " [sub_resource type="Resource" id=17] -resource_name = "qwet" +resource_name = "qwetwwqasd" script = SubResource( 16 ) rect = Rect2( 473, 331, 100, 100 ) locked = false @@ -232,7 +255,7 @@ func setup_property_inspector(inspector) -> void: " [sub_resource type="Resource" id=19] -resource_name = "qwesa" +resource_name = "qwesat" script = SubResource( 18 ) rect = Rect2( 613, 346, 100, 100 ) locked = false @@ -300,9 +323,50 @@ rect = Rect2( 256, 365, 100, 100 ) locked = false zones = [ ] +[sub_resource type="Resource" id=27] +resource_name = "asd" +script = ExtResource( 2 ) +rect = Rect2( 337, 79, 100, 100 ) +locked = false +zones = [ ] + +[sub_resource type="Resource" id=28] +resource_name = "asd" +script = ExtResource( 2 ) +rect = Rect2( 244, 234, 100, 100 ) +locked = false +zones = [ ] + +[sub_resource type="Resource" id=29] +script = ExtResource( 2 ) +rect = Rect2( 377, 69, 284, 238 ) +locked = false +zones = [ ] + +[sub_resource type="Resource" id=30] +resource_name = "tttttt" +script = ExtResource( 2 ) +rect = Rect2( 188, 225, 233, 259 ) +locked = false +zones = [ ] + +[sub_resource type="Resource" id=31] +resource_name = "ttttyuqtttt" +script = ExtResource( 2 ) +rect = Rect2( 339, 76, 220, 170 ) +locked = false +zones = [ ] + +[sub_resource type="Resource" id=33] +resource_name = "qttt" +script = ExtResource( 5 ) +rect = Rect2( 99, 78, 213, 105 ) +locked = false +zones = [ ] + [resource] resource_name = "asdasdsse" script = ExtResource( 1 ) rect = Rect2( 0, 0, 1000, 1000 ) locked = false -continents = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 17 ), SubResource( 19 ), SubResource( 20 ), SubResource( 22 ), SubResource( 23 ) ] +continents = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 17 ), SubResource( 19 ), SubResource( 20 ), SubResource( 22 ), SubResource( 23 ), SubResource( 27 ), SubResource( 28 ), SubResource( 29 ), SubResource( 30 ), SubResource( 31 ), SubResource( 33 ) ] diff --git a/game/addons/world_generator/ui/DataList.gd b/game/addons/world_generator/ui/DataList.gd index 6be0f63f..3ebede37 100644 --- a/game/addons/world_generator/ui/DataList.gd +++ b/game/addons/world_generator/ui/DataList.gd @@ -1,18 +1,58 @@ tool extends Tree -var edited_resource : WorldGenBaseResource = null +export(int, "Continent,Zone,Sub Zone") var class_types : int = 0 +var edited_resource : WorldGenBaseResource = null var name_edited_resource : WorldGenBaseResource = null func _init(): connect("item_activated", self, "on_item_activated") + +func _enter_tree(): + var dir : Directory = Directory.new() + + if dir.file_exists("res://world_generator_settings.tres"): + var wgs : WorldGeneratorSettings = load("res://world_generator_settings.tres") as WorldGeneratorSettings + + if !wgs: + return + + wgs.evaluate_scripts(class_types, $NameDialog/VBoxContainer/Tree) func add_item(item_name : String = "") -> void: if !edited_resource: return - edited_resource.create_content(item_name) + var ti : TreeItem = $NameDialog/VBoxContainer/Tree.get_selected() + + if !ti: + return + + var e : WorldGenBaseResource = null + + if ti.has_meta("class_name"): + var cn : String = ti.get_meta("class_name") + + if cn == "Continent": + e = Continent.new() + elif cn == "Zone": + e = Zone.new() + elif cn == "SubZone": + e = SubZone.new() + + elif ti.has_meta("file"): + var cls = load(ti.get_meta("file")) + + if cls: + e = cls.new() + + if !e: + return + + e.resource_name = item_name + + edited_resource.add_content(e) func refresh() -> void: clear() @@ -48,15 +88,18 @@ func set_edited_resource(res : WorldGenBaseResource)-> void: refresh() func add_button_pressed() -> void: - $NameDialog/TextEdit.text = "" + $NameDialog/VBoxContainer/LineEdit.text = "" $NameDialog.popup_centered() func name_dialog_ok_pressed() -> void: - if !name_edited_resource: - add_item($NameDialog/TextEdit.text) - else: - name_edited_resource.resource_name = $NameDialog/TextEdit.text + add_item($NameDialog/VBoxContainer/LineEdit.text) + +func name_edit_dialog_ok_pressed() -> void: + if name_edited_resource: + name_edited_resource.resource_name = $NameEditDialog/VBoxContainer/LineEdit.text + name_edited_resource.emit_changed() name_edited_resource = null + on_resource_changed() func delete_button_pressed() -> void: var item : TreeItem = get_selected() @@ -98,5 +141,5 @@ func on_item_activated() -> void: if !name_edited_resource: return - $NameDialog/TextEdit.text = name_edited_resource.resource_name - $NameDialog.popup_centered() + $NameEditDialog/VBoxContainer/LineEdit.text = name_edited_resource.resource_name + $NameEditDialog.popup_centered() diff --git a/game/addons/world_generator/ui/DataList.tscn b/game/addons/world_generator/ui/DataList.tscn index 9b207388..7852c4de 100644 --- a/game/addons/world_generator/ui/DataList.tscn +++ b/game/addons/world_generator/ui/DataList.tscn @@ -14,17 +14,71 @@ __meta__ = { } [node name="NameDialog" type="ConfirmationDialog" parent="."] -margin_right = 200.0 -margin_bottom = 70.0 +margin_right = 329.0 +margin_bottom = 313.0 window_title = "Name" +resizable = true __meta__ = { "_edit_use_anchors_": false } -[node name="TextEdit" type="TextEdit" parent="NameDialog"] +[node name="VBoxContainer" type="VBoxContainer" parent="NameDialog"] margin_left = 8.0 margin_top = 8.0 -margin_right = 192.0 -margin_bottom = 34.0 +margin_right = 321.0 +margin_bottom = 277.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label2" type="Label" parent="NameDialog/VBoxContainer"] +margin_right = 313.0 +margin_bottom = 14.0 +text = "Class" + +[node name="Tree" type="Tree" parent="NameDialog/VBoxContainer"] +margin_top = 18.0 +margin_right = 313.0 +margin_bottom = 223.0 +rect_min_size = Vector2( 0, 200 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="Label" type="Label" parent="NameDialog/VBoxContainer"] +margin_top = 227.0 +margin_right = 313.0 +margin_bottom = 241.0 +text = "Name" + +[node name="LineEdit" type="LineEdit" parent="NameDialog/VBoxContainer"] +margin_top = 245.0 +margin_right = 313.0 +margin_bottom = 269.0 + +[node name="NameEditDialog" type="ConfirmationDialog" parent="."] +margin_right = 223.0 +margin_bottom = 82.0 +window_title = "Name" +resizable = true +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="NameEditDialog"] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 215.0 +margin_bottom = 50.0 + +[node name="Label" type="Label" parent="NameEditDialog/VBoxContainer"] +margin_right = 207.0 +margin_bottom = 14.0 +text = "Name" + +[node name="LineEdit" type="LineEdit" parent="NameEditDialog/VBoxContainer"] +margin_top = 18.0 +margin_right = 207.0 +margin_bottom = 42.0 [connection signal="confirmed" from="NameDialog" to="." method="name_dialog_ok_pressed"] +[connection signal="confirmed" from="NameEditDialog" to="." method="name_edit_dialog_ok_pressed"] diff --git a/game/addons/world_generator/ui/tabs/Continent.tscn b/game/addons/world_generator/ui/tabs/Continent.tscn index 7f347ec5..8102c2f6 100644 --- a/game/addons/world_generator/ui/tabs/Continent.tscn +++ b/game/addons/world_generator/ui/tabs/Continent.tscn @@ -93,6 +93,7 @@ anchor_bottom = 0.0 margin_top = 42.0 margin_right = 173.0 margin_bottom = 576.0 +class_types = 1 [connection signal="pressed" from="HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/HBoxContainer/AddButton" to="HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/DataList" method="add_button_pressed"] [connection signal="pressed" from="HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/HBoxContainer/DeleteButton" to="HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/DataList" method="delete_button_pressed"] diff --git a/game/addons/world_generator/ui/tabs/Zone.tscn b/game/addons/world_generator/ui/tabs/Zone.tscn index 65f88067..a113ff04 100644 --- a/game/addons/world_generator/ui/tabs/Zone.tscn +++ b/game/addons/world_generator/ui/tabs/Zone.tscn @@ -98,6 +98,7 @@ anchor_bottom = 0.0 margin_top = 42.0 margin_right = 173.0 margin_bottom = 552.0 +class_types = 2 [connection signal="pressed" from="HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/HBoxContainer/AddButton" to="HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/DataList" method="add_button_pressed"] [connection signal="pressed" from="HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/HBoxContainer/DeleteButton" to="HSplitContainer/VBoxContainer/HBoxContainer2/VBoxContainer/DataList" method="delete_button_pressed"]