diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 19202a273c..9bbd806e4e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4137,6 +4137,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_gift_craft_select_about" = "You need to add up to **3 gifts** from the same collection for crafting."; "lng_gift_craft_select_your" = "Your gifts"; "lng_gift_craft_select_none" = "You don't have other gifts from this collection."; +"lng_gift_craft_search_none" = "Could not find other gifts from this collection."; "lng_gift_craft_select_market#one" = "{count} suitable gift on sale"; "lng_gift_craft_select_market#other" = "{count} suitable gifts on sale"; "lng_gift_craft_progress" = "Crafting"; diff --git a/Telegram/SourceFiles/boxes/star_gift_resale_box.cpp b/Telegram/SourceFiles/boxes/star_gift_resale_box.cpp index 114f6b76f9..8d86cec534 100644 --- a/Telegram/SourceFiles/boxes/star_gift_resale_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_resale_box.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/toast/toast.h" #include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" +#include "ui/wrap/slide_wrap.h" #include "ui/painter.h" #include "ui/ui_utility.h" #include "window/window_session_controller.h" @@ -108,9 +109,29 @@ struct ResaleTabs { }; const auto state = raw->lifetime().make_state(); state->filter = std::move(filter); + + const auto forCraft = state->filter.current().forCraft; + const auto wrapName = [=](QString name, int count) { + auto result = tr::marked(name); + if (!forCraft) { + result.append(' ').append(tr::bold( + Lang::FormatCountDecimal(count))); + } + return result; + }; + state->lists.backdrops = info.backdrops; state->lists.models = info.models; state->lists.patterns = info.patterns; + if (forCraft) { + using namespace Data; + const auto isRare = [](const UniqueGiftModelCount &entry) { + return entry.model.rarityType() != UniqueGiftRarity::Default; + }; + state->lists.models.erase( + ranges::remove_if(state->lists.models, isRare), + end(state->lists.models)); + } const auto scroll = [=] { return QPoint(int(base::SafeRound(state->scroll)), 0); @@ -264,11 +285,9 @@ struct ResaleTabs { if (type == GiftAttributeIdType::Model) { for (auto &entry : state->lists.models) { const auto id = IdFor(entry.model); - const auto text = TextWithEntities{ - entry.model.name - }.append(' ').append(tr::bold( - Lang::FormatCountDecimal(entry.count) - )); + const auto text = wrapName( + entry.model.name, + entry.count); actionWithDocument(text, [=] { toggle(id); }, id.value, checked(id)); @@ -276,11 +295,9 @@ struct ResaleTabs { } else if (type == GiftAttributeIdType::Backdrop) { for (auto &entry : state->lists.backdrops) { const auto id = IdFor(entry.backdrop); - const auto text = TextWithEntities{ - entry.backdrop.name - }.append(' ').append(tr::bold( - Lang::FormatCountDecimal(entry.count) - )); + const auto text = wrapName( + entry.backdrop.name, + entry.count); actionWithColor(text, [=] { toggle(id); }, entry.backdrop.centerColor, checked(id)); @@ -288,11 +305,9 @@ struct ResaleTabs { } else if (type == GiftAttributeIdType::Pattern) { for (auto &entry : state->lists.patterns) { const auto id = IdFor(entry.pattern); - const auto text = TextWithEntities{ - entry.pattern.name - }.append(' ').append(tr::bold( - Lang::FormatCountDecimal(entry.count) - )); + const auto text = wrapName( + entry.pattern.name, + entry.count); actionWithDocument(text, [=] { toggle(id); }, id.value, checked(id)); @@ -550,6 +565,7 @@ void AddResaleGiftsList( ResaleGiftsDescriptor data; rpl::variable filter; rpl::variable ton; + rpl::variable empty = true; rpl::lifetime loading; int lastMinHeight = 0; }; @@ -563,7 +579,19 @@ void AddResaleGiftsList( state->data, state->filter.value()); state->filter = std::move(tabs.filter); - container->add(std::move(tabs.widget)); + if (forCraft) { + const auto skip = st::giftBoxResaleTabsMargin.top() + - st::giftBoxTabsMargin.bottom(); + const auto wrap = container->add(object_ptr>( + container, + std::move(tabs.widget), + QMargins(0, 0, 0, skip))); + wrap->paintOn([=](QPainter &p) { + p.fillRect(wrap->rect(), st::windowBgOver); + }); + } else { + container->add(std::move(tabs.widget)); + } const auto session = &window->session(); state->filter.changes() | rpl::on_next([=](ResaleGiftsFilter value) { @@ -641,6 +669,7 @@ void AddResaleGiftsList( .mine = (gift.unique->ownerId == selfId), }); } + state->empty = result.list.empty(); return result; }), [=] { if (!state->data.offset.isEmpty() @@ -663,6 +692,31 @@ void AddResaleGiftsList( }); } }, customHandler)); + + const auto skip = st::defaultSubsectionTitlePadding.top(); + const auto wrap = container->add( + object_ptr>( + container, + object_ptr( + container, + tr::lng_gift_craft_search_none(), + st::craftYourListEmpty), + (st::boxRowPadding + QMargins(0, 0, 0, skip))), + style::al_top); + state->empty.value() | rpl::on_next([=](bool empty) { + // Scroll doesn't jump up if we show before rows are cleared, + // and we hide after rows are added. + if (empty) { + wrap->show(anim::type::instant); + } else { + crl::on_main(wrap, [=] { + if (!state->empty.current()) { + wrap->hide(anim::type::instant); + } + }); + } + }, wrap->lifetime()); + wrap->entity()->setTryMakeSimilarLines(true); } void ShowResaleGiftBoughtToast(