editor_properties_array_dict.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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) 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 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 "scene/gui/button.h"
  35. class EditorPropertyArrayObject : public Reference {
  36. GDCLASS(EditorPropertyArrayObject, Reference);
  37. Variant array;
  38. protected:
  39. bool _set(const StringName &p_name, const Variant &p_value);
  40. bool _get(const StringName &p_name, Variant &r_ret) const;
  41. public:
  42. void set_array(const Variant &p_array);
  43. Variant get_array();
  44. EditorPropertyArrayObject();
  45. };
  46. class EditorPropertyDictionaryObject : public Reference {
  47. GDCLASS(EditorPropertyDictionaryObject, Reference);
  48. Variant new_item_key;
  49. Variant new_item_value;
  50. Dictionary dict;
  51. protected:
  52. bool _set(const StringName &p_name, const Variant &p_value);
  53. bool _get(const StringName &p_name, Variant &r_ret) const;
  54. public:
  55. void set_dict(const Dictionary &p_dict);
  56. Dictionary get_dict();
  57. void set_new_item_key(const Variant &p_new_item);
  58. Variant get_new_item_key();
  59. void set_new_item_value(const Variant &p_new_item);
  60. Variant get_new_item_value();
  61. EditorPropertyDictionaryObject();
  62. };
  63. class EditorPropertyArray : public EditorProperty {
  64. GDCLASS(EditorPropertyArray, EditorProperty)
  65. PopupMenu *change_type;
  66. bool updating;
  67. Ref<EditorPropertyArrayObject> object;
  68. int page_len;
  69. int page_idx;
  70. int changing_type_idx;
  71. Button *edit;
  72. VBoxContainer *vbox;
  73. EditorSpinSlider *length;
  74. EditorSpinSlider *page;
  75. HBoxContainer *page_hb;
  76. Variant::Type array_type;
  77. Variant::Type subtype;
  78. PropertyHint subtype_hint;
  79. String subtype_hint_string;
  80. void _page_changed(double p_page);
  81. void _length_changed(double p_page);
  82. void _edit_pressed();
  83. void _property_changed(const String &p_prop, Variant p_value, bool changing = false);
  84. void _change_type(Object *p_button, int p_index);
  85. void _change_type_menu(int p_index);
  86. void _object_id_selected(const String &p_property, ObjectID p_id);
  87. protected:
  88. static void _bind_methods();
  89. void _notification(int p_what);
  90. public:
  91. void setup(Variant::Type p_array_type, const String &p_hint_string = "");
  92. virtual void update_property();
  93. EditorPropertyArray();
  94. };
  95. class EditorPropertyDictionary : public EditorProperty {
  96. GDCLASS(EditorPropertyDictionary, EditorProperty)
  97. PopupMenu *change_type;
  98. bool updating;
  99. Ref<EditorPropertyDictionaryObject> object;
  100. int page_len;
  101. int page_idx;
  102. int changing_type_idx;
  103. Button *edit;
  104. VBoxContainer *vbox;
  105. EditorSpinSlider *length;
  106. EditorSpinSlider *page;
  107. HBoxContainer *page_hb;
  108. void _page_changed(double p_page);
  109. void _edit_pressed();
  110. void _property_changed(const String &p_prop, Variant p_value, bool changing = false);
  111. void _change_type(Object *p_button, int p_index);
  112. void _change_type_menu(int p_index);
  113. void _add_key_value();
  114. void _object_id_selected(const String &p_property, ObjectID p_id);
  115. protected:
  116. static void _bind_methods();
  117. void _notification(int p_what);
  118. public:
  119. virtual void update_property();
  120. EditorPropertyDictionary();
  121. };
  122. #endif // EDITOR_PROPERTIES_ARRAY_DICT_H