diff options
author | Andreas Haas <liu.gam3@gmail.com> | 2016-10-27 16:32:41 +0200 |
---|---|---|
committer | Andreas Haas <liu.gam3@gmail.com> | 2016-10-27 16:32:41 +0200 |
commit | a3944e66dac9eda11b80fe0598db0ef7c207155c (patch) | |
tree | b0145b7731d8b934841c27ea4b271e367aa9e872 | |
parent | 8321e48ab0ac0700e1aef8f829140052c1ba4c6d (diff) |
Ability to drag script files from Filesystem dock to SceneTree dock.
Allows to attach scripts by dragging them onto the target Node.
-rw-r--r-- | tools/editor/scene_tree_dock.cpp | 11 | ||||
-rw-r--r-- | tools/editor/scene_tree_dock.h | 1 | ||||
-rw-r--r-- | tools/editor/scene_tree_editor.cpp | 25 | ||||
-rw-r--r-- | tools/editor/scene_tree_editor.h | 3 |
4 files changed, 38 insertions, 2 deletions
diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 56f10ff7f8..b67719fc42 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -1721,6 +1721,15 @@ void SceneTreeDock::_files_dropped(Vector<String> p_files,NodePath p_to,int p_ty _perform_instance_scenes(p_files,node,to_pos); } +void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) { + Ref<Script> scr = ResourceLoader::load(p_file); + ERR_FAIL_COND(!scr.is_valid()); + Node *n = get_node(p_to); + if (n) { + n->set_script(scr.get_ref_ptr()); + } +} + void SceneTreeDock::_nodes_dragged(Array p_nodes,NodePath p_to,int p_type) { Vector<Node*> nodes; @@ -1859,6 +1868,7 @@ void SceneTreeDock::_bind_methods() { ObjectTypeDB::bind_method(_MD("_new_scene_from"),&SceneTreeDock::_new_scene_from); ObjectTypeDB::bind_method(_MD("_nodes_dragged"),&SceneTreeDock::_nodes_dragged); ObjectTypeDB::bind_method(_MD("_files_dropped"),&SceneTreeDock::_files_dropped); + ObjectTypeDB::bind_method(_MD("_script_dropped"),&SceneTreeDock::_script_dropped); ObjectTypeDB::bind_method(_MD("_tree_rmb"),&SceneTreeDock::_tree_rmb); ObjectTypeDB::bind_method(_MD("_filter_changed"),&SceneTreeDock::_filter_changed); ObjectTypeDB::bind_method(_MD("_focus_node"),&SceneTreeDock::_focus_node); @@ -1941,6 +1951,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec scene_tree->connect("open_script",this,"_script_open_request"); scene_tree->connect("nodes_rearranged",this,"_nodes_dragged"); scene_tree->connect("files_dropped",this,"_files_dropped"); + scene_tree->connect("script_dropped",this,"_script_dropped"); scene_tree->connect("nodes_dragged",this,"_nodes_drag_begin"); scene_tree->get_scene_tree()->connect("item_double_clicked", this, "_focus_node"); diff --git a/tools/editor/scene_tree_dock.h b/tools/editor/scene_tree_dock.h index 8933a03883..ad205af770 100644 --- a/tools/editor/scene_tree_dock.h +++ b/tools/editor/scene_tree_dock.h @@ -147,6 +147,7 @@ class SceneTreeDock : public VBoxContainer { void _nodes_dragged(Array p_nodes,NodePath p_to,int p_type); void _files_dropped(Vector<String> p_files,NodePath p_to,int p_type); + void _script_dropped(String p_file, NodePath p_to); void _tree_rmb(const Vector2& p_menu_pos); diff --git a/tools/editor/scene_tree_editor.cpp b/tools/editor/scene_tree_editor.cpp index 53bfe8cc57..f5628d0c8f 100644 --- a/tools/editor/scene_tree_editor.cpp +++ b/tools/editor/scene_tree_editor.cpp @@ -971,6 +971,10 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2& p_point,Control* p_from) return drag_data; } +bool SceneTreeEditor::_is_script_type(const StringName &p_type) const { + return (script_types->find(p_type)); +} + bool SceneTreeEditor::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const { if (!can_rename) @@ -998,9 +1002,13 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2& p_point,const Variant& p_da if (files.size()==0) return false; //weird + if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(files[0]))) { + tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); + return true; + } for(int i=0;i<files.size();i++) { - String file = files[0]; + String file = files[i]; String ftype = EditorFileSystem::get_singleton()->get_file_type(file); if (ftype!="PackedScene") return false; @@ -1044,7 +1052,15 @@ void SceneTreeEditor::drop_data_fw(const Point2& p_point,const Variant& p_data,C if (String(d["type"])=="files") { - emit_signal("files_dropped",d["files"],np,section); + Vector<String> files = d["files"]; + + + String ftype = EditorFileSystem::get_singleton()->get_file_type(files[0]); + if (_is_script_type(ftype)) { + emit_signal("script_dropped", files[0],np); + } else { + emit_signal("files_dropped",files,np,section); + } } } @@ -1113,6 +1129,7 @@ void SceneTreeEditor::_bind_methods() { ADD_SIGNAL( MethodInfo("nodes_dragged") ); ADD_SIGNAL( MethodInfo("nodes_rearranged",PropertyInfo(Variant::ARRAY,"paths"),PropertyInfo(Variant::NODE_PATH,"to_path"),PropertyInfo(Variant::INT,"type") ) ); ADD_SIGNAL( MethodInfo("files_dropped",PropertyInfo(Variant::STRING_ARRAY,"files"),PropertyInfo(Variant::NODE_PATH,"to_path"),PropertyInfo(Variant::INT,"type") ) ); + ADD_SIGNAL( MethodInfo("script_dropped",PropertyInfo(Variant::STRING,"file"),PropertyInfo(Variant::NODE_PATH,"to_path"))); ADD_SIGNAL( MethodInfo("rmb_pressed",PropertyInfo(Variant::VECTOR2,"pos")) ) ; ADD_SIGNAL( MethodInfo("open") ); @@ -1209,12 +1226,16 @@ SceneTreeEditor::SceneTreeEditor(bool p_label,bool p_can_rename, bool p_can_open update_timer->set_wait_time(0.5); add_child(update_timer); + script_types = memnew(List<StringName>); + ObjectTypeDB::get_inheriters_from("Script", script_types); + } SceneTreeEditor::~SceneTreeEditor() { + memdelete(script_types); } diff --git a/tools/editor/scene_tree_editor.h b/tools/editor/scene_tree_editor.h index 79b7a64468..12d85ecdeb 100644 --- a/tools/editor/scene_tree_editor.h +++ b/tools/editor/scene_tree_editor.h @@ -137,6 +137,9 @@ class SceneTreeEditor : public Control { Timer* update_timer; + List<StringName> *script_types; + bool _is_script_type(const StringName &p_type) const; + public: void set_filter(const String& p_filter); |