Implement basic data list node. Also fix error spam.

This commit is contained in:
Relintai 2021-12-22 16:52:06 +01:00
parent afc929350b
commit 3f7f5c0e07
9 changed files with 101 additions and 7 deletions

View File

@ -10,5 +10,9 @@ func get_content() -> Array:
func set_content(arr : Array) -> void:
zones = arr
func add_content() -> void:
zones.append(Zone.new())
emit_changed()
func setup_property_inspector(inspector) -> void:
.setup_property_inspector(inspector)

View File

@ -9,6 +9,9 @@ func get_content() -> Array:
func set_content(arr : Array) -> void:
pass
func add_content() -> void:
pass
func setup_property_inspector(inspector) -> void:
inspector.add_slot_line_edit("get_name", "set_name", "Name")

View File

@ -10,6 +10,10 @@ func get_content() -> Array:
func set_content(arr : Array) -> void:
continents = arr
func add_content() -> void:
continents.append(Continent.new())
emit_changed()
func setup_property_inspector(inspector) -> void:
.setup_property_inspector(inspector)

View File

@ -10,5 +10,9 @@ func get_content() -> Array:
func set_content(arr : Array) -> void:
subzones = arr
func add_content() -> void:
subzones.append(SubZone.new())
emit_changed()
func setup_property_inspector(inspector) -> void:
.setup_property_inspector(inspector)

View File

@ -1,9 +1,30 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=7 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]
script = ExtResource( 2 )
rect = Rect2( 0, 0, 1, 1 )
zones = [ ]
[sub_resource type="Resource" id=2]
script = ExtResource( 2 )
rect = Rect2( 0, 0, 1, 1 )
zones = [ ]
[sub_resource type="Resource" id=3]
script = ExtResource( 2 )
rect = Rect2( 0, 0, 1, 1 )
zones = [ ]
[sub_resource type="Resource" id=4]
script = ExtResource( 2 )
rect = Rect2( 0, 0, 1, 1 )
zones = [ ]
[resource]
resource_name = "asdasdss"
script = ExtResource( 1 )
rect = Rect2( 0, 0, 1, 1 )
continents = [ ]
continents = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ) ]

View File

@ -1,3 +1,45 @@
tool
extends Tree
var edited_resource : WorldGenBaseResource = null
func add_item() -> void:
if !edited_resource:
return
edited_resource.add_content()
func refresh() -> void:
clear()
if !edited_resource:
return
var root : TreeItem = create_item()
var data : Array = edited_resource.get_content()
for d in data:
if d:
var n : String = d.resource_name
if n == "":
n = "<no name>"
var item : TreeItem = create_item(root)
item.set_text(0, n)
func set_edited_resource(res : WorldGenBaseResource)-> void:
if edited_resource:
edited_resource.disconnect("changed", self, "on_resource_changed")
edited_resource = res
if edited_resource:
edited_resource.connect("changed", self, "on_resource_changed")
refresh()
func on_resource_changed() -> void:
refresh()

View File

@ -5,6 +5,7 @@ var edited_world
func refresh() -> void:
$TabContainer/World/HSplitContainer/ResourcePropertyList.edit_resource(edited_world)
$TabContainer/World/VBoxContainer/DataList.set_edited_resource(edited_world)
func set_wgworld(wgw : WorldGenWorld) -> void:
edited_world = wgw

View File

@ -56,9 +56,17 @@ margin_left = 829.0
margin_right = 1002.0
margin_bottom = 550.0
[node name="HBoxContainer" type="HBoxContainer" parent="TabContainer/World/VBoxContainer"]
[node name="Label" type="Label" parent="TabContainer/World/VBoxContainer"]
margin_right = 173.0
margin_bottom = 20.0
margin_bottom = 14.0
text = "Continents"
align = 1
valign = 1
[node name="HBoxContainer" type="HBoxContainer" parent="TabContainer/World/VBoxContainer"]
margin_top = 18.0
margin_right = 173.0
margin_bottom = 38.0
[node name="AddButton" type="Button" parent="TabContainer/World/VBoxContainer/HBoxContainer"]
margin_right = 37.0
@ -80,7 +88,7 @@ text = "Duplicate"
[node name="DataList" parent="TabContainer/World/VBoxContainer" instance=ExtResource( 3 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 24.0
margin_top = 42.0
margin_right = 173.0
margin_bottom = 550.0
@ -164,3 +172,5 @@ margin_left = 41.0
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"]

View File

@ -239,7 +239,7 @@ func on_slot_line_edit_text_entered(text : String, slot_idx : int) -> void:
func clear() -> void:
properties.clear()
var content_node = $MainContainer/Content
if !content_node:
@ -254,7 +254,9 @@ func refresh() -> void:
if _edited_resource:
_edited_resource.setup_property_inspector(self)
_edited_resource.connect("changed", self, "on_edited_resource_changed")
if !_edited_resource.is_connected("changed", self, "on_edited_resource_changed"):
_edited_resource.connect("changed", self, "on_edited_resource_changed")
func edit_resource(wgw) -> void:
if _edited_resource:
@ -263,3 +265,6 @@ func edit_resource(wgw) -> void:
_edited_resource = wgw
refresh()
func on_edited_resource_changed() -> void:
refresh()