Selaa lähdekoodia

-Split EditorPlugin into EditorPlugin and EditorInterface
-Added EditorInterface to EditorScript
-Added functions to save the scene to EditorInterface

Juan Linietsky 8 vuotta sitten
vanhempi
commit
dd7145b778

+ 11 - 15
editor/editor_node.cpp

@@ -989,11 +989,7 @@ void EditorNode::_save_all_scenes() {
 		Node *scene = editor_data.get_edited_scene_root(i);
 		if (scene && scene->get_filename() != "") {
 			// save in background if in the script editor
-			if (i != editor_data.get_edited_scene() || _get_current_main_editor() == EDITOR_SCRIPT) {
-				_save_scene(scene->get_filename(), i);
-			} else {
-				_save_scene_with_preview(scene->get_filename());
-			}
+			_save_scene_with_preview(scene->get_filename());
 		} // else: ignore new scenes
 	}
 
@@ -1192,10 +1188,7 @@ void EditorNode::_dialog_action(String p_file) {
 
 				//_save_scene(p_file);
 				_save_default_environment();
-				if (scene_idx != editor_data.get_edited_scene() || _get_current_main_editor() == EDITOR_SCRIPT)
-					_save_scene(p_file, scene_idx);
-				else
-					_save_scene_with_preview(p_file);
+				_save_scene_with_preview(p_file);
 
 				if (scene_idx != -1)
 					_discard_changes();
@@ -1944,11 +1937,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
 			if (scene && scene->get_filename() != "") {
 
 				// save in background if in the script editor
-				if (scene_idx != editor_data.get_edited_scene() || _get_current_main_editor() == EDITOR_SCRIPT) {
-					_save_scene(scene->get_filename(), scene_idx);
-				} else {
-					_save_scene_with_preview(scene->get_filename());
-				}
+				_save_scene_with_preview(scene->get_filename());
 
 				if (scene_idx != -1)
 					_discard_changes();
@@ -2864,7 +2853,7 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor) {
 		tb->set_toggle_mode(true);
 		tb->connect("pressed", singleton, "_editor_select", varray(singleton->main_editor_buttons.size()));
 		tb->set_text(p_editor->get_name());
-		tb->set_icon(p_editor->get_base_control()->get_icon(p_editor->get_name(), "EditorIcons"));
+		tb->set_icon(singleton->gui_base->get_icon(p_editor->get_name(), "EditorIcons"));
 		tb->set_name(p_editor->get_name());
 		singleton->main_editor_buttons.push_back(tb);
 		singleton->main_editor_button_vb->add_child(tb);
@@ -3727,6 +3716,7 @@ void EditorNode::register_editor_types() {
 	ClassDB::register_class<EditorFileSystem>();
 	ClassDB::register_class<EditorFileSystemDirectory>();
 	ClassDB::register_virtual_class<ScriptEditor>();
+	ClassDB::register_virtual_class<EditorInterface>();
 
 	//ClassDB::register_type<EditorImporter>();
 	//ClassDB::register_type<EditorPostImport>();
@@ -6027,6 +6017,12 @@ EditorNode::EditorNode() {
 	} else {
 		WARN_PRINT("Asset Library not available, as it requires SSL to work.");
 	}
+
+	//add interface before adding plugins
+
+	editor_interface = memnew(EditorInterface);
+	add_child(editor_interface);
+
 	//more visually meaningful to have this later
 	raise_bottom_panel_item(AnimationPlayerEditor::singleton);
 

+ 8 - 1
editor/editor_node.h

@@ -420,6 +420,8 @@ private:
 	HBoxContainer *bottom_panel_hb;
 	VBoxContainer *bottom_panel_vb;
 
+	EditorInterface *editor_interface;
+
 	void _bottom_panel_switch(bool p_enable, int p_idx);
 
 	String external_file;
@@ -762,7 +764,12 @@ public:
 	static void progress_task_step_bg(const String &p_task, int p_step = -1);
 	static void progress_end_task_bg(const String &p_task);
 
-	void save_scene(String p_file) { _save_scene(p_file); }
+	void save_scene_to_path(String p_file, bool p_with_preview = true) {
+		if (p_with_preview)
+			_save_scene_with_preview(p_file);
+		else
+			_save_scene(p_file);
+	}
 
 	bool is_scene_in_use(const String &p_path);
 

+ 122 - 88
editor/editor_plugin.cpp

@@ -37,6 +37,124 @@
 #include "scene/3d/camera.h"
 #include "scene/gui/popup_menu.h"
 
+Control *EditorInterface::get_editor_viewport() {
+
+	return EditorNode::get_singleton()->get_viewport();
+}
+
+void EditorInterface::edit_resource(const Ref<Resource> &p_resource) {
+
+	EditorNode::get_singleton()->edit_resource(p_resource);
+}
+
+void EditorInterface::open_scene_from_path(const String &scene_path) {
+
+	if (EditorNode::get_singleton()->is_changing_scene()) {
+		return;
+	}
+
+	EditorNode::get_singleton()->open_request(scene_path);
+}
+
+void EditorInterface::reload_scene_from_path(const String &scene_path) {
+
+	if (EditorNode::get_singleton()->is_changing_scene()) {
+		return;
+	}
+
+	EditorNode::get_singleton()->reload_scene(scene_path);
+}
+
+Node *EditorInterface::get_edited_scene_root() {
+	return EditorNode::get_singleton()->get_edited_scene();
+}
+
+Array EditorInterface::get_open_scenes() const {
+
+	Array ret;
+	Vector<EditorData::EditedScene> scenes = EditorNode::get_singleton()->get_editor_data().get_edited_scenes();
+
+	int scns_amount = scenes.size();
+	for (int idx_scn = 0; idx_scn < scns_amount; idx_scn++) {
+		if (scenes[idx_scn].root == NULL)
+			continue;
+		ret.push_back(scenes[idx_scn].root->get_filename());
+	}
+	return ret;
+}
+
+ScriptEditor *EditorInterface::get_script_editor() {
+	return ScriptEditor::get_singleton();
+}
+
+void EditorInterface::inspect_object(Object *p_obj, const String &p_for_property) {
+
+	EditorNode::get_singleton()->push_item(p_obj, p_for_property);
+}
+
+EditorFileSystem *EditorInterface::get_resource_file_system() {
+	return EditorFileSystem::get_singleton();
+}
+
+EditorSelection *EditorInterface::get_selection() {
+	return EditorNode::get_singleton()->get_editor_selection();
+}
+
+EditorSettings *EditorInterface::get_editor_settings() {
+	return EditorSettings::get_singleton();
+}
+
+EditorResourcePreview *EditorInterface::get_resource_previewer() {
+	return EditorResourcePreview::get_singleton();
+}
+
+Control *EditorInterface::get_base_control() {
+
+	return EditorNode::get_singleton()->get_gui_base();
+}
+
+Error EditorInterface::save_scene() {
+	if (!get_edited_scene_root())
+		return ERR_CANT_CREATE;
+	if (get_edited_scene_root()->get_filename() == String())
+		return ERR_CANT_CREATE;
+
+	save_scene_as(get_edited_scene_root()->get_filename());
+	return OK;
+}
+
+void EditorInterface::save_scene_as(const String &p_scene, bool p_with_preview) {
+
+	EditorNode::get_singleton()->save_scene_to_path(p_scene, p_with_preview);
+}
+
+EditorInterface *EditorInterface::singleton = NULL;
+
+void EditorInterface::_bind_methods() {
+
+	ClassDB::bind_method(D_METHOD("inspect_object", "object", "for_property"), &EditorInterface::inspect_object, DEFVAL(String()));
+	ClassDB::bind_method(D_METHOD("get_selection"), &EditorInterface::get_selection);
+	ClassDB::bind_method(D_METHOD("get_editor_settings"), &EditorInterface::get_editor_settings);
+	ClassDB::bind_method(D_METHOD("get_script_editor"), &EditorInterface::get_script_editor);
+	ClassDB::bind_method(D_METHOD("get_base_control"), &EditorInterface::get_base_control);
+	ClassDB::bind_method(D_METHOD("edit_resource", "resource"), &EditorInterface::edit_resource);
+	ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath"), &EditorInterface::open_scene_from_path);
+	ClassDB::bind_method(D_METHOD("reload_scene_from_path", "scene_filepath"), &EditorInterface::reload_scene_from_path);
+	ClassDB::bind_method(D_METHOD("get_open_scenes"), &EditorInterface::get_open_scenes);
+	ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorInterface::get_edited_scene_root);
+	ClassDB::bind_method(D_METHOD("get_resource_previewer"), &EditorInterface::get_resource_previewer);
+	ClassDB::bind_method(D_METHOD("get_resource_filesystem"), &EditorInterface::get_resource_file_system);
+	ClassDB::bind_method(D_METHOD("get_editor_viewport"), &EditorInterface::get_editor_viewport);
+
+	ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene);
+	ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true));
+}
+
+EditorInterface::EditorInterface() {
+	singleton = this;
+}
+
+///////////////////////////////////////////
 void EditorPlugin::add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture> &p_icon) {
 
 	EditorNode::get_editor_data().add_custom_type(p_type, p_base, p_script, p_icon);
@@ -70,34 +188,6 @@ void EditorPlugin::remove_control_from_bottom_panel(Control *p_control) {
 	EditorNode::get_singleton()->remove_bottom_panel_item(p_control);
 }
 
-Control *EditorPlugin::get_editor_viewport() {
-
-	return EditorNode::get_singleton()->get_viewport();
-}
-
-void EditorPlugin::edit_resource(const Ref<Resource> &p_resource) {
-
-	EditorNode::get_singleton()->edit_resource(p_resource);
-}
-
-void EditorPlugin::open_scene_from_path(const String &scene_path) {
-
-	if (EditorNode::get_singleton()->is_changing_scene()) {
-		return;
-	}
-
-	EditorNode::get_singleton()->open_request(scene_path);
-}
-
-void EditorPlugin::reload_scene_from_path(const String &scene_path) {
-
-	if (EditorNode::get_singleton()->is_changing_scene()) {
-		return;
-	}
-
-	EditorNode::get_singleton()->reload_scene(scene_path);
-}
-
 void EditorPlugin::add_control_to_container(CustomControlContainer p_location, Control *p_control) {
 
 	switch (p_location) {
@@ -171,28 +261,6 @@ void EditorPlugin::set_input_event_forwarding_always_enabled() {
 	always_input_forwarding_list->add_plugin(this);
 }
 
-Node *EditorPlugin::get_edited_scene_root() {
-	return EditorNode::get_singleton()->get_edited_scene();
-}
-
-Array EditorPlugin::get_open_scenes() const {
-
-	Array ret;
-	Vector<EditorData::EditedScene> scenes = EditorNode::get_singleton()->get_editor_data().get_edited_scenes();
-
-	int scns_amount = scenes.size();
-	for (int idx_scn = 0; idx_scn < scns_amount; idx_scn++) {
-		if (scenes[idx_scn].root == NULL)
-			continue;
-		ret.push_back(scenes[idx_scn].root->get_filename());
-	}
-	return ret;
-}
-
-ScriptEditor *EditorPlugin::get_script_editor() {
-	return ScriptEditor::get_singleton();
-}
-
 void EditorPlugin::notify_scene_changed(const Node *scn_root) {
 	if (scn_root == NULL) return;
 	emit_signal("scene_changed", scn_root);
@@ -369,23 +437,6 @@ void EditorPlugin::queue_save_layout() const {
 	EditorNode::get_singleton()->save_layout();
 }
 
-EditorSelection *EditorPlugin::get_selection() {
-	return EditorNode::get_singleton()->get_editor_selection();
-}
-
-EditorSettings *EditorPlugin::get_editor_settings() {
-	return EditorSettings::get_singleton();
-}
-
-EditorResourcePreview *EditorPlugin::get_resource_previewer() {
-	return EditorResourcePreview::get_singleton();
-}
-
-Control *EditorPlugin::get_base_control() {
-
-	return EditorNode::get_singleton()->get_gui_base();
-}
-
 void EditorPlugin::make_bottom_panel_item_visible(Control *p_item) {
 
 	EditorNode::get_singleton()->make_bottom_panel_item_visible(p_item);
@@ -396,13 +447,8 @@ void EditorPlugin::hide_bottom_panel() {
 	EditorNode::get_singleton()->hide_bottom_panel();
 }
 
-void EditorPlugin::inspect_object(Object *p_obj, const String &p_for_property) {
-
-	EditorNode::get_singleton()->push_item(p_obj, p_for_property);
-}
-
-EditorFileSystem *EditorPlugin::get_resource_file_system() {
-	return EditorFileSystem::get_singleton();
+EditorInterface *EditorPlugin::get_editor_interface() {
+	return EditorInterface::get_singleton();
 }
 
 void EditorPlugin::_bind_methods() {
@@ -417,31 +463,19 @@ void EditorPlugin::_bind_methods() {
 	//ClassDB::bind_method(D_METHOD("remove_tool_menu_item", "name"),&EditorPlugin::remove_tool_menu_item);
 	ClassDB::bind_method(D_METHOD("add_custom_type", "type", "base", "script", "icon"), &EditorPlugin::add_custom_type);
 	ClassDB::bind_method(D_METHOD("remove_custom_type", "type"), &EditorPlugin::remove_custom_type);
-	ClassDB::bind_method(D_METHOD("get_editor_viewport"), &EditorPlugin::get_editor_viewport);
 
-	ClassDB::bind_method(D_METHOD("get_resource_previewer"), &EditorPlugin::get_resource_previewer);
-	ClassDB::bind_method(D_METHOD("get_resource_filesystem"), &EditorPlugin::get_resource_file_system);
-
-	ClassDB::bind_method(D_METHOD("inspect_object", "object", "for_property"), &EditorPlugin::inspect_object, DEFVAL(String()));
 	ClassDB::bind_method(D_METHOD("update_canvas"), &EditorPlugin::update_canvas);
 
 	ClassDB::bind_method(D_METHOD("make_bottom_panel_item_visible", "item"), &EditorPlugin::make_bottom_panel_item_visible);
 	ClassDB::bind_method(D_METHOD("hide_bottom_panel"), &EditorPlugin::hide_bottom_panel);
 
-	ClassDB::bind_method(D_METHOD("get_base_control"), &EditorPlugin::get_base_control);
 	ClassDB::bind_method(D_METHOD("get_undo_redo"), &EditorPlugin::_get_undo_redo);
-	ClassDB::bind_method(D_METHOD("get_selection"), &EditorPlugin::get_selection);
-	ClassDB::bind_method(D_METHOD("get_editor_settings"), &EditorPlugin::get_editor_settings);
-	ClassDB::bind_method(D_METHOD("get_script_editor"), &EditorPlugin::get_script_editor);
 	ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout);
-	ClassDB::bind_method(D_METHOD("edit_resource", "resource"), &EditorPlugin::edit_resource);
-	ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath"), &EditorPlugin::open_scene_from_path);
-	ClassDB::bind_method(D_METHOD("reload_scene_from_path", "scene_filepath"), &EditorPlugin::reload_scene_from_path);
 	ClassDB::bind_method(D_METHOD("add_import_plugin", "importer"), &EditorPlugin::add_import_plugin);
 	ClassDB::bind_method(D_METHOD("remove_import_plugin", "importer"), &EditorPlugin::remove_import_plugin);
 	ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled);
-	ClassDB::bind_method(D_METHOD("get_open_scenes"), &EditorPlugin::get_open_scenes);
-	ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorPlugin::get_edited_scene_root);
+
+	ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorPlugin::get_editor_interface);
 
 	ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
 	ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_draw_over_canvas", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "canvas:Control")));

+ 36 - 18
editor/editor_plugin.h

@@ -55,6 +55,40 @@ class EditorFileSystem;
 class EditorToolAddons;
 class ScriptEditor;
 
+class EditorInterface : public Node {
+	GDCLASS(EditorInterface, Node)
+protected:
+	static void _bind_methods();
+	static EditorInterface *singleton;
+
+public:
+	static EditorInterface *get_singleton() { return singleton; }
+
+	Control *get_editor_viewport();
+	void edit_resource(const Ref<Resource> &p_resource);
+	void open_scene_from_path(const String &scene_path);
+	void reload_scene_from_path(const String &scene_path);
+
+	Node *get_edited_scene_root();
+	Array get_open_scenes() const;
+	ScriptEditor *get_script_editor();
+
+	void inspect_object(Object *p_obj, const String &p_for_property = String());
+
+	EditorSelection *get_selection();
+	//EditorImportExport *get_import_export();
+	EditorSettings *get_editor_settings();
+	EditorResourcePreview *get_resource_previewer();
+	EditorFileSystem *get_resource_file_system();
+
+	Control *get_base_control();
+
+	Error save_scene();
+	void save_scene_as(const String &p_scene, bool p_with_preview = true);
+
+	EditorInterface();
+};
+
 class EditorPlugin : public Node {
 
 	GDCLASS(EditorPlugin, Node);
@@ -105,10 +139,6 @@ public:
 	void add_control_to_dock(DockSlot p_slot, Control *p_control);
 	void remove_control_from_docks(Control *p_control);
 	void remove_control_from_bottom_panel(Control *p_control);
-	Control *get_editor_viewport();
-	void edit_resource(const Ref<Resource> &p_resource);
-	void open_scene_from_path(const String &scene_path);
-	void reload_scene_from_path(const String &scene_path);
 
 	void add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud = Variant());
 	void add_tool_submenu_item(const String &p_name, Object *p_submenu);
@@ -117,10 +147,6 @@ public:
 	void set_input_event_forwarding_always_enabled();
 	bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; }
 
-	Node *get_edited_scene_root();
-	Array get_open_scenes() const;
-	ScriptEditor *get_script_editor();
-
 	void notify_main_screen_changed(const String &screen_name);
 	void notify_scene_changed(const Node *scn_root);
 	void notify_scene_closed(const String &scene_filepath);
@@ -146,23 +172,15 @@ public:
 	virtual void get_window_layout(Ref<ConfigFile> p_layout);
 	virtual void edited_scene_changed() {} // if changes are pending in editor, apply them
 
-	void update_canvas();
+	EditorInterface *get_editor_interface();
 
-	virtual void inspect_object(Object *p_obj, const String &p_for_property = String());
+	void update_canvas();
 
 	void queue_save_layout() const;
 
-	Control *get_base_control();
-
 	void make_bottom_panel_item_visible(Control *p_item);
 	void hide_bottom_panel();
 
-	EditorSelection *get_selection();
-	//EditorImportExport *get_import_export();
-	EditorSettings *get_editor_settings();
-	EditorResourcePreview *get_resource_previewer();
-	EditorFileSystem *get_resource_file_system();
-
 	virtual void restore_global_state();
 	virtual void save_global_state();
 

+ 6 - 0
editor/editor_run_script.cpp

@@ -46,6 +46,11 @@ void EditorScript::add_root_node(Node *p_node) {
 	//editor->set_edited_scene(p_node);
 }
 
+EditorInterface *EditorScript::get_editor_interface() {
+
+	return EditorInterface::get_singleton();
+}
+
 Node *EditorScript::get_scene() {
 
 	if (!editor) {
@@ -83,6 +88,7 @@ void EditorScript::_bind_methods() {
 
 	ClassDB::bind_method(D_METHOD("add_root_node", "node"), &EditorScript::add_root_node);
 	ClassDB::bind_method(D_METHOD("get_scene"), &EditorScript::get_scene);
+	ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorScript::get_editor_interface);
 	BIND_VMETHOD(MethodInfo("_run"));
 }
 

+ 2 - 2
editor/editor_run_script.h

@@ -30,8 +30,8 @@
 #ifndef EDITOR_RUN_SCRIPT_H
 #define EDITOR_RUN_SCRIPT_H
 
+#include "editor_plugin.h"
 #include "reference.h"
-
 class EditorNode;
 class EditorScript : public Reference {
 
@@ -45,7 +45,7 @@ protected:
 public:
 	void add_root_node(Node *p_node);
 	Node *get_scene();
-
+	EditorInterface *get_editor_interface();
 	virtual void _run();
 
 	void set_editor(EditorNode *p_editor);

+ 1 - 1
editor/plugins/curve_editor_plugin.cpp

@@ -775,7 +775,7 @@ CurveEditorPlugin::CurveEditorPlugin(EditorNode *p_node) {
 	_toggle_button = _editor_node->add_bottom_panel_item(get_name(), _view);
 	_toggle_button->hide();
 
-	get_resource_previewer()->add_preview_generator(memnew(CurvePreviewGenerator));
+	get_editor_interface()->get_resource_previewer()->add_preview_generator(memnew(CurvePreviewGenerator));
 }
 
 CurveEditorPlugin::~CurveEditorPlugin() {