123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- #ifndef EDITOR_PLUGIN_H
- #define EDITOR_PLUGIN_H
- #include "core/io/config_file.h"
- #include "core/undo_redo.h"
- #include "editor/editor_inspector.h"
- #include "editor/import/editor_import_plugin.h"
- #include "editor/import/resource_importer_scene.h"
- #include "editor/script_create_dialog.h"
- #include "scene/gui/tool_button.h"
- #include "scene/main/node.h"
- #include "scene/resources/texture.h"
- class EditorNode;
- class Spatial;
- class Camera;
- class EditorSelection;
- class EditorExport;
- class EditorSettings;
- class EditorImportPlugin;
- class EditorExportPlugin;
- class EditorSpatialGizmoPlugin;
- class EditorResourcePreview;
- class EditorFileSystem;
- class EditorToolAddons;
- class ScriptEditor;
- class EditorInterface : public Node {
- GDCLASS(EditorInterface, Node)
- protected:
- static void _bind_methods();
- static EditorInterface *singleton;
- Array _make_mesh_previews(const Array &p_meshes, int p_preview_size);
- 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 select_file(const String &p_file);
- String get_selected_path() const;
- void inspect_object(Object *p_obj, const String &p_for_property = String());
- EditorSelection *get_selection();
-
- EditorSettings *get_editor_settings();
- EditorResourcePreview *get_resource_previewer();
- EditorFileSystem *get_resource_file_system();
- Control *get_base_control();
- void set_plugin_enabled(const String &p_plugin, bool p_enabled);
- bool is_plugin_enabled(const String &p_plugin) const;
- Error save_scene();
- void save_scene_as(const String &p_scene, bool p_with_preview = true);
- Vector<Ref<Texture> > make_mesh_previews(const Vector<Ref<Mesh> > &p_meshes, int p_preview_size);
- EditorInterface();
- };
- class EditorPlugin : public Node {
- GDCLASS(EditorPlugin, Node);
- friend class EditorData;
- UndoRedo *undo_redo;
- UndoRedo *_get_undo_redo() { return undo_redo; }
- bool input_event_forwarding_always_enabled;
- bool force_draw_over_forwarding_enabled;
- String last_main_screen_name;
- String _dir_cache;
- protected:
- static void _bind_methods();
- UndoRedo &get_undo_redo() { return *undo_redo; }
- void add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture> &p_icon);
- void remove_custom_type(const String &p_type);
- public:
- enum CustomControlContainer {
- CONTAINER_TOOLBAR,
- CONTAINER_SPATIAL_EDITOR_MENU,
- CONTAINER_SPATIAL_EDITOR_SIDE_LEFT,
- CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT,
- CONTAINER_SPATIAL_EDITOR_BOTTOM,
- CONTAINER_CANVAS_EDITOR_MENU,
- CONTAINER_CANVAS_EDITOR_SIDE_LEFT,
- CONTAINER_CANVAS_EDITOR_SIDE_RIGHT,
- CONTAINER_CANVAS_EDITOR_BOTTOM,
- CONTAINER_PROPERTY_EDITOR_BOTTOM
- };
- 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
- };
-
- void add_control_to_container(CustomControlContainer p_location, Control *p_control);
- void remove_control_from_container(CustomControlContainer p_location, Control *p_control);
- ToolButton *add_control_to_bottom_panel(Control *p_control, const String &p_title);
- 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);
- 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);
- void set_input_event_forwarding_always_enabled();
- bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; }
- void set_force_draw_over_forwarding_enabled();
- bool is_force_draw_over_forwarding_enabled() { return force_draw_over_forwarding_enabled; }
- 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);
- void notify_resource_saved(const Ref<Resource> &p_resource);
- virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event);
- virtual void forward_canvas_draw_over_viewport(Control *p_overlay);
- virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay);
- virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event);
- virtual void forward_spatial_draw_over_viewport(Control *p_overlay);
- virtual void forward_spatial_force_draw_over_viewport(Control *p_overlay);
- virtual String get_name() const;
- virtual const Ref<Texture> get_icon() const;
- virtual bool has_main_screen() const;
- virtual void make_visible(bool p_visible);
- virtual void selected_notify() {}
- virtual void edit(Object *p_object);
- virtual bool handles(Object *p_object) const;
- virtual Dictionary get_state() const;
- virtual void set_state(const Dictionary &p_state);
- virtual void clear();
- virtual void save_external_data();
- virtual void apply_changes();
- virtual void get_breakpoints(List<String> *p_breakpoints);
- virtual bool get_remove_list(List<Node *> *p_list);
- virtual void set_window_layout(Ref<ConfigFile> p_layout);
- virtual void get_window_layout(Ref<ConfigFile> p_layout);
- virtual void edited_scene_changed() {}
- virtual bool build();
- EditorInterface *get_editor_interface();
- ScriptCreateDialog *get_script_create_dialog();
- int update_overlays() const;
- void queue_save_layout() const;
- void make_bottom_panel_item_visible(Control *p_item);
- void hide_bottom_panel();
- virtual void restore_global_state();
- virtual void save_global_state();
- void add_import_plugin(const Ref<EditorImportPlugin> &p_importer);
- void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer);
- void add_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
- void remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
- void add_spatial_gizmo_plugin(const Ref<EditorSpatialGizmoPlugin> &p_gizmo_plugin);
- void remove_spatial_gizmo_plugin(const Ref<EditorSpatialGizmoPlugin> &p_gizmo_plugin);
- void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
- void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
- void add_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
- void remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
- void add_autoload_singleton(const String &p_name, const String &p_path);
- void remove_autoload_singleton(const String &p_name);
- void set_dir_cache(const String &p_dir) { _dir_cache = p_dir; }
- String get_dir_cache() { return _dir_cache; }
- Ref<ConfigFile> get_config();
- void enable_plugin();
- void disable_plugin();
- EditorPlugin();
- virtual ~EditorPlugin();
- };
- VARIANT_ENUM_CAST(EditorPlugin::CustomControlContainer);
- VARIANT_ENUM_CAST(EditorPlugin::DockSlot);
- typedef EditorPlugin *(*EditorPluginCreateFunc)(EditorNode *);
- class EditorPlugins {
- enum {
- MAX_CREATE_FUNCS = 64
- };
- static EditorPluginCreateFunc creation_funcs[MAX_CREATE_FUNCS];
- static int creation_func_count;
- template <class T>
- static EditorPlugin *creator(EditorNode *p_node) {
- return memnew(T(p_node));
- }
- public:
- static int get_plugin_count() { return creation_func_count; }
- 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);
- }
- template <class T>
- static void add_by_type() {
- add_create_func(creator<T>);
- }
- static void add_create_func(EditorPluginCreateFunc p_func) {
- ERR_FAIL_COND(creation_func_count >= MAX_CREATE_FUNCS);
- creation_funcs[creation_func_count++] = p_func;
- }
- };
- #endif
|