Merge pull request #113753 from arkology/unique-right

Fix unique button for `EditorAudioStreamPicker`
This commit is contained in:
Thaddeus Crews 2025-12-15 08:01:16 -06:00
commit 2da239fa22
No known key found for this signature in database
GPG Key ID: 8C6E5FEB5FC03CCC
1 changed files with 54 additions and 51 deletions

View File

@ -94,58 +94,7 @@ void EditorResourcePicker::_update_resource() {
assign_button->set_button_icon(Ref<Texture2D>());
assign_button->set_text(TTR("<empty>"));
assign_button->set_tooltip_text("");
make_unique_button->set_disabled(true);
make_unique_button->set_visible(false);
} else {
Ref<Resource> parent_res = _has_parent_resource();
bool unique_enable = _is_uniqueness_enabled();
bool unique_recursive_enabled = _is_uniqueness_enabled(true);
bool is_internal = EditorNode::get_singleton()->is_resource_internal_to_scene(edited_resource);
int num_of_copies = EditorNode::get_singleton()->get_resource_count(edited_resource);
make_unique_button->set_button_icon(get_editor_theme_icon(SNAME("Instance")));
make_unique_button->set_visible((num_of_copies > 1 || !is_internal) && !Object::cast_to<Script>(edited_resource.ptr()));
make_unique_button->set_disabled((!unique_enable && !unique_recursive_enabled) || !editable);
String tooltip;
String resource_name = "resource";
if (edited_resource.is_valid()) {
resource_name = edited_resource->get_class();
if (edited_resource->has_meta(SceneStringName(_custom_type_script))) {
const Ref<Script> custom_script = PropertyUtils::get_custom_type_script(edited_resource.ptr());
if (custom_script.is_valid()) {
const String global_name = custom_script->get_global_name();
if (!global_name.is_empty()) {
resource_name = global_name;
}
}
}
}
if (num_of_copies > 1) {
tooltip = vformat(TTRN("This %s is used in %d place.", "This %s is used in %d places.", num_of_copies), resource_name, num_of_copies);
} else if (!is_internal) {
tooltip = vformat(TTR("This %s is external to scene."), resource_name);
}
if (!editable) {
tooltip += "\n" + vformat(TTR("The %s cannot be edited in the inspector and can't be made unique directly."), resource_name) + "\n";
} else {
if (unique_enable) {
tooltip += "\n" + TTR("Left-click to make it unique.") + "\n";
}
if (unique_recursive_enabled) {
tooltip += TTR("It is possible to make its subresources unique.") + "\n" + TTR("Right-click to make them unique.");
}
if (!unique_enable && EditorNode::get_singleton()->get_editor_selection()->get_full_selected_node_list().size() == 1) {
tooltip += TTR("In order to duplicate it, make its parent Resource unique.") + "\n";
}
}
make_unique_button->set_tooltip_text(tooltip);
assign_button->set_button_icon(EditorNode::get_singleton()->get_object_icon(edited_resource.operator->()));
if (!edited_resource->get_name().is_empty()) {
@ -168,6 +117,60 @@ void EditorResourcePicker::_update_resource() {
assign_button->set_tooltip_text(resource_path + TTR("Type:") + " " + edited_resource->get_class());
}
if (edited_resource.is_null()) {
make_unique_button->set_visible(false);
} else {
Ref<Resource> parent_res = _has_parent_resource();
bool unique_enable = _is_uniqueness_enabled();
bool unique_recursive_enabled = _is_uniqueness_enabled(true);
bool is_internal = EditorNode::get_singleton()->is_resource_internal_to_scene(edited_resource);
int num_of_copies = EditorNode::get_singleton()->get_resource_count(edited_resource);
make_unique_button->set_button_icon(get_editor_theme_icon(SNAME("Instance")));
make_unique_button->set_visible((num_of_copies > 1 || !is_internal) && !Object::cast_to<Script>(edited_resource.ptr()));
make_unique_button->set_disabled((!unique_enable && !unique_recursive_enabled) || !editable);
String tooltip;
String resource_name = "resource";
if (edited_resource.is_valid()) {
resource_name = edited_resource->get_class();
if (edited_resource->has_meta(SceneStringName(_custom_type_script))) {
const Ref<Script> custom_script = PropertyUtils::get_custom_type_script(edited_resource.ptr());
if (custom_script.is_valid()) {
const String global_name = custom_script->get_global_name();
if (!global_name.is_empty()) {
resource_name = global_name;
}
}
}
}
if (num_of_copies > 1) {
tooltip = vformat(TTRN("This %s is used in %d place.", "This %s is used in %d places.", num_of_copies), resource_name, num_of_copies);
} else if (!is_internal) {
tooltip = vformat(TTR("This %s is external to scene."), resource_name);
}
if (!editable) {
tooltip += "\n" + vformat(TTR("The %s cannot be edited in the inspector and can't be made unique directly."), resource_name) + "\n";
} else {
if (unique_enable) {
tooltip += "\n" + TTR("Left-click to make it unique.") + "\n";
}
if (unique_recursive_enabled) {
tooltip += TTR("It is possible to make its subresources unique.") + "\n" + TTR("Right-click to make them unique.");
}
if (!unique_enable && EditorNode::get_singleton()->get_editor_selection()->get_full_selected_node_list().size() == 1) {
tooltip += TTR("In order to duplicate it, make its parent Resource unique.") + "\n";
}
}
make_unique_button->set_tooltip_text(tooltip);
}
assign_button->set_disabled(!editable && edited_resource.is_null());
quick_load_button->set_visible(editable && edited_resource.is_null());
}