Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable lock and group buttons when selected item is not CanvasItem #88997

Merged
1 commit merged into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node *> selection = editor_selection->get_selected_node_list();
if (selection.is_empty()) {
all_locked = false;
Expand All @@ -2657,19 +2658,25 @@ 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;
}
}
}

all_locked = all_locked && has_canvas_item;
jsjtxietian marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand Down Expand Up @@ -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: {
Expand Down
27 changes: 18 additions & 9 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node *> &selection = editor_selection->get_selected_node_list();

Expand All @@ -7384,26 +7385,34 @@ void Node3DEditor::_refresh_menu_icons() {
all_grouped = false;
} else {
for (Node *E : selection) {
if (Object::cast_to<Node3D>(E) && !Object::cast_to<Node3D>(E)->has_meta("_edit_lock_")) {
all_locked = false;
break;
Node3D *node = Object::cast_to<Node3D>(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<Node3D>(E) && !Object::cast_to<Node3D>(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 <typename T>
Expand Down
Loading