editor_properties_array_dict.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**************************************************************************/
  2. /* editor_properties_array_dict.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_PROPERTIES_ARRAY_DICT_H
  31. #define EDITOR_PROPERTIES_ARRAY_DICT_H
  32. #include "editor/editor_inspector.h"
  33. #include "editor/editor_spin_slider.h"
  34. #include "editor/filesystem_dock.h"
  35. #include "scene/gui/button.h"
  36. class EditorPropertyArrayObject : public Reference {
  37. GDCLASS(EditorPropertyArrayObject, Reference);
  38. Variant array;
  39. protected:
  40. bool _set(const StringName &p_name, const Variant &p_value);
  41. bool _get(const StringName &p_name, Variant &r_ret) const;
  42. public:
  43. void set_array(const Variant &p_array);
  44. Variant get_array();
  45. EditorPropertyArrayObject();
  46. };
  47. class EditorPropertyDictionaryObject : public Reference {
  48. GDCLASS(EditorPropertyDictionaryObject, Reference);
  49. Variant new_item_key;
  50. Variant new_item_value;
  51. Dictionary dict;
  52. protected:
  53. bool _set(const StringName &p_name, const Variant &p_value);
  54. bool _get(const StringName &p_name, Variant &r_ret) const;
  55. public:
  56. void set_dict(const Dictionary &p_dict);
  57. Dictionary get_dict();
  58. void set_new_item_key(const Variant &p_new_item);
  59. Variant get_new_item_key();
  60. void set_new_item_value(const Variant &p_new_item);
  61. Variant get_new_item_value();
  62. EditorPropertyDictionaryObject();
  63. };
  64. class EditorPropertyArray : public EditorProperty {
  65. GDCLASS(EditorPropertyArray, EditorProperty);
  66. PopupMenu *change_type;
  67. bool updating;
  68. bool dropping;
  69. Ref<EditorPropertyArrayObject> object;
  70. int page_length = 20;
  71. int page_index = 0;
  72. int changing_type_index;
  73. Button *edit;
  74. VBoxContainer *vbox;
  75. EditorSpinSlider *size_slider;
  76. EditorSpinSlider *page_slider;
  77. HBoxContainer *page_hbox;
  78. Variant::Type array_type;
  79. Variant::Type subtype;
  80. PropertyHint subtype_hint;
  81. String subtype_hint_string;
  82. int reorder_from_index = -1;
  83. int reorder_to_index = -1;
  84. float reorder_mouse_y_delta = 0.0f;
  85. HBoxContainer *reorder_selected_element_hbox = nullptr;
  86. Button *reorder_selected_button = nullptr;
  87. void _page_changed(double p_page);
  88. void _length_changed(double p_page);
  89. void _edit_pressed();
  90. void _property_changed(const String &p_prop, Variant p_value, const String &p_name = String(), bool changing = false);
  91. void _change_type(Object *p_button, int p_index);
  92. void _change_type_menu(int p_index);
  93. void _object_id_selected(const String &p_property, ObjectID p_id);
  94. void _remove_pressed(int p_index);
  95. void _reorder_button_gui_input(const Ref<InputEvent> &p_event);
  96. void _reorder_button_down(int p_index);
  97. void _reorder_button_up();
  98. void _button_draw();
  99. bool _is_drop_valid(const Dictionary &p_drag_data) const;
  100. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  101. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  102. protected:
  103. static void _bind_methods();
  104. void _notification(int p_what);
  105. public:
  106. void setup(Variant::Type p_array_type, const String &p_hint_string = "");
  107. virtual void update_property();
  108. EditorPropertyArray();
  109. };
  110. class EditorPropertyDictionary : public EditorProperty {
  111. GDCLASS(EditorPropertyDictionary, EditorProperty);
  112. PopupMenu *change_type;
  113. bool updating;
  114. Ref<EditorPropertyDictionaryObject> object;
  115. int page_length = 20;
  116. int page_index = 0;
  117. int changing_type_index;
  118. Button *edit;
  119. VBoxContainer *vbox;
  120. EditorSpinSlider *size_slider;
  121. EditorSpinSlider *page_slider;
  122. HBoxContainer *page_hbox;
  123. Button *button_add_item;
  124. void _page_changed(double p_page);
  125. void _edit_pressed();
  126. void _property_changed(const String &p_prop, Variant p_value, const String &p_name = String(), bool changing = false);
  127. void _change_type(Object *p_button, int p_index);
  128. void _change_type_menu(int p_index);
  129. void _add_key_value();
  130. void _object_id_selected(const String &p_property, ObjectID p_id);
  131. protected:
  132. static void _bind_methods();
  133. void _notification(int p_what);
  134. public:
  135. virtual void update_property();
  136. EditorPropertyDictionary();
  137. };
  138. #endif // EDITOR_PROPERTIES_ARRAY_DICT_H