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