mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Put on / Take off collectible wearable.
This commit is contained in:
parent
4e46529eb6
commit
961d283325
3 changed files with 172 additions and 83 deletions
|
@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_credits.h"
|
#include "data/data_credits.h"
|
||||||
|
#include "data/data_emoji_statuses.h"
|
||||||
#include "data/data_media_types.h" // Data::GiveawayStart.
|
#include "data/data_media_types.h" // Data::GiveawayStart.
|
||||||
#include "data/data_peer_values.h" // Data::PeerPremiumValue.
|
#include "data/data_peer_values.h" // Data::PeerPremiumValue.
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -30,6 +31,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/stickers/data_custom_emoji.h"
|
#include "data/stickers/data_custom_emoji.h"
|
||||||
#include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget.
|
#include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget.
|
||||||
|
#include "info/profile/info_profile_badge.h"
|
||||||
|
#include "info/profile/info_profile_values.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
|
@ -189,6 +192,81 @@ constexpr auto kRarityTooltipDuration = 3 * crl::time(1000);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] object_ptr<Ui::RpWidget> MakePeerWithStatusValue(
|
||||||
|
not_null<Ui::TableLayout*> table,
|
||||||
|
std::shared_ptr<ChatHelpers::Show> show,
|
||||||
|
PeerId id,
|
||||||
|
Fn<void(not_null<Ui::RpWidget*>, EmojiStatusId)> pushStatusId) {
|
||||||
|
auto result = object_ptr<Ui::AbstractButton>(table);
|
||||||
|
const auto raw = result.data();
|
||||||
|
|
||||||
|
const auto &st = st::giveawayGiftCodeUserpic;
|
||||||
|
raw->resize(raw->width(), st.photoSize);
|
||||||
|
|
||||||
|
const auto peer = show->session().data().peer(id);
|
||||||
|
const auto userpic = Ui::CreateChild<Ui::UserpicButton>(raw, peer, st);
|
||||||
|
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
|
raw,
|
||||||
|
peer->name(),
|
||||||
|
table->st().defaultValue);
|
||||||
|
|
||||||
|
using namespace Info::Profile;
|
||||||
|
struct State {
|
||||||
|
rpl::variable<Badge::Content> content;
|
||||||
|
};
|
||||||
|
const auto state = label->lifetime().make_state<State>();
|
||||||
|
state->content = EmojiStatusIdValue(
|
||||||
|
peer
|
||||||
|
) | rpl::map([=](EmojiStatusId emojiStatusId) {
|
||||||
|
return Badge::Content{
|
||||||
|
.badge = BadgeType::Premium,
|
||||||
|
.emojiStatusId = emojiStatusId,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const auto badge = label->lifetime().make_state<Badge>(
|
||||||
|
raw,
|
||||||
|
st::infoPeerBadge,
|
||||||
|
&peer->session(),
|
||||||
|
state->content.value(),
|
||||||
|
nullptr,
|
||||||
|
[=] { return show->paused(ChatHelpers::PauseReason::Layer); });
|
||||||
|
state->content.value(
|
||||||
|
) | rpl::start_with_next([=](const Badge::Content &content) {
|
||||||
|
pushStatusId(badge->widget(), content.emojiStatusId);
|
||||||
|
}, raw->lifetime());
|
||||||
|
|
||||||
|
rpl::combine(
|
||||||
|
raw->widthValue(),
|
||||||
|
rpl::single(rpl::empty) | rpl::then(badge->updated())
|
||||||
|
) | rpl::start_with_next([=](int width, const auto &) {
|
||||||
|
const auto position = st::giveawayGiftCodeNamePosition;
|
||||||
|
const auto badgeWidget = badge->widget();
|
||||||
|
const auto badgeSkip = badgeWidget
|
||||||
|
? (st::normalFont->spacew + badgeWidget->width())
|
||||||
|
: 0;
|
||||||
|
label->resizeToNaturalWidth(width - position.x() - badgeSkip);
|
||||||
|
label->moveToLeft(position.x(), position.y(), width);
|
||||||
|
const auto top = (raw->height() - userpic->height()) / 2;
|
||||||
|
userpic->moveToLeft(0, top, width);
|
||||||
|
badge->widget()->moveToLeft(
|
||||||
|
position.x() + label->width() + st::normalFont->spacew,
|
||||||
|
(position.y()
|
||||||
|
+ table->st().defaultValue.style.font->ascent
|
||||||
|
- table->st().smallButton.style.font->ascent),
|
||||||
|
width);
|
||||||
|
}, label->lifetime());
|
||||||
|
|
||||||
|
userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
label->setTextColorOverride(st::windowActiveTextFg->c);
|
||||||
|
|
||||||
|
raw->setClickedCallback([=] {
|
||||||
|
show->showBox(PrepareShortInfoBox(peer, show));
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] object_ptr<Ui::RpWidget> MakeHiddenPeerTableValue(
|
[[nodiscard]] object_ptr<Ui::RpWidget> MakeHiddenPeerTableValue(
|
||||||
not_null<Ui::TableLayout*> table) {
|
not_null<Ui::TableLayout*> table) {
|
||||||
auto result = object_ptr<Ui::RpWidget>(table);
|
auto result = object_ptr<Ui::RpWidget>(table);
|
||||||
|
@ -1209,24 +1287,96 @@ void AddStarGiftTable(
|
||||||
const auto selfBareId = session->userPeerId().value;
|
const auto selfBareId = session->userPeerId().value;
|
||||||
const auto giftToSelf = (peerId == session->userPeerId())
|
const auto giftToSelf = (peerId == session->userPeerId())
|
||||||
&& (entry.in || entry.bareGiftOwnerId == selfBareId);
|
&& (entry.in || entry.bareGiftOwnerId == selfBareId);
|
||||||
|
|
||||||
|
const auto raw = std::make_shared<Ui::ImportantTooltip*>(nullptr);
|
||||||
|
const auto showTooltip = [=](
|
||||||
|
not_null<Ui::RpWidget*> widget,
|
||||||
|
rpl::producer<TextWithEntities> text) {
|
||||||
|
if (*raw) {
|
||||||
|
(*raw)->toggleAnimated(false);
|
||||||
|
}
|
||||||
|
const auto tooltip = Ui::CreateChild<Ui::ImportantTooltip>(
|
||||||
|
container,
|
||||||
|
Ui::MakeNiceTooltipLabel(
|
||||||
|
container,
|
||||||
|
std::move(text),
|
||||||
|
st::boxWideWidth,
|
||||||
|
st::defaultImportantTooltipLabel),
|
||||||
|
st::defaultImportantTooltip);
|
||||||
|
tooltip->toggleFast(false);
|
||||||
|
|
||||||
|
const auto update = [=] {
|
||||||
|
const auto geometry = Ui::MapFrom(
|
||||||
|
container,
|
||||||
|
widget,
|
||||||
|
widget->rect());
|
||||||
|
const auto countPosition = [=](QSize size) {
|
||||||
|
const auto left = geometry.x()
|
||||||
|
+ (geometry.width() - size.width()) / 2;
|
||||||
|
const auto right = container->width()
|
||||||
|
- st::normalFont->spacew;
|
||||||
|
return QPoint(
|
||||||
|
std::max(std::min(left, right - size.width()), 0),
|
||||||
|
geometry.y() - size.height() - st::normalFont->descent);
|
||||||
|
};
|
||||||
|
tooltip->pointAt(geometry, RectPart::Top, countPosition);
|
||||||
|
};
|
||||||
|
container->widthValue(
|
||||||
|
) | rpl::start_with_next(update, tooltip->lifetime());
|
||||||
|
|
||||||
|
update();
|
||||||
|
tooltip->toggleAnimated(true);
|
||||||
|
|
||||||
|
*raw = tooltip;
|
||||||
|
tooltip->shownValue() | rpl::filter(
|
||||||
|
!rpl::mappers::_1
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
crl::on_main(tooltip, [=] {
|
||||||
|
if (tooltip->isHidden()) {
|
||||||
|
if (*raw == tooltip) {
|
||||||
|
*raw = nullptr;
|
||||||
|
}
|
||||||
|
delete tooltip;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, tooltip->lifetime());
|
||||||
|
|
||||||
|
base::timer_once(
|
||||||
|
kRarityTooltipDuration
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
tooltip->toggleAnimated(false);
|
||||||
|
}, tooltip->lifetime());
|
||||||
|
};
|
||||||
|
|
||||||
if (unique && entry.bareGiftOwnerId) {
|
if (unique && entry.bareGiftOwnerId) {
|
||||||
const auto ownerId = PeerId(entry.bareGiftOwnerId);
|
const auto ownerId = PeerId(entry.bareGiftOwnerId);
|
||||||
const auto transfer = entry.in
|
const auto was = std::make_shared<std::optional<CollectibleId>>();
|
||||||
&& entry.bareMsgId
|
const auto handleChange = [=](
|
||||||
&& (unique->starsForTransfer >= 0);
|
not_null<Ui::RpWidget*> badge,
|
||||||
auto send = transfer ? tr::lng_gift_unique_owner_change() : nullptr;
|
EmojiStatusId emojiStatusId) {
|
||||||
auto handler = transfer ? Fn<void()>([=] {
|
const auto id = emojiStatusId.collectible
|
||||||
if (const auto window = show->resolveWindow()) {
|
? emojiStatusId.collectible->id
|
||||||
ShowTransferGiftBox(
|
: 0;
|
||||||
window,
|
const auto show = [&](const auto &phrase) {
|
||||||
entry.uniqueGift,
|
showTooltip(badge, phrase(
|
||||||
MsgId(entry.bareMsgId));
|
lt_name,
|
||||||
|
rpl::single(Ui::Text::Bold(UniqueGiftName(*unique))),
|
||||||
|
Ui::Text::WithEntities));
|
||||||
|
};
|
||||||
|
if (!*was || *was == id) {
|
||||||
|
*was = id;
|
||||||
|
return;
|
||||||
|
} else if (*was == unique->id) {
|
||||||
|
show(tr::lng_gift_wear_end_toast);
|
||||||
|
} else if (id == unique->id) {
|
||||||
|
show(tr::lng_gift_wear_start_toast);
|
||||||
}
|
}
|
||||||
}) : nullptr;
|
*was = id;
|
||||||
|
};
|
||||||
AddTableRow(
|
AddTableRow(
|
||||||
table,
|
table,
|
||||||
tr::lng_gift_unique_owner(),
|
tr::lng_gift_unique_owner(),
|
||||||
MakePeerTableValue(table, show, ownerId, send, handler),
|
MakePeerWithStatusValue(table, show, ownerId, handleChange),
|
||||||
st::giveawayGiftCodePeerMargin);
|
st::giveawayGiftCodePeerMargin);
|
||||||
} else if (unique) {
|
} else if (unique) {
|
||||||
AddTableRow(
|
AddTableRow(
|
||||||
|
@ -1279,84 +1429,29 @@ void AddStarGiftTable(
|
||||||
const auto marginWithButton = st::giveawayGiftCodeValueMargin
|
const auto marginWithButton = st::giveawayGiftCodeValueMargin
|
||||||
- QMargins(0, 0, 0, st::giveawayGiftCodeValueMargin.bottom());
|
- QMargins(0, 0, 0, st::giveawayGiftCodeValueMargin.bottom());
|
||||||
if (unique) {
|
if (unique) {
|
||||||
const auto raw = std::make_shared<Ui::ImportantTooltip*>(nullptr);
|
const auto showRarity = [=](
|
||||||
const auto showTooltip = [=](
|
|
||||||
not_null<Ui::RpWidget*> widget,
|
not_null<Ui::RpWidget*> widget,
|
||||||
int rarity) {
|
int rarity) {
|
||||||
if (*raw) {
|
const auto percent = QString::number(rarity / 10.) + '%';
|
||||||
(*raw)->toggleAnimated(false);
|
showTooltip(widget, tr::lng_gift_unique_rarity(
|
||||||
}
|
lt_percent,
|
||||||
const auto text = QString::number(rarity / 10.) + '%';
|
rpl::single(TextWithEntities{ percent }),
|
||||||
const auto tooltip = Ui::CreateChild<Ui::ImportantTooltip>(
|
Ui::Text::WithEntities));
|
||||||
container,
|
|
||||||
Ui::MakeNiceTooltipLabel(
|
|
||||||
container,
|
|
||||||
tr::lng_gift_unique_rarity(
|
|
||||||
lt_percent,
|
|
||||||
rpl::single(TextWithEntities{ text }),
|
|
||||||
Ui::Text::WithEntities),
|
|
||||||
st::boxWideWidth,
|
|
||||||
st::defaultImportantTooltipLabel),
|
|
||||||
st::defaultImportantTooltip);
|
|
||||||
tooltip->toggleFast(false);
|
|
||||||
|
|
||||||
const auto update = [=] {
|
|
||||||
const auto geometry = Ui::MapFrom(
|
|
||||||
container,
|
|
||||||
widget,
|
|
||||||
widget->rect());
|
|
||||||
const auto countPosition = [=](QSize size) {
|
|
||||||
const auto left = geometry.x()
|
|
||||||
+ (geometry.width() - size.width()) / 2;
|
|
||||||
const auto right = container->width()
|
|
||||||
- st::normalFont->spacew;
|
|
||||||
return QPoint(
|
|
||||||
std::max(std::min(left, right - size.width()), 0),
|
|
||||||
geometry.y() - size.height() - st::normalFont->descent);
|
|
||||||
};
|
|
||||||
tooltip->pointAt(geometry, RectPart::Top, countPosition);
|
|
||||||
};
|
|
||||||
container->widthValue(
|
|
||||||
) | rpl::start_with_next(update, tooltip->lifetime());
|
|
||||||
|
|
||||||
update();
|
|
||||||
tooltip->toggleAnimated(true);
|
|
||||||
|
|
||||||
*raw = tooltip;
|
|
||||||
tooltip->shownValue() | rpl::filter(
|
|
||||||
!rpl::mappers::_1
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
crl::on_main(tooltip, [=] {
|
|
||||||
if (tooltip->isHidden()) {
|
|
||||||
if (*raw == tooltip) {
|
|
||||||
*raw = nullptr;
|
|
||||||
}
|
|
||||||
delete tooltip;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, tooltip->lifetime());
|
|
||||||
|
|
||||||
base::timer_once(
|
|
||||||
kRarityTooltipDuration
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
tooltip->toggleAnimated(false);
|
|
||||||
}, tooltip->lifetime());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AddTableRow(
|
AddTableRow(
|
||||||
table,
|
table,
|
||||||
tr::lng_gift_unique_model(),
|
tr::lng_gift_unique_model(),
|
||||||
MakeAttributeValue(table, unique->model, showTooltip),
|
MakeAttributeValue(table, unique->model, showRarity),
|
||||||
marginWithButton);
|
marginWithButton);
|
||||||
AddTableRow(
|
AddTableRow(
|
||||||
table,
|
table,
|
||||||
tr::lng_gift_unique_backdrop(),
|
tr::lng_gift_unique_backdrop(),
|
||||||
MakeAttributeValue(table, unique->backdrop, showTooltip),
|
MakeAttributeValue(table, unique->backdrop, showRarity),
|
||||||
marginWithButton);
|
marginWithButton);
|
||||||
AddTableRow(
|
AddTableRow(
|
||||||
table,
|
table,
|
||||||
tr::lng_gift_unique_symbol(),
|
tr::lng_gift_unique_symbol(),
|
||||||
MakeAttributeValue(table, unique->pattern, showTooltip),
|
MakeAttributeValue(table, unique->pattern, showRarity),
|
||||||
marginWithButton);
|
marginWithButton);
|
||||||
} else {
|
} else {
|
||||||
AddTableRow(
|
AddTableRow(
|
||||||
|
|
|
@ -2292,14 +2292,10 @@ void ShowUniqueGiftWearBox(
|
||||||
box->setStyle(st::upgradeGiftBox);
|
box->setStyle(st::upgradeGiftBox);
|
||||||
|
|
||||||
const auto button = box->addButton(tr::lng_gift_wear_start(), [=] {
|
const auto button = box->addButton(tr::lng_gift_wear_start(), [=] {
|
||||||
|
box->closeBox();
|
||||||
show->session().data().emojiStatuses().set(
|
show->session().data().emojiStatuses().set(
|
||||||
show->session().user(),
|
show->session().user(),
|
||||||
show->session().data().emojiStatuses().fromUniqueGift(gift));
|
show->session().data().emojiStatuses().fromUniqueGift(gift));
|
||||||
box->closeBox();
|
|
||||||
show->showToast(tr::lng_gift_wear_start_toast(
|
|
||||||
tr::now,
|
|
||||||
lt_name,
|
|
||||||
UniqueGiftName(gift)));
|
|
||||||
});
|
});
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
box->widthValue(),
|
box->widthValue(),
|
||||||
|
|
|
@ -871,8 +871,6 @@ void FillUniqueGiftMenu(
|
||||||
if (now && unique->slug == now->slug) {
|
if (now && unique->slug == now->slug) {
|
||||||
menu->addAction(tr::lng_gift_transfer_take_off(tr::now), [=] {
|
menu->addAction(tr::lng_gift_transfer_take_off(tr::now), [=] {
|
||||||
show->session().data().emojiStatuses().set(peer, {});
|
show->session().data().emojiStatuses().set(peer, {});
|
||||||
show->showToast(
|
|
||||||
tr::lng_gift_wear_end_toast(tr::now, lt_name, name));
|
|
||||||
}, 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), [=] {
|
||||||
|
|
Loading…
Add table
Reference in a new issue