editor_data.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*************************************************************************/
  2. /* editor_data.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef EDITOR_DATA_H
  31. #define EDITOR_DATA_H
  32. #include "editor/editor_plugin.h"
  33. #include "editor/plugins/script_editor_plugin.h"
  34. #include "list.h"
  35. #include "pair.h"
  36. #include "scene/resources/texture.h"
  37. #include "undo_redo.h"
  38. class EditorHistory {
  39. enum {
  40. HISTORY_MAX = 64
  41. };
  42. struct Obj {
  43. REF ref;
  44. ObjectID object;
  45. String property;
  46. };
  47. struct History {
  48. Vector<Obj> path;
  49. int level;
  50. };
  51. friend class EditorData;
  52. Vector<History> history;
  53. int current;
  54. //Vector<EditorPlugin*> editor_plugins;
  55. struct PropertyData {
  56. String name;
  57. Variant value;
  58. };
  59. void _cleanup_history();
  60. void _add_object(ObjectID p_object, const String &p_property, int p_level_change);
  61. public:
  62. bool is_at_beginning() const;
  63. bool is_at_end() const;
  64. void add_object(ObjectID p_object);
  65. void add_object(ObjectID p_object, const String &p_subprop);
  66. void add_object(ObjectID p_object, int p_relevel);
  67. int get_history_len();
  68. int get_history_pos();
  69. ObjectID get_history_obj(int p_obj) const;
  70. bool next();
  71. bool previous();
  72. ObjectID get_current();
  73. int get_path_size() const;
  74. ObjectID get_path_object(int p_index) const;
  75. String get_path_property(int p_index) const;
  76. void clear();
  77. EditorHistory();
  78. };
  79. class EditorSelection;
  80. class EditorData {
  81. public:
  82. struct CustomType {
  83. String name;
  84. Ref<Script> script;
  85. Ref<Texture> icon;
  86. };
  87. struct EditedScene {
  88. Node *root;
  89. Dictionary editor_states;
  90. List<Node *> selection;
  91. Vector<EditorHistory::History> history_stored;
  92. int history_current;
  93. Dictionary custom_state;
  94. uint64_t version;
  95. NodePath live_edit_root;
  96. };
  97. private:
  98. Vector<EditorPlugin *> editor_plugins;
  99. struct PropertyData {
  100. String name;
  101. Variant value;
  102. };
  103. Map<String, Vector<CustomType> > custom_types;
  104. List<PropertyData> clipboard;
  105. UndoRedo undo_redo;
  106. void _cleanup_history();
  107. Vector<EditedScene> edited_scene;
  108. int current_edited_scene;
  109. bool _find_updated_instances(Node *p_root, Node *p_node, Set<String> &checked_paths);
  110. public:
  111. EditorPlugin *get_editor(Object *p_object);
  112. EditorPlugin *get_subeditor(Object *p_object);
  113. Vector<EditorPlugin *> get_subeditors(Object *p_object);
  114. EditorPlugin *get_editor(String p_name);
  115. void copy_object_params(Object *p_object);
  116. void paste_object_params(Object *p_object);
  117. Dictionary get_editor_states() const;
  118. Dictionary get_scene_editor_states(int p_idx) const;
  119. void set_editor_states(const Dictionary &p_states);
  120. void get_editor_breakpoints(List<String> *p_breakpoints);
  121. void clear_editor_states();
  122. void save_editor_external_data();
  123. void apply_changes_in_editors();
  124. void add_editor_plugin(EditorPlugin *p_plugin);
  125. void remove_editor_plugin(EditorPlugin *p_plugin);
  126. int get_editor_plugin_count() const;
  127. EditorPlugin *get_editor_plugin(int p_idx);
  128. UndoRedo &get_undo_redo();
  129. void save_editor_global_states();
  130. void restore_editor_global_states();
  131. void add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture> &p_icon);
  132. void remove_custom_type(const String &p_type);
  133. const Map<String, Vector<CustomType> > &get_custom_types() const { return custom_types; }
  134. int add_edited_scene(int p_at_pos);
  135. void move_edited_scene_index(int p_idx, int p_to_idx);
  136. void remove_scene(int p_idx);
  137. void set_edited_scene(int p_idx);
  138. void set_edited_scene_root(Node *p_root);
  139. int get_edited_scene() const;
  140. Node *get_edited_scene_root(int p_idx = -1);
  141. int get_edited_scene_count() const;
  142. Vector<EditedScene> get_edited_scenes() const;
  143. String get_scene_title(int p_idx) const;
  144. String get_scene_path(int p_idx) const;
  145. String get_scene_type(int p_idx) const;
  146. Ref<Script> get_scene_root_script(int p_idx) const;
  147. void set_edited_scene_version(uint64_t version, int p_scene_idx = -1);
  148. uint64_t get_edited_scene_version() const;
  149. uint64_t get_scene_version(int p_idx) const;
  150. void clear_edited_scenes();
  151. void set_edited_scene_live_edit_root(const NodePath &p_root);
  152. NodePath get_edited_scene_live_edit_root();
  153. bool check_and_update_scene(int p_idx);
  154. void move_edited_scene_to_index(int p_idx);
  155. void set_plugin_window_layout(Ref<ConfigFile> p_layout);
  156. void get_plugin_window_layout(Ref<ConfigFile> p_layout);
  157. void save_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history, const Dictionary &p_custom);
  158. Dictionary restore_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history);
  159. void notify_edited_scene_changed();
  160. EditorData();
  161. };
  162. class EditorSelection : public Object {
  163. GDCLASS(EditorSelection, Object);
  164. public:
  165. Map<Node *, Object *> selection;
  166. bool changed;
  167. bool nl_changed;
  168. void _node_removed(Node *p_node);
  169. List<Object *> editor_plugins;
  170. List<Node *> selected_node_list;
  171. void _update_nl();
  172. Array _get_selected_nodes();
  173. Array _get_transformable_selected_nodes();
  174. protected:
  175. static void _bind_methods();
  176. public:
  177. void add_node(Node *p_node);
  178. void remove_node(Node *p_node);
  179. bool is_selected(Node *) const;
  180. template <class T>
  181. T *get_node_editor_data(Node *p_node) {
  182. if (!selection.has(p_node))
  183. return NULL;
  184. return Object::cast_to<T>(selection[p_node]);
  185. }
  186. void add_editor_plugin(Object *p_object);
  187. void update();
  188. void clear();
  189. List<Node *> &get_selected_node_list();
  190. Map<Node *, Object *> &get_selection() { return selection; }
  191. EditorSelection();
  192. ~EditorSelection();
  193. };
  194. #endif // EDITOR_DATA_H