Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset Library author link, description popup size and UX details #88229

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 57 additions & 18 deletions editor/plugins/asset_library_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ void EditorAssetLibraryItem::_notification(int p_what) {
category->add_theme_color_override("font_color", Color(0.5, 0.5, 0.5));
author->add_theme_color_override("font_color", Color(0.5, 0.5, 0.5));
price->add_theme_color_override("font_color", Color(0.5, 0.5, 0.5));

if (author->get_default_cursor_shape() == CURSOR_ARROW) {
// Disable visible feedback if author link isn't clickable.
author->add_theme_color_override("font_pressed_color", Color(0.5, 0.5, 0.5));
author->add_theme_color_override("font_hover_color", Color(0.5, 0.5, 0.5));
}
} break;
}
}
Expand All @@ -106,7 +112,7 @@ void EditorAssetLibraryItem::_category_clicked() {
}

void EditorAssetLibraryItem::_author_clicked() {
emit_signal(SNAME("author_selected"), author_id);
emit_signal(SNAME("author_selected"), author->get_text());
}

void EditorAssetLibraryItem::_bind_methods() {
Expand All @@ -116,7 +122,7 @@ void EditorAssetLibraryItem::_bind_methods() {
ADD_SIGNAL(MethodInfo("author_selected"));
}

EditorAssetLibraryItem::EditorAssetLibraryItem() {
EditorAssetLibraryItem::EditorAssetLibraryItem(bool p_clickable) {
Ref<StyleBoxEmpty> border;
border.instantiate();
border->set_content_margin_all(5 * EDSCALE);
Expand All @@ -129,9 +135,6 @@ EditorAssetLibraryItem::EditorAssetLibraryItem() {

icon = memnew(TextureButton);
icon->set_custom_minimum_size(Size2(64, 64) * EDSCALE);
icon->set_default_cursor_shape(CURSOR_POINTING_HAND);
icon->connect("pressed", callable_mp(this, &EditorAssetLibraryItem::_asset_clicked));

hb->add_child(icon);

VBoxContainer *vb = memnew(VBoxContainer);
Expand All @@ -141,23 +144,48 @@ EditorAssetLibraryItem::EditorAssetLibraryItem() {

title = memnew(LinkButton);
title->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
title->connect("pressed", callable_mp(this, &EditorAssetLibraryItem::_asset_clicked));
vb->add_child(title);

category = memnew(LinkButton);
category->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
category->connect("pressed", callable_mp(this, &EditorAssetLibraryItem::_category_clicked));
vb->add_child(category);

HBoxContainer *author_price_hbox = memnew(HBoxContainer);
author_price_hbox->add_theme_constant_override("separation", 5 * EDSCALE);
vb->add_child(author_price_hbox);

author = memnew(LinkButton);
author->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
author->connect("pressed", callable_mp(this, &EditorAssetLibraryItem::_author_clicked));
vb->add_child(author);
author->set_tooltip_text(TTR("Author"));
author_price_hbox->add_child(author);

author_price_hbox->add_child(memnew(HSeparator));

if (p_clickable) {
author->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
icon->set_default_cursor_shape(CURSOR_POINTING_HAND);
icon->connect("pressed", callable_mp(this, &EditorAssetLibraryItem::_asset_clicked));
title->connect("pressed", callable_mp(this, &EditorAssetLibraryItem::_asset_clicked));
category->connect("pressed", callable_mp(this, &EditorAssetLibraryItem::_category_clicked));
author->connect("pressed", callable_mp(this, &EditorAssetLibraryItem::_author_clicked));
} else {
title->set_mouse_filter(MOUSE_FILTER_IGNORE);
category->set_mouse_filter(MOUSE_FILTER_IGNORE);
author->set_underline_mode(LinkButton::UNDERLINE_MODE_NEVER);
author->set_default_cursor_shape(CURSOR_ARROW);
}

Ref<StyleBoxEmpty> label_margin;
label_margin.instantiate();
label_margin->set_content_margin_all(0);

price = memnew(Label);
vb->add_child(price);
price->add_theme_style_override("normal", label_margin);
price->set_tooltip_text(TTR("License"));
price->set_mouse_filter(MOUSE_FILTER_PASS);

author_price_hbox->add_child(price);

set_custom_minimum_size(Size2(250, 100) * EDSCALE);
set_custom_minimum_size(Size2(250, 80) * EDSCALE);
set_h_size_flags(Control::SIZE_EXPAND_FILL);
}

Expand Down Expand Up @@ -262,6 +290,10 @@ void EditorAssetLibraryItemDescription::configure(const String &p_title, int p_a
}

void EditorAssetLibraryItemDescription::add_preview(int p_id, bool p_video, const String &p_url) {
if (preview_images.is_empty()) {
previews_vbox->show();
}

Preview new_preview;
new_preview.id = p_id;
new_preview.video_link = p_url;
Expand Down Expand Up @@ -290,15 +322,17 @@ EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() {
item = memnew(EditorAssetLibraryItem);

desc_vbox->add_child(item);
desc_vbox->set_custom_minimum_size(Size2(440 * EDSCALE, 0));
desc_vbox->set_custom_minimum_size(Size2(440 * EDSCALE, 440 * EDSCALE));

description = memnew(RichTextLabel);
desc_vbox->add_child(description);
description->set_v_size_flags(Control::SIZE_EXPAND_FILL);
description->connect("meta_clicked", callable_mp(this, &EditorAssetLibraryItemDescription::_link_click));
description->add_theme_constant_override("line_separation", Math::round(5 * EDSCALE));

VBoxContainer *previews_vbox = memnew(VBoxContainer);
previews_vbox = memnew(VBoxContainer);
previews_vbox->hide(); // Will be shown if we add any previews later.

hbox->add_child(previews_vbox);
previews_vbox->add_theme_constant_override("separation", 15 * EDSCALE);
previews_vbox->set_v_size_flags(Control::SIZE_EXPAND_FILL);
Expand Down Expand Up @@ -736,8 +770,12 @@ const char *EditorAssetLibrary::support_text[SUPPORT_MAX] = {
TTRC("Testing"),
};

void EditorAssetLibrary::_select_author(int p_id) {
// Open author window.
void EditorAssetLibrary::_select_author(const String &p_author) {
if (!host.contains("godotengine.org")) {
// Don't open the link for alternative repositories.
return;
}
OS::get_singleton()->shell_open("https://godotengine.org/asset-library/asset?user=" + p_author.uri_encode());
}

void EditorAssetLibrary::_select_category(int p_id) {
Expand Down Expand Up @@ -1342,7 +1380,7 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const
ERR_FAIL_COND(!category_map.has(r["category_id"]));
ERR_CONTINUE(!r.has("cost"));

EditorAssetLibraryItem *item = memnew(EditorAssetLibraryItem);
EditorAssetLibraryItem *item = memnew(EditorAssetLibraryItem(true));
asset_items->add_child(item);
item->configure(r["title"], r["asset_id"], category_map[r["category_id"]], r["category_id"], r["author"], r["author_id"], r["cost"]);
item->clamp_width(asset_items_column_width);
Expand Down Expand Up @@ -1382,7 +1420,6 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const

description = memnew(EditorAssetLibraryItemDescription);
add_child(description);
description->popup_centered();
description->connect("confirmed", callable_mp(this, &EditorAssetLibrary::_install_asset));

description->configure(r["title"], r["asset_id"], category_map[r["category_id"]], r["category_id"], r["author"], r["author_id"], r["cost"], r["version"], r["version_string"], r["description"], r["download_url"], r["browse_url"], r["download_hash"]);
Expand Down Expand Up @@ -1431,6 +1468,8 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const
}
}
}

description->popup_centered();
} break;
default:
break;
Expand Down
6 changes: 3 additions & 3 deletions editor/plugins/asset_library_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class EditorAssetLibraryItem : public PanelContainer {
LinkButton *title = nullptr;
LinkButton *category = nullptr;
LinkButton *author = nullptr;
TextureRect *stars[5];
Label *price = nullptr;

int asset_id = 0;
Expand All @@ -82,14 +81,15 @@ class EditorAssetLibraryItem : public PanelContainer {

void clamp_width(int p_max_width);

EditorAssetLibraryItem();
EditorAssetLibraryItem(bool p_clickable = false);
};

class EditorAssetLibraryItemDescription : public ConfirmationDialog {
GDCLASS(EditorAssetLibraryItemDescription, ConfirmationDialog);

EditorAssetLibraryItem *item = nullptr;
RichTextLabel *description = nullptr;
VBoxContainer *previews_vbox = nullptr;
ScrollContainer *previews = nullptr;
HBoxContainer *preview_hb = nullptr;
PanelContainer *previews_bg = nullptr;
Expand Down Expand Up @@ -294,7 +294,7 @@ class EditorAssetLibrary : public PanelContainer {

void _install_asset();

void _select_author(int p_id);
void _select_author(const String &p_author);
void _select_category(int p_id);
void _select_asset(int p_id);

Expand Down
Loading