summaryrefslogtreecommitdiff
path: root/editor/plugins/spatial_editor_plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/spatial_editor_plugin.cpp')
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp94
1 files changed, 91 insertions, 3 deletions
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index ba297539d3..321b136c3b 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -269,11 +269,21 @@ void SpatialEditorViewport::_select_clicked(bool p_append, bool p_single) {
if (!clicked)
return;
- Spatial *sp = Object::cast_to<Spatial>(ObjectDB::get_instance(clicked));
- if (!sp)
+ Node *node = Object::cast_to<Node>(ObjectDB::get_instance(clicked));
+ Spatial *selected = Object::cast_to<Spatial>(node);
+ if (!selected)
return;
- _select(sp, clicked_wants_append, true);
+ // Replace the node by the group if grouped
+ while (node && node != editor->get_edited_scene()->get_parent()) {
+ Spatial *selected_tmp = Object::cast_to<Spatial>(node);
+ if (selected_tmp && node->has_meta("_edit_group_")) {
+ selected = selected_tmp;
+ }
+ node = node->get_parent();
+ }
+
+ _select(selected, clicked_wants_append, true);
}
void SpatialEditorViewport::_select(Node *p_node, bool p_append, bool p_single) {
@@ -511,6 +521,19 @@ void SpatialEditorViewport::_select_region() {
item = item->get_owner();
}
+ // Replace the node by the group if grouped
+ if (item->is_class("Spatial")) {
+ Spatial *sel = Object::cast_to<Spatial>(item);
+ while (item && item != editor->get_edited_scene()->get_parent()) {
+ Spatial *selected_tmp = Object::cast_to<Spatial>(item);
+ if (selected_tmp && item->has_meta("_edit_group_")) {
+ sel = selected_tmp;
+ }
+ item = item->get_parent();
+ }
+ item = sel;
+ }
+
if (selected.find(item) != -1) continue;
Ref<EditorSpatialGizmo> seg = sp->get_gizmo();
@@ -4529,6 +4552,44 @@ void SpatialEditor::_menu_item_pressed(int p_option) {
_refresh_menu_icons();
} break;
+ case MENU_GROUP_SELECTED: {
+
+ List<Node *> &selection = editor_selection->get_selected_node_list();
+
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+
+ Spatial *spatial = Object::cast_to<Spatial>(E->get());
+ if (!spatial || !spatial->is_visible_in_tree())
+ continue;
+
+ if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ continue;
+
+ spatial->set_meta("_edit_group_", true);
+ emit_signal("item_group_status_changed");
+ }
+
+ _refresh_menu_icons();
+ } break;
+ case MENU_UNGROUP_SELECTED: {
+
+ List<Node *> &selection = editor_selection->get_selected_node_list();
+
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+
+ Spatial *spatial = Object::cast_to<Spatial>(E->get());
+ if (!spatial || !spatial->is_visible_in_tree())
+ continue;
+
+ if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ continue;
+
+ spatial->set_meta("_edit_group_", Variant());
+ emit_signal("item_group_status_changed");
+ }
+
+ _refresh_menu_icons();
+ } break;
}
}
@@ -4971,11 +5032,13 @@ bool SpatialEditor::is_any_freelook_active() const {
void SpatialEditor::_refresh_menu_icons() {
bool all_locked = true;
+ bool all_grouped = true;
List<Node *> &selection = editor_selection->get_selected_node_list();
if (selection.empty()) {
all_locked = false;
+ all_grouped = false;
} else {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
if (Object::cast_to<Spatial>(E->get()) && !Object::cast_to<Spatial>(E->get())->has_meta("_edit_lock_")) {
@@ -4983,11 +5046,21 @@ void SpatialEditor::_refresh_menu_icons() {
break;
}
}
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+ if (Object::cast_to<Spatial>(E->get()) && !Object::cast_to<Spatial>(E->get())->has_meta("_edit_group_")) {
+ all_grouped = false;
+ break;
+ }
+ }
}
tool_button[TOOL_LOCK_SELECTED]->set_visible(!all_locked);
tool_button[TOOL_LOCK_SELECTED]->set_disabled(selection.empty());
tool_button[TOOL_UNLOCK_SELECTED]->set_visible(all_locked);
+
+ tool_button[TOOL_GROUP_SELECTED]->set_visible(!all_grouped);
+ tool_button[TOOL_GROUP_SELECTED]->set_disabled(selection.empty());
+ tool_button[TOOL_UNGROUP_SELECTED]->set_visible(all_grouped);
}
template <typename T>
@@ -5157,6 +5230,8 @@ void SpatialEditor::_notification(int p_what) {
tool_button[SpatialEditor::TOOL_MODE_LIST_SELECT]->set_icon(get_icon("ListSelect", "EditorIcons"));
tool_button[SpatialEditor::TOOL_LOCK_SELECTED]->set_icon(get_icon("Lock", "EditorIcons"));
tool_button[SpatialEditor::TOOL_UNLOCK_SELECTED]->set_icon(get_icon("Unlock", "EditorIcons"));
+ tool_button[SpatialEditor::TOOL_GROUP_SELECTED]->set_icon(get_icon("Group", "EditorIcons"));
+ tool_button[SpatialEditor::TOOL_UNGROUP_SELECTED]->set_icon(get_icon("Ungroup", "EditorIcons"));
tool_option_button[SpatialEditor::TOOL_OPT_LOCAL_COORDS]->set_icon(get_icon("Object", "EditorIcons"));
tool_option_button[SpatialEditor::TOOL_OPT_USE_SNAP]->set_icon(get_icon("Snap", "EditorIcons"));
@@ -5351,6 +5426,7 @@ void SpatialEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo("transform_key_request"));
ADD_SIGNAL(MethodInfo("item_lock_status_changed"));
+ ADD_SIGNAL(MethodInfo("item_group_status_changed"));
}
void SpatialEditor::clear() {
@@ -5464,6 +5540,18 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
tool_button[TOOL_UNLOCK_SELECTED]->connect("pressed", this, "_menu_item_pressed", button_binds);
tool_button[TOOL_UNLOCK_SELECTED]->set_tooltip(TTR("Unlock the selected object (can be moved)."));
+ tool_button[TOOL_GROUP_SELECTED] = memnew(ToolButton);
+ hbc_menu->add_child(tool_button[TOOL_GROUP_SELECTED]);
+ button_binds.write[0] = MENU_GROUP_SELECTED;
+ tool_button[TOOL_GROUP_SELECTED]->connect("pressed", this, "_menu_item_pressed", button_binds);
+ tool_button[TOOL_GROUP_SELECTED]->set_tooltip(TTR("Makes sure the object's children are not selectable."));
+
+ tool_button[TOOL_UNGROUP_SELECTED] = memnew(ToolButton);
+ hbc_menu->add_child(tool_button[TOOL_UNGROUP_SELECTED]);
+ button_binds.write[0] = MENU_UNGROUP_SELECTED;
+ tool_button[TOOL_UNGROUP_SELECTED]->connect("pressed", this, "_menu_item_pressed", button_binds);
+ tool_button[TOOL_UNGROUP_SELECTED]->set_tooltip(TTR("Restores the object's children's ability to be selected."));
+
hbc_menu->add_child(memnew(VSeparator));
tool_option_button[TOOL_OPT_LOCAL_COORDS] = memnew(ToolButton);