editor_data.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*************************************************************************/
  2. /* editor_data.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_DATA_H
  30. #define EDITOR_DATA_H
  31. #include "tools/editor/editor_plugin.h"
  32. #include "scene/resources/texture.h"
  33. #include "list.h"
  34. #include "undo_redo.h"
  35. #include "pair.h"
  36. #include "default_saver.h"
  37. class EditorHistory {
  38. enum {
  39. HISTORY_MAX=64
  40. };
  41. struct Obj {
  42. RES res;
  43. ObjectID object;
  44. String property;
  45. };
  46. struct History {
  47. Vector<Obj> path;
  48. int level;
  49. };
  50. Vector<History> history;
  51. int current;
  52. //Vector<EditorPlugin*> editor_plugins;
  53. struct PropertyData {
  54. String name;
  55. Variant value;
  56. };
  57. void _cleanup_history();
  58. void _add_object(ObjectID p_object,const String& p_property,int p_level_change);
  59. public:
  60. void add_object(ObjectID p_object);
  61. void add_object(ObjectID p_object,const String& p_subprop);
  62. void add_object(ObjectID p_object,int p_relevel);
  63. bool next();
  64. bool previous();
  65. ObjectID get_current();
  66. int get_path_size() const;
  67. ObjectID get_path_object(int p_index) const;
  68. String get_path_property(int p_index) const;
  69. void clear();
  70. EditorHistory();
  71. };
  72. class EditorData {
  73. public:
  74. struct CustomType {
  75. String name;
  76. Ref<Script> script;
  77. Ref<Texture> icon;
  78. };
  79. private:
  80. Vector<EditorPlugin*> editor_plugins;
  81. struct PropertyData {
  82. String name;
  83. Variant value;
  84. };
  85. Map<String,Vector<CustomType> > custom_types;
  86. List<PropertyData> clipboard;
  87. UndoRedo undo_redo;
  88. void _cleanup_history();
  89. public:
  90. EditorPlugin* get_editor(Object *p_object);
  91. EditorPlugin* get_subeditor(Object *p_object);
  92. EditorPlugin* get_editor(String p_name);
  93. void copy_object_params(Object *p_object);
  94. void paste_object_params(Object *p_object);
  95. Dictionary get_editor_states() const;
  96. void set_editor_states(const Dictionary& p_states);
  97. void get_editor_breakpoints(List<String> *p_breakpoints);
  98. void clear_editor_states();
  99. void save_editor_external_data();
  100. void apply_changes_in_editors();
  101. void add_editor_plugin(EditorPlugin *p_plugin);
  102. void remove_editor_plugin(EditorPlugin *p_plugin);
  103. UndoRedo &get_undo_redo();
  104. void save_editor_global_states();
  105. void restore_editor_global_states();
  106. void add_custom_type(const String& p_type, const String& p_inherits,const Ref<Script>& p_script,const Ref<Texture>& p_icon );
  107. void remove_custom_type(const String& p_type);
  108. const Map<String,Vector<CustomType> >& get_custom_types() const { return custom_types; }
  109. EditorData();
  110. };
  111. class EditorSelection : public Object {
  112. OBJ_TYPE(EditorSelection,Object);
  113. public:
  114. Map<Node*,Object*> selection;
  115. bool changed;
  116. bool nl_changed;
  117. void _node_removed(Node *p_node);
  118. List<Object*> editor_plugins;
  119. List<Node*> selected_node_list;
  120. void _update_nl();
  121. protected:
  122. static void _bind_methods();
  123. public:
  124. void add_node(Node *p_node);
  125. void remove_node(Node *p_node);
  126. bool is_selected(Node *) const;
  127. template<class T>
  128. T* get_node_editor_data(Node *p_node) {
  129. if (!selection.has(p_node))
  130. return NULL;
  131. Object *obj = selection[p_node];
  132. if (!obj)
  133. return NULL;
  134. return obj->cast_to<T>();
  135. }
  136. void add_editor_plugin(Object *p_object);
  137. void update();
  138. void clear();
  139. List<Node*>& get_selected_node_list();
  140. Map<Node*,Object*>& get_selection() { return selection; }
  141. EditorSelection();
  142. ~EditorSelection();
  143. };
  144. #endif // EDITOR_DATA_H