2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_plugin.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
2020-01-01 18:16:22 +08:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 09:10:30 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 07:50:27 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
#ifndef EDITOR_PLUGIN_H
|
|
|
|
#define EDITOR_PLUGIN_H
|
|
|
|
|
2018-09-12 00:13:45 +08:00
|
|
|
#include "core/io/config_file.h"
|
|
|
|
#include "core/undo_redo.h"
|
2018-05-18 05:02:16 +08:00
|
|
|
#include "editor/editor_inspector.h"
|
2017-04-09 06:37:31 +08:00
|
|
|
#include "editor/import/editor_import_plugin.h"
|
2017-12-10 08:27:02 +08:00
|
|
|
#include "editor/import/resource_importer_scene.h"
|
2018-06-30 11:08:28 +08:00
|
|
|
#include "editor/script_create_dialog.h"
|
2016-07-25 03:16:02 +08:00
|
|
|
#include "scene/gui/tool_button.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
#include "scene/main/node.h"
|
|
|
|
#include "scene/resources/texture.h"
|
2016-09-11 02:32:17 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
class EditorNode;
|
2020-03-27 05:49:16 +08:00
|
|
|
class Node3D;
|
|
|
|
class Camera3D;
|
2016-02-27 11:32:00 +08:00
|
|
|
class EditorSelection;
|
2017-02-20 10:19:30 +08:00
|
|
|
class EditorExport;
|
2016-02-27 11:32:00 +08:00
|
|
|
class EditorSettings;
|
2016-02-28 10:10:44 +08:00
|
|
|
class EditorImportPlugin;
|
|
|
|
class EditorExportPlugin;
|
2020-03-27 05:49:16 +08:00
|
|
|
class EditorNode3DGizmoPlugin;
|
2016-09-11 02:32:17 +08:00
|
|
|
class EditorResourcePreview;
|
2016-09-11 04:34:27 +08:00
|
|
|
class EditorFileSystem;
|
2017-07-06 15:18:20 +08:00
|
|
|
class EditorToolAddons;
|
2020-03-17 08:40:15 +08:00
|
|
|
class FileSystemDock;
|
2017-07-06 15:18:20 +08:00
|
|
|
class ScriptEditor;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-08-26 21:32:15 +08:00
|
|
|
class EditorInterface : public Node {
|
2019-03-20 02:35:57 +08:00
|
|
|
GDCLASS(EditorInterface, Node);
|
|
|
|
|
2017-08-26 21:32:15 +08:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
static EditorInterface *singleton;
|
|
|
|
|
2017-08-28 11:03:34 +08:00
|
|
|
Array _make_mesh_previews(const Array &p_meshes, int p_preview_size);
|
|
|
|
|
2017-08-26 21:32:15 +08:00
|
|
|
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();
|
|
|
|
|
2017-12-21 04:44:16 +08:00
|
|
|
void select_file(const String &p_file);
|
|
|
|
String get_selected_path() const;
|
2019-09-01 13:51:33 +08:00
|
|
|
String get_current_path() const;
|
2017-12-21 04:44:16 +08:00
|
|
|
|
2017-08-26 21:32:15 +08:00
|
|
|
void inspect_object(Object *p_obj, const String &p_for_property = String());
|
|
|
|
|
|
|
|
EditorSelection *get_selection();
|
|
|
|
//EditorImportExport *get_import_export();
|
2019-07-03 15:49:46 +08:00
|
|
|
Ref<EditorSettings> get_editor_settings();
|
2017-08-26 21:32:15 +08:00
|
|
|
EditorResourcePreview *get_resource_previewer();
|
|
|
|
EditorFileSystem *get_resource_file_system();
|
|
|
|
|
2020-03-17 08:40:15 +08:00
|
|
|
FileSystemDock *get_file_system_dock();
|
|
|
|
|
2017-08-26 21:32:15 +08:00
|
|
|
Control *get_base_control();
|
|
|
|
|
2018-01-31 06:11:07 +08:00
|
|
|
void set_plugin_enabled(const String &p_plugin, bool p_enabled);
|
|
|
|
bool is_plugin_enabled(const String &p_plugin) const;
|
|
|
|
|
2019-03-12 14:43:48 +08:00
|
|
|
EditorInspector *get_inspector() const;
|
|
|
|
|
2017-08-26 21:32:15 +08:00
|
|
|
Error save_scene();
|
|
|
|
void save_scene_as(const String &p_scene, bool p_with_preview = true);
|
|
|
|
|
2020-03-17 14:33:00 +08:00
|
|
|
Vector<Ref<Texture2D>> make_mesh_previews(const Vector<Ref<Mesh>> &p_meshes, Vector<Transform> *p_transforms, int p_preview_size);
|
2017-08-28 11:03:34 +08:00
|
|
|
|
2019-08-06 01:57:23 +08:00
|
|
|
void set_main_screen_editor(const String &p_name);
|
|
|
|
void set_distraction_free_mode(bool p_enter);
|
|
|
|
|
2017-08-26 21:32:15 +08:00
|
|
|
EditorInterface();
|
|
|
|
};
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
class EditorPlugin : public Node {
|
2016-03-09 07:00:52 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
GDCLASS(EditorPlugin, Node);
|
|
|
|
friend class EditorData;
|
2014-02-10 09:10:30 +08:00
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
UndoRedo *_get_undo_redo() { return undo_redo; }
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-06-09 01:57:35 +08:00
|
|
|
bool input_event_forwarding_always_enabled;
|
2017-10-30 03:32:09 +08:00
|
|
|
bool force_draw_over_forwarding_enabled;
|
2017-06-09 01:57:35 +08:00
|
|
|
|
2017-07-06 15:18:20 +08:00
|
|
|
String last_main_screen_name;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2017-03-05 23:44:50 +08:00
|
|
|
UndoRedo &get_undo_redo() { return *undo_redo; }
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2019-06-12 02:43:37 +08:00
|
|
|
void add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon);
|
2017-03-05 23:44:50 +08:00
|
|
|
void remove_custom_type(const String &p_type);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum CustomControlContainer {
|
|
|
|
CONTAINER_TOOLBAR,
|
|
|
|
CONTAINER_SPATIAL_EDITOR_MENU,
|
2018-08-21 12:35:48 +08:00
|
|
|
CONTAINER_SPATIAL_EDITOR_SIDE_LEFT,
|
|
|
|
CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT,
|
2014-02-10 09:10:30 +08:00
|
|
|
CONTAINER_SPATIAL_EDITOR_BOTTOM,
|
|
|
|
CONTAINER_CANVAS_EDITOR_MENU,
|
2018-08-21 12:35:48 +08:00
|
|
|
CONTAINER_CANVAS_EDITOR_SIDE_LEFT,
|
|
|
|
CONTAINER_CANVAS_EDITOR_SIDE_RIGHT,
|
2016-05-24 04:10:26 +08:00
|
|
|
CONTAINER_CANVAS_EDITOR_BOTTOM,
|
2019-05-28 04:33:52 +08:00
|
|
|
CONTAINER_PROPERTY_EDITOR_BOTTOM,
|
|
|
|
CONTAINER_PROJECT_SETTING_TAB_LEFT,
|
|
|
|
CONTAINER_PROJECT_SETTING_TAB_RIGHT,
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
2016-02-28 10:10:44 +08:00
|
|
|
enum DockSlot {
|
|
|
|
DOCK_SLOT_LEFT_UL,
|
|
|
|
DOCK_SLOT_LEFT_BL,
|
|
|
|
DOCK_SLOT_LEFT_UR,
|
|
|
|
DOCK_SLOT_LEFT_BR,
|
|
|
|
DOCK_SLOT_RIGHT_UL,
|
|
|
|
DOCK_SLOT_RIGHT_BL,
|
|
|
|
DOCK_SLOT_RIGHT_UR,
|
|
|
|
DOCK_SLOT_RIGHT_BR,
|
|
|
|
DOCK_SLOT_MAX
|
|
|
|
};
|
|
|
|
|
2017-08-08 13:02:49 +08:00
|
|
|
//TODO: send a resource for editing to the editor node?
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-02-27 11:32:00 +08:00
|
|
|
void add_control_to_container(CustomControlContainer p_location, Control *p_control);
|
2018-02-14 05:21:19 +08:00
|
|
|
void remove_control_from_container(CustomControlContainer p_location, Control *p_control);
|
2016-07-25 03:16:02 +08:00
|
|
|
ToolButton *add_control_to_bottom_panel(Control *p_control, const String &p_title);
|
2017-03-05 23:44:50 +08:00
|
|
|
void add_control_to_dock(DockSlot p_slot, Control *p_control);
|
2016-02-28 10:10:44 +08:00
|
|
|
void remove_control_from_docks(Control *p_control);
|
2016-02-29 03:58:17 +08:00
|
|
|
void remove_control_from_bottom_panel(Control *p_control);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
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);
|
|
|
|
void remove_tool_menu_item(const String &p_name);
|
2016-08-07 22:01:22 +08:00
|
|
|
|
2017-06-09 01:57:35 +08:00
|
|
|
void set_input_event_forwarding_always_enabled();
|
|
|
|
bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; }
|
|
|
|
|
2017-10-30 03:32:09 +08:00
|
|
|
void set_force_draw_over_forwarding_enabled();
|
|
|
|
bool is_force_draw_over_forwarding_enabled() { return force_draw_over_forwarding_enabled; }
|
|
|
|
|
2017-07-06 15:18:20 +08:00
|
|
|
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);
|
2018-01-13 05:43:29 +08:00
|
|
|
void notify_resource_saved(const Ref<Resource> &p_resource);
|
2017-07-06 15:18:20 +08:00
|
|
|
|
2017-10-16 04:33:25 +08:00
|
|
|
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
|
2018-09-19 02:00:07 +08:00
|
|
|
virtual void forward_canvas_draw_over_viewport(Control *p_overlay);
|
|
|
|
virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay);
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
virtual bool forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event);
|
2018-09-19 02:00:07 +08:00
|
|
|
virtual void forward_spatial_draw_over_viewport(Control *p_overlay);
|
|
|
|
virtual void forward_spatial_force_draw_over_viewport(Control *p_overlay);
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
virtual String get_name() const;
|
2019-06-12 02:43:37 +08:00
|
|
|
virtual const Ref<Texture2D> get_icon() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
virtual bool has_main_screen() const;
|
|
|
|
virtual void make_visible(bool p_visible);
|
2017-03-05 23:44:50 +08:00
|
|
|
virtual void selected_notify() {} //notify that it was raised by the user, not the editor
|
2014-02-10 09:10:30 +08:00
|
|
|
virtual void edit(Object *p_object);
|
2017-08-13 00:52:50 +08:00
|
|
|
virtual bool handles(Object *p_object) const;
|
2014-02-10 09:10:30 +08:00
|
|
|
virtual Dictionary get_state() const; //save editor state so it can't be reloaded when reloading scene
|
2017-03-05 23:44:50 +08:00
|
|
|
virtual void set_state(const Dictionary &p_state); //restore editor state (likely was saved with the scene)
|
2018-01-19 04:37:17 +08:00
|
|
|
virtual void clear(); // clear any temporary data in the editor, reset it (likely new scene or load another scene)
|
2017-03-05 23:44:50 +08:00
|
|
|
virtual void save_external_data(); // if editor references external resources/scenes, save them
|
|
|
|
virtual void apply_changes(); // if changes are pending in editor, apply them
|
2014-02-10 09:10:30 +08:00
|
|
|
virtual void get_breakpoints(List<String> *p_breakpoints);
|
2017-03-05 23:44:50 +08:00
|
|
|
virtual bool get_remove_list(List<Node *> *p_list);
|
2015-06-22 11:03:19 +08:00
|
|
|
virtual void set_window_layout(Ref<ConfigFile> p_layout);
|
|
|
|
virtual void get_window_layout(Ref<ConfigFile> p_layout);
|
2017-03-05 23:44:50 +08:00
|
|
|
virtual void edited_scene_changed() {} // if changes are pending in editor, apply them
|
2018-01-08 23:55:22 +08:00
|
|
|
virtual bool build(); // builds with external tools. Returns true if safe to continue running scene.
|
2016-09-11 01:44:28 +08:00
|
|
|
|
2017-08-26 21:32:15 +08:00
|
|
|
EditorInterface *get_editor_interface();
|
2018-06-30 11:08:28 +08:00
|
|
|
ScriptCreateDialog *get_script_create_dialog();
|
2016-09-11 01:44:28 +08:00
|
|
|
|
2017-10-30 03:32:09 +08:00
|
|
|
int update_overlays() const;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-08-16 01:49:58 +08:00
|
|
|
void queue_save_layout() const;
|
2016-02-27 11:32:00 +08:00
|
|
|
|
2016-09-17 22:59:12 +08:00
|
|
|
void make_bottom_panel_item_visible(Control *p_item);
|
|
|
|
void hide_bottom_panel();
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
virtual void restore_global_state();
|
|
|
|
virtual void save_global_state();
|
|
|
|
|
2017-04-09 06:37:31 +08:00
|
|
|
void add_import_plugin(const Ref<EditorImportPlugin> &p_importer);
|
2017-06-11 17:18:22 +08:00
|
|
|
void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer);
|
2017-04-09 06:37:31 +08:00
|
|
|
|
2017-09-15 06:38:38 +08:00
|
|
|
void add_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
|
|
|
|
void remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
|
|
|
|
|
2020-03-27 05:49:16 +08:00
|
|
|
void add_spatial_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin);
|
|
|
|
void remove_spatial_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin);
|
2018-10-29 18:30:28 +08:00
|
|
|
|
2018-05-18 05:02:16 +08:00
|
|
|
void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
|
|
|
|
void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
|
|
|
|
|
2017-12-08 02:44:20 +08:00
|
|
|
void add_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
|
|
|
|
void remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
|
|
|
|
|
2018-02-14 12:31:38 +08:00
|
|
|
void add_autoload_singleton(const String &p_name, const String &p_path);
|
|
|
|
void remove_autoload_singleton(const String &p_name);
|
|
|
|
|
2018-06-11 08:59:53 +08:00
|
|
|
void enable_plugin();
|
|
|
|
void disable_plugin();
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
EditorPlugin();
|
|
|
|
virtual ~EditorPlugin();
|
|
|
|
};
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
VARIANT_ENUM_CAST(EditorPlugin::CustomControlContainer);
|
|
|
|
VARIANT_ENUM_CAST(EditorPlugin::DockSlot);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
typedef EditorPlugin *(*EditorPluginCreateFunc)(EditorNode *);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
class EditorPlugins {
|
|
|
|
|
|
|
|
enum {
|
2017-03-05 23:44:50 +08:00
|
|
|
MAX_CREATE_FUNCS = 64
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static EditorPluginCreateFunc creation_funcs[MAX_CREATE_FUNCS];
|
|
|
|
static int creation_func_count;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
template <class T>
|
2014-02-10 09:10:30 +08:00
|
|
|
static EditorPlugin *creator(EditorNode *p_node) {
|
2017-03-05 23:44:50 +08:00
|
|
|
return memnew(T(p_node));
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static int get_plugin_count() { return creation_func_count; }
|
2017-03-05 23:44:50 +08:00
|
|
|
static EditorPlugin *create(int p_idx, EditorNode *p_editor) {
|
|
|
|
ERR_FAIL_INDEX_V(p_idx, creation_func_count, NULL);
|
|
|
|
return creation_funcs[p_idx](p_editor);
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
template <class T>
|
2014-02-10 09:10:30 +08:00
|
|
|
static void add_by_type() {
|
|
|
|
add_create_func(creator<T>);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_create_func(EditorPluginCreateFunc p_func) {
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ERR_FAIL_COND(creation_func_count >= MAX_CREATE_FUNCS);
|
|
|
|
creation_funcs[creation_func_count++] = p_func;
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|