Skip to content

Commit bbeb4a2

Browse files
committed
Merge pull request #119176 from ryevdokimov/lock-transform
Fix 3D transform gizmo visibility after node lock/unlock
2 parents 685c3ee + 363c95c commit bbeb4a2

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

editor/scene/3d/node_3d_editor_plugin.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,17 @@ int Node3DEditorViewport::get_selected_count() const {
599599
return count;
600600
}
601601

602+
bool Node3DEditorViewport::_has_unlocked_selection() const {
603+
const List<Node *> &selection = editor_selection->get_top_selected_node_list();
604+
for (Node *E : selection) {
605+
Node3D *sp = Object::cast_to<Node3D>(E);
606+
if (sp && !_is_node_locked(sp)) {
607+
return true;
608+
}
609+
}
610+
return false;
611+
}
612+
602613
void Node3DEditorViewport::cancel_transform() {
603614
const List<Node *> &selection = editor_selection->get_top_selected_node_list();
604615

@@ -2733,7 +2744,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
27332744
bool is_select_mode = (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_TRANSFORM);
27342745
bool is_clicked_selected = editor_selection->is_selected(ObjectDB::get_instance<Node>(clicked));
27352746

2736-
if (_edit.mode == TRANSFORM_NONE && (is_select_mode || is_clicked_selected)) {
2747+
if (_edit.mode == TRANSFORM_NONE && (is_select_mode || is_clicked_selected) && _has_unlocked_selection()) {
27372748
_compute_edit(_edit.original_mouse_pos);
27382749
clicked = ObjectID();
27392750
_edit.mode = TRANSFORM_TRANSLATE;
@@ -3001,7 +3012,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
30013012
begin_transform(TRANSFORM_SCALE, true);
30023013
}
30033014
}
3004-
if (ED_IS_SHORTCUT("spatial_editor/collision_reposition", event_mod) && editor_selection->get_top_selected_node_list().size() == 1 && !collision_reposition) {
3015+
if (ED_IS_SHORTCUT("spatial_editor/collision_reposition", event_mod) && editor_selection->get_top_selected_node_list().size() == 1 && !collision_reposition && _has_unlocked_selection()) {
30053016
if (_edit.mode == TRANSFORM_NONE || _edit.instant) {
30063017
if (_edit.mode == TRANSFORM_NONE) {
30073018
_compute_edit(_edit.mouse_pos);
@@ -6161,6 +6172,10 @@ void Node3DEditorViewport::begin_transform(TransformMode p_mode, bool instant) {
61616172
}
61626173

61636174
if (get_selected_count() > 0) {
6175+
if (!_has_unlocked_selection()) {
6176+
return;
6177+
}
6178+
61646179
_edit.children_original_globals.clear();
61656180

61666181
_edit.mode = p_mode;
@@ -8249,6 +8264,8 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
82498264

82508265
undo_redo->add_do_method(this, "_refresh_menu_icons");
82518266
undo_redo->add_undo_method(this, "_refresh_menu_icons");
8267+
undo_redo->add_do_method(this, "update_transform_gizmo");
8268+
undo_redo->add_undo_method(this, "update_transform_gizmo");
82528269
undo_redo->commit_action();
82538270
} break;
82548271
case MENU_UNLOCK_SELECTED: {
@@ -8270,6 +8287,8 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
82708287

82718288
undo_redo->add_do_method(this, "_refresh_menu_icons");
82728289
undo_redo->add_undo_method(this, "_refresh_menu_icons");
8290+
undo_redo->add_do_method(this, "update_transform_gizmo");
8291+
undo_redo->add_undo_method(this, "update_transform_gizmo");
82738292
undo_redo->commit_action();
82748293
} break;
82758294
case MENU_GROUP_SELECTED: {

editor/scene/3d/node_3d_editor_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ class Node3DEditorViewport : public Control {
302302

303303
Transform3D _get_camera_transform() const;
304304
int get_selected_count() const;
305+
bool _has_unlocked_selection() const;
305306
void cancel_transform();
306307
void _update_shrink();
307308

editor/scene/scene_tree_editor.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "editor/editor_undo_redo_manager.h"
4646
#include "editor/file_system/editor_file_system.h"
4747
#include "editor/gui/filter_line_edit.h"
48+
#include "editor/scene/3d/node_3d_editor_plugin.h"
4849
#include "editor/scene/canvas_item_editor_plugin.h"
4950
#include "editor/script/script_editor_plugin.h"
5051
#include "editor/settings/editor_settings.h"
@@ -144,8 +145,18 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
144145
undo_redo->add_undo_method(n, "set_meta", "_edit_lock_", true);
145146
undo_redo->add_do_method(this, "emit_signal", "node_changed");
146147
undo_redo->add_undo_method(this, "emit_signal", "node_changed");
147-
undo_redo->add_do_method(CanvasItemEditor::get_singleton(), "emit_signal", "item_lock_status_changed");
148-
undo_redo->add_undo_method(CanvasItemEditor::get_singleton(), "emit_signal", "item_lock_status_changed");
148+
if (Object::cast_to<CanvasItem>(n)) {
149+
undo_redo->add_do_method(CanvasItemEditor::get_singleton(), "emit_signal", "item_lock_status_changed");
150+
undo_redo->add_undo_method(CanvasItemEditor::get_singleton(), "emit_signal", "item_lock_status_changed");
151+
} else if (Object::cast_to<Node3D>(n)) {
152+
Node3DEditor *node_3d_editor = Node3DEditor::get_singleton();
153+
undo_redo->add_do_method(node_3d_editor, "emit_signal", "item_lock_status_changed");
154+
undo_redo->add_undo_method(node_3d_editor, "emit_signal", "item_lock_status_changed");
155+
undo_redo->add_do_method(node_3d_editor, "_refresh_menu_icons");
156+
undo_redo->add_undo_method(node_3d_editor, "_refresh_menu_icons");
157+
undo_redo->add_do_method(node_3d_editor, "update_transform_gizmo");
158+
undo_redo->add_undo_method(node_3d_editor, "update_transform_gizmo");
159+
}
149160
undo_redo->commit_action();
150161
} else if (p_id == BUTTON_PIN) {
151162
if (n->is_class("AnimationMixer")) {

0 commit comments

Comments
 (0)