editor_inspector.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*************************************************************************/
  2. /* editor_inspector.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_INSPECTOR_H
  31. #define EDITOR_INSPECTOR_H
  32. #include "scene/gui/box_container.h"
  33. #include "scene/gui/line_edit.h"
  34. #include "scene/gui/scroll_container.h"
  35. class UndoRedo;
  36. class EditorPropertyRevert {
  37. public:
  38. static bool may_node_be_in_instance(Node *p_node);
  39. static bool get_instanced_node_original_property(Node *p_node, const StringName &p_prop, Variant &value);
  40. static bool is_node_property_different(Node *p_node, const Variant &p_current, const Variant &p_orig);
  41. static bool can_property_revert(Object *p_object, const StringName &p_property);
  42. };
  43. class EditorProperty : public Container {
  44. GDCLASS(EditorProperty, Container)
  45. private:
  46. String label;
  47. int text_size;
  48. friend class EditorInspector;
  49. Object *object;
  50. StringName property;
  51. int property_usage;
  52. bool read_only;
  53. bool checkable;
  54. bool checked;
  55. bool draw_red;
  56. bool keying;
  57. Rect2 right_child_rect;
  58. Rect2 bottom_child_rect;
  59. Rect2 keying_rect;
  60. bool keying_hover;
  61. Rect2 revert_rect;
  62. bool revert_hover;
  63. Rect2 check_rect;
  64. bool check_hover;
  65. bool can_revert;
  66. bool use_folding;
  67. bool draw_top_bg;
  68. bool _is_property_different(const Variant &p_current, const Variant &p_orig);
  69. bool _get_instanced_node_original_property(const StringName &p_prop, Variant &value);
  70. void _focusable_focused(int p_index);
  71. bool selectable;
  72. bool selected;
  73. int selected_focusable;
  74. float split_ratio;
  75. Vector<Control *> focusables;
  76. Control *label_reference;
  77. Control *bottom_editor;
  78. mutable String tooltip_text;
  79. protected:
  80. void _notification(int p_what);
  81. static void _bind_methods();
  82. void _gui_input(const Ref<InputEvent> &p_event);
  83. public:
  84. virtual Size2 get_minimum_size() const;
  85. void set_label(const String &p_label);
  86. String get_label() const;
  87. void set_read_only(bool p_read_only);
  88. bool is_read_only() const;
  89. Object *get_edited_object();
  90. StringName get_edited_property();
  91. virtual void update_property();
  92. void update_reload_status();
  93. virtual bool use_keying_next() const;
  94. void set_checkable(bool p_checkable);
  95. bool is_checkable() const;
  96. void set_checked(bool p_checked);
  97. bool is_checked() const;
  98. void set_draw_red(bool p_draw_red);
  99. bool is_draw_red() const;
  100. void set_keying(bool p_keying);
  101. bool is_keying() const;
  102. void add_focusable(Control *p_control);
  103. void select(int p_focusable = -1);
  104. void deselect();
  105. bool is_selected() const;
  106. void set_label_reference(Control *p_control);
  107. void set_bottom_editor(Control *p_editor);
  108. void set_use_folding(bool p_use_folding);
  109. bool is_using_folding() const;
  110. virtual void expand_all_folding();
  111. virtual void collapse_all_folding();
  112. virtual Variant get_drag_data(const Point2 &p_point);
  113. void set_selectable(bool p_selectable);
  114. bool is_selectable() const;
  115. void set_name_split_ratio(float p_ratio);
  116. float get_name_split_ratio() const;
  117. void set_object_and_property(Object *p_object, const StringName &p_property);
  118. virtual Control *make_custom_tooltip(const String &p_text) const;
  119. String get_tooltip_text() const;
  120. void set_draw_top_bg(bool p_draw) { draw_top_bg = p_draw; }
  121. bool can_revert_to_default() const { return can_revert; }
  122. EditorProperty();
  123. };
  124. class EditorInspectorPlugin : public Reference {
  125. GDCLASS(EditorInspectorPlugin, Reference)
  126. friend class EditorInspector;
  127. struct AddedEditor {
  128. Control *property_editor;
  129. Vector<String> properties;
  130. String label;
  131. };
  132. List<AddedEditor> added_editors;
  133. protected:
  134. static void _bind_methods();
  135. public:
  136. void add_custom_control(Control *control);
  137. void add_property_editor(const String &p_for_property, Control *p_prop);
  138. void add_property_editor_for_multiple_properties(const String &p_label, const Vector<String> &p_properties, Control *p_prop);
  139. virtual bool can_handle(Object *p_object);
  140. virtual void parse_begin(Object *p_object);
  141. virtual void parse_category(Object *p_object, const String &p_parse_category);
  142. virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage);
  143. virtual void parse_end();
  144. };
  145. class EditorInspectorCategory : public Control {
  146. GDCLASS(EditorInspectorCategory, Control);
  147. friend class EditorInspector;
  148. Ref<Texture> icon;
  149. String label;
  150. Color bg_color;
  151. mutable String tooltip_text;
  152. protected:
  153. void _notification(int p_what);
  154. static void _bind_methods();
  155. public:
  156. virtual Size2 get_minimum_size() const;
  157. virtual Control *make_custom_tooltip(const String &p_text) const;
  158. String get_tooltip_text() const;
  159. EditorInspectorCategory();
  160. };
  161. class EditorInspectorSection : public Container {
  162. GDCLASS(EditorInspectorSection, Container);
  163. String label;
  164. String section;
  165. Object *object;
  166. VBoxContainer *vbox;
  167. bool vbox_added; //optimization
  168. Color bg_color;
  169. bool foldable;
  170. void _test_unfold();
  171. protected:
  172. void _notification(int p_what);
  173. static void _bind_methods();
  174. void _gui_input(const Ref<InputEvent> &p_event);
  175. public:
  176. virtual Size2 get_minimum_size() const;
  177. void setup(const String &p_section, const String &p_label, Object *p_object, const Color &p_bg_color, bool p_foldable);
  178. VBoxContainer *get_vbox();
  179. void unfold();
  180. void fold();
  181. Object *get_edited_object();
  182. EditorInspectorSection();
  183. ~EditorInspectorSection();
  184. };
  185. class EditorInspector : public ScrollContainer {
  186. GDCLASS(EditorInspector, ScrollContainer);
  187. UndoRedo *undo_redo;
  188. enum {
  189. MAX_PLUGINS = 1024
  190. };
  191. static Ref<EditorInspectorPlugin> inspector_plugins[MAX_PLUGINS];
  192. static int inspector_plugin_count;
  193. VBoxContainer *main_vbox;
  194. //map use to cache the instanced editors
  195. Map<StringName, List<EditorProperty *> > editor_property_map;
  196. List<EditorInspectorSection *> sections;
  197. Set<StringName> pending;
  198. void _clear();
  199. Object *object;
  200. //
  201. LineEdit *search_box;
  202. bool show_categories;
  203. bool hide_script;
  204. bool use_doc_hints;
  205. bool capitalize_paths;
  206. bool use_filter;
  207. bool autoclear;
  208. bool use_folding;
  209. int changing;
  210. bool update_all_pending;
  211. bool read_only;
  212. bool keying;
  213. bool use_sub_inspector_bg;
  214. float refresh_countdown;
  215. bool update_tree_pending;
  216. StringName _prop_edited;
  217. StringName property_selected;
  218. int property_focusable;
  219. int update_scroll_request;
  220. Map<StringName, Map<StringName, String> > descr_cache;
  221. Map<StringName, String> class_descr_cache;
  222. Set<StringName> restart_request_props;
  223. Map<ObjectID, int> scroll_cache;
  224. String property_prefix; //used for sectioned inspector
  225. String object_class;
  226. void _edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field);
  227. void _property_changed(const String &p_path, const Variant &p_value, bool changing = false);
  228. void _property_changed_update_all(const String &p_path, const Variant &p_value);
  229. void _multiple_properties_changed(Vector<String> p_paths, Array p_values);
  230. void _property_keyed(const String &p_path, bool p_advance);
  231. void _property_keyed_with_value(const String &p_path, const Variant &p_value, bool p_advance);
  232. void _property_checked(const String &p_path, bool p_checked);
  233. void _resource_selected(const String &p_path, RES p_resource);
  234. void _property_selected(const String &p_path, int p_focusable);
  235. void _object_id_selected(const String &p_path, ObjectID p_id);
  236. void _node_removed(Node *p_node);
  237. void _changed_callback(Object *p_changed, const char *p_prop);
  238. void _edit_request_change(Object *p_changed, const String &p_prop);
  239. void _filter_changed(const String &p_text);
  240. void _parse_added_editors(VBoxContainer *current_vbox, Ref<EditorInspectorPlugin> ped);
  241. void _vscroll_changed(double);
  242. protected:
  243. static void _bind_methods();
  244. void _notification(int p_what);
  245. public:
  246. static void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
  247. static void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
  248. static void cleanup_plugins();
  249. static EditorProperty *instantiate_property_editor(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage);
  250. void set_undo_redo(UndoRedo *p_undo_redo);
  251. String get_selected_path() const;
  252. void update_tree();
  253. void update_property(const String &p_prop);
  254. void refresh();
  255. void edit(Object *p_object);
  256. Object *get_edited_object();
  257. void set_keying(bool p_active);
  258. void set_read_only(bool p_read_only);
  259. bool is_capitalize_paths_enabled() const;
  260. void set_enable_capitalize_paths(bool p_capitalize);
  261. void set_autoclear(bool p_enable);
  262. void set_show_categories(bool p_show);
  263. void set_use_doc_hints(bool p_enable);
  264. void set_hide_script(bool p_hide);
  265. void set_use_filter(bool p_use);
  266. void register_text_enter(Node *p_line_edit);
  267. void set_use_folding(bool p_enable);
  268. bool is_using_folding();
  269. void collapse_all_folding();
  270. void expand_all_folding();
  271. void set_scroll_offset(int p_offset);
  272. int get_scroll_offset() const;
  273. void set_property_prefix(const String &p_prefix);
  274. String get_property_prefix() const;
  275. void set_object_class(const String &p_class);
  276. String get_object_class() const;
  277. void set_use_sub_inspector_bg(bool p_enable);
  278. EditorInspector();
  279. };
  280. #endif // INSPECTOR_H