From b04720661921bd17930213832826cf585135fa14 Mon Sep 17 00:00:00 2001 From: jsjtxietian Date: Mon, 4 Mar 2024 15:00:01 +0800 Subject: [PATCH] Update lock and group button state when selection changed --- editor/plugins/canvas_item_editor_plugin.cpp | 62 +++++++++++--------- editor/plugins/canvas_item_editor_plugin.h | 1 + 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 74468575829..f8ce5484b95 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -2640,6 +2640,38 @@ void CanvasItemEditor::_update_cursor() { set_default_cursor_shape(c); } +void CanvasItemEditor::_update_lock_and_group_button() { + bool all_locked = true; + bool all_group = true; + List selection = editor_selection->get_selected_node_list(); + if (selection.is_empty()) { + all_locked = false; + all_group = false; + } else { + for (Node *E : selection) { + CanvasItem *item = Object::cast_to(E); + if (item) { + if (all_locked && !item->has_meta("_edit_lock_")) { + all_locked = false; + } + if (all_group && !item->has_meta("_edit_group_")) { + all_group = false; + } + } + if (!all_locked && !all_group) { + break; + } + } + } + + lock_button->set_visible(!all_locked); + lock_button->set_disabled(selection.is_empty()); + unlock_button->set_visible(all_locked); + group_button->set_visible(!all_group); + group_button->set_disabled(selection.is_empty()); + ungroup_button->set_visible(all_group); +} + Control::CursorShape CanvasItemEditor::get_cursor_shape(const Point2 &p_pos) const { // Compute an eventual rotation of the cursor const CursorShape rotation_array[4] = { CURSOR_HSIZE, CURSOR_BDIAGSIZE, CURSOR_VSIZE, CURSOR_FDIAGSIZE }; @@ -3795,35 +3827,6 @@ void CanvasItemEditor::_draw_viewport() { transform.columns[2] = -view_offset * zoom; EditorNode::get_singleton()->get_scene_root()->set_global_canvas_transform(transform); - // hide/show buttons depending on the selection - bool all_locked = true; - bool all_group = true; - List selection = editor_selection->get_selected_node_list(); - if (selection.is_empty()) { - all_locked = false; - all_group = false; - } else { - for (Node *E : selection) { - if (Object::cast_to(E) && !Object::cast_to(E)->has_meta("_edit_lock_")) { - all_locked = false; - break; - } - } - for (Node *E : selection) { - if (Object::cast_to(E) && !Object::cast_to(E)->has_meta("_edit_group_")) { - all_group = false; - break; - } - } - } - - lock_button->set_visible(!all_locked); - lock_button->set_disabled(selection.is_empty()); - unlock_button->set_visible(all_locked); - group_button->set_visible(!all_group); - group_button->set_disabled(selection.is_empty()); - ungroup_button->set_visible(all_group); - _draw_grid(); _draw_ruler_tool(); _draw_axis(); @@ -4027,6 +4030,7 @@ void CanvasItemEditor::_notification(int p_what) { } void CanvasItemEditor::_selection_changed() { + _update_lock_and_group_button(); if (!selected_from_canvas) { _reset_drag(); } diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 4e160dde473..723dbc7f593 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -477,6 +477,7 @@ private: void _gui_input_viewport(const Ref &p_event); void _update_cursor(); + void _update_lock_and_group_button(); void _selection_changed(); void _focus_selection(int p_op);