diff --git a/game/addons/world_generator/test/test_world.tres b/game/addons/world_generator/test/test_world.tres index dda51a40..86181704 100644 --- a/game/addons/world_generator/test/test_world.tres +++ b/game/addons/world_generator/test/test_world.tres @@ -5,7 +5,7 @@ [sub_resource type="Resource" id=1] script = ExtResource( 2 ) -rect = Rect2( 0, 0, 1, 1 ) +rect = Rect2( 0, 0, 100, 100 ) zones = [ ] [sub_resource type="Resource" id=2] diff --git a/game/addons/world_generator/ui/RectEditor.tscn b/game/addons/world_generator/ui/RectEditor.tscn index 33cdb044..9c15d328 100644 --- a/game/addons/world_generator/ui/RectEditor.tscn +++ b/game/addons/world_generator/ui/RectEditor.tscn @@ -15,8 +15,8 @@ __meta__ = { [node name="ScrollContainer" type="ScrollContainer" parent="."] margin_left = 7.0 margin_top = 7.0 -margin_right = 7.0 -margin_bottom = 7.0 +margin_right = 1017.0 +margin_bottom = 593.0 [node name="MarginContainer" type="MarginContainer" parent="ScrollContainer"] margin_right = 400.0 diff --git a/game/addons/world_generator/ui/RectEditorNode.gd b/game/addons/world_generator/ui/RectEditorNode.gd deleted file mode 100644 index 4793f36e..00000000 --- a/game/addons/world_generator/ui/RectEditorNode.gd +++ /dev/null @@ -1,5 +0,0 @@ -tool -extends MarginContainer - -func _draw(): - draw_rect(Rect2(get_position(), get_size()), Color(1, 1, 1, 1)) diff --git a/game/addons/world_generator/ui/RectEditorNode.tscn b/game/addons/world_generator/ui/RectEditorNode.tscn deleted file mode 100644 index c0e8051d..00000000 --- a/game/addons/world_generator/ui/RectEditorNode.tscn +++ /dev/null @@ -1,11 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://addons/world_generator/ui/RectEditorNode.gd" type="Script" id=1] - -[node name="RectEditorNode" type="MarginContainer"] -anchor_right = 1.0 -anchor_bottom = 1.0 -script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} diff --git a/game/addons/world_generator/ui/RectView.gd b/game/addons/world_generator/ui/RectView.gd index 97f4649f..48825210 100644 --- a/game/addons/world_generator/ui/RectView.gd +++ b/game/addons/world_generator/ui/RectView.gd @@ -1,7 +1,7 @@ tool extends Control -#"res://addons/world_generator/ui/RectEditorNode.tscn" +var rect_editor_node_scene : PackedScene = preload("res://addons/world_generator/ui/RectViewNode.tscn") var edited_resource : WorldGenBaseResource = null @@ -24,21 +24,42 @@ func refresh() -> void: p.add_constant_override("margin_right", rect.size.x / 4.0) p.add_constant_override("margin_top", rect.size.y / 4.0) p.add_constant_override("margin_bottom", rect.size.y / 4.0) - + + refresh_rects() + func clear() -> void: pass +func refresh_rects() -> void: + clear_rects() + + if !edited_resource: + return + + var cont : Array = edited_resource.get_content() + + for c in cont: + if c: + var s : Node = rect_editor_node_scene.instance() + + add_child(s) + s.set_edited_resource(c) + +func clear_rects(): + for c in get_children(): + c.queue_free() + remove_child(c) + func set_edited_resource(res : WorldGenBaseResource): - if edited_resource: - edited_resource.disconnect("changed", self, "on_edited_resource_changed") +# if edited_resource: +# edited_resource.disconnect("changed", self, "on_edited_resource_changed") edited_resource = res refresh() - if edited_resource: - edited_resource.connect("changed", self, "on_edited_resource_changed") +# if edited_resource: +# edited_resource.connect("changed", self, "on_edited_resource_changed") -func on_edited_resource_changed() -> void: - pass - #refresh() +#func on_edited_resource_changed() -> void: +# pass diff --git a/game/addons/world_generator/ui/RectViewNode.gd b/game/addons/world_generator/ui/RectViewNode.gd new file mode 100644 index 00000000..e524fe90 --- /dev/null +++ b/game/addons/world_generator/ui/RectViewNode.gd @@ -0,0 +1,24 @@ +tool +extends MarginContainer + +var edited_resource : WorldGenBaseResource = null + +func _draw(): + draw_rect(Rect2(get_position(), get_size()), Color(1, 1, 1, 1)) + +func refresh() -> void: + if !edited_resource: + return + + var rect : Rect2 = edited_resource.get_rect() + + rect_position = rect.position + rect_size = rect.size + + update() + +func set_edited_resource(res : WorldGenBaseResource): + edited_resource = res + + refresh() + diff --git a/game/addons/world_generator/ui/RectViewNode.tscn b/game/addons/world_generator/ui/RectViewNode.tscn new file mode 100644 index 00000000..a1f7886c --- /dev/null +++ b/game/addons/world_generator/ui/RectViewNode.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/world_generator/ui/RectViewNode.gd" type="Script" id=1] + +[node name="RectViewNode" type="MarginContainer"] +margin_right = 1024.0 +margin_bottom = 600.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +}