summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-07-01 18:28:47 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-07-01 18:28:47 +0200
commit13ea24c5bb6ec221541de6ccf77aa250f55b3d69 (patch)
tree54c9994c8ccea020a3db3231150ff36c64edc403
parentd4fdf16353074e4117383f6fe7af67fd096034d5 (diff)
parent1d69358471f18fb7a073c09bad63f8c50e1f20d5 (diff)
downloadredot-engine-13ea24c5bb6ec221541de6ccf77aa250f55b3d69.tar.gz
Merge pull request #93671 from KoBeWi/burn_the_box
Prevent selecting when a CanvasItem is selected
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp41
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h4
2 files changed, 35 insertions, 10 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 5b4341bbe1..4e2940a8cb 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -780,19 +780,24 @@ bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_po
return still_selected;
}
-List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool retrieve_locked, bool remove_canvas_item_if_parent_in_selection) const {
+List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool p_retrieve_locked, bool p_remove_canvas_item_if_parent_in_selection, bool *r_has_locked_items) const {
List<CanvasItem *> selection;
for (const KeyValue<Node *, Object *> &E : editor_selection->get_selection()) {
CanvasItem *ci = Object::cast_to<CanvasItem>(E.key);
- if (ci && ci->is_visible_in_tree() && ci->get_viewport() == EditorNode::get_singleton()->get_scene_root() && (retrieve_locked || !_is_node_locked(ci))) {
- CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(ci);
- if (se) {
- selection.push_back(ci);
+ if (ci) {
+ if (ci->is_visible_in_tree() && ci->get_viewport() == EditorNode::get_singleton()->get_scene_root() && (p_retrieve_locked || !_is_node_locked(ci))) {
+ CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(ci);
+ if (se) {
+ selection.push_back(ci);
+ }
+ } else if (r_has_locked_items) {
+ // CanvasItem is selected, but can't be interacted with.
+ *r_has_locked_items = true;
}
}
}
- if (remove_canvas_item_if_parent_in_selection) {
+ if (p_remove_canvas_item_if_parent_in_selection) {
List<CanvasItem *> filtered_selection;
for (CanvasItem *E : selection) {
if (!selection.find(E->get_parent())) {
@@ -1454,7 +1459,8 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) {
if (drag_type == DRAG_NONE) {
if (b.is_valid() && b->get_button_index() == MouseButton::LEFT && b->is_pressed()) {
if ((b->is_command_or_control_pressed() && !b->is_alt_pressed() && tool == TOOL_SELECT) || tool == TOOL_ROTATE) {
- List<CanvasItem *> selection = _get_edited_canvas_items();
+ bool has_locked_items = false;
+ List<CanvasItem *> selection = _get_edited_canvas_items(false, true, &has_locked_items);
// Remove not movable nodes
for (CanvasItem *E : selection) {
@@ -1477,6 +1483,11 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) {
}
_save_canvas_item_state(drag_selection);
return true;
+ } else {
+ if (has_locked_items) {
+ EditorToaster::get_singleton()->popup_str(TTR(locked_transform_warning), EditorToaster::SEVERITY_WARNING);
+ }
+ return has_locked_items;
}
}
}
@@ -1917,7 +1928,8 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {
// Drag resize handles
if (drag_type == DRAG_NONE) {
if (b.is_valid() && b->get_button_index() == MouseButton::LEFT && b->is_pressed() && ((b->is_alt_pressed() && b->is_command_or_control_pressed()) || tool == TOOL_SCALE)) {
- List<CanvasItem *> selection = _get_edited_canvas_items();
+ bool has_locked_items = false;
+ List<CanvasItem *> selection = _get_edited_canvas_items(false, true, &has_locked_items);
if (selection.size() == 1) {
CanvasItem *ci = selection.front()->get();
@@ -1946,6 +1958,11 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {
_save_canvas_item_state(drag_selection);
return true;
}
+ } else {
+ if (has_locked_items) {
+ EditorToaster::get_singleton()->popup_str(TTR(locked_transform_warning), EditorToaster::SEVERITY_WARNING);
+ }
+ return has_locked_items;
}
}
}
@@ -2056,7 +2073,8 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) {
//Start moving the nodes
if (b.is_valid() && b->get_button_index() == MouseButton::LEFT && b->is_pressed()) {
if ((b->is_alt_pressed() && !b->is_command_or_control_pressed()) || tool == TOOL_MOVE) {
- List<CanvasItem *> selection = _get_edited_canvas_items();
+ bool has_locked_items = false;
+ List<CanvasItem *> selection = _get_edited_canvas_items(false, true, &has_locked_items);
if (selection.size() > 0) {
drag_selection.clear();
@@ -2089,6 +2107,11 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) {
_save_canvas_item_state(drag_selection);
return true;
+ } else {
+ if (has_locked_items) {
+ EditorToaster::get_singleton()->popup_str(TTR(locked_transform_warning), EditorToaster::SEVERITY_WARNING);
+ }
+ return has_locked_items;
}
}
}
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index a9de5e9a0b..bae9efebc9 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -188,6 +188,8 @@ private:
GRID_VISIBILITY_HIDE,
};
+ const String locked_transform_warning = TTRC("All selected CanvasItems are either invisible or locked in some way and can't be transformed.");
+
bool selection_menu_additive_selection = false;
Tool tool = TOOL_SELECT;
@@ -430,7 +432,7 @@ private:
ThemePreviewMode theme_preview = THEME_PREVIEW_PROJECT;
void _switch_theme_preview(int p_mode);
- List<CanvasItem *> _get_edited_canvas_items(bool retrieve_locked = false, bool remove_canvas_item_if_parent_in_selection = true) const;
+ List<CanvasItem *> _get_edited_canvas_items(bool p_retrieve_locked = false, bool p_remove_canvas_item_if_parent_in_selection = true, bool *r_has_locked_items = nullptr) const;
Rect2 _get_encompassing_rect_from_list(const List<CanvasItem *> &p_list);
void _expand_encompassing_rect_using_children(Rect2 &r_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D(), bool include_locked_nodes = true);
Rect2 _get_encompassing_rect(const Node *p_node);