Ability to discard instancing from menu, closes #4903

This commit is contained in:
Juan Linietsky 2016-06-11 23:00:06 -03:00
parent 1555608276
commit 1785f6939f
3 changed files with 49 additions and 1 deletions

View File

@ -201,6 +201,7 @@ static String _get_name_num_separator() {
return " ";
}
void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
current_option=p_tool;
@ -519,6 +520,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
EditorNode::get_singleton()->push_item(mne.ptr());
} break;
case TOOL_ERASE: {
List<Node*> remove_list = editor_selection->get_selected_node_list();

View File

@ -93,6 +93,29 @@ void SceneTreeEditor::_subscene_option(int p_idx) {
} break;
case SCENE_MENU_CLEAR_INHERITANCE: {
clear_inherit_confirm->popup_centered_minsize();
} break;
case SCENE_MENU_CLEAR_INSTANCING: {
Node*root=EditorNode::get_singleton()->get_edited_scene();
if (!root)
break;
ERR_FAIL_COND(node->get_filename()==String());
undo_redo->create_action("Discard Instancing");
undo_redo->add_do_method(node,"set_filename","");
undo_redo->add_undo_method(node,"set_filename",node->get_filename());
_node_replace_owner(node,node,root);
undo_redo->add_do_method(this,"update_tree");
undo_redo->add_undo_method(this,"update_tree");
undo_redo->commit_action();
} break;
case SCENE_MENU_OPEN_INHERITED: {
if (node && node->get_scene_inherited_state().is_valid()) {
@ -108,11 +131,30 @@ void SceneTreeEditor::_subscene_option(int p_idx) {
} break;
}
}
void SceneTreeEditor::_node_replace_owner(Node* p_base,Node* p_node,Node* p_root) {
if (p_base!=p_node) {
if (p_node->get_owner()==p_base) {
undo_redo->add_do_method(p_node,"set_owner",p_root);
undo_redo->add_undo_method(p_node,"set_owner",p_base);
}
}
for(int i=0;i<p_node->get_child_count();i++) {
_node_replace_owner(p_base,p_node->get_child(i),p_root);
}
}
void SceneTreeEditor::_cell_button_pressed(Object *p_item,int p_column,int p_id) {
TreeItem *item=p_item->cast_to<TreeItem>();
@ -606,7 +648,7 @@ void SceneTreeEditor::_notification(int p_what) {
get_tree()->connect("node_removed",this,"_node_removed");
get_tree()->connect("node_configuration_warning_changed",this,"_warning_changed");
instance_menu->set_item_icon(3,get_icon("Load","EditorIcons"));
instance_menu->set_item_icon(5,get_icon("Load","EditorIcons"));
tree->connect("item_collapsed",this,"_cell_collapsed");
inheritance_menu->set_item_icon(2,get_icon("Load","EditorIcons"));
clear_inherit_confirm->connect("confirmed",this,"_subscene_option",varray(SCENE_MENU_CLEAR_INHERITANCE_CONFIRM));
@ -1109,6 +1151,8 @@ SceneTreeEditor::SceneTreeEditor(bool p_label,bool p_can_rename, bool p_can_open
instance_menu->add_check_item(TTR("Editable Children"),SCENE_MENU_EDITABLE_CHILDREN);
instance_menu->add_check_item(TTR("Load As Placeholder"),SCENE_MENU_USE_PLACEHOLDER);
instance_menu->add_separator();
instance_menu->add_item(TTR("Discard Instancing"),SCENE_MENU_CLEAR_INSTANCING);
instance_menu->add_separator();
instance_menu->add_item(TTR("Open in Editor"),SCENE_MENU_OPEN);
instance_menu->connect("item_pressed",this,"_subscene_option");
add_child(instance_menu);

View File

@ -61,6 +61,7 @@ class SceneTreeEditor : public Control {
SCENE_MENU_CLEAR_INHERITANCE,
SCENE_MENU_OPEN_INHERITED,
SCENE_MENU_CLEAR_INHERITANCE_CONFIRM,
SCENE_MENU_CLEAR_INSTANCING,
};
Tree *tree;
@ -117,6 +118,7 @@ class SceneTreeEditor : public Control {
void _node_visibility_changed(Node *p_node);
void _subscene_option(int p_idx);
void _node_replace_owner(Node* p_base,Node* p_node,Node* p_root);
void _selection_changed();