Initial cleanups and setup for the uv editor.

This commit is contained in:
Relintai 2022-01-20 17:21:50 +01:00
parent 1629224aeb
commit 34b6877afc
5 changed files with 51 additions and 39 deletions

View File

@ -4,19 +4,28 @@ extends Control
var plugin : EditorPlugin var plugin : EditorPlugin
export var uv_preview_path : NodePath export var uv_preview_path : NodePath
export var uv_editor_path : NodePath
var uv_preview : Node var uv_preview : Node
var uv_editor : Node
func _enter_tree(): func _enter_tree():
uv_preview = get_node(uv_preview_path) uv_preview = get_node(uv_preview_path)
uv_editor = get_node(uv_editor_path)
func set_mesh_data_resource(a : MeshDataResource) -> void: func set_mesh_data_resource(a : MeshDataResource) -> void:
if uv_preview: if uv_preview:
uv_preview.set_mesh_data_resource(a) uv_preview.set_mesh_data_resource(a)
if uv_editor:
uv_editor.set_mesh_data_resource(a)
func set_mesh_data_instance(a : MeshDataInstance) -> void: func set_mesh_data_instance(a : MeshDataInstance) -> void:
if uv_preview: if uv_preview:
uv_preview.set_mesh_data_instance(a) uv_preview.set_mesh_data_instance(a)
if uv_editor:
uv_editor.set_mesh_data_instance(a)
func _unhandled_key_input(event : InputEventKey) -> void: func _unhandled_key_input(event : InputEventKey) -> void:
if event.echo: if event.echo:

View File

@ -14,6 +14,7 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
uv_preview_path = NodePath("VBoxContainer/ScrollContainer/VBoxContainer2/Operations/Operations/UVDisplay") uv_preview_path = NodePath("VBoxContainer/ScrollContainer/VBoxContainer2/Operations/Operations/UVDisplay")
uv_editor_path = NodePath("Popups/UVEditorPopup/UVEditor")
[node name="VBoxContainer" type="VBoxContainer" parent="."] [node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 7.0 margin_left = 7.0
@ -520,17 +521,17 @@ margin_bottom = 593.0
mouse_filter = 2 mouse_filter = 2
[node name="UVEditorPopup" type="ConfirmationDialog" parent="Popups"] [node name="UVEditorPopup" type="ConfirmationDialog" parent="Popups"]
margin_left = 245.0 margin_left = 149.0
margin_top = 92.0 margin_top = 35.0
margin_right = 753.0 margin_right = 901.0
margin_bottom = 476.0 margin_bottom = 803.0
window_title = "UV Editor" window_title = "UV Editor"
resizable = true resizable = true
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="RectEditor" parent="Popups/UVEditorPopup" instance=ExtResource( 4 )] [node name="UVEditor" parent="Popups/UVEditorPopup" instance=ExtResource( 4 )]
margin_left = 8.0 margin_left = 8.0
margin_top = 8.0 margin_top = 8.0
margin_right = -8.0 margin_right = -8.0

View File

@ -5,5 +5,8 @@ func _init():
# Control/EditorZoomWidget # Control/EditorZoomWidget
pass pass
func set_edited_resource(res : WorldGenBaseResource): func set_mesh_data_resource(a : MeshDataResource) -> void:
$ScrollContainer/MarginContainer/RectView.set_edited_resource(res) $ScrollContainer/MarginContainer/RectView.set_mesh_data_resource(a)
func set_mesh_data_instance(a : MeshDataInstance) -> void:
$ScrollContainer/MarginContainer/RectView.set_mesh_data_instance(a)

View File

@ -1,13 +1,16 @@
tool tool
extends Control extends Control
var rect_editor_node_scene : PackedScene = preload("res://addons/world_generator/ui/RectViewNode.tscn") var rect_editor_node_scene : PackedScene = preload("res://addons/mesh_data_resource_editor/uv_editor/RectViewNode.tscn")
export(NodePath) var zoom_widget_path : NodePath = "" export(NodePath) var zoom_widget_path : NodePath = ""
var _rect_scale : float = 1 var _rect_scale : float = 1
var edited_resource : WorldGenBaseResource = null var _mdr : MeshDataResource = null
var _background_texture : Texture = null
var base_rect : Rect2 = Rect2(0, 0, 600, 600)
var edited_resource_current_size : Vector2 = Vector2() var edited_resource_current_size : Vector2 = Vector2()
func _enter_tree(): func _enter_tree():
@ -23,13 +26,11 @@ func _enter_tree():
connect("visibility_changed", self, "on_visibility_changed") connect("visibility_changed", self, "on_visibility_changed")
func on_visibility_changed() -> void: func on_visibility_changed() -> void:
call_deferred("apply_zoom") if is_visible_in_tree():
call_deferred("refresh")
func apply_zoom() -> void: func apply_zoom() -> void:
if !edited_resource: var rect : Rect2 = base_rect
return
var rect : Rect2 = edited_resource.rect
edited_resource_current_size = rect.size edited_resource_current_size = rect.size
rect.position = rect.position * _rect_scale rect.position = rect.position * _rect_scale
rect.size = rect.size * _rect_scale rect.size = rect.size * _rect_scale
@ -52,13 +53,13 @@ func on_zoom_changed(zoom : float) -> void:
func _draw(): func _draw():
draw_rect(Rect2(Vector2(), get_size()), Color(0.2, 0.2, 0.2, 1)) draw_rect(Rect2(Vector2(), get_size()), Color(0.2, 0.2, 0.2, 1))
if _background_texture:
draw_texture_rect_region(_background_texture, Rect2(Vector2(), get_size()), Rect2(Vector2(), _background_texture.get_size()))
func refresh() -> void: func refresh() -> void:
clear() clear()
if !edited_resource: var rect : Rect2 = base_rect
return
var rect : Rect2 = edited_resource.rect
edited_resource_current_size = rect.size edited_resource_current_size = rect.size
rect.position = rect.position * _rect_scale rect.position = rect.position * _rect_scale
rect.size = rect.size * _rect_scale rect.size = rect.size * _rect_scale
@ -74,35 +75,33 @@ func clear() -> void:
func refresh_rects() -> void: func refresh_rects() -> void:
clear_rects() clear_rects()
if !edited_resource: if !_mdr:
return return
var cont : Array = edited_resource.get_content() # var cont : Array = edited_resource.get_content()
#
for c in cont: # for c in cont:
if c: # if c:
var s : Node = rect_editor_node_scene.instance() # var s : Node = rect_editor_node_scene.instance()
#
add_child(s) # add_child(s)
s.set_editor_rect_scale(_rect_scale) # s.set_editor_rect_scale(_rect_scale)
s.edited_resource_parent_size = edited_resource_current_size # s.edited_resource_parent_size = edited_resource_current_size
s.set_edited_resource(c) # s.set_edited_resource(c)
func clear_rects(): func clear_rects():
for c in get_children(): for c in get_children():
c.queue_free() c.queue_free()
remove_child(c) remove_child(c)
func set_edited_resource(res : WorldGenBaseResource): func set_mesh_data_resource(a : MeshDataResource) -> void:
if edited_resource: _mdr = a
edited_resource.disconnect("changed", self, "on_edited_resource_changed")
func set_mesh_data_instance(a : MeshDataInstance) -> void:
_background_texture = null
edited_resource = res if a:
_background_texture = a.texture
refresh()
if edited_resource:
edited_resource.connect("changed", self, "on_edited_resource_changed")
func on_edited_resource_changed() -> void: func on_edited_resource_changed() -> void:
call_deferred("refresh") call_deferred("refresh")

View File

@ -4,7 +4,7 @@
[ext_resource path="res://addons/mesh_data_resource_editor/widgets/EditorZoomWidget.tscn" type="PackedScene" id=2] [ext_resource path="res://addons/mesh_data_resource_editor/widgets/EditorZoomWidget.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/mesh_data_resource_editor/uv_editor/RectView.gd" type="Script" id=3] [ext_resource path="res://addons/mesh_data_resource_editor/uv_editor/RectView.gd" type="Script" id=3]
[node name="RectEditor" type="PanelContainer"] [node name="UVEditor" type="PanelContainer"]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
script = ExtResource( 1 ) script = ExtResource( 1 )