| 2813 | } |
| 2814 | |
| 2815 | void EditorInspectorArray::_resize_array(int p_size) { |
| 2816 | ERR_FAIL_COND(p_size < 0); |
| 2817 | if (p_size == count) { |
| 2818 | return; |
| 2819 | } |
| 2820 | |
| 2821 | EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); |
| 2822 | undo_redo->create_action(vformat(TTR("Resize Property Array with Prefix %s"), array_element_prefix)); |
| 2823 | if (p_size > count) { |
| 2824 | if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) { |
| 2825 | for (int i = count; i < p_size; i++) { |
| 2826 | // Call the function. |
| 2827 | Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name()); |
| 2828 | if (move_function.is_valid()) { |
| 2829 | move_function.call(undo_redo, object, array_element_prefix, -1, -1); |
| 2830 | } else { |
| 2831 | WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name())); |
| 2832 | } |
| 2833 | } |
| 2834 | } else if (mode == MODE_USE_COUNT_PROPERTY) { |
| 2835 | undo_redo->add_undo_property(object, count_property, count); |
| 2836 | undo_redo->add_do_property(object, count_property, p_size); |
| 2837 | } |
| 2838 | } else { |
| 2839 | if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) { |
| 2840 | for (int i = count - 1; i > p_size - 1; i--) { |
| 2841 | // Call the function. |
| 2842 | Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name()); |
| 2843 | if (move_function.is_valid()) { |
| 2844 | move_function.call(undo_redo, object, array_element_prefix, i, -1); |
| 2845 | } else { |
| 2846 | WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name())); |
| 2847 | } |
| 2848 | } |
| 2849 | } else if (mode == MODE_USE_COUNT_PROPERTY) { |
| 2850 | List<PropertyInfo> object_property_list; |
| 2851 | object->get_property_list(&object_property_list); |
| 2852 | |
| 2853 | Array properties_as_array = _extract_properties_as_array(object_property_list); |
| 2854 | properties_as_array.resize(count); |
| 2855 | |
| 2856 | // For undoing things |
| 2857 | undo_redo->add_undo_property(object, count_property, count); |
| 2858 | for (int i = count - 1; i > p_size - 1; i--) { |
| 2859 | Dictionary d = Dictionary(properties_as_array[i]); |
| 2860 | for (const KeyValue<Variant, Variant> &kv : d) { |
| 2861 | undo_redo->add_undo_property(object, vformat(kv.key, i), kv.value); |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | // Change the array size then set the properties. |
| 2866 | undo_redo->add_do_property(object, count_property, p_size); |
| 2867 | } |
| 2868 | } |
| 2869 | undo_redo->commit_action(); |
| 2870 | |
| 2871 | // Handle page change and update counts. |
| 2872 | emit_signal(SNAME("page_change_request"), 0); |
nothing calls this directly
no test coverage detected