From 816812ee6cb84f9c899e1c6de52f9a4c9e7d2c0c Mon Sep 17 00:00:00 2001 From: jsjtxietian Date: Wed, 6 Mar 2024 17:51:14 +0800 Subject: [PATCH] Disable lock and group buttons when selected item can't be locked or grouped --- editor/plugins/canvas_item_editor_plugin.cpp | 14 ++++++++-- editor/plugins/node_3d_editor_plugin.cpp | 27 +++++++++++++------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 894eef74ec0..41e5eee486e 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -2643,6 +2643,7 @@ void CanvasItemEditor::_update_cursor() { void CanvasItemEditor::_update_lock_and_group_button() { bool all_locked = true; bool all_group = true; + bool has_canvas_item = false; List selection = editor_selection->get_selected_node_list(); if (selection.is_empty()) { all_locked = false; @@ -2657,6 +2658,7 @@ void CanvasItemEditor::_update_lock_and_group_button() { if (all_group && !item->has_meta("_edit_group_")) { all_group = false; } + has_canvas_item = true; } if (!all_locked && !all_group) { break; @@ -2664,12 +2666,17 @@ void CanvasItemEditor::_update_lock_and_group_button() { } } + all_locked = all_locked && has_canvas_item; + all_group = all_group && has_canvas_item; + lock_button->set_visible(!all_locked); - lock_button->set_disabled(selection.is_empty()); + lock_button->set_disabled(!has_canvas_item); unlock_button->set_visible(all_locked); + unlock_button->set_disabled(!has_canvas_item); group_button->set_visible(!all_group); - group_button->set_disabled(selection.is_empty()); + group_button->set_disabled(!has_canvas_item); ungroup_button->set_visible(all_group); + ungroup_button->set_disabled(!has_canvas_item); } Control::CursorShape CanvasItemEditor::get_cursor_shape(const Point2 &p_pos) const { @@ -4011,6 +4018,9 @@ void CanvasItemEditor::_notification(int p_what) { AnimationPlayerEditor::get_singleton()->connect("animation_selected", callable_mp(this, &CanvasItemEditor::_keying_changed).unbind(1)); _keying_changed(); _update_editor_settings(); + + connect("item_lock_status_changed", callable_mp(this, &CanvasItemEditor::_update_lock_and_group_button)); + connect("item_group_status_changed", callable_mp(this, &CanvasItemEditor::_update_lock_and_group_button)); } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index f38d42f6812..7a4a7ddaecb 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -7376,6 +7376,7 @@ void Node3DEditor::_selection_changed() { void Node3DEditor::_refresh_menu_icons() { bool all_locked = true; bool all_grouped = true; + bool has_node3d_item = false; List &selection = editor_selection->get_selected_node_list(); @@ -7384,26 +7385,34 @@ void Node3DEditor::_refresh_menu_icons() { all_grouped = false; } else { for (Node *E : selection) { - if (Object::cast_to(E) && !Object::cast_to(E)->has_meta("_edit_lock_")) { - all_locked = false; - break; + Node3D *node = Object::cast_to(E); + if (node) { + if (all_locked && !node->has_meta("_edit_lock_")) { + all_locked = false; + } + if (all_grouped && !node->has_meta("_edit_group_")) { + all_grouped = false; + } + has_node3d_item = true; } - } - for (Node *E : selection) { - if (Object::cast_to(E) && !Object::cast_to(E)->has_meta("_edit_group_")) { - all_grouped = false; + if (!all_locked && !all_grouped) { break; } } } + all_locked = all_locked && has_node3d_item; + all_grouped = all_grouped && has_node3d_item; + tool_button[TOOL_LOCK_SELECTED]->set_visible(!all_locked); - tool_button[TOOL_LOCK_SELECTED]->set_disabled(selection.is_empty()); + tool_button[TOOL_LOCK_SELECTED]->set_disabled(!has_node3d_item); tool_button[TOOL_UNLOCK_SELECTED]->set_visible(all_locked); + tool_button[TOOL_UNLOCK_SELECTED]->set_disabled(!has_node3d_item); tool_button[TOOL_GROUP_SELECTED]->set_visible(!all_grouped); - tool_button[TOOL_GROUP_SELECTED]->set_disabled(selection.is_empty()); + tool_button[TOOL_GROUP_SELECTED]->set_disabled(!has_node3d_item); tool_button[TOOL_UNGROUP_SELECTED]->set_visible(all_grouped); + tool_button[TOOL_UNGROUP_SELECTED]->set_disabled(!has_node3d_item); } template