From 42918bc5fcaff4dc7fa54d35dd443356252f23a9 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 20 Jan 2022 19:30:58 +0100 Subject: [PATCH] Implemented the ok and cancel buttons for the uv editor. --- .../mesh_data_resource_editor/MDIEd.tscn | 4 +- .../uv_editor/RectEditor.gd | 6 +++ .../uv_editor/RectView.gd | 43 +++++++++++++++++++ .../uv_editor/UVEditor.tscn | 21 ++++----- .../uv_editor/UVEditorPopup.gd | 12 ++++++ 5 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 game/addons/mesh_data_resource_editor/uv_editor/UVEditorPopup.gd diff --git a/game/addons/mesh_data_resource_editor/MDIEd.tscn b/game/addons/mesh_data_resource_editor/MDIEd.tscn index aee8279a..b93b147c 100644 --- a/game/addons/mesh_data_resource_editor/MDIEd.tscn +++ b/game/addons/mesh_data_resource_editor/MDIEd.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://addons/mesh_data_resource_editor/MDIEd.gd" type="Script" id=1] [ext_resource path="res://addons/mesh_data_resource_editor/button_groups/vertex_position_operation_bg.tres" type="ButtonGroup" id=2] [ext_resource path="res://addons/mesh_data_resource_editor/UVEditor.gd" type="Script" id=3] [ext_resource path="res://addons/mesh_data_resource_editor/uv_editor/UVEditor.tscn" type="PackedScene" id=4] [ext_resource path="res://addons/mesh_data_resource_editor/button_groups/edit_mode_button_group.tres" type="ButtonGroup" id=5] +[ext_resource path="res://addons/mesh_data_resource_editor/uv_editor/UVEditorPopup.gd" type="Script" id=6] [node name="MDIEd" type="PanelContainer"] anchor_right = 1.0 @@ -527,6 +528,7 @@ margin_right = 901.0 margin_bottom = 803.0 window_title = "UV Editor" resizable = true +script = ExtResource( 6 ) __meta__ = { "_edit_use_anchors_": false } diff --git a/game/addons/mesh_data_resource_editor/uv_editor/RectEditor.gd b/game/addons/mesh_data_resource_editor/uv_editor/RectEditor.gd index 48c6fc34..8226092f 100644 --- a/game/addons/mesh_data_resource_editor/uv_editor/RectEditor.gd +++ b/game/addons/mesh_data_resource_editor/uv_editor/RectEditor.gd @@ -10,3 +10,9 @@ func set_mesh_data_resource(a : MeshDataResource) -> void: func set_mesh_data_instance(a : MeshDataInstance) -> void: $ScrollContainer/MarginContainer/RectView.set_mesh_data_instance(a) + +func ok_pressed() -> void: + $ScrollContainer/MarginContainer/RectView.ok_pressed() + +func cancel_pressed() -> void: + $ScrollContainer/MarginContainer/RectView.cancel_pressed() diff --git a/game/addons/mesh_data_resource_editor/uv_editor/RectView.gd b/game/addons/mesh_data_resource_editor/uv_editor/RectView.gd index f5902774..91d90eb4 100644 --- a/game/addons/mesh_data_resource_editor/uv_editor/RectView.gd +++ b/game/addons/mesh_data_resource_editor/uv_editor/RectView.gd @@ -15,6 +15,8 @@ var _background_texture : Texture = null var base_rect : Rect2 = Rect2(0, 0, 600, 600) var edited_resource_current_size : Vector2 = Vector2() +var _stored_uvs : PoolVector2Array = PoolVector2Array() + func _enter_tree(): var zoom_widget : Node = get_node_or_null(zoom_widget_path) @@ -29,6 +31,7 @@ func _enter_tree(): func on_visibility_changed() -> void: if is_visible_in_tree(): + store_uvs() call_deferred("refresh") func apply_zoom() -> void: @@ -106,3 +109,43 @@ func set_mesh_data_instance(a : MeshDataInstance) -> void: func on_edited_resource_changed() -> void: call_deferred("refresh") + +func store_uvs() -> void: + _stored_uvs.resize(0) + + if !_mdr: + return + + var arrays : Array = _mdr.get_array() + + if arrays.size() != ArrayMesh.ARRAY_MAX: + return + + if arrays[ArrayMesh.ARRAY_TEX_UV] == null: + return + + # Make sure it gets copied + _stored_uvs.append_array(arrays[ArrayMesh.ARRAY_TEX_UV]) + + +func ok_pressed() -> void: + #todo undo redo + pass + +func cancel_pressed() -> void: + if !_mdr: + return + + var arrays : Array = _mdr.get_array() + + if arrays.size() != ArrayMesh.ARRAY_MAX: + return + + # Make sure it gets copied + var uvs : PoolVector2Array = PoolVector2Array() + uvs.append_array(_stored_uvs) + arrays[ArrayMesh.ARRAY_TEX_UV] = uvs + + _mdr.array = arrays + + _stored_uvs.resize(0) diff --git a/game/addons/mesh_data_resource_editor/uv_editor/UVEditor.tscn b/game/addons/mesh_data_resource_editor/uv_editor/UVEditor.tscn index 10a8d1c7..72b861fe 100644 --- a/game/addons/mesh_data_resource_editor/uv_editor/UVEditor.tscn +++ b/game/addons/mesh_data_resource_editor/uv_editor/UVEditor.tscn @@ -19,18 +19,19 @@ margin_right = 1017.0 margin_bottom = 593.0 [node name="MarginContainer" type="MarginContainer" parent="ScrollContainer"] -margin_right = 400.0 -margin_bottom = 400.0 -custom_constants/margin_right = 200 -custom_constants/margin_top = 200 -custom_constants/margin_left = 200 -custom_constants/margin_bottom = 200 +margin_right = 700.0 +margin_bottom = 700.0 +custom_constants/margin_right = 50 +custom_constants/margin_top = 50 +custom_constants/margin_left = 50 +custom_constants/margin_bottom = 50 [node name="RectView" type="Control" parent="ScrollContainer/MarginContainer"] -margin_left = 200.0 -margin_top = 200.0 -margin_right = 200.0 -margin_bottom = 200.0 +margin_left = 50.0 +margin_top = 50.0 +margin_right = 650.0 +margin_bottom = 650.0 +rect_min_size = Vector2( 600, 600 ) script = ExtResource( 3 ) zoom_widget_path = NodePath("../../../Control/EditorZoomWidget") diff --git a/game/addons/mesh_data_resource_editor/uv_editor/UVEditorPopup.gd b/game/addons/mesh_data_resource_editor/uv_editor/UVEditorPopup.gd new file mode 100644 index 00000000..8b0d529c --- /dev/null +++ b/game/addons/mesh_data_resource_editor/uv_editor/UVEditorPopup.gd @@ -0,0 +1,12 @@ +tool +extends ConfirmationDialog + +func _enter_tree(): + connect("confirmed", self, "on_ok_pressed") + get_cancel().connect("pressed", self, "on_cancel_pressed") + +func on_ok_pressed() -> void: + $UVEditor.ok_pressed() + +func on_cancel_pressed() -> void: + $UVEditor.cancel_pressed()