Skip to content

Commit

Permalink
Merge pull request #56398 from KoBeWi/cooler_picker
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jan 5, 2022
2 parents cbf8757 + 9568789 commit 8f6cba3
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions editor/editor_resource_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,23 @@ void EditorResourcePicker::_update_resource() {
if (edited_resource == RES()) {
assign_button->set_icon(Ref<Texture2D>());
assign_button->set_text(TTR("[empty]"));
assign_button->set_tooltip("");
} else {
assign_button->set_icon(EditorNode::get_singleton()->get_object_icon(edited_resource.operator->(), "Object"));

if (!edited_resource->get_name().is_empty()) {
assign_button->set_text(edited_resource->get_name());
} else if (edited_resource->get_path().is_resource_file()) {
assign_button->set_text(edited_resource->get_path().get_file());
assign_button->set_tooltip(edited_resource->get_path());
} else {
assign_button->set_text(edited_resource->get_class());
}

String resource_path;
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.
EditorResourcePreview::get_singleton()->queue_edited_resource_preview(edited_resource, this, "_update_resource_preview", edited_resource->get_instance_id());
Expand Down Expand Up @@ -514,12 +516,14 @@ void EditorResourcePicker::_get_allowed_types(bool p_with_convert, Set<String> *
}

if (p_with_convert) {
if (base == "StandardMaterial3D") {
if (base == "BaseMaterial3D") {
p_vector->insert("Texture2D");
} else if (base == "ShaderMaterial") {
p_vector->insert("Shader");
} else if (base == "Font") {
p_vector->insert("FontData");
} else if (base == "Texture2D") {
p_vector->insert("Image");
}
}
}
Expand Down Expand Up @@ -636,26 +640,46 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
for (Set<String>::Element *E = allowed_types.front(); E; E = E->next()) {
String at = E->get().strip_edges();

if (at == "StandardMaterial3D" && ClassDB::is_parent_class(dropped_resource->get_class(), "Texture2D")) {
Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D);
if (at == "BaseMaterial3D" && ClassDB::is_parent_class(dropped_resource->get_class(), "Texture2D")) {
// Use existing resource if possible and only replace its data.
Ref<StandardMaterial3D> mat = edited_resource;
if (!mat.is_valid()) {
mat.instantiate();
}
mat->set_texture(StandardMaterial3D::TextureParam::TEXTURE_ALBEDO, dropped_resource);
dropped_resource = mat;
break;
}

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_valid()) {
mat.instantiate();
}
mat->set_shader(dropped_resource);
dropped_resource = mat;
break;
}

if (at == "Font" && ClassDB::is_parent_class(dropped_resource->get_class(), "FontData")) {
Ref<Font> font = memnew(Font);
Ref<Font> font = edited_resource;
if (!font.is_valid()) {
font.instantiate();
}
font->add_data(dropped_resource);
dropped_resource = font;
break;
}

if (at == "Texture2D" && ClassDB::is_parent_class(dropped_resource->get_class(), "Image")) {
Ref<ImageTexture> texture = edited_resource;
if (!texture.is_valid()) {
texture.instantiate();
}
texture->create_from_image(dropped_resource);
dropped_resource = texture;
break;
}
}
}

Expand Down

0 comments on commit 8f6cba3

Please sign in to comment.