editor_properties_array_dict.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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_locale_dialog.h"
  34. #include "editor/filesystem_dock.h"
  35. class Button;
  36. class EditorSpinSlider;
  37. class EditorPropertyArrayObject : public RefCounted {
  38. GDCLASS(EditorPropertyArrayObject, RefCounted);
  39. Variant array;
  40. protected:
  41. bool _set(const StringName &p_name, const Variant &p_value);
  42. bool _get(const StringName &p_name, Variant &r_ret) const;
  43. public:
  44. void set_array(const Variant &p_array);
  45. Variant get_array();
  46. EditorPropertyArrayObject();
  47. };
  48. class EditorPropertyDictionaryObject : public RefCounted {
  49. GDCLASS(EditorPropertyDictionaryObject, RefCounted);
  50. Variant new_item_key;
  51. Variant new_item_value;
  52. Dictionary dict;
  53. protected:
  54. bool _set(const StringName &p_name, const Variant &p_value);
  55. bool _get(const StringName &p_name, Variant &r_ret) const;
  56. public:
  57. void set_dict(const Dictionary &p_dict);
  58. Dictionary get_dict();
  59. void set_new_item_key(const Variant &p_new_item);
  60. Variant get_new_item_key();
  61. void set_new_item_value(const Variant &p_new_item);
  62. Variant get_new_item_value();
  63. EditorPropertyDictionaryObject();
  64. };
  65. class EditorPropertyArray : public EditorProperty {
  66. GDCLASS(EditorPropertyArray, EditorProperty);
  67. PopupMenu *change_type = nullptr;
  68. int page_length = 20;
  69. int page_index = 0;
  70. int changing_type_index;
  71. Button *edit = nullptr;
  72. MarginContainer *container = nullptr;
  73. VBoxContainer *property_vbox = nullptr;
  74. EditorSpinSlider *size_slider = nullptr;
  75. Button *button_add_item = nullptr;
  76. EditorPaginator *paginator = nullptr;
  77. Variant::Type array_type;
  78. Variant::Type subtype;
  79. PropertyHint subtype_hint;
  80. String subtype_hint_string;
  81. int reorder_from_index = -1;
  82. int reorder_to_index = -1;
  83. float reorder_mouse_y_delta = 0.0f;
  84. HBoxContainer *reorder_selected_element_hbox = nullptr;
  85. Button *reorder_selected_button = nullptr;
  86. void initialize_array(Variant &p_array);
  87. void _page_changed(int p_page);
  88. void _reorder_button_gui_input(const Ref<InputEvent> &p_event);
  89. void _reorder_button_down(int p_index);
  90. void _reorder_button_up();
  91. protected:
  92. Ref<EditorPropertyArrayObject> object;
  93. bool updating = false;
  94. bool dropping = false;
  95. static void _bind_methods();
  96. void _notification(int p_what);
  97. virtual void _add_element();
  98. virtual void _length_changed(double p_page);
  99. virtual void _edit_pressed();
  100. virtual void _property_changed(const String &p_property, Variant p_value, const String &p_name = "", bool p_changing = false);
  101. virtual void _change_type(Object *p_button, int p_index);
  102. virtual void _change_type_menu(int p_index);
  103. virtual void _object_id_selected(const StringName &p_property, ObjectID p_id);
  104. virtual void _remove_pressed(int p_index);
  105. virtual void _button_draw();
  106. virtual bool _is_drop_valid(const Dictionary &p_drag_data) const;
  107. virtual bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  108. virtual void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  109. public:
  110. void setup(Variant::Type p_array_type, const String &p_hint_string = "");
  111. virtual void update_property() override;
  112. EditorPropertyArray();
  113. };
  114. class EditorPropertyDictionary : public EditorProperty {
  115. GDCLASS(EditorPropertyDictionary, EditorProperty);
  116. PopupMenu *change_type = nullptr;
  117. bool updating = false;
  118. Ref<EditorPropertyDictionaryObject> object;
  119. int page_length = 20;
  120. int page_index = 0;
  121. int changing_type_index;
  122. Button *edit = nullptr;
  123. MarginContainer *container = nullptr;
  124. VBoxContainer *property_vbox = nullptr;
  125. EditorSpinSlider *size_sliderv = nullptr;
  126. Button *button_add_item = nullptr;
  127. EditorPaginator *paginator = nullptr;
  128. PropertyHint property_hint;
  129. void _page_changed(int p_page);
  130. void _edit_pressed();
  131. void _property_changed(const String &p_property, Variant p_value, const String &p_name = "", bool p_changing = false);
  132. void _change_type(Object *p_button, int p_index);
  133. void _change_type_menu(int p_index);
  134. void _add_key_value();
  135. void _object_id_selected(const StringName &p_property, ObjectID p_id);
  136. protected:
  137. static void _bind_methods();
  138. void _notification(int p_what);
  139. public:
  140. void setup(PropertyHint p_hint);
  141. virtual void update_property() override;
  142. EditorPropertyDictionary();
  143. };
  144. class EditorPropertyLocalizableString : public EditorProperty {
  145. GDCLASS(EditorPropertyLocalizableString, EditorProperty);
  146. EditorLocaleDialog *locale_select = nullptr;
  147. bool updating;
  148. Ref<EditorPropertyDictionaryObject> object;
  149. int page_length = 20;
  150. int page_index = 0;
  151. Button *edit = nullptr;
  152. MarginContainer *container = nullptr;
  153. VBoxContainer *property_vbox = nullptr;
  154. EditorSpinSlider *size_slider = nullptr;
  155. Button *button_add_item = nullptr;
  156. EditorPaginator *paginator = nullptr;
  157. void _page_changed(int p_page);
  158. void _edit_pressed();
  159. void _remove_item(Object *p_button, int p_index);
  160. void _property_changed(const String &p_property, Variant p_value, const String &p_name = "", bool p_changing = false);
  161. void _add_locale_popup();
  162. void _add_locale(const String &p_locale);
  163. void _object_id_selected(const StringName &p_property, ObjectID p_id);
  164. protected:
  165. static void _bind_methods();
  166. void _notification(int p_what);
  167. public:
  168. virtual void update_property() override;
  169. EditorPropertyLocalizableString();
  170. };
  171. #endif // EDITOR_PROPERTIES_ARRAY_DICT_H