property_editor.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*************************************************************************/
  2. /* property_editor.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 PROPERTY_EDITOR_H
  31. #define PROPERTY_EDITOR_H
  32. #include "editor/editor_file_dialog.h"
  33. #include "editor/scene_tree_editor.h"
  34. #include "scene/gui/button.h"
  35. #include "scene/gui/check_box.h"
  36. #include "scene/gui/check_button.h"
  37. #include "scene/gui/color_picker.h"
  38. #include "scene/gui/dialogs.h"
  39. #include "scene/gui/grid_container.h"
  40. #include "scene/gui/label.h"
  41. #include "scene/gui/menu_button.h"
  42. #include "scene/gui/split_container.h"
  43. #include "scene/gui/text_edit.h"
  44. #include "scene/gui/texture_rect.h"
  45. #include "scene/gui/tree.h"
  46. /**
  47. @author Juan Linietsky <reduzio@gmail.com>
  48. */
  49. class PropertyValueEvaluator;
  50. class CreateDialog;
  51. class PropertySelector;
  52. class EditorResourceConversionPlugin : public Reference {
  53. GDCLASS(EditorResourceConversionPlugin, Reference)
  54. protected:
  55. static void _bind_methods();
  56. public:
  57. virtual String converts_to() const;
  58. virtual bool handles(const Ref<Resource> &p_resource) const;
  59. virtual Ref<Resource> convert(const Ref<Resource> &p_resource);
  60. };
  61. class CustomPropertyEditor : public Popup {
  62. GDCLASS(CustomPropertyEditor, Popup);
  63. enum {
  64. MAX_VALUE_EDITORS = 12,
  65. MAX_ACTION_BUTTONS = 5,
  66. OBJ_MENU_LOAD = 0,
  67. OBJ_MENU_EDIT = 1,
  68. OBJ_MENU_CLEAR = 2,
  69. OBJ_MENU_MAKE_UNIQUE = 3,
  70. OBJ_MENU_COPY = 4,
  71. OBJ_MENU_PASTE = 5,
  72. OBJ_MENU_NEW_SCRIPT = 6,
  73. OBJ_MENU_SHOW_IN_FILE_SYSTEM = 7,
  74. TYPE_BASE_ID = 100,
  75. CONVERT_BASE_ID = 1000
  76. };
  77. enum {
  78. EASING_LINEAR,
  79. EASING_EASE_IN,
  80. EASING_EASE_OUT,
  81. EASING_ZERO,
  82. EASING_IN_OUT,
  83. EASING_OUT_IN
  84. };
  85. PopupMenu *menu;
  86. SceneTreeDialog *scene_tree;
  87. EditorFileDialog *file;
  88. ConfirmationDialog *error;
  89. String name;
  90. Variant::Type type;
  91. Variant v;
  92. List<String> field_names;
  93. int hint;
  94. String hint_text;
  95. LineEdit *value_editor[MAX_VALUE_EDITORS];
  96. int focused_value_editor;
  97. Label *value_label[MAX_VALUE_EDITORS];
  98. HScrollBar *scroll[4];
  99. Button *action_buttons[MAX_ACTION_BUTTONS];
  100. MenuButton *type_button;
  101. Vector<String> inheritors_array;
  102. TextureRect *texture_preview;
  103. ColorPicker *color_picker;
  104. TextEdit *text_edit;
  105. bool read_only;
  106. bool picking_viewport;
  107. GridContainer *checks20gc;
  108. CheckBox *checks20[20];
  109. SpinBox *spinbox;
  110. HSlider *slider;
  111. Control *easing_draw;
  112. CreateDialog *create_dialog;
  113. PropertySelector *property_select;
  114. Object *owner;
  115. bool updating;
  116. PropertyValueEvaluator *evaluator;
  117. void _text_edit_changed();
  118. void _file_selected(String p_file);
  119. void _modified(String p_string);
  120. void _range_modified(double p_value);
  121. void _focus_enter();
  122. void _focus_exit();
  123. void _action_pressed(int p_which);
  124. void _type_create_selected(int p_idx);
  125. void _create_dialog_callback();
  126. void _create_selected_property(const String &p_prop);
  127. void _color_changed(const Color &p_color);
  128. void _draw_easing();
  129. void _menu_option(int p_which);
  130. void _drag_easing(const Ref<InputEvent> &p_ev);
  131. void _node_path_selected(NodePath p_path);
  132. void show_value_editors(int p_amount);
  133. void config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings);
  134. void config_action_buttons(const List<String> &p_strings);
  135. void _emit_changed_whole_or_field();
  136. protected:
  137. void _notification(int p_what);
  138. static void _bind_methods();
  139. public:
  140. void hide_menu();
  141. Variant get_variant() const;
  142. String get_name() const;
  143. void set_read_only(bool p_read_only) { read_only = p_read_only; }
  144. void set_value_evaluator(PropertyValueEvaluator *p_evaluator) { evaluator = p_evaluator; }
  145. bool edit(Object *p_owner, const String &p_name, Variant::Type p_type, const Variant &p_variant, int p_hint, String p_hint_text);
  146. CustomPropertyEditor();
  147. };
  148. class PropertyEditor : public Control {
  149. GDCLASS(PropertyEditor, Control);
  150. Tree *tree;
  151. Label *top_label;
  152. LineEdit *search_box;
  153. PropertyValueEvaluator *evaluator;
  154. Object *obj;
  155. StringName _prop_edited;
  156. bool capitalize_paths;
  157. bool changing;
  158. bool update_tree_pending;
  159. bool autoclear;
  160. bool keying;
  161. bool read_only;
  162. bool show_categories;
  163. bool show_type_icons;
  164. float refresh_countdown;
  165. bool use_doc_hints;
  166. bool use_filter;
  167. bool subsection_selectable;
  168. bool hide_script;
  169. bool use_folding;
  170. bool property_selectable;
  171. bool updating_folding;
  172. HashMap<String, String> pending;
  173. String selected_property;
  174. Map<StringName, Map<StringName, String> > descr_cache;
  175. Map<StringName, String> class_descr_cache;
  176. CustomPropertyEditor *custom_editor;
  177. void _resource_edit_request();
  178. void _custom_editor_edited();
  179. void _custom_editor_edited_field(const String &p_field_name);
  180. void _custom_editor_request(bool p_arrow);
  181. void _item_selected();
  182. void _item_rmb_edited();
  183. void _item_edited();
  184. TreeItem *get_parent_node(String p_path, HashMap<String, TreeItem *> &item_paths, TreeItem *root, TreeItem *category);
  185. void set_item_text(TreeItem *p_item, int p_type, const String &p_name, int p_hint = PROPERTY_HINT_NONE, const String &p_hint_text = "");
  186. TreeItem *find_item(TreeItem *p_item, const String &p_name);
  187. virtual void _changed_callback(Object *p_changed, const char *p_prop);
  188. virtual void _changed_callbacks(Object *p_changed, const String &p_prop);
  189. void _check_reload_status(const String &p_name, TreeItem *item);
  190. void _edit_button(Object *p_item, int p_column, int p_button);
  191. void _node_removed(Node *p_node);
  192. friend class ProjectExportDialog;
  193. void _edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all = false, const String &p_changed_field = "");
  194. void _draw_flags(Object *p_object, const Rect2 &p_rect);
  195. bool _might_be_in_instance();
  196. bool _get_instanced_node_original_property(const StringName &p_prop, Variant &value);
  197. bool _is_property_different(const Variant &p_current, const Variant &p_orig, int p_usage = 0);
  198. void _refresh_item(TreeItem *p_item);
  199. void _set_range_def(Object *p_item, String prop, float p_frame);
  200. void _filter_changed(const String &p_text);
  201. void _mark_drop_fields(TreeItem *p_at);
  202. void _clear_drop_fields(TreeItem *p_at);
  203. bool _is_drop_valid(const Dictionary &p_drag_data, const Dictionary &p_item_data) const;
  204. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  205. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  206. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  207. void _resource_preview_done(const String &p_path, const Ref<Texture> &p_preview, Variant p_ud);
  208. void _draw_transparency(Object *t, const Rect2 &p_rect);
  209. void _item_folded(Object *item_obj);
  210. UndoRedo *undo_redo;
  211. protected:
  212. void _notification(int p_what);
  213. static void _bind_methods();
  214. public:
  215. void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  216. String get_selected_path() const;
  217. Tree *get_scene_tree();
  218. Label *get_top_label();
  219. void hide_top_label();
  220. void update_tree();
  221. void update_property(const String &p_prop);
  222. void refresh();
  223. void edit(Object *p_object);
  224. void set_keying(bool p_active);
  225. void set_read_only(bool p_read_only) {
  226. read_only = p_read_only;
  227. custom_editor->set_read_only(p_read_only);
  228. }
  229. bool is_capitalize_paths_enabled() const;
  230. void set_enable_capitalize_paths(bool p_capitalize);
  231. void set_autoclear(bool p_enable);
  232. void set_show_categories(bool p_show);
  233. void set_use_doc_hints(bool p_enable) { use_doc_hints = p_enable; }
  234. void set_hide_script(bool p_hide) { hide_script = p_hide; }
  235. void set_use_filter(bool p_use);
  236. void register_text_enter(Node *p_line_edit);
  237. void set_subsection_selectable(bool p_selectable);
  238. void set_property_selectable(bool p_selectable);
  239. void set_use_folding(bool p_enable);
  240. PropertyEditor();
  241. ~PropertyEditor();
  242. };
  243. class SectionedPropertyEditorFilter;
  244. class SectionedPropertyEditor : public HBoxContainer {
  245. GDCLASS(SectionedPropertyEditor, HBoxContainer);
  246. ObjectID obj;
  247. Tree *sections;
  248. SectionedPropertyEditorFilter *filter;
  249. Map<String, TreeItem *> section_map;
  250. PropertyEditor *editor;
  251. LineEdit *search_box;
  252. static void _bind_methods();
  253. void _section_selected();
  254. void _search_changed(const String &p_what);
  255. public:
  256. void register_search_box(LineEdit *p_box);
  257. PropertyEditor *get_property_editor();
  258. void edit(Object *p_object);
  259. String get_full_item_path(const String &p_item);
  260. void set_current_section(const String &p_section);
  261. String get_current_section() const;
  262. void update_category_list();
  263. SectionedPropertyEditor();
  264. ~SectionedPropertyEditor();
  265. };
  266. class PropertyValueEvaluator : public ValueEvaluator {
  267. GDCLASS(PropertyValueEvaluator, ValueEvaluator);
  268. Object *obj;
  269. ScriptLanguage *script_language;
  270. String _build_script(const String &p_text);
  271. _FORCE_INLINE_ double _default_eval(const String &p_text) {
  272. return p_text.to_double();
  273. }
  274. public:
  275. void edit(Object *p_obj);
  276. double eval(const String &p_text);
  277. PropertyValueEvaluator();
  278. ~PropertyValueEvaluator();
  279. };
  280. #endif