property_editor.h 9.8 KB

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