|
|
|
|
@ -65,6 +65,8 @@ void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, co
|
|
|
|
|
author->set_text(p_author);
|
|
|
|
|
author_id = p_author_id;
|
|
|
|
|
price->set_text(p_cost);
|
|
|
|
|
|
|
|
|
|
_calculate_misc_links_size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorAssetLibraryItem::set_image(int p_type, int p_index, const Ref<Texture2D> &p_image) {
|
|
|
|
|
@ -87,10 +89,53 @@ void EditorAssetLibraryItem::_notification(int p_what) {
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculate_misc_links_ratio();
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case NOTIFICATION_THEME_CHANGED:
|
|
|
|
|
case NOTIFICATION_TRANSLATION_CHANGED: {
|
|
|
|
|
_calculate_misc_links_size();
|
|
|
|
|
calculate_misc_links_ratio();
|
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorAssetLibraryItem::_calculate_misc_links_size() {
|
|
|
|
|
Ref<TextLine> text_buf;
|
|
|
|
|
text_buf.instantiate();
|
|
|
|
|
text_buf->add_string(author->get_text(), author->get_button_font(), author->get_button_font_size());
|
|
|
|
|
author_width = text_buf->get_line_width();
|
|
|
|
|
|
|
|
|
|
text_buf->clear();
|
|
|
|
|
const Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Label"));
|
|
|
|
|
const int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Label"));
|
|
|
|
|
text_buf->add_string(price->get_text(), font, font_size);
|
|
|
|
|
price_width = text_buf->get_line_width();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorAssetLibraryItem::calculate_misc_links_ratio() {
|
|
|
|
|
const int separators_width = 15 * EDSCALE;
|
|
|
|
|
const float total_width = author_price_hbox->get_size().width - (separator->get_size().width + separators_width);
|
|
|
|
|
if (total_width <= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float ratio_left = 1;
|
|
|
|
|
// Make the ratios a fraction bigger, to avoid unnecessary trimming.
|
|
|
|
|
const float extra_ratio = 4.0 / total_width;
|
|
|
|
|
|
|
|
|
|
const float author_ratio = MIN(1, author_width / total_width);
|
|
|
|
|
author->set_stretch_ratio(author_ratio + extra_ratio);
|
|
|
|
|
ratio_left -= author_ratio;
|
|
|
|
|
|
|
|
|
|
const float price_ratio = MIN(1, price_width / total_width);
|
|
|
|
|
price->set_stretch_ratio(price_ratio + extra_ratio);
|
|
|
|
|
ratio_left -= price_ratio;
|
|
|
|
|
|
|
|
|
|
spacer->set_stretch_ratio(ratio_left);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorAssetLibraryItem::_asset_clicked() {
|
|
|
|
|
emit_signal(SNAME("asset_selected"), asset_id);
|
|
|
|
|
}
|
|
|
|
|
@ -144,7 +189,7 @@ EditorAssetLibraryItem::EditorAssetLibraryItem(bool p_clickable) {
|
|
|
|
|
category->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
|
|
|
|
|
vb->add_child(category);
|
|
|
|
|
|
|
|
|
|
HBoxContainer *author_price_hbox = memnew(HBoxContainer);
|
|
|
|
|
author_price_hbox = memnew(HBoxContainer);
|
|
|
|
|
author_price_hbox->add_theme_constant_override("separation", 5 * EDSCALE);
|
|
|
|
|
vb->add_child(author_price_hbox);
|
|
|
|
|
|
|
|
|
|
@ -152,9 +197,11 @@ EditorAssetLibraryItem::EditorAssetLibraryItem(bool p_clickable) {
|
|
|
|
|
author->set_tooltip_text(TTRC("Author"));
|
|
|
|
|
author->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
|
|
|
|
|
author->set_accessibility_name(TTRC("Author"));
|
|
|
|
|
author->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
|
author_price_hbox->add_child(author);
|
|
|
|
|
|
|
|
|
|
author_price_hbox->add_child(memnew(HSeparator));
|
|
|
|
|
separator = memnew(HSeparator);
|
|
|
|
|
author_price_hbox->add_child(separator);
|
|
|
|
|
|
|
|
|
|
if (p_clickable) {
|
|
|
|
|
author->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
|
|
|
|
|
@ -178,11 +225,16 @@ EditorAssetLibraryItem::EditorAssetLibraryItem(bool p_clickable) {
|
|
|
|
|
price->set_focus_mode(FOCUS_ACCESSIBILITY);
|
|
|
|
|
price->add_theme_style_override(CoreStringName(normal), label_margin);
|
|
|
|
|
price->set_tooltip_text(TTRC("License"));
|
|
|
|
|
price->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
|
|
|
|
|
price->set_accessibility_name(TTRC("License"));
|
|
|
|
|
price->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
|
price->set_mouse_filter(MOUSE_FILTER_PASS);
|
|
|
|
|
|
|
|
|
|
author_price_hbox->add_child(price);
|
|
|
|
|
|
|
|
|
|
spacer = memnew(Control);
|
|
|
|
|
spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
|
author_price_hbox->add_child(spacer);
|
|
|
|
|
|
|
|
|
|
set_custom_minimum_size(Size2(250, 80) * EDSCALE);
|
|
|
|
|
set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
|
|
|
|
}
|
|
|
|
|
@ -1386,6 +1438,7 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const
|
|
|
|
|
|
|
|
|
|
EditorAssetLibraryItem *item = memnew(EditorAssetLibraryItem(true));
|
|
|
|
|
asset_items->add_child(item);
|
|
|
|
|
asset_items->connect(SceneStringName(sort_children), callable_mp(item, &EditorAssetLibraryItem::calculate_misc_links_ratio));
|
|
|
|
|
item->configure(r["title"], r["asset_id"], category_map[r["category_id"]], r["category_id"], r["author"], r["author_id"], r["cost"]);
|
|
|
|
|
item->connect("asset_selected", callable_mp(this, &EditorAssetLibrary::_select_asset));
|
|
|
|
|
item->connect("author_selected", callable_mp(this, &EditorAssetLibrary::_select_author));
|
|
|
|
|
|