2021-12-22 16:15:39 +01:00
|
|
|
tool
|
|
|
|
extends Control
|
|
|
|
|
2021-12-23 17:45:36 +01:00
|
|
|
var rect_editor_node_scene : PackedScene = preload("res://addons/world_generator/ui/RectViewNode.tscn")
|
2021-12-22 16:15:39 +01:00
|
|
|
|
2021-12-23 18:08:13 +01:00
|
|
|
export(NodePath) var zoom_widget_path : NodePath = ""
|
|
|
|
|
2021-12-23 16:46:54 +01:00
|
|
|
var edited_resource : WorldGenBaseResource = null
|
2021-12-22 16:15:39 +01:00
|
|
|
|
2021-12-23 18:08:13 +01:00
|
|
|
func _enter_tree():
|
|
|
|
var zoom_widget : Node = get_node_or_null(zoom_widget_path)
|
|
|
|
|
|
|
|
if !zoom_widget:
|
|
|
|
return
|
|
|
|
|
|
|
|
zoom_widget.connect("zoom_changed", self, "on_zoom_changed")
|
|
|
|
|
|
|
|
func on_zoom_changed(zoom : float) -> void:
|
|
|
|
rect_scale = Vector2(zoom, zoom)
|
|
|
|
|
2021-12-23 16:46:54 +01:00
|
|
|
func _draw():
|
|
|
|
draw_rect(Rect2(Vector2(), get_size()), Color(0.2, 0.2, 0.2, 1))
|
|
|
|
|
|
|
|
func refresh() -> void:
|
|
|
|
clear()
|
|
|
|
|
|
|
|
if !edited_resource:
|
|
|
|
return
|
|
|
|
|
|
|
|
var rect : Rect2 = edited_resource.rect
|
|
|
|
|
|
|
|
set_custom_minimum_size(rect.size)
|
|
|
|
|
|
|
|
var p : MarginContainer = get_parent() as MarginContainer
|
2021-12-22 16:15:39 +01:00
|
|
|
|
2021-12-23 16:46:54 +01:00
|
|
|
p.add_constant_override("margin_left", rect.size.x / 4.0)
|
|
|
|
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)
|
2021-12-23 17:45:36 +01:00
|
|
|
|
|
|
|
refresh_rects()
|
|
|
|
|
2021-12-23 16:46:54 +01:00
|
|
|
func clear() -> void:
|
|
|
|
pass
|
|
|
|
|
2021-12-23 17:45:36 +01:00
|
|
|
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)
|
|
|
|
|
2021-12-23 16:46:54 +01:00
|
|
|
func set_edited_resource(res : WorldGenBaseResource):
|
2021-12-23 17:45:36 +01:00
|
|
|
# if edited_resource:
|
|
|
|
# edited_resource.disconnect("changed", self, "on_edited_resource_changed")
|
2021-12-23 16:46:54 +01:00
|
|
|
|
|
|
|
edited_resource = res
|
|
|
|
|
|
|
|
refresh()
|
|
|
|
|
2021-12-23 17:45:36 +01:00
|
|
|
# if edited_resource:
|
|
|
|
# edited_resource.connect("changed", self, "on_edited_resource_changed")
|
2021-12-22 16:15:39 +01:00
|
|
|
|
2021-12-23 17:45:36 +01:00
|
|
|
#func on_edited_resource_changed() -> void:
|
|
|
|
# pass
|