Improvements to EditorResourcePicker
(cherry picked from commit 9568789a9d
)
This commit is contained in:
parent
22f93bccb4
commit
3f8bb6fb53
|
@ -51,6 +51,7 @@ void EditorResourcePicker::_update_resource() {
|
||||||
if (edited_resource == RES()) {
|
if (edited_resource == RES()) {
|
||||||
assign_button->set_icon(Ref<Texture>());
|
assign_button->set_icon(Ref<Texture>());
|
||||||
assign_button->set_text(TTR("[empty]"));
|
assign_button->set_text(TTR("[empty]"));
|
||||||
|
assign_button->set_tooltip("");
|
||||||
} else {
|
} else {
|
||||||
assign_button->set_icon(EditorNode::get_singleton()->get_object_icon(edited_resource.operator->(), "Object"));
|
assign_button->set_icon(EditorNode::get_singleton()->get_object_icon(edited_resource.operator->(), "Object"));
|
||||||
|
|
||||||
|
@ -58,14 +59,15 @@ void EditorResourcePicker::_update_resource() {
|
||||||
assign_button->set_text(edited_resource->get_name());
|
assign_button->set_text(edited_resource->get_name());
|
||||||
} else if (edited_resource->get_path().is_resource_file()) {
|
} else if (edited_resource->get_path().is_resource_file()) {
|
||||||
assign_button->set_text(edited_resource->get_path().get_file());
|
assign_button->set_text(edited_resource->get_path().get_file());
|
||||||
assign_button->set_tooltip(edited_resource->get_path());
|
|
||||||
} else {
|
} else {
|
||||||
assign_button->set_text(edited_resource->get_class());
|
assign_button->set_text(edited_resource->get_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String resource_path;
|
||||||
if (edited_resource->get_path().is_resource_file()) {
|
if (edited_resource->get_path().is_resource_file()) {
|
||||||
assign_button->set_tooltip(edited_resource->get_path());
|
resource_path = edited_resource->get_path() + "\n";
|
||||||
}
|
}
|
||||||
|
assign_button->set_tooltip(resource_path + TTR("Type:") + " " + edited_resource->get_class());
|
||||||
|
|
||||||
// Preview will override the above, so called at the end.
|
// 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());
|
EditorResourcePreview::get_singleton()->queue_edited_resource_preview(edited_resource, this, "_update_resource_preview", edited_resource->get_instance_id());
|
||||||
|
@ -520,6 +522,8 @@ void EditorResourcePicker::_get_allowed_types(bool p_with_convert, Set<String> *
|
||||||
p_vector->insert("Texture");
|
p_vector->insert("Texture");
|
||||||
} else if (base == "ShaderMaterial") {
|
} else if (base == "ShaderMaterial") {
|
||||||
p_vector->insert("Shader");
|
p_vector->insert("Shader");
|
||||||
|
} else if (base == "Texture") {
|
||||||
|
p_vector->insert("Image");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -638,18 +642,35 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
|
||||||
String at = E->get().strip_edges();
|
String at = E->get().strip_edges();
|
||||||
|
|
||||||
if (at == "SpatialMaterial" && ClassDB::is_parent_class(dropped_resource->get_class(), "Texture")) {
|
if (at == "SpatialMaterial" && ClassDB::is_parent_class(dropped_resource->get_class(), "Texture")) {
|
||||||
Ref<SpatialMaterial> mat = memnew(SpatialMaterial);
|
// Use existing resource if possible and only replace its data.
|
||||||
|
Ref<SpatialMaterial> mat = edited_resource;
|
||||||
|
if (mat.is_null()) {
|
||||||
|
mat.instance();
|
||||||
|
}
|
||||||
mat->set_texture(SpatialMaterial::TextureParam::TEXTURE_ALBEDO, dropped_resource);
|
mat->set_texture(SpatialMaterial::TextureParam::TEXTURE_ALBEDO, dropped_resource);
|
||||||
dropped_resource = mat;
|
dropped_resource = mat;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (at == "ShaderMaterial" && ClassDB::is_parent_class(dropped_resource->get_class(), "Shader")) {
|
if (at == "ShaderMaterial" && ClassDB::is_parent_class(dropped_resource->get_class(), "Shader")) {
|
||||||
Ref<ShaderMaterial> mat = memnew(ShaderMaterial);
|
Ref<ShaderMaterial> mat = edited_resource;
|
||||||
|
if (mat.is_null()) {
|
||||||
|
mat.instance();
|
||||||
|
}
|
||||||
mat->set_shader(dropped_resource);
|
mat->set_shader(dropped_resource);
|
||||||
dropped_resource = mat;
|
dropped_resource = mat;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (at == "Texture" && ClassDB::is_parent_class(dropped_resource->get_class(), "Image")) {
|
||||||
|
Ref<ImageTexture> texture = edited_resource;
|
||||||
|
if (texture.is_null()) {
|
||||||
|
texture.instance();
|
||||||
|
}
|
||||||
|
texture->create_from_image(dropped_resource);
|
||||||
|
dropped_resource = texture;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue