property_editor.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*************************************************************************/
  2. /* property_editor.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 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) const;
  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. real_t _parse_real_expression(String text);
  121. void _range_modified(double p_value);
  122. void _focus_enter();
  123. void _focus_exit();
  124. void _action_pressed(int p_which);
  125. void _type_create_selected(int p_idx);
  126. void _create_dialog_callback();
  127. void _create_selected_property(const String &p_prop);
  128. void _color_changed(const Color &p_color);
  129. void _draw_easing();
  130. void _menu_option(int p_which);
  131. void _drag_easing(const Ref<InputEvent> &p_ev);
  132. void _node_path_selected(NodePath p_path);
  133. void show_value_editors(int p_amount);
  134. void config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings);
  135. void config_action_buttons(const List<String> &p_strings);
  136. void _emit_changed_whole_or_field();
  137. protected:
  138. void _notification(int p_what);
  139. static void _bind_methods();
  140. public:
  141. void hide_menu();
  142. Variant get_variant() const;
  143. String get_name() const;
  144. void set_read_only(bool p_read_only) { read_only = p_read_only; }
  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. #endif