diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 8a15f4912a8..a6c7d6b617d 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -111,6 +111,7 @@ bool EditorPropertyDictionaryObject::_set(const StringName &p_name, const Varian } if (name.begins_with("indices")) { + dict = dict.duplicate(); int index = name.get_slicec('/', 1).to_int(); Variant key = dict.get_key_at_index(index); dict[key] = p_value; @@ -171,6 +172,31 @@ Variant EditorPropertyDictionaryObject::get_new_item_value() { return new_item_value; } +String EditorPropertyDictionaryObject::get_property_name_for_index(int p_index) { + switch (p_index) { + case NEW_KEY_INDEX: + return "new_item_key"; + case NEW_VALUE_INDEX: + return "new_item_value"; + default: + return "indices/" + itos(p_index); + } +} + +String EditorPropertyDictionaryObject::get_label_for_index(int p_index) { + switch (p_index) { + case NEW_KEY_INDEX: + return TTR("New Key:"); + break; + case NEW_VALUE_INDEX: + return TTR("New Value:"); + break; + default: + return dict.get_key_at_index(p_index).get_construct_string(); + break; + } +} + EditorPropertyDictionaryObject::EditorPropertyDictionaryObject() { } @@ -230,15 +256,14 @@ void EditorPropertyArray::_change_type_menu(int p_index) { Variant array = object->get_array().duplicate(); array.set(slots[changing_type_index].index, value); - emit_changed(get_edited_property(), array, "", true); - update_property(); + emit_changed(get_edited_property(), array); } void EditorPropertyArray::_object_id_selected(const StringName &p_property, ObjectID p_id) { emit_signal(SNAME("object_id_selected"), p_property, p_id); } -void EditorPropertyArray::create_new_property_slot() { +void EditorPropertyArray::_create_new_property_slot() { int idx = slots.size(); HBoxContainer *hbox = memnew(HBoxContainer); @@ -365,7 +390,7 @@ void EditorPropertyArray::update_property() { vbox->add_child(paginator); for (int i = 0; i < page_length; i++) { - create_new_property_slot(); + _create_new_property_slot(); } } @@ -434,8 +459,7 @@ void EditorPropertyArray::_remove_pressed(int p_slot_index) { Variant array = object->get_array().duplicate(); array.call("remove_at", slots[p_slot_index].index); - emit_changed(get_edited_property(), array, "", false); - update_property(); + emit_changed(get_edited_property(), array); } void EditorPropertyArray::_button_draw() { @@ -514,8 +538,7 @@ void EditorPropertyArray::drop_data_fw(const Point2 &p_point, const Variant &p_d } } - emit_changed(get_edited_property(), array, "", false); - update_property(); + emit_changed(get_edited_property(), array); } } @@ -607,8 +630,7 @@ void EditorPropertyArray::_length_changed(double p_page) { Variant array = object->get_array().duplicate(); array.call("resize", int(p_page)); - emit_changed(get_edited_property(), array, "", false); - update_property(); + emit_changed(get_edited_property(), array); } void EditorPropertyArray::_add_element() { @@ -700,8 +722,7 @@ void EditorPropertyArray::_reorder_button_up() { array.call("remove_at", reorder_slot.index); array.call("insert", reorder_to_index, value_to_move); - reorder_slot.index = reorder_slot.index % page_length + page_index * page_length; - emit_changed(get_edited_property(), array, "", false); + emit_changed(get_edited_property(), array); } Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); @@ -748,31 +769,19 @@ void EditorPropertyDictionary::_property_changed(const String &p_property, Varia p_value = Variant(); // `EditorResourcePicker` resets to `Ref()`. See GH-82716. } - if (p_property == "new_item_key") { - object->set_new_item_key(p_value); - } else if (p_property == "new_item_value") { - object->set_new_item_value(p_value); - } else if (p_property.begins_with("indices")) { - int index = p_property.get_slice("/", 1).to_int(); - - Dictionary dict = object->get_dict().duplicate(); - Variant key = dict.get_key_at_index(index); - dict[key] = p_value; - - object->set_dict(dict); - emit_changed(get_edited_property(), dict, "", true); - } + object->set(p_property, p_value); + emit_changed(get_edited_property(), object->get_dict(), p_name, p_changing); } -void EditorPropertyDictionary::_change_type(Object *p_button, int p_index) { +void EditorPropertyDictionary::_change_type(Object *p_button, int p_slot_index) { Button *button = Object::cast_to