| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/io/config_file.h" |
| 34 |
#include "editor/docks/dock_constants.h" |
| 35 |
#include "editor/inspector/editor_context_menu_plugin.h" |
| 36 |
#include "scene/3d/camera_3d.h" |
| 37 |
#include "scene/gui/control.h" |
| 38 |
|
| 39 |
class Node3D; |
| 40 |
class Button; |
| 41 |
class PopupMenu; |
| 42 |
class EditorDebuggerPlugin; |
| 43 |
class EditorDock; |
| 44 |
class EditorExport; |
| 45 |
class EditorExportPlugin; |
| 46 |
class EditorExportPlatform; |
| 47 |
class EditorImportPlugin; |
| 48 |
class EditorInspectorPlugin; |
| 49 |
class EditorInterface; |
| 50 |
class EditorNode3DGizmoPlugin; |
| 51 |
class EditorResourceConversionPlugin; |
| 52 |
class EditorSceneFormatImporter; |
| 53 |
class EditorScenePostImportPlugin; |
| 54 |
class EditorToolAddons; |
| 55 |
class EditorTranslationParserPlugin; |
| 56 |
class EditorUndoRedoManager; |
| 57 |
class ScriptCreateDialog; |
| 58 |
|
| 59 |
class EditorPlugin : public Node { |
| 60 |
GDCLASS(EditorPlugin, Node); |
| 61 |
friend class EditorData; |
| 62 |
|
| 63 |
bool input_event_forwarding_always_enabled = false; |
| 64 |
bool force_draw_over_forwarding_enabled = false; |
| 65 |
|
| 66 |
String last_main_screen_name; |
| 67 |
String plugin_version; |
| 68 |
|
| 69 |
#ifndef DISABLE_DEPRECATED |
| 70 |
static inline HashMap<Control *, EditorDock *> legacy_docks; |
| 71 |
|
| 72 |
void _editor_project_settings_changed(); |
| 73 |
#endif |
| 74 |
|
| 75 |
public: |
| 76 |
enum CustomControlContainer { |
| 77 |
CONTAINER_TOOLBAR, |
| 78 |
CONTAINER_SPATIAL_EDITOR_MENU, |
| 79 |
CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, |
| 80 |
CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, |
| 81 |
CONTAINER_SPATIAL_EDITOR_BOTTOM, |
| 82 |
CONTAINER_CANVAS_EDITOR_MENU, |
| 83 |
CONTAINER_CANVAS_EDITOR_SIDE_LEFT, |
| 84 |
CONTAINER_CANVAS_EDITOR_SIDE_RIGHT, |
| 85 |
CONTAINER_CANVAS_EDITOR_BOTTOM, |
| 86 |
CONTAINER_INSPECTOR_BOTTOM, |
| 87 |
CONTAINER_PROJECT_SETTING_TAB_LEFT, |
| 88 |
CONTAINER_PROJECT_SETTING_TAB_RIGHT, |
| 89 |
}; |
| 90 |
|
| 91 |
enum DockSlot { |
| 92 |
DOCK_SLOT_NONE = DockConstants::DOCK_SLOT_NONE, |
| 93 |
DOCK_SLOT_LEFT_UL = DockConstants::DOCK_SLOT_LEFT_UL, |
| 94 |
DOCK_SLOT_LEFT_BL = DockConstants::DOCK_SLOT_LEFT_BL, |
| 95 |
DOCK_SLOT_LEFT_UR = DockConstants::DOCK_SLOT_LEFT_UR, |
| 96 |
DOCK_SLOT_LEFT_BR = DockConstants::DOCK_SLOT_LEFT_BR, |
| 97 |
DOCK_SLOT_RIGHT_UL = DockConstants::DOCK_SLOT_RIGHT_UL, |
| 98 |
DOCK_SLOT_RIGHT_BL = DockConstants::DOCK_SLOT_RIGHT_BL, |
| 99 |
DOCK_SLOT_RIGHT_UR = DockConstants::DOCK_SLOT_RIGHT_UR, |
| 100 |
DOCK_SLOT_RIGHT_BR = DockConstants::DOCK_SLOT_RIGHT_BR, |
| 101 |
DOCK_SLOT_BOTTOM = DockConstants::DOCK_SLOT_BOTTOM, |
| 102 |
DOCK_SLOT_MAX = DockConstants::DOCK_SLOT_MAX |
| 103 |
}; |
| 104 |
|
| 105 |
enum AfterGUIInput { |
| 106 |
AFTER_GUI_INPUT_PASS, |
| 107 |
AFTER_GUI_INPUT_STOP, |
| 108 |
AFTER_GUI_INPUT_CUSTOM, |
| 109 |
}; |
| 110 |
|
| 111 |
protected: |
| 112 |
void _notification(int p_what); |
| 113 |
|
| 114 |
static void _bind_methods(); |
| 115 |
EditorUndoRedoManager *get_undo_redo(); |
| 116 |
|
| 117 |
void add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon); |
| 118 |
void remove_custom_type(const String &p_type); |
| 119 |
|
| 120 |
GDVIRTUAL1R(bool, _forward_canvas_gui_input, Ref<InputEvent>) |
| 121 |
GDVIRTUAL1(_forward_canvas_draw_over_viewport, Control *) |
| 122 |
GDVIRTUAL1(_forward_canvas_force_draw_over_viewport, Control *) |
| 123 |
GDVIRTUAL2R(int, _forward_3d_gui_input, Camera3D *, Ref<InputEvent>) |
| 124 |
GDVIRTUAL1(_forward_3d_draw_over_viewport, Control *) |
| 125 |
GDVIRTUAL1(_forward_3d_force_draw_over_viewport, Control *) |
| 126 |
GDVIRTUAL0RC(String, _get_plugin_name) |
| 127 |
GDVIRTUAL0RC(Ref<Texture2D>, _get_plugin_icon) |
| 128 |
GDVIRTUAL0RC(bool, _has_main_screen) |
| 129 |
GDVIRTUAL1(_make_visible, bool) |
| 130 |
GDVIRTUAL1(_edit, Object *) |
| 131 |
GDVIRTUAL1RC(bool, _handles, Object *) |
| 132 |
GDVIRTUAL0RC(Dictionary, _get_state) |
| 133 |
GDVIRTUAL1(_set_state, Dictionary) |
| 134 |
GDVIRTUAL0(_clear) |
| 135 |
GDVIRTUAL1RC(String, _get_unsaved_status, String) |
| 136 |
GDVIRTUAL0(_save_external_data) |
| 137 |
GDVIRTUAL0(_apply_changes) |
| 138 |
GDVIRTUAL0RC(Vector<String>, _get_breakpoints) |
| 139 |
GDVIRTUAL1(_set_window_layout, Ref<ConfigFile>) |
| 140 |
GDVIRTUAL1(_get_window_layout, Ref<ConfigFile>) |
| 141 |
GDVIRTUAL0R(bool, _build) |
| 142 |
GDVIRTUAL2RC(Vector<String>, _run_scene, String, Vector<String>) |
| 143 |
GDVIRTUAL0(_enable_plugin) |
| 144 |
GDVIRTUAL0(_disable_plugin) |
| 145 |
|
| 146 |
#ifndef DISABLE_DEPRECATED |
| 147 |
Button *_add_control_to_bottom_panel_compat_88081(Control *p_control, const String &p_title); |
| 148 |
void _add_control_to_dock_compat_88081(DockSlot p_slot, Control *p_control); |
| 149 |
static void _bind_compatibility_methods(); |
| 150 |
|
| 151 |
void add_control_to_dock(DockSlot p_slot, Control *p_control, const Ref<Shortcut> &p_shortcut = nullptr); |
| 152 |
void remove_control_from_docks(Control *p_control); |
| 153 |
void set_dock_tab_icon(Control *p_control, const Ref<Texture2D> &p_icon); |
| 154 |
|
| 155 |
Button *add_control_to_bottom_panel(Control *p_control, const String &p_title, const Ref<Shortcut> &p_shortcut = nullptr); |
| 156 |
void remove_control_from_bottom_panel(Control *p_control); |
| 157 |
#endif |
| 158 |
|
| 159 |
public: |
| 160 |
|
| 161 |
|
| 162 |
void add_control_to_container(CustomControlContainer p_location, Control *p_control); |
| 163 |
void remove_control_from_container(CustomControlContainer p_location, Control *p_control); |
| 164 |
|
| 165 |
void add_dock(EditorDock *p_dock); |
| 166 |
void remove_dock(EditorDock *p_dock); |
| 167 |
|
| 168 |
void add_tool_menu_item(const String &p_name, const Callable &p_callable); |
| 169 |
void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu); |
| 170 |
void remove_tool_menu_item(const String &p_name); |
| 171 |
|
| 172 |
PopupMenu *get_export_as_menu(); |
| 173 |
|
| 174 |
void set_input_event_forwarding_always_enabled(); |
| 175 |
bool is_input_event_forwarding_always_enabled() { return input_event_forwarding_always_enabled; } |
| 176 |
|
| 177 |
void set_force_draw_over_forwarding_enabled(); |
| 178 |
bool is_force_draw_over_forwarding_enabled() { return force_draw_over_forwarding_enabled; } |
| 179 |
|
| 180 |
void notify_main_screen_changed(const String &screen_name); |
| 181 |
void notify_scene_changed(const Node *scn_root); |
| 182 |
void notify_scene_closed(const String &scene_filepath); |
| 183 |
void notify_resource_saved(const Ref<Resource> &p_resource); |
| 184 |
void notify_scene_saved(const String &p_scene_filepath); |
| 185 |
|
| 186 |
virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event); |
| 187 |
virtual void forward_canvas_draw_over_viewport(Control *p_overlay); |
| 188 |
virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay); |
| 189 |
|
| 190 |
virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event); |
| 191 |
virtual void forward_3d_draw_over_viewport(Control *p_overlay); |
| 192 |
virtual void forward_3d_force_draw_over_viewport(Control *p_overlay); |
| 193 |
|
| 194 |
virtual String get_plugin_name() const; |
| 195 |
virtual const Ref<Texture2D> get_plugin_icon() const; |
| 196 |
virtual String get_plugin_version() const; |
| 197 |
virtual void set_plugin_version(const String &p_version); |
| 198 |
virtual bool has_main_screen() const; |
| 199 |
virtual void make_visible(bool p_visible); |
| 200 |
virtual void selected_notify() {} |
| 201 |
virtual void edit(Object *p_object); |
| 202 |
virtual bool handles(Object *p_object) const; |
| 203 |
virtual bool can_auto_hide() const; |
| 204 |
virtual Dictionary get_state() const; |
| 205 |
virtual void set_state(const Dictionary &p_state); |
| 206 |
virtual void clear(); |
| 207 |
virtual String get_unsaved_status(const String &p_for_scene = "") const; |
| 208 |
virtual void save_external_data(); |
| 209 |
virtual void apply_changes(); |
| 210 |
virtual void get_breakpoints(List<String> *p_breakpoints); |
| 211 |
virtual bool get_remove_list(List<Node *> *p_list); |
| 212 |
virtual void set_window_layout(Ref<ConfigFile> p_layout); |
| 213 |
virtual void get_window_layout(Ref<ConfigFile> p_layout); |
| 214 |
virtual void edited_scene_changed() {} |
| 215 |
virtual bool build(); |
| 216 |
virtual void run_scene(const String &p_scene, Vector<String> &r_args); |
| 217 |
|
| 218 |
EditorInterface *get_editor_interface(); |
| 219 |
ScriptCreateDialog *get_script_create_dialog(); |
| 220 |
|
| 221 |
void add_undo_redo_inspector_hook_callback(Callable p_callable); |
| 222 |
void remove_undo_redo_inspector_hook_callback(Callable p_callable); |
| 223 |
|
| 224 |
int update_overlays() const; |
| 225 |
|
| 226 |
void queue_save_layout(); |
| 227 |
|
| 228 |
void make_bottom_panel_item_visible(Control *p_item); |
| 229 |
void hide_bottom_panel(); |
| 230 |
|
| 231 |
void add_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser); |
| 232 |
void remove_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser); |
| 233 |
|
| 234 |
void add_import_plugin(const Ref<EditorImportPlugin> &p_importer, bool p_first_priority = false); |
| 235 |
void remove_import_plugin(const Ref<EditorImportPlugin> &p_importer); |
| 236 |
|
| 237 |
void add_export_plugin(const Ref<EditorExportPlugin> &p_exporter); |
| 238 |
void remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter); |
| 239 |
|
| 240 |
void add_export_platform(const Ref<EditorExportPlatform> &p_platform); |
| 241 |
void remove_export_platform(const Ref<EditorExportPlatform> &p_platform); |
| 242 |
|
| 243 |
void add_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin); |
| 244 |
void remove_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin); |
| 245 |
|
| 246 |
void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin); |
| 247 |
void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin); |
| 248 |
|
| 249 |
void add_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer, bool p_first_priority = false); |
| 250 |
void remove_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer); |
| 251 |
|
| 252 |
void add_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_importer, bool p_first_priority = false); |
| 253 |
void remove_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_importer); |
| 254 |
|
| 255 |
void add_autoload_singleton(const String &p_name, const String &p_path); |
| 256 |
void remove_autoload_singleton(const String &p_name); |
| 257 |
|
| 258 |
void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin); |
| 259 |
void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin); |
| 260 |
|
| 261 |
void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin); |
| 262 |
void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin); |
| 263 |
|
| 264 |
void add_context_menu_plugin(EditorContextMenuPlugin::ContextMenuSlot p_slot, const Ref<EditorContextMenuPlugin> &p_plugin); |
| 265 |
void remove_context_menu_plugin(const Ref<EditorContextMenuPlugin> &p_plugin); |
| 266 |
|
| 267 |
void enable_plugin(); |
| 268 |
void disable_plugin(); |
| 269 |
}; |
| 270 |
|
| 271 |
VARIANT_ENUM_CAST(EditorPlugin::CustomControlContainer); |
| 272 |
VARIANT_ENUM_CAST(EditorPlugin::DockSlot); |
| 273 |
VARIANT_ENUM_CAST(EditorPlugin::AfterGUIInput); |
| 274 |
|
| 275 |
typedef EditorPlugin *(*EditorPluginCreateFunc)(); |
| 276 |
|
| 277 |
class EditorPlugins { |
| 278 |
enum { |
| 279 |
MAX_CREATE_FUNCS = 128 |
| 280 |
}; |
| 281 |
|
| 282 |
static EditorPluginCreateFunc creation_funcs[MAX_CREATE_FUNCS]; |
| 283 |
static int creation_func_count; |
| 284 |
|
| 285 |
template <typename T> |
| 286 |
static EditorPlugin *creator() { |
| 287 |
return memnew(T); |
| 288 |
} |
| 289 |
|
| 290 |
public: |
| 291 |
static int get_plugin_count() { return creation_func_count; } |
| 292 |
static EditorPlugin *create(int p_idx) { |
| 293 |
ERR_FAIL_INDEX_V(p_idx, creation_func_count, nullptr); |
| 294 |
return creation_funcs[p_idx](); |
| 295 |
} |
| 296 |
|
| 297 |
template <typename T> |
| 298 |
static void add_by_type() { |
| 299 |
add_create_func(creator<T>); |
| 300 |
} |
| 301 |
|
| 302 |
static void add_create_func(EditorPluginCreateFunc p_func) { |
| 303 |
ERR_FAIL_COND(creation_func_count >= MAX_CREATE_FUNCS); |
| 304 |
creation_funcs[creation_func_count++] = p_func; |
| 305 |
} |
| 306 |
}; |