Implemented editing the names of resources in the DataList widget.

This commit is contained in:
Relintai 2021-12-25 02:15:17 +01:00
parent 4cc9baf23b
commit 87e4318e06
8 changed files with 92 additions and 11 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -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 ) ]

View File

@ -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()

View File

@ -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"]

View File

@ -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"]