Merge pull request #28862 from KoBeWi/editable_clones

Keep editable children on node duplicate
This commit is contained in:
Rémi Verschelde 2019-05-28 18:38:46 +02:00 committed by GitHub
commit d4811e6897
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 21 deletions

View file

@ -518,6 +518,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
editor_data->get_undo_redo().add_do_method(editor_selection, "clear");
Node *dupsingle = NULL;
List<Node *> editable_children;
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
@ -530,6 +531,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
Map<const Node *, Node *> duplimap;
Node *dup = node->duplicate_from_editor(duplimap);
if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node))
editable_children.push_back(dup);
ERR_CONTINUE(!dup);
if (selection.size() == 1)
@ -562,6 +566,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
if (dupsingle)
editor->push_item(dupsingle);
for (List<Node *>::Element *E = editable_children.front(); E; E = E->next())
_toggle_editable_children(E->get());
} break;
case TOOL_REPARENT: {
@ -797,7 +804,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
editable_instance_remove_dialog->popup_centered_minsize();
break;
}
_toggle_editable_children();
_toggle_editable_children(node);
}
}
} break;
@ -1613,32 +1620,29 @@ void SceneTreeDock::_script_created(Ref<Script> p_script) {
_update_script_button();
}
void SceneTreeDock::_toggle_editable_children() {
void SceneTreeDock::_toggle_editable_children_from_selection() {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *>::Element *e = selection.front();
if (e) {
Node *node = e->get();
if (node) {
bool editable = EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node);
int editable_item_idx = menu->get_item_idx_from_text(TTR("Editable Children"));
int placeholder_item_idx = menu->get_item_idx_from_text(TTR("Load As Placeholder"));
editable = !editable;
EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(node, editable);
menu->set_item_checked(editable_item_idx, editable);
if (editable) {
node->set_scene_instance_load_placeholder(false);
menu->set_item_checked(placeholder_item_idx, false);
_toggle_editable_children(e->get());
}
}
SpatialEditor::get_singleton()->update_all_gizmos(node);
void SceneTreeDock::_toggle_editable_children(Node *p_node) {
if (p_node) {
bool editable = !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node);
EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(p_node, editable);
if (editable)
p_node->set_scene_instance_load_placeholder(false);
SpatialEditor::get_singleton()->update_all_gizmos(p_node);
scene_tree->update_tree();
}
}
}
void SceneTreeDock::_delete_confirm() {
@ -2476,7 +2480,7 @@ void SceneTreeDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_input"), &SceneTreeDock::_input);
ClassDB::bind_method(D_METHOD("_nodes_drag_begin"), &SceneTreeDock::_nodes_drag_begin);
ClassDB::bind_method(D_METHOD("_delete_confirm"), &SceneTreeDock::_delete_confirm);
ClassDB::bind_method(D_METHOD("_toggle_editable_children"), &SceneTreeDock::_toggle_editable_children);
ClassDB::bind_method(D_METHOD("_toggle_editable_children_from_selection"), &SceneTreeDock::_toggle_editable_children_from_selection);
ClassDB::bind_method(D_METHOD("_node_prerenamed"), &SceneTreeDock::_node_prerenamed);
ClassDB::bind_method(D_METHOD("_import_subscene"), &SceneTreeDock::_import_subscene);
ClassDB::bind_method(D_METHOD("_selection_changed"), &SceneTreeDock::_selection_changed);
@ -2644,7 +2648,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
editable_instance_remove_dialog = memnew(ConfirmationDialog);
add_child(editable_instance_remove_dialog);
editable_instance_remove_dialog->connect("confirmed", this, "_toggle_editable_children");
editable_instance_remove_dialog->connect("confirmed", this, "_toggle_editable_children_from_selection");
import_subscene_dialog = memnew(EditorSubScene);
add_child(import_subscene_dialog);

View file

@ -172,7 +172,8 @@ class SceneTreeDock : public VBoxContainer {
void _delete_confirm();
void _toggle_editable_children();
void _toggle_editable_children_from_selection();
void _toggle_editable_children(Node *p_node);
void _node_prerenamed(Node *p_node, const String &p_new_name);