#include "editor_properties_array_dict.h" #include "editor/editor_scale.h" #include "editor_properties.h" 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() { } /////////////////// bool EditorPropertyDictionaryObject::_set(const StringName &p_name, const Variant &p_value) { String pn = p_name; if (pn == "new_item_key") { new_item_key = p_value; return true; } if (pn == "new_item_value") { new_item_value = p_value; return true; } if (pn.begins_with("indices")) { int idx = pn.get_slicec('/', 1).to_int(); Variant key = dict.get_key_at_index(idx); dict[key] = p_value; return true; } return false; } bool EditorPropertyDictionaryObject::_get(const StringName &p_name, Variant &r_ret) const { String pn = p_name; if (pn == "new_item_key") { r_ret = new_item_key; return true; } if (pn == "new_item_value") { r_ret = new_item_value; return true; } if (pn.begins_with("indices")) { int idx = pn.get_slicec('/', 1).to_int(); Variant key = dict.get_key_at_index(idx); r_ret = dict[key]; return true; } return false; } void EditorPropertyDictionaryObject::set_dict(const Dictionary &p_dict) { dict = p_dict; } Dictionary EditorPropertyDictionaryObject::get_dict() { return dict; } void EditorPropertyDictionaryObject::set_new_item_key(const Variant &p_new_item) { new_item_key = p_new_item; } Variant EditorPropertyDictionaryObject::get_new_item_key() { return new_item_key; } void EditorPropertyDictionaryObject::set_new_item_value(const Variant &p_new_item) { new_item_value = p_new_item; } Variant EditorPropertyDictionaryObject::get_new_item_value() { return new_item_value; } EditorPropertyDictionaryObject::EditorPropertyDictionaryObject() { } ///////////////////// ARRAY /////////////////////////// void EditorPropertyArray::_property_changed(const String &p_prop, Variant p_value, bool changing) { 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, true); 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