diff --git a/Telegram/Resources/icons/payments/ton_emoji.svg b/Telegram/Resources/icons/payments/ton_emoji.svg new file mode 100644 index 0000000000..7de741c10e --- /dev/null +++ b/Telegram/Resources/icons/payments/ton_emoji.svg @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/Telegram/SourceFiles/boxes/send_credits_box.cpp b/Telegram/SourceFiles/boxes/send_credits_box.cpp index 8f355b1aa6..c35951da35 100644 --- a/Telegram/SourceFiles/boxes/send_credits_box.cpp +++ b/Telegram/SourceFiles/boxes/send_credits_box.cpp @@ -567,6 +567,49 @@ not_null SetButtonMarkedLabel( }), st, textFg); } +void SetButtonTwoLabels( + not_null button, + rpl::producer title, + rpl::producer subtitle, + const style::FlatLabel &st, + const style::FlatLabel &subst, + const style::color *textFg) { + const auto buttonTitle = Ui::CreateChild( + button, + std::move(title), + st); + const auto buttonSubtitle = Ui::CreateChild( + button, + std::move(subtitle), + subst); + buttonSubtitle->setOpacity(0.6); + if (textFg) { + buttonTitle->setTextColorOverride((*textFg)->c); + buttonSubtitle->setTextColorOverride((*textFg)->c); + style::PaletteChanged() | rpl::start_with_next([=] { + buttonTitle->setTextColorOverride((*textFg)->c); + buttonSubtitle->setTextColorOverride((*textFg)->c); + }, buttonTitle->lifetime()); + } + rpl::combine( + button->sizeValue(), + buttonTitle->sizeValue(), + buttonSubtitle->sizeValue() + ) | rpl::start_with_next([=](QSize outer, QSize title, QSize subtitle) { + const auto two = title.height() + subtitle.height(); + const auto titleTop = (outer.height() - two) / 2; + const auto subtitleTop = titleTop + title.height(); + buttonTitle->moveToLeft( + (outer.width() - title.width()) / 2, + titleTop); + buttonSubtitle->moveToLeft( + (outer.width() - subtitle.width()) / 2, + subtitleTop); + }, buttonTitle->lifetime()); + buttonTitle->setAttribute(Qt::WA_TransparentForMouseEvents); + buttonSubtitle->setAttribute(Qt::WA_TransparentForMouseEvents); +} + void SendStarsForm( not_null session, std::shared_ptr data, diff --git a/Telegram/SourceFiles/boxes/send_credits_box.h b/Telegram/SourceFiles/boxes/send_credits_box.h index 6dcaef1f8e..f8227846b9 100644 --- a/Telegram/SourceFiles/boxes/send_credits_box.h +++ b/Telegram/SourceFiles/boxes/send_credits_box.h @@ -52,6 +52,14 @@ not_null SetButtonMarkedLabel( const style::FlatLabel &st, const style::color *textFg = nullptr); +void SetButtonTwoLabels( + not_null button, + rpl::producer title, + rpl::producer subtitle, + const style::FlatLabel &st, + const style::FlatLabel &subst, + const style::color *textFg = nullptr); + void SendStarsForm( not_null session, std::shared_ptr data, diff --git a/Telegram/SourceFiles/boxes/star_gift_box.cpp b/Telegram/SourceFiles/boxes/star_gift_box.cpp index fd46e1813a..89a9b9cbed 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_box.cpp @@ -3907,7 +3907,7 @@ void ShowStarGiftBox( void SetupResalePriceButton( not_null parent, rpl::producer background, - rpl::producer price, + rpl::producer price, Fn click) { const auto resale = Ui::CreateChild< Ui::FadeWrapScaled @@ -3928,11 +3928,13 @@ void SetupResalePriceButton( }, button->lifetime()); text->setTextColorOverride(QColor(255, 255, 255, 255)); - std::move(price) | rpl::start_with_next([=](int value) { - if (value > 0) { - text->setMarkedText( - Ui::Text::IconEmoji(&st::starIconEmoji).append( - Lang::FormatCountDecimal(value))); + std::move(price) | rpl::start_with_next([=](CreditsAmount value) { + if (value) { + text->setMarkedText(value.ton() + ? Ui::Text::IconEmoji(&st::tonIconEmoji).append( + Lang::FormatCreditsAmountDecimal(value)) + : Ui::Text::IconEmoji(&st::starIconEmoji).append( + Lang::FormatCountDecimal(value.whole()))); resale->toggle(true, anim::type::normal); } else { resale->toggle(false, anim::type::normal); @@ -3968,7 +3970,7 @@ void AddUniqueGiftCover( not_null container, rpl::producer data, rpl::producer subtitleOverride, - rpl::producer resalePrice, + rpl::producer resalePrice, Fn resaleClick) { const auto cover = container->add(object_ptr(container)); @@ -4494,7 +4496,7 @@ void UpdateGiftSellPrice( std::shared_ptr unique, Data::SavedStarGiftId savedId, CreditsAmount price) { - const auto was = unique->starsForResale; + const auto wasOnResale = (unique->starsForResale > 0); const auto session = &show->session(); session->api().request(MTPpayments_UpdateStarGiftPrice( Api::InputSavedStarGiftId(savedId, unique), @@ -4505,7 +4507,7 @@ void UpdateGiftSellPrice( session->api().applyUpdates(result); show->showToast((!price ? tr::lng_gift_sell_removed - : (was > 0) + : wasOnResale ? tr::lng_gift_sell_updated : tr::lng_gift_sell_toast)( tr::now, diff --git a/Telegram/SourceFiles/boxes/star_gift_box.h b/Telegram/SourceFiles/boxes/star_gift_box.h index 5b42d785d3..f9daf942fa 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.h +++ b/Telegram/SourceFiles/boxes/star_gift_box.h @@ -59,7 +59,7 @@ void AddUniqueGiftCover( not_null container, rpl::producer data, rpl::producer subtitleOverride = nullptr, - rpl::producer resalePrice = nullptr, + rpl::producer resalePrice = nullptr, Fn resaleClick = nullptr); void AddWearGiftCover( not_null container, diff --git a/Telegram/SourceFiles/boxes/transfer_gift_box.cpp b/Telegram/SourceFiles/boxes/transfer_gift_box.cpp index 54b77db265..389f919d49 100644 --- a/Telegram/SourceFiles/boxes/transfer_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/transfer_gift_box.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "payments/payments_checkout_process.h" #include "ui/boxes/confirm_box.h" +#include "ui/controls/ton_common.h" #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" #include "ui/toast/toast.h" @@ -503,7 +504,7 @@ void BuyResaleGift( using Flag = MTPDinputInvoiceStarGiftResale::Flag; const auto invoice = MTP_inputInvoiceStarGiftResale( - MTP_flags(Flag()), + MTP_flags(gift->onlyAcceptTon ? Flag::f_ton : Flag()), MTP_string(gift->slug), to->input); @@ -662,8 +663,15 @@ void ShowBuyResaleGiftBox( auto transfer = tr::lng_gift_buy_resale_button( lt_cost, - rpl::single( - Ui::Text::IconEmoji(&st::starIconEmoji).append( + rpl::single(gift->onlyAcceptTon + ? Ui::Text::IconEmoji( + &st::tonIconEmoji + ).append( + Lang::FormatCreditsAmountDecimal(CreditsAmount( + gift->nanoTonForResale / Ui::kNanosInOne, + gift->nanoTonForResale % Ui::kNanosInOne, + CreditsType::Ton))) + : Ui::Text::IconEmoji(&st::starIconEmoji).append( Lang::FormatCountDecimal(gift->starsForResale))), Ui::Text::WithEntities); @@ -698,19 +706,29 @@ void ShowBuyResaleGiftBox( lt_name, rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))), lt_price, - tr::lng_action_gift_for_stars( - lt_count, - rpl::single(gift->starsForResale * 1.), - Ui::Text::Bold), + (gift->onlyAcceptTon + ? tr::lng_action_gift_for_ton( + lt_count, + rpl::single(gift->nanoTonForResale / 1'000'000'000.), + Ui::Text::Bold) + : tr::lng_action_gift_for_stars( + lt_count_decimal, + rpl::single(gift->starsForResale * 1.), + Ui::Text::Bold)), Ui::Text::WithEntities) : tr::lng_gift_buy_resale_confirm( lt_name, rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))), lt_price, - tr::lng_action_gift_for_stars( - lt_count, - rpl::single(gift->starsForResale * 1.), - Ui::Text::Bold), + (gift->onlyAcceptTon + ? tr::lng_action_gift_for_ton( + lt_count, + rpl::single(gift->nanoTonForResale / 1'000'000'000.), + Ui::Text::Bold) + : tr::lng_action_gift_for_stars( + lt_count_decimal, + rpl::single(gift->starsForResale * 1.), + Ui::Text::Bold)), lt_user, rpl::single(Ui::Text::Bold(to->shortName())), Ui::Text::WithEntities), diff --git a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp index 6de1cbd29d..925005e0c4 100644 --- a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp +++ b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp @@ -1021,26 +1021,6 @@ uint64 CustomEmojiManager::coloredSetId() const { return _coloredSetId; } -TextWithEntities CustomEmojiManager::tonEmoji(QMargins padding) { - return Ui::Text::SingleCustomEmoji(registerInternalEmoji( - u"builtin:ton_emoji"_q, - Ui::Earn::IconCurrencyColored( - st::tonIconEmojiSize, - st::currencyFg->c), - st::tonIconEmojiPadding + padding, - false)); -} - -TextWithEntities CustomEmojiManager::monoTonEmoji(QMargins padding) { - return Ui::Text::SingleCustomEmoji(registerInternalEmoji( - u"builtin:monoton_emoji"_q, - Ui::Earn::IconCurrencyColored( - st::tonIconEmojiSize, - st::currencyFg->c), - st::tonIconEmojiPadding + padding, - true)); -} - TextWithEntities CustomEmojiManager::creditsEmoji(QMargins padding) { return Ui::Text::SingleCustomEmoji(registerInternalEmoji( u"builtin:credits_emoji"_q, diff --git a/Telegram/SourceFiles/data/stickers/data_custom_emoji.h b/Telegram/SourceFiles/data/stickers/data_custom_emoji.h index c7f4f0719b..a279a5999c 100644 --- a/Telegram/SourceFiles/data/stickers/data_custom_emoji.h +++ b/Telegram/SourceFiles/data/stickers/data_custom_emoji.h @@ -100,8 +100,6 @@ public: [[nodiscard]] uint64 coloredSetId() const; - [[nodiscard]] TextWithEntities tonEmoji(QMargins padding = {}); - [[nodiscard]] TextWithEntities monoTonEmoji(QMargins padding = {}); [[nodiscard]] TextWithEntities creditsEmoji(QMargins padding = {}); [[nodiscard]] TextWithEntities ministarEmoji(QMargins padding = {}); diff --git a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp index db369e328c..8f31abcb1d 100644 --- a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp +++ b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_common.cpp @@ -742,7 +742,7 @@ TextWithEntities Delegate::monostar() { } TextWithEntities Delegate::monoton() { - return _session->data().customEmojiManager().monoTonEmoji(); + return Ui::Text::IconEmoji(&st::tonIconEmoji); } TextWithEntities Delegate::ministar() { diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index aa78c3bde4..0b13184819 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "boxes/gift_premium_box.h" #include "boxes/share_box.h" +#include "boxes/send_credits_box.h" // SetButtonTwoLabels #include "boxes/star_gift_box.h" #include "boxes/transfer_gift_box.h" #include "chat_helpers/stickers_gift_box_pack.h" @@ -62,6 +63,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_credits.h" #include "statistics/widgets/chart_header_widget.h" #include "ui/boxes/confirm_box.h" +#include "ui/controls/ton_common.h" #include "ui/controls/userpic_button.h" #include "ui/dynamic_image.h" #include "ui/dynamic_thumbnails.h" @@ -1067,8 +1069,8 @@ void FillUniqueGiftMenu( } } if (CanResellGift(&show->session(), e)) { - const auto resalePrice = unique->starsForResale; - const auto editPrice = (resalePrice > 0 + const auto inResale = (unique->starsForResale > 0); + const auto editPrice = (inResale ? tr::lng_gift_transfer_update : tr::lng_gift_transfer_sell)(tr::now); menu->addAction(editPrice, [=] { @@ -1077,7 +1079,7 @@ void FillUniqueGiftMenu( : GiftWearBoxStyleOverride(); ShowUniqueGiftSellBox(show, unique, savedId, style); }, st.resell ? st.resell : &st::menuIconTagSell); - if (resalePrice > 0) { + if (inResale) { menu->addAction(tr::lng_gift_transfer_unlist(tr::now), [=] { const auto name = UniqueGiftName(*unique); const auto confirm = [=](Fn close) { @@ -1240,7 +1242,12 @@ void GenericCreditsEntryBox( return (update.action == Data::GiftUpdate::Action::ResaleChange) && (update.slug == slug); }) | rpl::to_empty) | rpl::map([unique = e.uniqueGift] { - return unique->starsForResale; + return unique->onlyAcceptTon + ? CreditsAmount( + unique->nanoTonForResale / Ui::kNanosInOne, + unique->nanoTonForResale % Ui::kNanosInOne, + CreditsType::Ton) + : CreditsAmount(unique->starsForResale); }); auto change = [=] { const auto style = st.giftWearBox @@ -2100,12 +2107,36 @@ void GenericCreditsEntryBox( } }); if (canBuyResold) { - button->setText(tr::lng_gift_buy_resale_button( - lt_cost, - rpl::single( - Ui::Text::IconEmoji(&st::starIconEmoji).append( + if (uniqueGift->onlyAcceptTon) { + button->setText(rpl::single(QString())); + Ui::SetButtonTwoLabels( + button, + tr::lng_gift_buy_resale_button( + lt_cost, + rpl::single(Ui::Text::IconEmoji( + &st::tonIconEmoji + ).append( + Lang::FormatCreditsAmountDecimal(CreditsAmount( + uniqueGift->nanoTonForResale / Ui::kNanosInOne, + uniqueGift->nanoTonForResale % Ui::kNanosInOne, + CreditsType::Ton)))), + Ui::Text::WithEntities), + tr::lng_gift_buy_resale_equals( + lt_cost, + rpl::single(Ui::Text::IconEmoji( + &st::starIconEmojiSmall + ).append(Lang::FormatCountDecimal( + uniqueGift->starsForResale))), + Ui::Text::WithEntities), + st::giftResaleButtonTitle, + st::giftResaleButtonSubtitle); + } else { + button->setText(tr::lng_gift_buy_resale_button( + lt_cost, + rpl::single(Ui::Text::IconEmoji(&st::starIconEmoji).append( Lang::FormatCountDecimal(uniqueGift->starsForResale))), - Ui::Text::WithEntities)); + Ui::Text::WithEntities)); + } } { using namespace Info::Statistics; diff --git a/Telegram/SourceFiles/ui/effects/credits.style b/Telegram/SourceFiles/ui/effects/credits.style index 096a869a09..6a0483ceea 100644 --- a/Telegram/SourceFiles/ui/effects/credits.style +++ b/Telegram/SourceFiles/ui/effects/credits.style @@ -81,8 +81,11 @@ starIconEmojiSmall: IconEmoji { icon: icon{{ "chat/mini_stars", creditsBg1 }}; padding: margins(0px, 4px, 0px, 0px); } +tonIconEmoji: IconEmoji { + icon: icon{{ "payments/ton_emoji-18x18", currencyFg }}; + padding: margins(0px, 1px, 0px, 0px); +} tonIconEmojiSize: 18px; -tonIconEmojiPadding: margins(0px, 2px, 0px, 0px); creditsHistoryEntryTypeAds: icon {{ "folders/folders_channels", premiumButtonFg }}; @@ -320,3 +323,13 @@ creditsHistoryRowRightMinorTop: 18px; creditsHistoryRowRightStyle: TextStyle(defaultTextStyle) { font: font(fsize); } +giftResaleButtonTitle: FlatLabel(defaultFlatLabel) { + style: semiboldTextStyle; + textFg: activeButtonFg; +} +giftResaleButtonSubtitle: FlatLabel(defaultFlatLabel) { + style: TextStyle(defaultTextStyle) { + font: font(12px semibold); + } + textFg: activeButtonFg; +}