From eded06166860b3c052310cc8db28cc080655b510 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 19 May 2018 16:09:38 -0300 Subject: Dictionary editing does the comeback to the inspector, fixes #19046 --- editor/editor_properties_array_dict.cpp | 477 ++++++++++++++++++++++++++++++++ 1 file changed, 477 insertions(+) create mode 100644 editor/editor_properties_array_dict.cpp (limited to 'editor/editor_properties_array_dict.cpp') diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp new file mode 100644 index 000000000..f8f69ea25 --- /dev/null +++ b/editor/editor_properties_array_dict.cpp @@ -0,0 +1,477 @@ +#include "editor_properties_array_dict.h" +#include "editor_properties.h" +#define ITEMS_PER_PAGE 100 + +bool EditorPropertyArrayObject::_set(const StringName &p_name, const Variant &p_value) { + + String pn = p_name; + + if (pn.begins_with("indices")) { + int idx = pn.get_slicec('/', 1).to_int(); + array.set(idx, p_value); + return true; + } + + return false; +} + +bool EditorPropertyArrayObject::_get(const StringName &p_name, Variant &r_ret) const { + + String pn = p_name; + + if (pn.begins_with("indices")) { + + int idx = pn.get_slicec('/', 1).to_int(); + bool valid; + r_ret = array.get(idx, &valid); + return valid; + } + + return false; +} + +void EditorPropertyArrayObject::set_array(const Variant &p_array) { + array = p_array; +} + +Variant EditorPropertyArrayObject::get_array() { + return array; +} + +EditorPropertyArrayObject::EditorPropertyArrayObject() { +} + +///////////////////// + +void EditorPropertyArray::_property_changed(const String &p_prop, Variant p_value) { + + if (p_prop.begins_with("indices")) { + int idx = p_prop.get_slice("/", 1).to_int(); + Variant array = object->get_array(); + array.set(idx, p_value); + emit_signal("property_changed", get_edited_property(), array); + + if (array.get_type() == Variant::ARRAY) { + array = array.call("duplicate"); //dupe, so undo/redo works better + } + object->set_array(array); + } +} + +void EditorPropertyArray::_change_type(Object *p_button, int p_index) { + + Button *button = Object::cast_to