Also ported the uv rect editor's ui.

This commit is contained in:
Relintai 2022-04-14 00:57:27 +02:00
parent dfa336c427
commit 29972b6f6d
4 changed files with 113 additions and 152 deletions

View File

@ -22,160 +22,114 @@ SOFTWARE.
#include "mdr_uv_rect_editor.h" #include "mdr_uv_rect_editor.h"
#include "editor/editor_plugin.h"
#include "../../mesh_data_resource.h" #include "../../mesh_data_resource.h"
#include "../../nodes/mesh_data_instance.h" #include "../../nodes/mesh_data_instance.h"
#include "../mdi_ed_plugin.h" #include "../mdi_ed_plugin.h"
#include "editor/editor_plugin.h"
#include "editor/editor_zoom_widget.h"
#include "mdr_uv_rect_view.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/scroll_container.h"
#include "scene/gui/separator.h"
#include "scene/gui/spin_box.h"
void MDRUVRectEditor::set_plugin(MDIEdPlugin *plugin) { void MDRUVRectEditor::set_plugin(MDIEdPlugin *plugin) {
//$ScrollContainer/MarginContainer/RectView.set_plugin(plugin) uv_rect_view->set_plugin(plugin);
} }
void MDRUVRectEditor::set_mesh_data_resource(Ref<MeshDataResource> a) { void MDRUVRectEditor::set_mesh_data_resource(Ref<MeshDataResource> a) {
//$ScrollContainer/MarginContainer/RectView.set_mesh_data_resource(a) uv_rect_view->set_mesh_data_resource(a);
} }
void MDRUVRectEditor::set_mesh_data_instance(MeshDataInstance *a) { void MDRUVRectEditor::set_mesh_data_instance(MeshDataInstance *a) {
//$ScrollContainer/MarginContainer/RectView.set_mesh_data_instance(a) uv_rect_view->set_mesh_data_instance(a);
} }
void MDRUVRectEditor::ok_pressed() { void MDRUVRectEditor::ok_pressed() {
//$ScrollContainer/MarginContainer/RectView.ok_pressed() uv_rect_view->ok_pressed();
} }
void MDRUVRectEditor::cancel_pressed() { void MDRUVRectEditor::cancel_pressed() {
//$ScrollContainer/MarginContainer/RectView.cancel_pressed() uv_rect_view->cancel_pressed();
} }
MDRUVRectEditor::MDRUVRectEditor() { MDRUVRectEditor::MDRUVRectEditor() {
/* // -- Main ScrollContainer
ScrollContainer *main_scroll_container = memnew(ScrollContainer);
add_child(main_scroll_container);
[gd_scene load_steps=8 format=2] MarginContainer *main_margin_container = memnew(MarginContainer);
main_margin_container->set_size(Size2(700, 700));
main_scroll_container->add_child(main_margin_container);
[ext_resource path="res://addons/mesh_data_resource_editor/uv_editor/RectEditor.gd" type="Script" id=1] uv_rect_view = memnew(MDRUVRectView);
[ext_resource path="res://addons/mesh_data_resource_editor/widgets/EditorZoomWidget.tscn" type="PackedScene" id=2] main_margin_container->set_custom_minimum_size(Size2(600, 600));
[ext_resource path="res://addons/mesh_data_resource_editor/uv_editor/RectView.gd" type="Script" id=3] main_margin_container->add_child(uv_rect_view);
[ext_resource path="res://addons/mesh_data_resource_editor/icons/icon_v_mirror.png" type="Texture" id=4]
[ext_resource path="res://addons/mesh_data_resource_editor/icons/icon_h_mirror.png" type="Texture" id=5]
[ext_resource path="res://addons/mesh_data_resource_editor/icons/icon_rot_right.png" type="Texture" id=6]
[ext_resource path="res://addons/mesh_data_resource_editor/icons/icon_rot_left.png" type="Texture" id=7]
[node name="UVEditor" type="PanelContainer"] // -- Main Buttons
anchor_right = 1.0 VBoxContainer *main_control_container = memnew(VBoxContainer);
anchor_bottom = 1.0 main_control_container->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
script = ExtResource( 1 ) main_control_container->set_h_size_flags(SIZE_EXPAND_FILL);
__meta__ = { main_control_container->set_v_size_flags(SIZE_EXPAND_FILL);
"_edit_use_anchors_": false add_child(main_control_container);
}
[node name="ScrollContainer" type="ScrollContainer" parent="."] HBoxContainer *control_container = memnew(HBoxContainer);
margin_left = 7.0 control_container->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
margin_top = 7.0 control_container->set_h_size_flags(SIZE_EXPAND_FILL);
margin_right = 1017.0 main_control_container->add_child(control_container);
margin_bottom = 593.0
[node name="MarginContainer" type="MarginContainer" parent="ScrollContainer"] EditorZoomWidget *ezw = memnew(EditorZoomWidget);
margin_right = 700.0 ezw->connect("zoom_changed", uv_rect_view, "on_zoom_changed");
margin_bottom = 700.0 control_container->add_child(ezw);
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"] control_container->add_child(memnew(VSeparator));
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/HBoxContainer/EditorZoomWidget")
mirror_horizontal_button_path = NodePath("../../../Control/HBoxContainer/HorizontalMirror")
mirror_vertical_button_path = NodePath("../../../Control/HBoxContainer/VerticalMirror")
rotate_left_button_path = NodePath("../../../Control/HBoxContainer/RotLeft")
rotate_amount_spinbox_path = NodePath("../../../Control/HBoxContainer/SpinBox")
rotate_right_button_path = NodePath("../../../Control/HBoxContainer/RotRight")
[node name="Control" type="VBoxContainer" parent="."] horizontal_mirror_button = memnew(Button);
margin_left = 7.0 horizontal_mirror_button->set_tooltip("Mirror the selected island horizontally.");
margin_top = 7.0 horizontal_mirror_button->connect("pressed", uv_rect_view, "on_mirror_horizontal_button_pressed");
margin_right = 1017.0 control_container->add_child(horizontal_mirror_button);
margin_bottom = 593.0
mouse_filter = 2
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="HBoxContainer" type="HBoxContainer" parent="Control"] vertical_mirror_button = memnew(Button);
margin_right = 1010.0 vertical_mirror_button->set_tooltip("Mirror the selected island vertically.");
margin_bottom = 24.0 vertical_mirror_button->connect("pressed", uv_rect_view, "on_mirror_vertical_button_pressed");
mouse_filter = 2 control_container->add_child(vertical_mirror_button);
size_flags_horizontal = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="EditorZoomWidget" parent="Control/HBoxContainer" instance=ExtResource( 2 )] control_container->add_child(memnew(VSeparator));
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 115.0
margin_bottom = 24.0
custom_constants/separation = -8
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VSeparator2" type="VSeparator" parent="Control/HBoxContainer"] rotate_left_button = memnew(Button);
margin_left = 119.0 rotate_left_button->set_tooltip("Rotate left.");
margin_right = 123.0 rotate_left_button->connect("pressed", uv_rect_view, "on_rotate_left_button_button_pressed");
margin_bottom = 24.0 control_container->add_child(rotate_left_button);
[node name="HorizontalMirror" type="Button" parent="Control/HBoxContainer"] SpinBox *sb = memnew(SpinBox);
margin_left = 127.0 sb->set_tooltip("Rotate amount in degrees.");
margin_right = 155.0 sb->set_value(45);
margin_bottom = 24.0 sb->set_max(360);
hint_tooltip = "Mirror the selected island horizontally.." sb->set_allow_lesser(true);
icon = ExtResource( 5 ) sb->set_allow_greater(true);
sb->connect("value_changed", uv_rect_view, "on_rotate_amount_spinbox_changed");
control_container->add_child(sb);
[node name="VerticalMirror" type="Button" parent="Control/HBoxContainer"] rotate_right_button = memnew(Button);
margin_left = 159.0 rotate_right_button->set_tooltip("Rotate right.");
margin_right = 187.0 rotate_right_button->connect("pressed", uv_rect_view, "on_rotate_right_button_button_pressed");
margin_bottom = 24.0 control_container->add_child(rotate_right_button);
hint_tooltip = "Mirror the selected island vertically."
icon = ExtResource( 4 )
[node name="VSeparator" type="VSeparator" parent="Control/HBoxContainer"]
margin_left = 191.0
margin_right = 195.0
margin_bottom = 24.0
[node name="RotLeft" type="Button" parent="Control/HBoxContainer"]
margin_left = 199.0
margin_right = 227.0
margin_bottom = 24.0
hint_tooltip = "Rotate left."
icon = ExtResource( 7 )
[node name="SpinBox" type="SpinBox" parent="Control/HBoxContainer"]
margin_left = 231.0
margin_right = 305.0
margin_bottom = 24.0
hint_tooltip = "Rotate amount in degrees."
max_value = 360.0
value = 45.0
allow_greater = true
allow_lesser = true
[node name="RotRight" type="Button" parent="Control/HBoxContainer"]
margin_left = 309.0
margin_right = 337.0
margin_bottom = 24.0
hint_tooltip = "Rotate right."
icon = ExtResource( 6 )
*/
} }
MDRUVRectEditor::~MDRUVRectEditor() { MDRUVRectEditor::~MDRUVRectEditor() {
} }
void MDRUVRectEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
horizontal_mirror_button->set_icon(get_icon("MirrorX", "EditorIcons"));
vertical_mirror_button->set_icon(get_icon("MirrorY", "EditorIcons"));
rotate_left_button->set_icon(get_icon("RotateLeft", "EditorIcons"));
rotate_right_button->set_icon(get_icon("RotateRight", "EditorIcons"));
} break;
}
}
void MDRUVRectEditor::_bind_methods() { void MDRUVRectEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("ok_pressed"), &MDRUVRectEditor::ok_pressed); ClassDB::bind_method(D_METHOD("ok_pressed"), &MDRUVRectEditor::ok_pressed);
ClassDB::bind_method(D_METHOD("cancel_pressed"), &MDRUVRectEditor::cancel_pressed); ClassDB::bind_method(D_METHOD("cancel_pressed"), &MDRUVRectEditor::cancel_pressed);

View File

@ -30,6 +30,8 @@ class EditorPlugin;
class MeshDataResource; class MeshDataResource;
class MeshDataInstance; class MeshDataInstance;
class MDIEdPlugin; class MDIEdPlugin;
class MDRUVRectView;
class Button;
class MDRUVRectEditor : public PanelContainer { class MDRUVRectEditor : public PanelContainer {
GDCLASS(MDRUVRectEditor, PanelContainer); GDCLASS(MDRUVRectEditor, PanelContainer);
@ -44,7 +46,15 @@ public:
MDRUVRectEditor(); MDRUVRectEditor();
~MDRUVRectEditor(); ~MDRUVRectEditor();
MDRUVRectView *uv_rect_view;
Button *horizontal_mirror_button;
Button *vertical_mirror_button;
Button *rotate_left_button;
Button *rotate_right_button;
protected: protected:
void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
}; };

View File

@ -260,6 +260,17 @@ void MDRUVRectView::apply_zoom() {
} }
} }
void MDRUVRectView::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_POSTINITIALIZE: {
connect("visibility_changed", this, "on_visibility_changed");
} break;
case NOTIFICATION_DRAW: {
_draw();
} break;
}
}
MDRUVRectView::MDRUVRectView() { MDRUVRectView::MDRUVRectView() {
_rect_scale = 1; _rect_scale = 1;
@ -271,38 +282,6 @@ MDRUVRectView::MDRUVRectView() {
selected_rect = nullptr; selected_rect = nullptr;
rotation_amount = 45; rotation_amount = 45;
/* var zoom_widget : Node = get_node_or_null(zoom_widget_path)
if zoom_widget && !zoom_widget.is_connected("zoom_changed", self, "on_zoom_changed"):
zoom_widget.connect("zoom_changed", self, "on_zoom_changed")
var mirror_horizontal_button : Button = get_node_or_null(mirror_horizontal_button_path)
if mirror_horizontal_button && !mirror_horizontal_button.is_connected("pressed", self, "on_mirror_horizontal_button_pressed"):
mirror_horizontal_button.connect("pressed", self, "on_mirror_horizontal_button_pressed")
var mirror_vertical_button : Button = get_node_or_null(mirror_vertical_button_path)
if mirror_vertical_button && !mirror_vertical_button.is_connected("pressed", self, "on_mirror_vertical_button_pressed"):
mirror_vertical_button.connect("pressed", self, "on_mirror_vertical_button_pressed")
var rotate_left_button : Button = get_node_or_null(rotate_left_button_path)
if rotate_left_button && !rotate_left_button.is_connected("pressed", self, "on_rotate_left_button_button_pressed"):
rotate_left_button.connect("pressed", self, "on_rotate_left_button_button_pressed")
var rotate_amount_spinbox : SpinBox = get_node_or_null(rotate_amount_spinbox_path)
if rotate_amount_spinbox:
rotation_amount = rotate_amount_spinbox.value
if !rotate_amount_spinbox.is_connected("value_changed", self, "on_rotate_amount_spinbox_changed"):
rotate_amount_spinbox.connect("value_changed", self, "on_rotate_amount_spinbox_changed")
var rotate_right_button : Button = get_node_or_null(rotate_right_button_path)
if rotate_right_button && !rotate_right_button.is_connected("pressed", self, "on_rotate_right_button_button_pressed"):
rotate_right_button.connect("pressed", self, "on_rotate_right_button_button_pressed")
if !is_connected("visibility_changed", self, "on_visibility_changed"):
connect("visibility_changed", self, "on_visibility_changed")
*/
} }
MDRUVRectView::~MDRUVRectView() { MDRUVRectView::~MDRUVRectView() {
@ -310,4 +289,21 @@ MDRUVRectView::~MDRUVRectView() {
void MDRUVRectView::_bind_methods() { void MDRUVRectView::_bind_methods() {
ClassDB::bind_method(D_METHOD("refresh"), &MDRUVRectView::refresh); ClassDB::bind_method(D_METHOD("refresh"), &MDRUVRectView::refresh);
ClassDB::bind_method(D_METHOD("apply_uvs"), &MDRUVRectView::apply_uvs);
ClassDB::bind_method(D_METHOD("on_mirror_horizontal_button_pressed"), &MDRUVRectView::on_mirror_horizontal_button_pressed);
ClassDB::bind_method(D_METHOD("on_mirror_vertical_button_pressed"), &MDRUVRectView::on_mirror_vertical_button_pressed);
ClassDB::bind_method(D_METHOD("on_rotate_left_button_button_pressed"), &MDRUVRectView::on_rotate_left_button_button_pressed);
ClassDB::bind_method(D_METHOD("on_rotate_amount_spinbox_changed"), &MDRUVRectView::on_rotate_amount_spinbox_changed);
ClassDB::bind_method(D_METHOD("on_rotate_right_button_button_pressed"), &MDRUVRectView::on_rotate_right_button_button_pressed);
ClassDB::bind_method(D_METHOD("on_edited_resource_changed"), &MDRUVRectView::on_edited_resource_changed);
ClassDB::bind_method(D_METHOD("on_zoom_changed", "zoom"), &MDRUVRectView::on_zoom_changed);
ClassDB::bind_method(D_METHOD("on_visibility_changed"), &MDRUVRectView::on_visibility_changed);
ClassDB::bind_method(D_METHOD("ok_pressed"), &MDRUVRectView::ok_pressed);
ClassDB::bind_method(D_METHOD("cancel_pressed"), &MDRUVRectView::cancel_pressed);
} }

View File

@ -80,6 +80,7 @@ public:
~MDRUVRectView(); ~MDRUVRectView();
protected: protected:
void _notification(int p_what);
static void _bind_methods(); static void _bind_methods();
EditorZoomWidget *zoom_widget; EditorZoomWidget *zoom_widget;