editor_plugin.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*************************************************************************/
  2. /* editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef EDITOR_PLUGIN_H
  30. #define EDITOR_PLUGIN_H
  31. #include "scene/main/node.h"
  32. #include "scene/resources/texture.h"
  33. #include "undo_redo.h"
  34. /**
  35. @author Juan Linietsky <[email protected]>
  36. */
  37. class EditorNode;
  38. class Spatial;
  39. class Camera;
  40. class EditorPlugin : public Node {
  41. OBJ_TYPE( EditorPlugin, Node );
  42. friend class EditorData;
  43. UndoRedo *undo_redo;
  44. UndoRedo* _get_undo_redo() { return undo_redo; }
  45. protected:
  46. static void _bind_methods();
  47. UndoRedo& get_undo_redo() { return *undo_redo; }
  48. void add_custom_type(const String& p_type, const String& p_base,const Ref<Script>& p_script, const Ref<Texture>& p_icon);
  49. void remove_custom_type(const String& p_type);
  50. public:
  51. enum CustomControlContainer {
  52. CONTAINER_TOOLBAR,
  53. CONTAINER_SPATIAL_EDITOR_MENU,
  54. CONTAINER_SPATIAL_EDITOR_SIDE,
  55. CONTAINER_SPATIAL_EDITOR_BOTTOM,
  56. CONTAINER_CANVAS_EDITOR_MENU,
  57. CONTAINER_CANVAS_EDITOR_SIDE
  58. };
  59. //TODO: send a resoucre for editing to the editor node?
  60. void add_custom_control(CustomControlContainer p_location,Control *p_control);
  61. virtual bool create_spatial_gizmo(Spatial* p_spatial);
  62. virtual bool forward_input_event(const InputEvent& p_event);
  63. virtual bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event);
  64. virtual String get_name() const;
  65. virtual bool has_main_screen() const;
  66. virtual void make_visible(bool p_visible);
  67. virtual void selected_notify() {}//notify that it was raised by the user, not the editor
  68. virtual void edit(Object *p_object);
  69. virtual bool handles(Object *p_node) const;
  70. virtual Dictionary get_state() const; //save editor state so it can't be reloaded when reloading scene
  71. virtual void set_state(const Dictionary& p_state) ; //restore editor state (likely was saved with the scene)
  72. virtual void clear() ; // clear any temporary data in te editor, reset it (likely new scene or load another scene)
  73. virtual void save_external_data() ; // if editor references external resources/scenes, save them
  74. virtual void apply_changes() ; // if changes are pending in editor, apply them
  75. virtual void get_breakpoints(List<String> *p_breakpoints);
  76. virtual bool get_remove_list(List<Node*> *p_list);
  77. virtual void restore_global_state();
  78. virtual void save_global_state();
  79. EditorPlugin();
  80. virtual ~EditorPlugin();
  81. };
  82. VARIANT_ENUM_CAST( EditorPlugin::CustomControlContainer );
  83. typedef EditorPlugin* (*EditorPluginCreateFunc)(EditorNode *);
  84. class EditorPlugins {
  85. enum {
  86. MAX_CREATE_FUNCS=64
  87. };
  88. static EditorPluginCreateFunc creation_funcs[MAX_CREATE_FUNCS];
  89. static int creation_func_count;
  90. template<class T>
  91. static EditorPlugin *creator(EditorNode *p_node) {
  92. return memnew( T(p_node) );
  93. }
  94. public:
  95. static int get_plugin_count() { return creation_func_count; }
  96. 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); }
  97. template<class T>
  98. static void add_by_type() {
  99. add_create_func(creator<T>);
  100. }
  101. static void add_create_func(EditorPluginCreateFunc p_func) {
  102. ERR_FAIL_COND(creation_func_count>=MAX_CREATE_FUNCS);
  103. creation_funcs[creation_func_count++]=p_func;
  104. }
  105. };
  106. #endif