Prechádzať zdrojové kódy

Merge pull request #4174 from Hodes/master

Multiple editor plugins for same obj type
Rémi Verschelde 9 rokov pred
rodič
commit
aad31ee986

+ 10 - 0
tools/editor/editor_data.cpp

@@ -260,6 +260,16 @@ EditorPlugin* EditorData::get_subeditor(Object *p_object) {
 	return NULL;
 }
 
+Vector<EditorPlugin*> EditorData::get_subeditors(Object* p_object) {
+	Vector<EditorPlugin*> sub_plugins;
+	for (int i = 0; i < editor_plugins.size(); i++) {
+		if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
+			sub_plugins.push_back(editor_plugins[i]);
+		}
+	}
+	return sub_plugins;
+}
+
 EditorPlugin* EditorData::get_editor(String p_name) {
 
 	for(int i=0;i<editor_plugins.size();i++) {

+ 1 - 0
tools/editor/editor_data.h

@@ -150,6 +150,7 @@ public:
 
 	EditorPlugin* get_editor(Object *p_object);
 	EditorPlugin* get_subeditor(Object *p_object);
+	Vector<EditorPlugin*> get_subeditors(Object *p_object);
 	EditorPlugin* get_editor(String p_name);
 
 	void copy_object_params(Object *p_object);

+ 92 - 24
tools/editor/editor_node.cpp

@@ -1571,15 +1571,27 @@ void EditorNode::_imported(Node *p_node) {
 }
 
 
+void EditorNode::_hide_top_editors() {
 
+	_display_top_editors(false);
 
-void EditorNode::_hide_top_editors() {
+	editor_plugins_over->clear();
+}
+
+void EditorNode::_display_top_editors(bool p_display) {
+	editor_plugins_over->make_visible(p_display);
+}
+
+void EditorNode::_set_top_editors(Vector<EditorPlugin*> p_editor_plugins_over) {
+	editor_plugins_over->set_plugins_list(p_editor_plugins_over);
+}
 
-	if (editor_plugin_over)
-		editor_plugin_over->make_visible(false);
-	editor_plugin_over=NULL;
+void EditorNode::_set_editing_top_editors(Object* p_current_object) {
+	editor_plugins_over->edit(p_current_object);
 }
 
+
+
 void EditorNode::_edit_current() {
 
 	uint32_t current = editor_history.get_current();
@@ -1598,8 +1610,7 @@ void EditorNode::_edit_current() {
 		property_editor->edit( NULL );
 		object_menu->set_disabled(true);
 
-		if (editor_plugin_over)
-			editor_plugin_over->make_visible(false);
+		_display_top_editors(false);
 
 		return;
 	}
@@ -1679,20 +1690,18 @@ void EditorNode::_edit_current() {
 
 	}
 
-	EditorPlugin *sub_plugin = editor_data.get_subeditor(current_obj);
-
-	if (sub_plugin) {
+	Vector<EditorPlugin*> sub_plugins = editor_data.get_subeditors(current_obj);
 
+	if (!sub_plugins.empty()) {
+		_display_top_editors(false);
 
-		if (editor_plugin_over)
-			editor_plugin_over->make_visible(false);
-		editor_plugin_over=sub_plugin;
-		editor_plugin_over->edit(current_obj);
-		editor_plugin_over->make_visible(true);
-	} else if (editor_plugin_over) {
+		_set_top_editors(sub_plugins);
+		_set_editing_top_editors(current_obj);
+		_display_top_editors(true);
+                
+	} else if (!editor_plugins_over->get_plugins_list().empty()) {
 
-		editor_plugin_over->make_visible(false);
-		editor_plugin_over=NULL;
+		_hide_top_editors();
 
 	}
 /*
@@ -2583,10 +2592,9 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
 			}
 
 			editor_data.get_undo_redo().clear_history();
-			if (editor_plugin_over) { //reload editor plugin
-				editor_plugin_over->edit(NULL);
-				editor_plugin_over->edit(current);
-			}
+
+			_set_editing_top_editors(NULL);
+			_set_editing_top_editors(current);
 
 		} break;
 		case OBJECT_CALL_METHOD: {
@@ -6138,7 +6146,7 @@ EditorNode::EditorNode() {
 	_rebuild_import_menu();
 
 	editor_plugin_screen=NULL;
-	editor_plugin_over=NULL;
+	editor_plugins_over = memnew(EditorPluginList);
 
 //	force_top_viewport(true);
 	_edit_current();
@@ -6270,12 +6278,72 @@ EditorNode::EditorNode() {
 
 
 EditorNode::~EditorNode() {
-
-
+        
 	memdelete( EditorHelp::get_doc_data() );
 	memdelete(editor_selection);
+	memdelete(editor_plugins_over);
 	memdelete(file_server);
 	EditorSettings::destroy();
 }
 
+/*
+ * EDITOR PLUGIN LIST
+ */
+
+
+void EditorPluginList::make_visible(bool p_visible) {
+	if (!plugins_list.empty()) {
+		for (int i = 0; i < plugins_list.size(); i++) {
+			plugins_list[i]->make_visible(p_visible);
+		}
+	}
+}
+
+void EditorPluginList::edit(Object* p_object) {
+	if (!plugins_list.empty()) {
+		for (int i = 0; i < plugins_list.size(); i++) {
+			plugins_list[i]->edit(p_object);
+		}
+	}
+}
+
+bool EditorPluginList::forward_input_event(const InputEvent& p_event) {
+	bool discard = false;
+	if (!plugins_list.empty()) {
+		for (int i = 0; i < plugins_list.size(); i++) {
+			if (plugins_list[i]->forward_input_event(p_event)) {
+				discard = true;
+			}
+		}
+	}
+	return discard;
+}
+
+bool EditorPluginList::forward_spatial_input_event(Camera* p_camera, const InputEvent& p_event) {
+	bool discard = false;
+	if (!plugins_list.empty()) {
+		for (int i = 0; i < plugins_list.size(); i++) {
+			if (plugins_list[i]->forward_spatial_input_event(p_camera, p_event)) {
+				discard = true;
+			}
+		}
+	}
+	return discard;
+}
+
+bool EditorPluginList::empty() {
+	return plugins_list.empty();
+}
+
+void EditorPluginList::clear() {
+	plugins_list.clear();
+}
+
+EditorPluginList::EditorPluginList() {
+}
+
+EditorPluginList::~EditorPluginList() {
+}
+        
+
 

+ 33 - 3
tools/editor/editor_node.h

@@ -95,7 +95,7 @@
 
 typedef void (*EditorNodeInitCallback)();
 
-
+class EditorPluginList;
 
 class EditorNode : public Node {
 
@@ -372,7 +372,7 @@ private:
 
 	Vector<EditorPlugin*> editor_plugins;
 	EditorPlugin *editor_plugin_screen;
-	EditorPlugin *editor_plugin_over;
+	EditorPluginList *editor_plugins_over;
 
 	EditorHistory editor_history;
 	EditorData editor_data;
@@ -449,6 +449,10 @@ private:
 	void _transform_keyed(Object *sp,const String& p_sub,const Transform& p_key);
 
 	void _hide_top_editors();
+	void _display_top_editors(bool p_display);
+	void _set_top_editors(Vector<EditorPlugin*> p_editor_plugins_over);
+	void _set_editing_top_editors(Object * p_current_object);
+        
 	void _quick_opened();
 	void _quick_run();
 
@@ -575,7 +579,7 @@ public:
 
 
 	EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; }
-	EditorPlugin *get_editor_plugin_over() { return editor_plugin_over; }
+	EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
 	PropertyEditor *get_property_editor() { return property_editor; }
 
 	static void add_editor_plugin(EditorPlugin *p_editor);
@@ -710,6 +714,32 @@ struct EditorProgress {
 	~EditorProgress() { EditorNode::progress_end_task(task); }
 };
 
+class EditorPluginList : public Object {
+private:
+	Vector<EditorPlugin*> plugins_list;
+
+public:
+
+	void set_plugins_list(Vector<EditorPlugin*> p_plugins_list) {
+		plugins_list = p_plugins_list;
+	}
+
+	Vector<EditorPlugin*> get_plugins_list() {
+		return plugins_list;
+	}
+
+	void make_visible(bool p_visible);
+	void edit(Object *p_object);
+	bool forward_input_event(const InputEvent& p_event);
+	bool forward_spatial_input_event(Camera* p_camera, const InputEvent& p_event);
+	void clear();
+	bool empty();
+
+	EditorPluginList();
+	~EditorPluginList();
+
+} ; 
+
 struct EditorProgressBG {
 
 	String task;

+ 3 - 3
tools/editor/plugins/canvas_item_editor_plugin.cpp

@@ -1037,10 +1037,10 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) {
 	 {
 
 		EditorNode *en = editor;
-		EditorPlugin *over_plugin = en->get_editor_plugin_over();
+		EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
 
-		if (over_plugin) {
-			bool discard = over_plugin->forward_input_event(p_event);
+		if (!over_plugin_list->empty()) {
+			bool discard = over_plugin_list->forward_input_event(p_event);
 			if (discard) {
 				accept_event();
 				return;

+ 5 - 5
tools/editor/plugins/spatial_editor_plugin.cpp

@@ -834,10 +834,10 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
 	{
 
 		EditorNode *en = editor;
-		EditorPlugin *over_plugin = en->get_editor_plugin_over();
+		EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
 
-		if (over_plugin) {
-			bool discard = over_plugin->forward_spatial_input_event(camera,p_event);
+		if (!over_plugin_list->empty()) {
+			bool discard = over_plugin_list->forward_spatial_input_event(camera,p_event);
 			if (discard)
 				return;
 		}
@@ -3576,9 +3576,9 @@ void SpatialEditor::_unhandled_key_input(InputEvent p_event) {
 	{
 
 		EditorNode *en = editor;
-		EditorPlugin *over_plugin = en->get_editor_plugin_over();
+		EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
 
-		if (over_plugin && over_plugin->forward_input_event(p_event)) {
+		if (!over_plugin_list->empty() && over_plugin_list->forward_input_event(p_event)) {
 
 			return; //ate the over input event
 		}

+ 1 - 2
tools/editor/scene_tree_dock.cpp

@@ -1098,8 +1098,7 @@ void SceneTreeDock::_delete_confirm() {
 		return;
 
 
-	if (editor->get_editor_plugin_over())
-		editor->get_editor_plugin_over()->make_visible(false);
+	editor->get_editor_plugins_over()->make_visible(false);
 
 	editor_data->get_undo_redo().create_action("Remove Node(s)");