diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-01-10 01:04:31 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-01-10 01:07:03 -0300 |
commit | a503f8aadcb8cbc85bde589fb25ea06e599b367b (patch) | |
tree | 070ebbf0dd6af2d43c5519f5e32045b3512f0e9e /tools/editor | |
parent | 68c008ca8d87a1f72fcf17467ee43714954e9ce4 (diff) |
Groundbreaking!! Godot resources can now be flagged to be local to the scene being edited!
This means that each time this scene is instanced, the resource will be unique!
As such, thanks to this, the following features were implemented:
-ButtonGroup is no longer a control, it's now a resource local to the scene
-ViewportTexture can be created from the editor and set to any object, making ViewportSprite and other kind of nodes obsolete!
Diffstat (limited to 'tools/editor')
-rw-r--r-- | tools/editor/editor_data.cpp | 2 | ||||
-rw-r--r-- | tools/editor/editor_node.cpp | 9 | ||||
-rw-r--r-- | tools/editor/io_plugins/editor_texture_import_plugin.cpp | 2 | ||||
-rw-r--r-- | tools/editor/plugins/canvas_item_editor_plugin.cpp | 17 | ||||
-rw-r--r-- | tools/editor/plugins/canvas_item_editor_plugin.h | 3 | ||||
-rw-r--r-- | tools/editor/plugins/theme_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | tools/editor/property_editor.cpp | 43 | ||||
-rw-r--r-- | tools/editor/property_editor.h | 1 | ||||
-rw-r--r-- | tools/editor/scene_tree_dock.cpp | 6 |
9 files changed, 71 insertions, 14 deletions
diff --git a/tools/editor/editor_data.cpp b/tools/editor/editor_data.cpp index 11ba30f4f0..f27fe79a85 100644 --- a/tools/editor/editor_data.cpp +++ b/tools/editor/editor_data.cpp @@ -584,7 +584,7 @@ bool EditorData::check_and_update_scene(int p_idx) { Error err = pscene->pack(edited_scene[p_idx].root); ERR_FAIL_COND_V(err!=OK,false); ep.step(TTR("Updating scene.."),1); - Node *new_scene = pscene->instance(true); + Node *new_scene = pscene->instance(PackedScene::GEN_EDIT_STATE_MAIN); ERR_FAIL_COND_V(!new_scene,false); //transfer selection diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 5eb5f42001..2306f98349 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -3745,7 +3745,7 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo sdata->set_path(lpath,true); //take over path } - Node*new_scene=sdata->instance(true); + Node*new_scene=sdata->instance(PackedScene::GEN_EDIT_STATE_MAIN); if (!new_scene) { @@ -5365,8 +5365,15 @@ void EditorNode::_bind_methods() { } +static Node* _resource_get_edited_scene() { + + return EditorNode::get_singleton()->get_edited_scene(); +} + EditorNode::EditorNode() { + Resource::_get_local_scene_func=_resource_get_edited_scene; + VisualServer::get_singleton()->textures_keep_original(true); EditorHelp::generate_doc(); //before any editor classes are crated diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.cpp b/tools/editor/io_plugins/editor_texture_import_plugin.cpp index 16bc334cce..96e49a0a7f 100644 --- a/tools/editor/io_plugins/editor_texture_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_texture_import_plugin.cpp @@ -664,7 +664,7 @@ EditorTextureImportDialog::EditorTextureImportDialog(EditorTextureImportPlugin* mode_hb->add_child(vbcg); mode_hb->add_constant_override("separation",15); - ButtonGroup *bg = memnew( ButtonGroup ); + VBoxContainer *bg = memnew( VBoxContainer ); vbcg->add_margin_child("Import Mode",bg); for(int i=0;i<EditorTextureImportPlugin::MODE_MAX;i++) { diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index 7fecd60484..6839326886 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -3671,7 +3671,10 @@ void CanvasItemEditorViewport::_on_select_type(Object* selected) { } void CanvasItemEditorViewport::_on_change_type() { - CheckBox* check=btn_group->get_pressed_button()->cast_to<CheckBox>(); + if (!button_group->get_pressed_button()) + return; + + CheckBox* check=button_group->get_pressed_button()->cast_to<CheckBox>(); default_type=check->get_text(); _perform_drop_data(); selector->hide(); @@ -3798,7 +3801,7 @@ bool CanvasItemEditorViewport::_create_instance(Node* parent, String& path, cons return false; } - Node* instanced_scene=sdata->instance(true); + Node* instanced_scene=sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!instanced_scene) { // error on instancing return false; } @@ -3899,7 +3902,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2& p_point,const Variant String type=res->get_class(); if (type=="PackedScene") { Ref<PackedScene> sdata=ResourceLoader::load(files[i]); - Node* instanced_scene=sdata->instance(true); + Node* instanced_scene=sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!instanced_scene) { continue; } @@ -3957,7 +3960,8 @@ void CanvasItemEditorViewport::drop_data(const Point2& p_point,const Variant& p_ if (is_alt) { List<BaseButton*> btn_list; - btn_group->get_button_list(&btn_list); + button_group->get_buttons(&btn_list); + for (int i=0;i<btn_list.size();i++) { CheckBox* check=btn_list[i]->cast_to<CheckBox>(); check->set_pressed(check->get_text()==default_type); @@ -4016,7 +4020,9 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte selector_label->set_custom_minimum_size(Size2(0,30)*EDSCALE); vbc->add_child(selector_label); - btn_group=memnew( ButtonGroup ); + button_group.instance(); + + btn_group=memnew( VBoxContainer ); btn_group->set_h_size_flags(0); btn_group->connect("button_selected", this, "_on_select_type"); @@ -4024,6 +4030,7 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte CheckBox* check=memnew(CheckBox); check->set_text(types[i]); btn_group->add_child(check); + check->set_button_group(button_group); } vbc->add_child(btn_group); diff --git a/tools/editor/plugins/canvas_item_editor_plugin.h b/tools/editor/plugins/canvas_item_editor_plugin.h index f74df9d6e0..ee36554477 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.h +++ b/tools/editor/plugins/canvas_item_editor_plugin.h @@ -473,7 +473,8 @@ class CanvasItemEditorViewport : public VBoxContainer { Label* selector_label; Label* label; Label* label_desc; - ButtonGroup* btn_group; + VBoxContainer* btn_group; + Ref<ButtonGroup> button_group; void _on_mouse_exit(); void _on_select_type(Object* selected); diff --git a/tools/editor/plugins/theme_editor_plugin.cpp b/tools/editor/plugins/theme_editor_plugin.cpp index ad0968178b..a700ddce7a 100644 --- a/tools/editor/plugins/theme_editor_plugin.cpp +++ b/tools/editor/plugins/theme_editor_plugin.cpp @@ -711,7 +711,7 @@ ThemeEditor::ThemeEditor() { first_vb->add_child(cbx ); - ButtonGroup *bg = memnew( ButtonGroup ); + VBoxContainer *bg = memnew( VBoxContainer ); bg->set_v_size_flags(SIZE_EXPAND_FILL); VBoxContainer *gbvb = memnew( VBoxContainer ); gbvb->set_v_size_flags(SIZE_EXPAND_FILL); diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 1a2749cd95..4c69412b3b 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -226,8 +226,19 @@ void CustomPropertyEditor::_menu_option(int p_which) { ERR_FAIL_COND( inheritors_array.empty() ); + + String intype=inheritors_array[p_which-TYPE_BASE_ID]; + if (intype=="ViewportTexture") { + + scene_tree->set_title(TTR("Pick a Viewport")); + scene_tree->popup_centered_ratio(); + picking_viewport=true; + return; + + } + Object *obj = ClassDB::instance(intype); ERR_BREAK( !obj ); Resource *res=obj->cast_to<Resource>(); @@ -1126,6 +1137,22 @@ void CustomPropertyEditor::_color_changed(const Color& p_color) { void CustomPropertyEditor::_node_path_selected(NodePath p_path) { + if (picking_viewport) { + + Node* to_node=get_node(p_path); + if (!to_node->cast_to<Viewport>()) { + EditorNode::get_singleton()->show_warning("Selected node is not a Viewport!"); + return; + } + + Ref<ViewportTexture> vt; + vt.instance(); + vt->set_viewport_path_in_scene(get_tree()->get_edited_scene_root()->get_path_to(to_node)); + vt->setup_local_to_scene(); + v=vt; + emit_signal("variant_changed"); + return; + } if (hint==PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && hint_text!=String()) { @@ -1262,7 +1289,8 @@ void CustomPropertyEditor::_action_pressed(int p_which) { if (p_which==0) { - + picking_viewport=false; + scene_tree->set_title(TTR("Pick a Node")); scene_tree->popup_centered_ratio(); } else if (p_which==1) { @@ -3807,6 +3835,8 @@ void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value) { undo_redo->create_action(TTR("Set")+" "+p_name,UndoRedo::MERGE_ENDS); undo_redo->add_do_property(obj,p_name,p_value); undo_redo->add_undo_property(obj,p_name,obj->get(p_name)); + + undo_redo->add_do_method(this,"_changed_callback",obj,p_name); undo_redo->add_undo_method(this,"_changed_callback",obj,p_name); @@ -3816,6 +3846,17 @@ void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value) { undo_redo->add_do_method(r,"set_edited",true); undo_redo->add_undo_method(r,"set_edited",false); } + + if (String(p_name)=="resource_local_to_scene") { + bool prev = obj->get(p_name); + bool next = p_value; + if (next) { + undo_redo->add_do_method(this,"setup_local_to_scene"); + } + if (prev) { + undo_redo->add_undo_method(this,"setup_local_to_scene"); + } + } } undo_redo->add_do_method(this,"emit_signal",_prop_edited,p_name); undo_redo->add_undo_method(this,"emit_signal",_prop_edited,p_name); diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h index df180cab18..af7d01f935 100644 --- a/tools/editor/property_editor.h +++ b/tools/editor/property_editor.h @@ -99,6 +99,7 @@ class CustomPropertyEditor : public Popup { ColorPicker *color_picker; TextEdit *text_edit; bool read_only; + bool picking_viewport; CheckBox *checks20[20]; SpinBox *spinbox; HSlider *slider; diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 70195862de..c171c49c7b 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -174,7 +174,7 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String>& p_files,Node* } - Node*instanced_scene=sdata->instance(true); + Node*instanced_scene=sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!instanced_scene) { current_option=-1; //accept->get_cancel()->hide(); @@ -250,7 +250,7 @@ void SceneTreeDock::_replace_with_branch_scene(const String& p_file,Node* base) return; } - Node *instanced_scene=sdata->instance(true); + Node *instanced_scene=sdata->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); if (!instanced_scene) { accept->get_ok()->set_text(TTR("Ugh")); accept->set_text(vformat(TTR("Error instancing scene from %s"),p_file)); @@ -744,7 +744,7 @@ Node *SceneTreeDock::_duplicate(Node *p_node, Map<Node*,Node*> &duplimap) { Ref<PackedScene> sd = ResourceLoader::load( p_node->get_filename() ); ERR_FAIL_COND_V(!sd.is_valid(),NULL); - node = sd->instance(true); + node = sd->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); ERR_FAIL_COND_V(!node,NULL); //node->generate_instance_state(); } else { |