Use "Display on my Page" big button.

This commit is contained in:
John Preston 2025-01-13 15:16:01 +04:00
parent 006ecf9a56
commit d2be10cd4e
8 changed files with 104 additions and 106 deletions

View file

@ -3279,16 +3279,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_view_unpack" = "Unpack"; "lng_gift_view_unpack" = "Unpack";
"lng_gift_anonymous_hint" = "Only you can see the sender's name."; "lng_gift_anonymous_hint" = "Only you can see the sender's name.";
"lng_gift_hidden_hint" = "This gift is hidden. Only you can see it."; "lng_gift_hidden_hint" = "This gift is hidden. Only you can see it.";
"lng_gift_visible_hint" = "This gift is visible to visitors of your page."; "lng_gift_visible_hint" = "This gift is visible on your page.";
"lng_gift_hidden_hint_channel" = "This gift is hidden from visitors of your channel."; "lng_gift_hidden_hint_channel" = "This gift is hidden from visitors of your channel.";
"lng_gift_visible_hint_channel" = "This gift is visible in your channel's Gifts."; "lng_gift_visible_hint_channel" = "This gift is visible in your channel's Gifts.";
"lng_gift_visible_hide" = "Hide >";
"lng_gift_show_on_page" = "Display on my Page";
"lng_gift_availability" = "Availability"; "lng_gift_availability" = "Availability";
"lng_gift_from_hidden" = "Hidden User"; "lng_gift_from_hidden" = "Hidden User";
"lng_gift_visibility" = "Visibility";
"lng_gift_visibility_shown" = "Visible on your page";
"lng_gift_visibility_hidden" = "Not visible on your page";
"lng_gift_visibility_show" = "show";
"lng_gift_visibility_hide" = "hide";
"lng_gift_self_status" = "buy yourself a gift"; "lng_gift_self_status" = "buy yourself a gift";
"lng_gift_self_title" = "Buy a Gift"; "lng_gift_self_title" = "Buy a Gift";
"lng_gift_self_about" = "Buy yourself a gift to display on your page or reserve for later.\n\nLimited-edition gifts upgraded to collectibles can be gifted to others later."; "lng_gift_self_about" = "Buy yourself a gift to display on your page or reserve for later.\n\nLimited-edition gifts upgraded to collectibles can be gifted to others later.";

View file

@ -183,7 +183,7 @@ constexpr auto kRarityTooltipDuration = 3 * crl::time(1000);
userpic->setAttribute(Qt::WA_TransparentForMouseEvents); userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
label->setAttribute(Qt::WA_TransparentForMouseEvents); label->setAttribute(Qt::WA_TransparentForMouseEvents);
label->setTextColorOverride(st::windowActiveTextFg->c); label->setTextColorOverride(table->st().defaultValue.palette.linkFg->c);
raw->setClickedCallback([=] { raw->setClickedCallback([=] {
show->showBox(PrepareShortInfoBox(peer, show)); show->showBox(PrepareShortInfoBox(peer, show));
@ -258,7 +258,7 @@ constexpr auto kRarityTooltipDuration = 3 * crl::time(1000);
userpic->setAttribute(Qt::WA_TransparentForMouseEvents); userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
label->setAttribute(Qt::WA_TransparentForMouseEvents); label->setAttribute(Qt::WA_TransparentForMouseEvents);
label->setTextColorOverride(st::windowActiveTextFg->c); label->setTextColorOverride(table->st().defaultValue.palette.linkFg->c);
raw->setClickedCallback([=] { raw->setClickedCallback([=] {
show->showBox(PrepareShortInfoBox(peer, show)); show->showBox(PrepareShortInfoBox(peer, show));
@ -436,59 +436,6 @@ void AddTableRow(
return result; return result;
} }
[[nodiscard]] object_ptr<Ui::RpWidget> MakeVisibilityTableValue(
not_null<Ui::TableLayout*> table,
bool savedToProfile,
Fn<void(bool)> toggleVisibility) {
auto result = object_ptr<Ui::RpWidget>(table);
const auto raw = result.data();
const auto label = Ui::CreateChild<Ui::FlatLabel>(
raw,
(savedToProfile
? tr::lng_gift_visibility_shown()
: tr::lng_gift_visibility_hidden()),
table->st().defaultValue,
st::defaultPopupMenu);
const auto toggle = Ui::CreateChild<Ui::RoundButton>(
raw,
(savedToProfile
? tr::lng_gift_visibility_hide()
: tr::lng_gift_visibility_show()),
table->st().smallButton);
toggle->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
toggle->setClickedCallback([=] {
toggleVisibility(!savedToProfile);
});
rpl::combine(
raw->widthValue(),
toggle->widthValue()
) | rpl::start_with_next([=](int width, int toggleWidth) {
const auto toggleSkip = toggleWidth
? (st::normalFont->spacew + toggleWidth)
: 0;
label->resizeToNaturalWidth(width - toggleSkip);
label->moveToLeft(0, 0, width);
toggle->moveToLeft(
label->width() + st::normalFont->spacew,
(table->st().defaultValue.style.font->ascent
- table->st().smallButton.style.font->ascent),
width);
}, label->lifetime());
label->heightValue() | rpl::start_with_next([=](int height) {
raw->resize(
raw->width(),
height + st::giveawayGiftCodeValueMargin.bottom());
}, raw->lifetime());
label->setAttribute(Qt::WA_TransparentForMouseEvents);
return result;
}
[[nodiscard]] object_ptr<Ui::RpWidget> MakeNonUniqueStatusTableValue( [[nodiscard]] object_ptr<Ui::RpWidget> MakeNonUniqueStatusTableValue(
not_null<Ui::TableLayout*> table, not_null<Ui::TableLayout*> table,
Fn<void()> startUpgrade) { Fn<void()> startUpgrade) {
@ -1273,7 +1220,6 @@ void AddStarGiftTable(
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
Settings::CreditsEntryBoxStyleOverrides st, Settings::CreditsEntryBoxStyleOverrides st,
const Data::CreditsHistoryEntry &entry, const Data::CreditsHistoryEntry &entry,
Fn<void(bool)> toggleVisibility,
Fn<void()> convertToStars, Fn<void()> convertToStars,
Fn<void()> startUpgrade) { Fn<void()> startUpgrade) {
auto table = container->add( auto table = container->add(
@ -1464,16 +1410,6 @@ void AddStarGiftTable(
std::move(convertToStars)), std::move(convertToStars)),
marginWithButton); marginWithButton);
} }
if (toggleVisibility) {
AddTableRow(
table,
tr::lng_gift_visibility(),
MakeVisibilityTableValue(
table,
entry.savedToProfile,
std::move(toggleVisibility)),
marginWithButton);
}
if (entry.limitedCount > 0 && !entry.giftRefunded) { if (entry.limitedCount > 0 && !entry.giftRefunded) {
auto amount = rpl::single(TextWithEntities{ auto amount = rpl::single(TextWithEntities{
Lang::FormatCountDecimal(entry.limitedCount) Lang::FormatCountDecimal(entry.limitedCount)

View file

@ -67,7 +67,6 @@ void AddStarGiftTable(
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
Settings::CreditsEntryBoxStyleOverrides st, Settings::CreditsEntryBoxStyleOverrides st,
const Data::CreditsHistoryEntry &entry, const Data::CreditsHistoryEntry &entry,
Fn<void(bool)> toggleVisibility,
Fn<void()> convertToStars, Fn<void()> convertToStars,
Fn<void()> startUpgrade); Fn<void()> startUpgrade);
void AddCreditsHistoryEntryTable( void AddCreditsHistoryEntryTable(

View file

@ -2227,10 +2227,12 @@ void AddWearGiftCover(
void ShowUniqueGiftWearBox( void ShowUniqueGiftWearBox(
std::shared_ptr<ChatHelpers::Show> show, std::shared_ptr<ChatHelpers::Show> show,
const Data::UniqueGift &gift, const Data::UniqueGift &gift,
Settings::CreditsEntryBoxStyleOverrides st) { Settings::GiftWearBoxStyleOverride st) {
show->show(Box([=](not_null<Ui::GenericBox*> box) { show->show(Box([=](not_null<Ui::GenericBox*> box) {
box->setNoContentMargin(true); box->setNoContentMargin(true);
box->setStyle(st.box ? *st.box : st::upgradeGiftBox);
const auto content = box->verticalLayout(); const auto content = box->verticalLayout();
AddWearGiftCover(content, gift, show->session().user()); AddWearGiftCover(content, gift, show->session().user());
@ -2246,13 +2248,13 @@ void ShowUniqueGiftWearBox(
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(
raw, raw,
std::move(title) | Ui::Text::ToBold(), std::move(title) | Ui::Text::ToBold(),
st::defaultFlatLabel), st.infoTitle ? *st.infoTitle : st::defaultFlatLabel),
st::settingsPremiumRowTitlePadding); st::settingsPremiumRowTitlePadding);
raw->add( raw->add(
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(
raw, raw,
std::move(text), std::move(text),
st::boxDividerLabel), st.infoAbout ? *st.infoAbout : st::boxDividerLabel),
st::settingsPremiumRowAboutPadding); st::settingsPremiumRowAboutPadding);
object_ptr<Info::Profile::FloatingIcon>( object_ptr<Info::Profile::FloatingIcon>(
raw, raw,
@ -2266,28 +2268,26 @@ void ShowUniqueGiftWearBox(
tr::lng_gift_wear_title( tr::lng_gift_wear_title(
lt_name, lt_name,
rpl::single(UniqueGiftName(gift))), rpl::single(UniqueGiftName(gift))),
st::uniqueGiftTitle), st.title ? *st.title : st::uniqueGiftTitle),
st::settingsPremiumRowTitlePadding); st::settingsPremiumRowTitlePadding);
content->add( content->add(
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(
content, content,
tr::lng_gift_wear_about(), tr::lng_gift_wear_about(),
st::uniqueGiftSubtitle), st.subtitle ? *st.subtitle : st::uniqueGiftSubtitle),
st::settingsPremiumRowAboutPadding); st::settingsPremiumRowAboutPadding);
infoRow( infoRow(
tr::lng_gift_wear_badge_title(), tr::lng_gift_wear_badge_title(),
tr::lng_gift_wear_badge_about(), tr::lng_gift_wear_badge_about(),
&st::menuIconUnique); st.radiantIcon ? st.radiantIcon : &st::menuIconUnique);
//infoRow( //infoRow(
// tr::lng_gift_wear_design_title(), // tr::lng_gift_wear_design_title(),
// tr::lng_gift_wear_design_about(), // tr::lng_gift_wear_design_about(),
// &st::menuIconUniqueProfile); // &st::menuIconUniqueProfile);
infoRow( infoRow(
tr::lng_gift_wear_proof_title(), tr::lng_gift_wear_proof_title(),
tr::lng_gift_wear_proof_about(), tr::lng_gift_wear_proof_about(), // todo collectibles
&st::menuIconTradable); // todo collectibles st.proofIcon ? st.proofIcon : &st::menuIconTradable);
box->setStyle(st::upgradeGiftBox);
const auto button = box->addButton(tr::lng_gift_wear_start(), [=] { const auto button = box->addButton(tr::lng_gift_wear_start(), [=] {
const auto session = &show->session(); const auto session = &show->session();
@ -2312,7 +2312,7 @@ void ShowUniqueGiftWearBox(
} }
}, box->lifetime()); }, box->lifetime());
AddUniqueCloseButton(box, st); AddUniqueCloseButton(box, {});
})); }));
} }

View file

@ -22,6 +22,7 @@ enum class CheckoutResult;
} // namespace Payments } // namespace Payments
namespace Settings { namespace Settings {
struct GiftWearBoxStyleOverride;
struct CreditsEntryBoxStyleOverrides; struct CreditsEntryBoxStyleOverrides;
} // namespace Settings } // namespace Settings
@ -58,7 +59,7 @@ void AddWearGiftCover(
void ShowUniqueGiftWearBox( void ShowUniqueGiftWearBox(
std::shared_ptr<ChatHelpers::Show> show, std::shared_ptr<ChatHelpers::Show> show,
const Data::UniqueGift &gift, const Data::UniqueGift &gift,
Settings::CreditsEntryBoxStyleOverrides st); Settings::GiftWearBoxStyleOverride st);
struct PatternPoint { struct PatternPoint {
QPointF position; QPointF position;

View file

@ -874,12 +874,26 @@ void FillUniqueGiftMenu(
}, st.transfer ? st.transfer : &st::menuIconReplace); }, st.transfer ? st.transfer : &st::menuIconReplace);
} else { } else {
menu->addAction(tr::lng_gift_transfer_wear(tr::now), [=] { menu->addAction(tr::lng_gift_transfer_wear(tr::now), [=] {
ShowUniqueGiftWearBox(show, *unique, st); ShowUniqueGiftWearBox(show, *unique, st.giftWearBox
? *st.giftWearBox
: GiftWearBoxStyleOverride());
}, st.transfer ? st.transfer : &st::menuIconReplace); }, st.transfer ? st.transfer : &st::menuIconReplace);
} }
} }
} }
GiftWearBoxStyleOverride DarkGiftWearBoxStyle() {
return {
.box = &st::darkUpgradeGiftBox,
.title = &st::darkUpgradeGiftTitle,
.subtitle = &st::darkUpgradeGiftSubtitle,
.radiantIcon = &st::darkUpgradeGiftRadiant,
.proofIcon = &st::darkUpgradeGiftProof,
.infoTitle = &st::darkUpgradeGiftInfoTitle,
.infoAbout = &st::darkUpgradeGiftInfoAbout,
};
}
CreditsEntryBoxStyleOverrides DarkCreditsEntryBoxStyle() { CreditsEntryBoxStyleOverrides DarkCreditsEntryBoxStyle() {
return { return {
.box = &st::darkGiftCodeBox, .box = &st::darkGiftCodeBox,
@ -892,6 +906,8 @@ CreditsEntryBoxStyleOverrides DarkCreditsEntryBoxStyle() {
.transfer = &st::darkGiftTransfer, .transfer = &st::darkGiftTransfer,
.shareBox = std::make_shared<ShareBoxStyleOverrides>( .shareBox = std::make_shared<ShareBoxStyleOverrides>(
DarkShareBoxStyle()), DarkShareBoxStyle()),
.giftWearBox = std::make_shared<GiftWearBoxStyleOverride>(
DarkGiftWearBoxStyle()),
}; };
} }
@ -1351,6 +1367,9 @@ void GenericCreditsEntryBox(
}; };
const auto state = box->lifetime().make_state<State>(); const auto state = box->lifetime().make_state<State>();
const auto canToggle = (canConvert || couldConvert || nonConvertible)
&& !e.giftTransferred
&& !e.giftRefunded;
const auto toggleVisibility = [=, weak = Ui::MakeWeak(box)](bool save) { const auto toggleVisibility = [=, weak = Ui::MakeWeak(box)](bool save) {
const auto showSection = !e.fromGiftsList; const auto showSection = !e.fromGiftsList;
const auto itemId = MsgId(e.bareMsgId); const auto itemId = MsgId(e.bareMsgId);
@ -1456,16 +1475,11 @@ void GenericCreditsEntryBox(
} }
}); });
}; };
const auto canToggle = (canConvert || couldConvert || nonConvertible)
&& !e.giftTransferred
&& !e.giftRefunded;
AddStarGiftTable( AddStarGiftTable(
show, show,
content, content,
st, st,
e, e,
canToggle ? toggleVisibility : Fn<void(bool)>(),
canConvert ? convert : Fn<void()>(), canConvert ? convert : Fn<void()>(),
canUpgrade ? upgrade : Fn<void()>()); canUpgrade ? upgrade : Fn<void()>());
} else { } else {
@ -1487,22 +1501,38 @@ void GenericCreditsEntryBox(
tr::lng_credits_box_out_about_link(tr::now)), tr::lng_credits_box_out_about_link(tr::now)),
Ui::Text::WithEntities), Ui::Text::WithEntities),
st::creditsBoxAboutDivider))); st::creditsBoxAboutDivider)));
} else if (gotStarGift && e.fromGiftsList) { } else if (gotStarGift) {
box->addRow(object_ptr<Ui::CenterWrap<>>( auto withHide = rpl::combine(
box, tr::lng_gift_visible_hint(),
object_ptr<Ui::FlatLabel>( tr::lng_gift_visible_hide()
) | rpl::map([](QString &&hint, QString &&hide) {
return TextWithEntities{ std::move(hint) }.append(' ').append(
Ui::Text::Link(std::move(hide)));
});
auto text = !e.savedToProfile // todo channel gifts
? tr::lng_gift_hidden_hint(Ui::Text::WithEntities)
: canToggle
? std::move(withHide)
: tr::lng_gift_visible_hint(Ui::Text::WithEntities);
if (e.anonymous && e.barePeerId) {
text = rpl::combine(
std::move(text),
tr::lng_gift_anonymous_hint()
) | rpl::map([](TextWithEntities &&a, QString &&b) {
return a.append("\n\n").append(b);
});
}
const auto label = box->addRow(
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
box, box,
(e.savedToProfile object_ptr<Ui::FlatLabel>(
? tr::lng_gift_visible_hint() box,
: tr::lng_gift_hidden_hint()), // todo channel gifts std::move(text),
st::creditsBoxAboutDivider))); st::creditsBoxAboutDivider)))->entity();
} else if (gotStarGift && e.anonymous) { label->setClickHandlerFilter([=](const auto &...) {
box->addRow(object_ptr<Ui::CenterWrap<>>( toggleVisibility(!e.savedToProfile);
box, return false;
object_ptr<Ui::FlatLabel>( });
box,
tr::lng_gift_anonymous_hint(),
st::creditsBoxAboutDivider)));
} }
if (s) { if (s) {
const auto user = peer ? peer->asUser() : nullptr; const auto user = peer ? peer->asUser() : nullptr;
@ -1579,6 +1609,8 @@ void GenericCreditsEntryBox(
? tr::lng_credits_subscription_off_rejoin_button() ? tr::lng_credits_subscription_off_rejoin_button()
: canUpgradeFree : canUpgradeFree
? tr::lng_gift_upgrade_free() ? tr::lng_gift_upgrade_free()
: (canToggle && !e.savedToProfile)
? tr::lng_gift_show_on_page()
: tr::lng_box_ok())); : tr::lng_box_ok()));
const auto send = [=, weak = Ui::MakeWeak(box)] { const auto send = [=, weak = Ui::MakeWeak(box)] {
if (toRejoin) { if (toRejoin) {
@ -1635,6 +1667,8 @@ void GenericCreditsEntryBox(
send(); send();
} else if (canUpgradeFree) { } else if (canUpgradeFree) {
upgrade(); upgrade();
} else if (canToggle && !e.savedToProfile) {
toggleVisibility(true);
} else { } else {
box->closeBox(); box->closeBox();
} }

View file

@ -90,6 +90,17 @@ void AddWithdrawalWidget(
bool withdrawalEnabled, bool withdrawalEnabled,
rpl::producer<QString> usdValue); rpl::producer<QString> usdValue);
struct GiftWearBoxStyleOverride {
const style::Box *box = nullptr;
const style::FlatLabel *title = nullptr;
const style::FlatLabel *subtitle = nullptr;
const style::icon *radiantIcon = nullptr;
const style::icon *proofIcon = nullptr;
const style::FlatLabel *infoTitle = nullptr;
const style::FlatLabel *infoAbout = nullptr;
};
[[nodiscard]] GiftWearBoxStyleOverride DarkGiftWearBoxStyle();
struct CreditsEntryBoxStyleOverrides { struct CreditsEntryBoxStyleOverrides {
const style::Box *box = nullptr; const style::Box *box = nullptr;
const style::PopupMenu *menu = nullptr; const style::PopupMenu *menu = nullptr;
@ -100,6 +111,7 @@ struct CreditsEntryBoxStyleOverrides {
const style::icon *share = nullptr; const style::icon *share = nullptr;
const style::icon *transfer = nullptr; const style::icon *transfer = nullptr;
std::shared_ptr<ShareBoxStyleOverrides> shareBox; std::shared_ptr<ShareBoxStyleOverrides> shareBox;
std::shared_ptr<GiftWearBoxStyleOverride> giftWearBox;
}; };
[[nodiscard]] CreditsEntryBoxStyleOverrides DarkCreditsEntryBoxStyle(); [[nodiscard]] CreditsEntryBoxStyleOverrides DarkCreditsEntryBoxStyle();

View file

@ -211,3 +211,22 @@ uniqueMenuButton: IconButton(uniqueCloseButton) {
upgradeGiftBox: Box(giftBox) { upgradeGiftBox: Box(giftBox) {
buttonPadding: margins(22px, 3px, 22px, 22px); buttonPadding: margins(22px, 3px, 22px, 22px);
} }
darkUpgradeGiftTitle: FlatLabel(uniqueGiftTitle) {
textFg: groupCallMembersFg;
}
darkUpgradeGiftSubtitle: FlatLabel(uniqueGiftSubtitle) {
textFg: groupCallMembersFg;
}
darkUpgradeGiftBox: Box(upgradeGiftBox) {
bg: groupCallMembersBg;
title: darkUpgradeGiftTitle;
titleAdditionalFg: groupCallMemberNotJoinedStatus;
}
darkUpgradeGiftRadiant: icon{{ "menu/unique", groupCallMembersFg }};
darkUpgradeGiftProof: icon{{ "menu/tradable", groupCallMembersFg }};
darkUpgradeGiftInfoTitle: FlatLabel(defaultFlatLabel) {
textFg: groupCallMembersFg;
}
darkUpgradeGiftInfoAbout: FlatLabel(boxDividerLabel) {
textFg: groupCallMemberNotJoinedStatus;
}