editor_data.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*************************************************************************/
  2. /* editor_data.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "core/list.h"
  33. #include "core/pair.h"
  34. #include "core/undo_redo.h"
  35. #include "editor/editor_plugin.h"
  36. #include "editor/plugins/script_editor_plugin.h"
  37. #include "scene/resources/texture.h"
  38. class EditorHistory {
  39. enum {
  40. HISTORY_MAX = 64
  41. };
  42. struct Obj {
  43. REF ref;
  44. ObjectID object;
  45. String property;
  46. bool inspector_only;
  47. };
  48. struct History {
  49. Vector<Obj> path;
  50. int level;
  51. };
  52. friend class EditorData;
  53. Vector<History> history;
  54. int current;
  55. //Vector<EditorPlugin*> editor_plugins;
  56. struct PropertyData {
  57. String name;
  58. Variant value;
  59. };
  60. void _add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only = false);
  61. public:
  62. void cleanup_history();
  63. bool is_at_beginning() const;
  64. bool is_at_end() const;
  65. void add_object_inspector_only(ObjectID p_object);
  66. void add_object(ObjectID p_object);
  67. void add_object(ObjectID p_object, const String &p_subprop);
  68. void add_object(ObjectID p_object, int p_relevel);
  69. int get_history_len();
  70. int get_history_pos();
  71. ObjectID get_history_obj(int p_obj) const;
  72. bool is_history_obj_inspector_only(int p_obj) const;
  73. bool next();
  74. bool previous();
  75. ObjectID get_current();
  76. bool is_current_inspector_only() const;
  77. int get_path_size() const;
  78. ObjectID get_path_object(int p_index) const;
  79. String get_path_property(int p_index) const;
  80. void clear();
  81. EditorHistory();
  82. };
  83. class EditorSelection;
  84. class EditorData {
  85. public:
  86. struct CustomType {
  87. String name;
  88. Ref<Script> script;
  89. Ref<Texture> icon;
  90. };
  91. struct EditedScene {
  92. Node *root;
  93. Dictionary editor_states;
  94. List<Node *> selection;
  95. Vector<EditorHistory::History> history_stored;
  96. int history_current;
  97. Dictionary custom_state;
  98. uint64_t version;
  99. NodePath live_edit_root;
  100. };
  101. private:
  102. Vector<EditorPlugin *> editor_plugins;
  103. struct PropertyData {
  104. String name;
  105. Variant value;
  106. };
  107. Map<String, Vector<CustomType> > custom_types;
  108. List<PropertyData> clipboard;
  109. UndoRedo undo_redo;
  110. void _cleanup_history();
  111. Vector<EditedScene> edited_scene;
  112. int current_edited_scene;
  113. bool _find_updated_instances(Node *p_root, Node *p_node, Set<String> &checked_paths);
  114. HashMap<StringName, String> _script_class_icon_paths;
  115. HashMap<String, StringName> _script_class_file_to_path;
  116. public:
  117. EditorPlugin *get_editor(Object *p_object);
  118. EditorPlugin *get_subeditor(Object *p_object);
  119. Vector<EditorPlugin *> get_subeditors(Object *p_object);
  120. EditorPlugin *get_editor(String p_name);
  121. void copy_object_params(Object *p_object);
  122. void paste_object_params(Object *p_object);
  123. Dictionary get_editor_states() const;
  124. Dictionary get_scene_editor_states(int p_idx) const;
  125. void set_editor_states(const Dictionary &p_states);
  126. void get_editor_breakpoints(List<String> *p_breakpoints);
  127. void clear_editor_states();
  128. void save_editor_external_data();
  129. void apply_changes_in_editors();
  130. void add_editor_plugin(EditorPlugin *p_plugin);
  131. void remove_editor_plugin(EditorPlugin *p_plugin);
  132. int get_editor_plugin_count() const;
  133. EditorPlugin *get_editor_plugin(int p_idx);
  134. UndoRedo &get_undo_redo();
  135. void save_editor_global_states();
  136. void restore_editor_global_states();
  137. void add_custom_type(const String &p_type, const String &p_inherits, const Ref<Script> &p_script, const Ref<Texture> &p_icon);
  138. Object *instance_custom_type(const String &p_type, const String &p_inherits);
  139. void remove_custom_type(const String &p_type);
  140. const Map<String, Vector<CustomType> > &get_custom_types() const { return custom_types; }
  141. int add_edited_scene(int p_at_pos);
  142. void move_edited_scene_index(int p_idx, int p_to_idx);
  143. void remove_scene(int p_idx);
  144. void set_edited_scene(int p_idx);
  145. void set_edited_scene_root(Node *p_root);
  146. int get_edited_scene() const;
  147. Node *get_edited_scene_root(int p_idx = -1);
  148. int get_edited_scene_count() const;
  149. Vector<EditedScene> get_edited_scenes() const;
  150. String get_scene_title(int p_idx) const;
  151. String get_scene_path(int p_idx) const;
  152. String get_scene_type(int p_idx) const;
  153. void set_scene_path(int p_idx, const String &p_path);
  154. Ref<Script> get_scene_root_script(int p_idx) const;
  155. void set_edited_scene_version(uint64_t version, int p_scene_idx = -1);
  156. uint64_t get_edited_scene_version() const;
  157. uint64_t get_scene_version(int p_idx) const;
  158. void clear_edited_scenes();
  159. void set_edited_scene_live_edit_root(const NodePath &p_root);
  160. NodePath get_edited_scene_live_edit_root();
  161. bool check_and_update_scene(int p_idx);
  162. void move_edited_scene_to_index(int p_idx);
  163. bool call_build();
  164. void set_plugin_window_layout(Ref<ConfigFile> p_layout);
  165. void get_plugin_window_layout(Ref<ConfigFile> p_layout);
  166. void save_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history, const Dictionary &p_custom);
  167. Dictionary restore_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history);
  168. void notify_edited_scene_changed();
  169. void notify_resource_saved(const Ref<Resource> &p_resource);
  170. bool script_class_is_parent(const String &p_class, const String &p_inherits);
  171. StringName script_class_get_base(const String &p_class) const;
  172. Object *script_class_instance(const String &p_class);
  173. StringName script_class_get_name(const String &p_path) const;
  174. void script_class_set_name(const String &p_path, const StringName &p_class);
  175. String script_class_get_icon_path(const String &p_class) const;
  176. void script_class_set_icon_path(const String &p_class, const String &p_icon_path);
  177. void script_class_clear_icon_paths() { _script_class_icon_paths.clear(); }
  178. void script_class_save_icon_paths();
  179. void script_class_load_icon_paths();
  180. EditorData();
  181. };
  182. class EditorSelection : public Object {
  183. GDCLASS(EditorSelection, Object);
  184. private:
  185. Map<Node *, Object *> selection;
  186. bool emitted;
  187. bool changed;
  188. bool nl_changed;
  189. void _node_removed(Node *p_node);
  190. List<Object *> editor_plugins;
  191. List<Node *> selected_node_list;
  192. void _update_nl();
  193. Array _get_transformable_selected_nodes();
  194. void _emit_change();
  195. protected:
  196. static void _bind_methods();
  197. public:
  198. Array get_selected_nodes();
  199. void add_node(Node *p_node);
  200. void remove_node(Node *p_node);
  201. bool is_selected(Node *) const;
  202. template <class T>
  203. T *get_node_editor_data(Node *p_node) {
  204. if (!selection.has(p_node))
  205. return NULL;
  206. return Object::cast_to<T>(selection[p_node]);
  207. }
  208. void add_editor_plugin(Object *p_object);
  209. void update();
  210. void clear();
  211. List<Node *> &get_selected_node_list();
  212. Map<Node *, Object *> &get_selection() { return selection; }
  213. EditorSelection();
  214. ~EditorSelection();
  215. };
  216. #endif // EDITOR_DATA_H