Add support for resource conversion plugins in filesystem dock.

This commit is contained in:
SaracenOne 2022-09-09 19:39:37 +01:00 committed by Saracen
parent 6681f2563b
commit f44bce2ee0
7 changed files with 324 additions and 58 deletions

View file

@ -286,12 +286,13 @@ void EditorResourcePicker::_update_menu_items() {
// Add options to convert existing resource to another type of resource.
if (is_editable() && edited_resource.is_valid()) {
Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(edited_resource);
if (conversions.size()) {
Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin_for_resource(edited_resource);
if (!conversions.is_empty()) {
edit_menu->add_separator();
}
for (int i = 0; i < conversions.size(); i++) {
String what = conversions[i]->converts_to();
int relative_id = 0;
for (const Ref<EditorResourceConversionPlugin> &conversion : conversions) {
String what = conversion->converts_to();
Ref<Texture2D> icon;
if (has_theme_icon(what, EditorStringName(EditorIcons))) {
icon = get_editor_theme_icon(what);
@ -299,7 +300,8 @@ void EditorResourcePicker::_update_menu_items() {
icon = get_theme_icon(what, SNAME("Resource"));
}
edit_menu->add_icon_item(icon, vformat(TTR("Convert to %s"), what), CONVERT_BASE_ID + i);
edit_menu->add_icon_item(icon, vformat(TTR("Convert to %s"), what), CONVERT_BASE_ID + relative_id);
relative_id++;
}
}
}
@ -451,7 +453,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
if (p_which >= CONVERT_BASE_ID) {
int to_type = p_which - CONVERT_BASE_ID;
Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(edited_resource);
Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin_for_resource(edited_resource);
ERR_FAIL_INDEX(to_type, conversions.size());
edited_resource = conversions[to_type]->convert(edited_resource);