property_editor.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*************************************************************************/
  2. /* property_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. class PropertyValueEvaluator;
  47. class CreateDialog;
  48. class PropertySelector;
  49. class EditorResourceConversionPlugin : public Reference {
  50. GDCLASS(EditorResourceConversionPlugin, Reference);
  51. protected:
  52. static void _bind_methods();
  53. public:
  54. virtual String converts_to() const;
  55. virtual bool handles(const Ref<Resource> &p_resource) const;
  56. virtual Ref<Resource> convert(const Ref<Resource> &p_resource) const;
  57. };
  58. class CustomPropertyEditor : public Popup {
  59. GDCLASS(CustomPropertyEditor, Popup);
  60. enum {
  61. MAX_VALUE_EDITORS = 12,
  62. MAX_ACTION_BUTTONS = 5,
  63. OBJ_MENU_LOAD = 0,
  64. OBJ_MENU_EDIT = 1,
  65. OBJ_MENU_CLEAR = 2,
  66. OBJ_MENU_MAKE_UNIQUE = 3,
  67. OBJ_MENU_COPY = 4,
  68. OBJ_MENU_PASTE = 5,
  69. OBJ_MENU_NEW_SCRIPT = 6,
  70. OBJ_MENU_EXTEND_SCRIPT = 7,
  71. OBJ_MENU_SHOW_IN_FILE_SYSTEM = 8,
  72. TYPE_BASE_ID = 100,
  73. CONVERT_BASE_ID = 1000
  74. };
  75. enum {
  76. EASING_LINEAR,
  77. EASING_EASE_IN,
  78. EASING_EASE_OUT,
  79. EASING_ZERO,
  80. EASING_IN_OUT,
  81. EASING_OUT_IN
  82. };
  83. PopupMenu *menu;
  84. SceneTreeDialog *scene_tree;
  85. EditorFileDialog *file;
  86. ConfirmationDialog *error;
  87. String name;
  88. Variant::Type type;
  89. Variant v;
  90. List<String> field_names;
  91. int hint;
  92. String hint_text;
  93. LineEdit *value_editor[MAX_VALUE_EDITORS];
  94. int focused_value_editor;
  95. Label *value_label[MAX_VALUE_EDITORS];
  96. HScrollBar *scroll[4];
  97. Button *action_buttons[MAX_ACTION_BUTTONS];
  98. MenuButton *type_button;
  99. Vector<String> inheritors_array;
  100. TextureRect *texture_preview;
  101. ColorPicker *color_picker;
  102. TextEdit *text_edit;
  103. bool read_only;
  104. bool picking_viewport;
  105. GridContainer *checks20gc;
  106. CheckBox *checks20[20];
  107. SpinBox *spinbox;
  108. HSlider *slider;
  109. Control *easing_draw;
  110. CreateDialog *create_dialog;
  111. PropertySelector *property_select;
  112. Object *owner;
  113. bool updating;
  114. PropertyValueEvaluator *evaluator;
  115. void _text_edit_changed();
  116. void _file_selected(String p_file);
  117. void _modified(String p_string);
  118. real_t _parse_real_expression(String text);
  119. void _range_modified(double p_value);
  120. void _focus_enter();
  121. void _focus_exit();
  122. void _action_pressed(int p_which);
  123. void _type_create_selected(int p_idx);
  124. void _create_dialog_callback();
  125. void _create_selected_property(const String &p_prop);
  126. void _color_changed(const Color &p_color);
  127. void _draw_easing();
  128. void _menu_option(int p_which);
  129. void _drag_easing(const Ref<InputEvent> &p_ev);
  130. void _node_path_selected(NodePath p_path);
  131. void show_value_editors(int p_amount);
  132. void config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings);
  133. void config_action_buttons(const List<String> &p_strings);
  134. void _emit_changed_whole_or_field();
  135. protected:
  136. void _notification(int p_what);
  137. static void _bind_methods();
  138. public:
  139. void hide_menu();
  140. Variant get_variant() const;
  141. String get_name() const;
  142. void set_read_only(bool p_read_only) { read_only = p_read_only; }
  143. bool edit(Object *p_owner, const String &p_name, Variant::Type p_type, const Variant &p_variant, int p_hint, String p_hint_text);
  144. CustomPropertyEditor();
  145. };
  146. #endif