From 5ca145ba5df1a3ca96265144a0b543569c64f98e Mon Sep 17 00:00:00 2001 From: Lightning_A Date: Mon, 29 Mar 2021 10:45:42 -0600 Subject: [PATCH] Add the ability to reorder arrays from the inspector --- editor/editor_properties_array_dict.cpp | 354 +++++++++++++++--------- editor/editor_properties_array_dict.h | 34 ++- editor/icons/icon_triple_bar.svg | 1 + 3 files changed, 248 insertions(+), 141 deletions(-) create mode 100644 editor/icons/icon_triple_bar.svg diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 8c79ffd83f8..6e6e5c45a24 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -31,15 +31,17 @@ #include "editor_properties_array_dict.h" #include "core/io/marshalls.h" +#include "core/os/input.h" +#include "editor/editor_node.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; + String name = p_name; - if (pn.begins_with("indices")) { - int idx = pn.get_slicec('/', 1).to_int(); - array.set(idx, p_value); + if (name.begins_with("indices")) { + int index = name.get_slicec('/', 1).to_int(); + array.set(index, p_value); return true; } @@ -47,12 +49,12 @@ bool EditorPropertyArrayObject::_set(const StringName &p_name, const Variant &p_ } bool EditorPropertyArrayObject::_get(const StringName &p_name, Variant &r_ret) const { - String pn = p_name; + String name = p_name; - if (pn.begins_with("indices")) { - int idx = pn.get_slicec('/', 1).to_int(); + if (name.begins_with("indices")) { + int index = name.get_slicec('/', 1).to_int(); bool valid; - r_ret = array.get(idx, &valid); + r_ret = array.get(index, &valid); if (r_ret.get_type() == Variant::OBJECT && Object::cast_to(r_ret)) { r_ret = Object::cast_to(r_ret)->get_object_id(); } @@ -77,21 +79,21 @@ EditorPropertyArrayObject::EditorPropertyArrayObject() { /////////////////// bool EditorPropertyDictionaryObject::_set(const StringName &p_name, const Variant &p_value) { - String pn = p_name; + String name = p_name; - if (pn == "new_item_key") { + if (name == "new_item_key") { new_item_key = p_value; return true; } - if (pn == "new_item_value") { + if (name == "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); + if (name.begins_with("indices")) { + int index = name.get_slicec('/', 1).to_int(); + Variant key = dict.get_key_at_index(index); dict[key] = p_value; return true; } @@ -100,21 +102,21 @@ bool EditorPropertyDictionaryObject::_set(const StringName &p_name, const Varian } bool EditorPropertyDictionaryObject::_get(const StringName &p_name, Variant &r_ret) const { - String pn = p_name; + String name = p_name; - if (pn == "new_item_key") { + if (name == "new_item_key") { r_ret = new_item_key; return true; } - if (pn == "new_item_value") { + if (name == "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); + if (name.begins_with("indices")) { + int index = name.get_slicec('/', 1).to_int(); + Variant key = dict.get_key_at_index(index); r_ret = dict[key]; if (r_ret.get_type() == Variant::OBJECT && Object::cast_to(r_ret)) { r_ret = Object::cast_to(r_ret)->get_object_id(); @@ -155,15 +157,15 @@ EditorPropertyDictionaryObject::EditorPropertyDictionaryObject() { ///////////////////// ARRAY /////////////////////////// -void EditorPropertyArray::_property_changed(const String &p_prop, Variant p_value, const String &p_name, bool changing) { - if (p_prop.begins_with("indices")) { - int idx = p_prop.get_slice("/", 1).to_int(); +void EditorPropertyArray::_property_changed(const String &p_property, Variant p_value, const String &p_name, bool p_changing) { + if (p_property.begins_with("indices")) { + int index = p_property.get_slice("/", 1).to_int(); Variant array = object->get_array(); - array.set(idx, p_value); + array.set(index, p_value); emit_changed(get_edited_property(), array, "", true); if (array.get_type() == Variant::ARRAY) { - array = array.call("duplicate"); //dupe, so undo/redo works better + array = array.call("duplicate"); // Duplicate, so undo/redo works better. } object->set_array(array); } @@ -171,7 +173,7 @@ void EditorPropertyArray::_property_changed(const String &p_prop, Variant p_valu void EditorPropertyArray::_change_type(Object *p_button, int p_index) { Button *button = Object::cast_to