diff options
Diffstat (limited to 'editor/editor_resource_picker.cpp')
-rw-r--r-- | editor/editor_resource_picker.cpp | 132 |
1 files changed, 76 insertions, 56 deletions
diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index e5c1836205..f717188b3b 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -61,8 +61,8 @@ void EditorResourcePicker::_update_resource() { if (edited_resource == Ref<Resource>()) { assign_button->set_icon(Ref<Texture2D>()); - assign_button->set_text(TTR("[empty]")); - assign_button->set_tooltip(""); + assign_button->set_text(TTR("<empty>")); + assign_button->set_tooltip_text(""); } else { assign_button->set_icon(EditorNode::get_singleton()->get_object_icon(edited_resource.operator->(), "Object")); @@ -73,14 +73,16 @@ void EditorResourcePicker::_update_resource() { } else { assign_button->set_text(edited_resource->get_class()); } - assign_button->set_tooltip(resource_path + TTR("Type:") + " " + edited_resource->get_class()); + assign_button->set_tooltip_text(resource_path + TTR("Type:") + " " + edited_resource->get_class()); // Preview will override the above, so called at the end. EditorResourcePreview::get_singleton()->queue_edited_resource_preview(edited_resource, this, "_update_resource_preview", edited_resource->get_instance_id()); } } else if (edited_resource.is_valid()) { - assign_button->set_tooltip(resource_path + TTR("Type:") + " " + edited_resource->get_class()); + assign_button->set_tooltip_text(resource_path + TTR("Type:") + " " + edited_resource->get_class()); } + + assign_button->set_disabled(!editable && !edited_resource.is_valid()); } void EditorResourcePicker::_update_resource_preview(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, ObjectID p_obj) { @@ -106,7 +108,7 @@ void EditorResourcePicker::_update_resource_preview(const String &p_path, const preview_rect->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); thumbnail_size *= EDSCALE; - assign_button->set_custom_minimum_size(Size2(MIN(1, assign_button_min_size.x), MIN(thumbnail_size, assign_button_min_size.y))); + assign_button->set_custom_minimum_size(Size2(MAX(1, assign_button_min_size.x), MAX(thumbnail_size, assign_button_min_size.y))); } preview_rect->set_texture(p_preview); @@ -171,35 +173,50 @@ void EditorResourcePicker::_update_menu_items() { edit_menu->clear(); // Add options for creating specific subtypes of the base resource type. - set_create_options(edit_menu); + if (is_editable()) { + set_create_options(edit_menu); - // Add an option to load a resource from a file using the QuickOpen dialog. - edit_menu->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Quick Load"), OBJ_MENU_QUICKLOAD); + // Add an option to load a resource from a file using the QuickOpen dialog. + edit_menu->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Quick Load"), OBJ_MENU_QUICKLOAD); - // Add an option to load a resource from a file using the regular file dialog. - edit_menu->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Load"), OBJ_MENU_LOAD); + // Add an option to load a resource from a file using the regular file dialog. + edit_menu->add_icon_item(get_theme_icon(SNAME("Load"), SNAME("EditorIcons")), TTR("Load"), OBJ_MENU_LOAD); + } // Add options for changing existing value of the resource. if (edited_resource.is_valid()) { - edit_menu->add_icon_item(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), TTR("Edit"), OBJ_MENU_EDIT); - edit_menu->add_icon_item(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), TTR("Clear"), OBJ_MENU_CLEAR); - edit_menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE); - - // Check whether the resource has subresources. - List<PropertyInfo> property_list; - edited_resource->get_property_list(&property_list); - bool has_subresources = false; - for (PropertyInfo &p : property_list) { - if ((p.type == Variant::OBJECT) && (p.hint == PROPERTY_HINT_RESOURCE_TYPE) && (p.name != "script")) { - has_subresources = true; - break; - } - } - if (has_subresources) { - edit_menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Make Unique (Recursive)"), OBJ_MENU_MAKE_UNIQUE_RECURSIVE); + // Determine if the edited resource is part of another scene (foreign) which was imported + bool is_edited_resource_foreign_import = EditorNode::get_singleton()->is_resource_read_only(edited_resource); + + // If the resource is determined to be foreign and imported, change the menu entry's description to 'inspect' rather than 'edit' + // since will only be able to view its properties in read-only mode. + if (is_edited_resource_foreign_import) { + // The 'Search' icon is a magnifying glass, which seems appropriate, but maybe a bespoke icon is preferred here. + edit_menu->add_icon_item(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")), TTR("Inspect"), OBJ_MENU_INSPECT); + } else { + edit_menu->add_icon_item(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), TTR("Edit"), OBJ_MENU_INSPECT); } - edit_menu->add_icon_item(get_theme_icon(SNAME("Save"), SNAME("EditorIcons")), TTR("Save"), OBJ_MENU_SAVE); + if (is_editable()) { + edit_menu->add_icon_item(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), TTR("Clear"), OBJ_MENU_CLEAR); + edit_menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE); + + // Check whether the resource has subresources. + List<PropertyInfo> property_list; + edited_resource->get_property_list(&property_list); + bool has_subresources = false; + for (PropertyInfo &p : property_list) { + if ((p.type == Variant::OBJECT) && (p.hint == PROPERTY_HINT_RESOURCE_TYPE) && (p.name != "script")) { + has_subresources = true; + break; + } + } + if (has_subresources) { + edit_menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Make Unique (Recursive)"), OBJ_MENU_MAKE_UNIQUE_RECURSIVE); + } + + edit_menu->add_icon_item(get_theme_icon(SNAME("Save"), SNAME("EditorIcons")), TTR("Save"), OBJ_MENU_SAVE); + } if (edited_resource->get_path().is_resource_file()) { edit_menu->add_separator(); @@ -210,14 +227,16 @@ void EditorResourcePicker::_update_menu_items() { // Add options to copy/paste resource. Ref<Resource> cb = EditorSettings::get_singleton()->get_resource_clipboard(); bool paste_valid = false; - if (cb.is_valid()) { - if (base_type.is_empty()) { - paste_valid = true; - } else { - for (int i = 0; i < base_type.get_slice_count(","); i++) { - if (ClassDB::is_parent_class(cb->get_class(), base_type.get_slice(",", i))) { - paste_valid = true; - break; + if (is_editable()) { + if (cb.is_valid()) { + if (base_type.is_empty()) { + paste_valid = true; + } else { + for (int i = 0; i < base_type.get_slice_count(","); i++) { + if (ClassDB::is_parent_class(cb->get_class(), base_type.get_slice(",", i))) { + paste_valid = true; + break; + } } } } @@ -236,7 +255,7 @@ void EditorResourcePicker::_update_menu_items() { } // Add options to convert existing resource to another type of resource. - if (edited_resource.is_valid()) { + if (is_editable() && edited_resource.is_valid()) { Vector<Ref<EditorResourceConversionPlugin>> conversions = EditorNode::get_singleton()->find_resource_conversion_plugin(edited_resource); if (conversions.size()) { edit_menu->add_separator(); @@ -295,7 +314,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { quick_open->set_title(TTR("Resource")); } break; - case OBJ_MENU_EDIT: { + case OBJ_MENU_INSPECT: { if (edited_resource.is_valid()) { emit_signal(SNAME("resource_selected"), edited_resource, true); } @@ -491,20 +510,21 @@ void EditorResourcePicker::_button_draw() { } void EditorResourcePicker::_button_input(const Ref<InputEvent> &p_event) { - if (!editable) { - return; - } - Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { if (mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) { - _update_menu_items(); - - Vector2 pos = get_screen_position() + mb->get_position(); - edit_menu->reset_size(); - edit_menu->set_position(pos); - edit_menu->popup(); + // Only attempt to update and show the menu if we have + // a valid resource or the Picker is editable, as + // there will otherwise be nothing to display. + if (edited_resource.is_valid() || is_editable()) { + _update_menu_items(); + + Vector2 pos = get_screen_position() + mb->get_position(); + edit_menu->reset_size(); + edit_menu->set_position(pos); + edit_menu->popup(); + } } } } @@ -734,7 +754,7 @@ void EditorResourcePicker::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "toggle_mode"), "set_toggle_mode", "is_toggle_mode"); - ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::BOOL, "edit"))); + ADD_SIGNAL(MethodInfo("resource_selected", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::BOOL, "inspect"))); ADD_SIGNAL(MethodInfo("resource_changed", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); } @@ -755,14 +775,14 @@ void EditorResourcePicker::_notification(int p_what) { case NOTIFICATION_DRAG_BEGIN: { if (editable && _is_drop_valid(get_viewport()->gui_get_drag_data())) { dropping = true; - assign_button->update(); + assign_button->queue_redraw(); } } break; case NOTIFICATION_DRAG_END: { if (dropping) { dropping = false; - assign_button->update(); + assign_button->queue_redraw(); } } break; } @@ -866,7 +886,7 @@ void EditorResourcePicker::set_toggle_pressed(bool p_pressed) { void EditorResourcePicker::set_editable(bool p_editable) { editable = p_editable; - assign_button->set_disabled(!editable); + assign_button->set_disabled(!editable && !edited_resource.is_valid()); edit_button->set_visible(editable); } @@ -1029,7 +1049,7 @@ void EditorAudioStreamPicker::_notification(int p_what) { Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(audio_stream); if (preview.is_valid()) { if (preview->get_version() != last_preview_version) { - stream_preview_rect->update(); + stream_preview_rect->queue_redraw(); last_preview_version = preview->get_version(); } } @@ -1063,10 +1083,10 @@ void EditorAudioStreamPicker::_notification(int p_what) { } } - stream_preview_rect->update(); + stream_preview_rect->queue_redraw(); } else { if (tagged_frame_offset_count != 0) { - stream_preview_rect->update(); + stream_preview_rect->queue_redraw(); } tagged_frame_offset_count = 0; } @@ -1087,13 +1107,13 @@ void EditorAudioStreamPicker::_update_resource() { set_assign_button_min_size(Size2(1, font->get_height(font_size) * 1.5)); } - stream_preview_rect->update(); + stream_preview_rect->queue_redraw(); } void EditorAudioStreamPicker::_preview_draw() { Ref<AudioStream> audio_stream = get_edited_resource(); if (!audio_stream.is_valid()) { - get_assign_button()->set_text(TTR("[empty]")); + get_assign_button()->set_text(TTR("<empty>")); return; } |