editor_data.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*************************************************************************/
  2. /* editor_data.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 "list.h"
  34. #include "pair.h"
  35. #include "scene/resources/texture.h"
  36. #include "undo_redo.h"
  37. class EditorHistory {
  38. enum {
  39. HISTORY_MAX = 64
  40. };
  41. struct Obj {
  42. REF ref;
  43. ObjectID object;
  44. String property;
  45. };
  46. struct History {
  47. Vector<Obj> path;
  48. int level;
  49. };
  50. friend class EditorData;
  51. Vector<History> history;
  52. int current;
  53. //Vector<EditorPlugin*> editor_plugins;
  54. struct PropertyData {
  55. String name;
  56. Variant value;
  57. };
  58. void _cleanup_history();
  59. void _add_object(ObjectID p_object, const String &p_property, int p_level_change);
  60. public:
  61. bool is_at_begining() const;
  62. bool is_at_end() const;
  63. void add_object(ObjectID p_object);
  64. void add_object(ObjectID p_object, const String &p_subprop);
  65. void add_object(ObjectID p_object, int p_relevel);
  66. int get_history_len();
  67. int get_history_pos();
  68. ObjectID get_history_obj(int p_obj) const;
  69. bool next();
  70. bool previous();
  71. ObjectID get_current();
  72. int get_path_size() const;
  73. ObjectID get_path_object(int p_index) const;
  74. String get_path_property(int p_index) const;
  75. void clear();
  76. EditorHistory();
  77. };
  78. class EditorSelection;
  79. class EditorData {
  80. public:
  81. struct CustomType {
  82. String name;
  83. Ref<Script> script;
  84. Ref<Texture> icon;
  85. };
  86. private:
  87. Vector<EditorPlugin *> editor_plugins;
  88. struct PropertyData {
  89. String name;
  90. Variant value;
  91. };
  92. Map<String, Vector<CustomType> > custom_types;
  93. List<PropertyData> clipboard;
  94. UndoRedo undo_redo;
  95. void _cleanup_history();
  96. struct EditedScene {
  97. Node *root;
  98. Dictionary editor_states;
  99. Ref<ResourceImportMetadata> medatata;
  100. List<Node *> selection;
  101. Vector<EditorHistory::History> history_stored;
  102. int history_current;
  103. Dictionary custom_state;
  104. uint64_t version;
  105. NodePath live_edit_root;
  106. };
  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. void set_edited_scene_import_metadata(Ref<ResourceImportMetadata> p_mdata);
  140. Ref<ResourceImportMetadata> get_edited_scene_import_metadata(int p_idx = -1) const;
  141. int get_edited_scene() const;
  142. Node *get_edited_scene_root(int p_idx = -1);
  143. int get_edited_scene_count() const;
  144. String get_scene_title(int p_idx) const;
  145. String get_scene_path(int p_idx) const;
  146. String get_scene_type(int p_idx) const;
  147. Ref<Script> get_scene_root_script(int p_idx) const;
  148. void set_edited_scene_version(uint64_t version, int p_scene_idx = -1);
  149. uint64_t get_edited_scene_version() const;
  150. uint64_t get_scene_version(int p_idx) const;
  151. void clear_edited_scenes();
  152. void set_edited_scene_live_edit_root(const NodePath &p_root);
  153. NodePath get_edited_scene_live_edit_root();
  154. bool check_and_update_scene(int p_idx);
  155. void move_edited_scene_to_index(int p_idx);
  156. void set_plugin_window_layout(Ref<ConfigFile> p_layout);
  157. void get_plugin_window_layout(Ref<ConfigFile> p_layout);
  158. void save_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history, const Dictionary &p_custom);
  159. Dictionary restore_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history);
  160. void notify_edited_scene_changed();
  161. EditorData();
  162. };
  163. class EditorSelection : public Object {
  164. OBJ_TYPE(EditorSelection, Object);
  165. public:
  166. Map<Node *, Object *> selection;
  167. bool changed;
  168. bool nl_changed;
  169. void _node_removed(Node *p_node);
  170. List<Object *> editor_plugins;
  171. List<Node *> selected_node_list;
  172. void _update_nl();
  173. Array _get_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. Object *obj = selection[p_node];
  185. if (!obj)
  186. return NULL;
  187. return obj->cast_to<T>();
  188. }
  189. void add_editor_plugin(Object *p_object);
  190. void update();
  191. void clear();
  192. List<Node *> &get_selected_node_list();
  193. Map<Node *, Object *> &get_selection() { return selection; }
  194. EditorSelection();
  195. ~EditorSelection();
  196. };
  197. #endif // EDITOR_DATA_H