2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_plugin.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef EDITOR_PLUGIN_H
|
|
|
|
#define EDITOR_PLUGIN_H
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
#include "io/config_file.h"
|
2016-07-24 21:16:02 +02:00
|
|
|
#include "scene/gui/tool_button.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/main/node.h"
|
|
|
|
#include "scene/resources/texture.h"
|
|
|
|
#include "undo_redo.h"
|
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
class EditorNode;
|
|
|
|
class Spatial;
|
|
|
|
class Camera;
|
2016-02-27 04:32:00 +01:00
|
|
|
class EditorSelection;
|
|
|
|
class EditorImportExport;
|
|
|
|
class EditorSettings;
|
2016-02-28 03:10:44 +01:00
|
|
|
class SpatialEditorGizmo;
|
|
|
|
class EditorImportPlugin;
|
|
|
|
class EditorExportPlugin;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class EditorPlugin : public Node {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
OBJ_TYPE(EditorPlugin, Node);
|
|
|
|
friend class EditorData;
|
2014-02-10 02:10:30 +01:00
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
UndoRedo *_get_undo_redo() { return undo_redo; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2017-03-19 00:36:26 +01:00
|
|
|
UndoRedo &get_undo_redo() { return *undo_redo; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
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);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum CustomControlContainer {
|
|
|
|
CONTAINER_TOOLBAR,
|
|
|
|
CONTAINER_SPATIAL_EDITOR_MENU,
|
|
|
|
CONTAINER_SPATIAL_EDITOR_SIDE,
|
|
|
|
CONTAINER_SPATIAL_EDITOR_BOTTOM,
|
|
|
|
CONTAINER_CANVAS_EDITOR_MENU,
|
2015-01-12 00:52:42 +01:00
|
|
|
CONTAINER_CANVAS_EDITOR_SIDE,
|
2016-05-23 22:10:26 +02:00
|
|
|
CONTAINER_CANVAS_EDITOR_BOTTOM,
|
|
|
|
CONTAINER_PROPERTY_EDITOR_BOTTOM
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2016-02-28 03:10:44 +01: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
|
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
//TODO: send a resoucre for editing to the editor node?
|
|
|
|
|
2016-02-27 04:32:00 +01:00
|
|
|
void add_control_to_container(CustomControlContainer p_location, Control *p_control);
|
2016-07-24 21:16:02 +02:00
|
|
|
ToolButton *add_control_to_bottom_panel(Control *p_control, const String &p_title);
|
2017-03-19 00:36:26 +01:00
|
|
|
void add_control_to_dock(DockSlot p_slot, Control *p_control);
|
2016-02-28 03:10:44 +01:00
|
|
|
void remove_control_from_docks(Control *p_control);
|
2016-02-28 20:58:17 +01:00
|
|
|
void remove_control_from_bottom_panel(Control *p_control);
|
2017-03-19 00:36:26 +01:00
|
|
|
Control *get_editor_viewport();
|
|
|
|
void edit_resource(const Ref<Resource> &p_resource);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
|
|
|
|
virtual bool forward_input_event(const InputEvent &p_event);
|
|
|
|
virtual bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event);
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual String get_name() const;
|
|
|
|
virtual bool has_main_screen() const;
|
|
|
|
virtual void make_visible(bool p_visible);
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void selected_notify() {} //notify that it was raised by the user, not the editor
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void edit(Object *p_object);
|
|
|
|
virtual bool handles(Object *p_node) const;
|
|
|
|
virtual Dictionary get_state() const; //save editor state so it can't be reloaded when reloading scene
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual void set_state(const Dictionary &p_state); //restore editor state (likely was saved with the scene)
|
|
|
|
virtual void clear(); // clear any temporary data in te editor, reset it (likely new scene or load another scene)
|
|
|
|
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 02:10:30 +01:00
|
|
|
virtual void get_breakpoints(List<String> *p_breakpoints);
|
2017-03-19 00:36:26 +01:00
|
|
|
virtual bool get_remove_list(List<Node *> *p_list);
|
2015-06-22 05:03:19 +02:00
|
|
|
virtual void set_window_layout(Ref<ConfigFile> p_layout);
|
|
|
|
virtual void get_window_layout(Ref<ConfigFile> p_layout);
|
2015-12-09 13:08:41 +01:00
|
|
|
virtual void edited_scene_changed(){}; // if changes are pending in editor, apply them
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-08-15 19:49:58 +02:00
|
|
|
void queue_save_layout() const;
|
2016-02-27 04:32:00 +01:00
|
|
|
|
2016-02-28 03:10:44 +01:00
|
|
|
Control *get_base_control();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void add_import_plugin(const Ref<EditorImportPlugin> &p_editor_import);
|
|
|
|
void remove_import_plugin(const Ref<EditorImportPlugin> &p_editor_import);
|
2016-02-28 03:10:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void add_export_plugin(const Ref<EditorExportPlugin> &p_editor_export);
|
|
|
|
void remove_export_plugin(const Ref<EditorExportPlugin> &p_editor_export);
|
2016-02-28 03:10:44 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
EditorSelection *get_selection();
|
2016-02-28 03:10:44 +01:00
|
|
|
//EditorImportExport *get_import_export();
|
2016-02-27 04:32:00 +01:00
|
|
|
EditorSettings *get_editor_settings();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void restore_global_state();
|
|
|
|
virtual void save_global_state();
|
|
|
|
|
|
|
|
EditorPlugin();
|
|
|
|
virtual ~EditorPlugin();
|
|
|
|
};
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
VARIANT_ENUM_CAST(EditorPlugin::CustomControlContainer);
|
|
|
|
VARIANT_ENUM_CAST(EditorPlugin::DockSlot);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
typedef EditorPlugin *(*EditorPluginCreateFunc)(EditorNode *);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class EditorPlugins {
|
|
|
|
|
|
|
|
enum {
|
2017-03-19 00:36:26 +01:00
|
|
|
MAX_CREATE_FUNCS = 64
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static EditorPluginCreateFunc creation_funcs[MAX_CREATE_FUNCS];
|
|
|
|
static int creation_func_count;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
template <class T>
|
2014-02-10 02:10:30 +01:00
|
|
|
static EditorPlugin *creator(EditorNode *p_node) {
|
2017-03-19 00:36:26 +01:00
|
|
|
return memnew(T(p_node));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static int get_plugin_count() { return creation_func_count; }
|
2017-03-19 00:36:26 +01: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 02:10:30 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
template <class T>
|
2014-02-10 02:10:30 +01:00
|
|
|
static void add_by_type() {
|
|
|
|
add_create_func(creator<T>);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_create_func(EditorPluginCreateFunc p_func) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_COND(creation_func_count >= MAX_CREATE_FUNCS);
|
|
|
|
creation_funcs[creation_func_count++] = p_func;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|