From 720deca86ce63255425f47a34b3443b49b351a8e Mon Sep 17 00:00:00 2001 From: SaracenOne Date: Sat, 23 Apr 2022 13:32:55 +0100 Subject: [PATCH] Fix message case, drag callback, and variable init in 3d material drag and drop --- editor/plugins/node_3d_editor_plugin.cpp | 21 ++++++++++----------- editor/plugins/node_3d_editor_plugin.h | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index ba22157012bb..72843cbeaa63 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -1822,11 +1822,6 @@ void Node3DEditorViewport::_sinput(const Ref &p_event) { default: { } } - - // Clear preview material when dropped outside applicable object - if (spatial_editor->get_preview_material().is_valid() && !is_drag_successful()) { - _remove_preview_material(); - } } Ref magnify_gesture = p_event; @@ -2692,6 +2687,13 @@ void Node3DEditorViewport::_notification(int p_what) { cinema_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); locked_label->add_theme_style_override("normal", gui_base->get_theme_stylebox(SNAME("Information3dViewport"), SNAME("EditorStyles"))); } break; + + case NOTIFICATION_DRAG_END: { + // Clear preview material when dropped outside applicable object. + if (spatial_editor->get_preview_material().is_valid() && !is_drag_successful()) { + _remove_preview_material(); + } + } break; } } @@ -3891,7 +3893,7 @@ void Node3DEditorViewport::_reset_preview_material() const { MeshInstance3D *mesh_instance = Object::cast_to(last_target_inst); GeometryInstance3D *geometry_instance = Object::cast_to(last_target_inst); - if (spatial_editor->get_preview_material_surface() != -1 && mesh_instance) { + if (mesh_instance && spatial_editor->get_preview_material_surface() != -1) { mesh_instance->set_surface_override_material(spatial_editor->get_preview_material_surface(), spatial_editor->get_preview_reset_material()); spatial_editor->set_preview_material_surface(-1); } else if (geometry_instance) { @@ -4011,12 +4013,12 @@ void Node3DEditorViewport::_perform_drop_data() { GeometryInstance3D *geometry_instance = Object::cast_to(ObjectDB::get_instance(spatial_editor->get_preview_material_target())); MeshInstance3D *mesh_instance = Object::cast_to(ObjectDB::get_instance(spatial_editor->get_preview_material_target())); if (mesh_instance && spatial_editor->get_preview_material_surface() != -1) { - editor_data->get_undo_redo().create_action(vformat(TTR("Set surface %d override material"), spatial_editor->get_preview_material_surface())); + editor_data->get_undo_redo().create_action(vformat(TTR("Set Surface %d Override Material"), spatial_editor->get_preview_material_surface())); editor_data->get_undo_redo().add_do_method(geometry_instance, "set_surface_override_material", spatial_editor->get_preview_material_surface(), spatial_editor->get_preview_material()); editor_data->get_undo_redo().add_undo_method(geometry_instance, "set_surface_override_material", spatial_editor->get_preview_material_surface(), spatial_editor->get_preview_reset_material()); editor_data->get_undo_redo().commit_action(); } else if (geometry_instance) { - editor_data->get_undo_redo().create_action(TTR("Set material override")); + editor_data->get_undo_redo().create_action(TTR("Set Material Override")); editor_data->get_undo_redo().add_do_method(geometry_instance, "set_material_override", spatial_editor->get_preview_material()); editor_data->get_undo_redo().add_undo_method(geometry_instance, "set_material_override", spatial_editor->get_preview_reset_material()); editor_data->get_undo_redo().commit_action(); @@ -7837,9 +7839,6 @@ Node3DEditor::Node3DEditor() { // Drag and drop support; preview_node = memnew(Node3D); preview_bounds = AABB(); - preview_material = Ref(); - preview_reset_material = Ref(); - preview_material_target = ObjectID(); ED_SHORTCUT("spatial_editor/bottom_view", TTR("Bottom View"), KeyModifierMask::ALT + Key::KP_7); ED_SHORTCUT("spatial_editor/top_view", TTR("Top View"), Key::KP_7); diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index b3a6167ebc54..facdd23e15b1 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -601,7 +601,7 @@ class Node3DEditor : public VBoxContainer { Ref preview_material; Ref preview_reset_material; ObjectID preview_material_target; - int preview_material_surface; + int preview_material_surface = -1; struct Gizmo { bool visible = false;