From 87e4318e067aa76fce2a49c101f94f2b7366470f Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 25 Dec 2021 02:15:17 +0100 Subject: [PATCH] Implemented editing the names of resources in the DataList widget. --- .../world_generator/resources/continent.gd | 8 +++-- .../resources/world_gen_base_resource.gd | 2 +- .../resources/world_gen_world.gd | 3 +- game/addons/world_generator/resources/zone.gd | 7 ++-- .../world_generator/test/test_world.tres | 29 +++++++++++++-- game/addons/world_generator/ui/DataList.gd | 36 +++++++++++++++++-- game/addons/world_generator/ui/DataList.tscn | 16 +++++++++ .../addons/world_generator/ui/MainScreen.tscn | 2 +- 8 files changed, 92 insertions(+), 11 deletions(-) diff --git a/game/addons/world_generator/resources/continent.gd b/game/addons/world_generator/resources/continent.gd index 9067be16..4ad5910d 100644 --- a/game/addons/world_generator/resources/continent.gd +++ b/game/addons/world_generator/resources/continent.gd @@ -10,8 +10,12 @@ func get_content() -> Array: func set_content(arr : Array) -> void: zones = arr -func add_content() -> void: - zones.append(Zone.new()) +func add_content(item_name : String = "") -> void: + var zone : Zone = Zone.new() + zone.resource_name = item_name + + zones.append(zone) + emit_changed() func setup_property_inspector(inspector) -> void: diff --git a/game/addons/world_generator/resources/world_gen_base_resource.gd b/game/addons/world_generator/resources/world_gen_base_resource.gd index f5cbaaa3..a4f7b492 100644 --- a/game/addons/world_generator/resources/world_gen_base_resource.gd +++ b/game/addons/world_generator/resources/world_gen_base_resource.gd @@ -18,7 +18,7 @@ func get_content() -> Array: func set_content(arr : Array) -> void: pass -func add_content() -> void: +func add_content(item_name : String = "") -> void: pass func setup_property_inspector(inspector) -> void: diff --git a/game/addons/world_generator/resources/world_gen_world.gd b/game/addons/world_generator/resources/world_gen_world.gd index 46a1dc49..eb62f918 100644 --- a/game/addons/world_generator/resources/world_gen_world.gd +++ b/game/addons/world_generator/resources/world_gen_world.gd @@ -10,8 +10,9 @@ func get_content() -> Array: func set_content(arr : Array) -> void: continents = arr -func add_content() -> void: +func add_content(item_name : String = "") -> void: var continent : Continent = Continent.new() + continent.resource_name = item_name var r : Rect2 = get_rect() r.size.x /= 10.0 diff --git a/game/addons/world_generator/resources/zone.gd b/game/addons/world_generator/resources/zone.gd index 13371857..7e79ff7a 100644 --- a/game/addons/world_generator/resources/zone.gd +++ b/game/addons/world_generator/resources/zone.gd @@ -10,8 +10,11 @@ func get_content() -> Array: func set_content(arr : Array) -> void: subzones = arr -func add_content() -> void: - subzones.append(SubZone.new()) +func add_content(item_name : String = "") -> void: + var subzone : SubZone = SubZone.new() + subzone.resource_name = item_name + + subzones.append(subzone) emit_changed() func setup_property_inspector(inspector) -> void: diff --git a/game/addons/world_generator/test/test_world.tres b/game/addons/world_generator/test/test_world.tres index c2e7a1bb..dbd703ce 100644 --- a/game/addons/world_generator/test/test_world.tres +++ b/game/addons/world_generator/test/test_world.tres @@ -1,35 +1,60 @@ -[gd_resource type="Resource" load_steps=7 format=2] +[gd_resource type="Resource" load_steps=10 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] [sub_resource type="Resource" id=1] +resource_name = "wwww" script = ExtResource( 2 ) rect = Rect2( 133, 63, 224, 158 ) locked = false zones = [ ] [sub_resource type="Resource" id=2] +resource_name = "efefef" script = ExtResource( 2 ) rect = Rect2( 107, 271, 100, 49 ) locked = false zones = [ ] [sub_resource type="Resource" id=3] +resource_name = "grgrg" script = ExtResource( 2 ) rect = Rect2( 498, 185, 100, 100 ) locked = false zones = [ ] [sub_resource type="Resource" id=4] +resource_name = "qwdasd" script = ExtResource( 2 ) rect = Rect2( 522, 29, 63, 54 ) locked = false zones = [ ] +[sub_resource type="Resource" id=5] +resource_name = "qwe" +script = ExtResource( 2 ) +rect = Rect2( 473, 331, 100, 100 ) +locked = false +zones = [ ] + +[sub_resource type="Resource" id=6] +resource_name = "asdasdq" +script = ExtResource( 2 ) +rect = Rect2( 304, 280, 100, 100 ) +locked = false +zones = [ ] + +[sub_resource type="Resource" id=7] +resource_name = "343" +script = ExtResource( 2 ) +rect = Rect2( 14, 134, 100, 100 ) +locked = false +zones = [ ] + [resource] resource_name = "asdasdss" script = ExtResource( 1 ) rect = Rect2( 0, 0, 1000, 1000 ) locked = false -continents = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ) ] +continents = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ), SubResource( 7 ) ] diff --git a/game/addons/world_generator/ui/DataList.gd b/game/addons/world_generator/ui/DataList.gd index 68c100e0..2bc00533 100644 --- a/game/addons/world_generator/ui/DataList.gd +++ b/game/addons/world_generator/ui/DataList.gd @@ -3,11 +3,16 @@ extends Tree var edited_resource : WorldGenBaseResource = null -func add_item() -> void: +var name_edited_resource : WorldGenBaseResource = null + +func _init(): + connect("item_activated", self, "on_item_activated") + +func add_item(item_name : String = "") -> void: if !edited_resource: return - edited_resource.add_content() + edited_resource.add_content(item_name) func refresh() -> void: clear() @@ -29,6 +34,7 @@ func refresh() -> void: var item : TreeItem = create_item(root) item.set_text(0, n) + item.set_meta("res", d) func set_edited_resource(res : WorldGenBaseResource)-> void: if edited_resource: @@ -41,5 +47,31 @@ func set_edited_resource(res : WorldGenBaseResource)-> void: refresh() +func add_button_pressed() -> void: + $NameDialog/TextEdit.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 + name_edited_resource = null + + func on_resource_changed() -> void: refresh() + +func on_item_activated() -> void: + var item : TreeItem = get_selected() + + if !item: + return + + name_edited_resource = item.get_meta("res") + + if !name_edited_resource: + return + + $NameDialog/TextEdit.text = name_edited_resource.resource_name + $NameDialog.popup_centered() diff --git a/game/addons/world_generator/ui/DataList.tscn b/game/addons/world_generator/ui/DataList.tscn index 6accb4a5..9b207388 100644 --- a/game/addons/world_generator/ui/DataList.tscn +++ b/game/addons/world_generator/ui/DataList.tscn @@ -12,3 +12,19 @@ script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } + +[node name="NameDialog" type="ConfirmationDialog" parent="."] +margin_right = 200.0 +margin_bottom = 70.0 +window_title = "Name" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="TextEdit" type="TextEdit" parent="NameDialog"] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 192.0 +margin_bottom = 34.0 + +[connection signal="confirmed" from="NameDialog" to="." method="name_dialog_ok_pressed"] diff --git a/game/addons/world_generator/ui/MainScreen.tscn b/game/addons/world_generator/ui/MainScreen.tscn index e11cb64c..2fb6562f 100644 --- a/game/addons/world_generator/ui/MainScreen.tscn +++ b/game/addons/world_generator/ui/MainScreen.tscn @@ -173,4 +173,4 @@ margin_right = 96.0 margin_bottom = 20.0 text = "Delete" -[connection signal="pressed" from="TabContainer/World/VBoxContainer/HBoxContainer/AddButton" to="TabContainer/World/VBoxContainer/DataList" method="add_item"] +[connection signal="pressed" from="TabContainer/World/VBoxContainer/HBoxContainer/AddButton" to="TabContainer/World/VBoxContainer/DataList" method="add_button_pressed"]