mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Nice referral link icon in the box.
This commit is contained in:
parent
1ebd25e76e
commit
d8892c4eb4
4 changed files with 107 additions and 5 deletions
BIN
Telegram/Resources/animations/starref_link.tgs
Normal file
BIN
Telegram/Resources/animations/starref_link.tgs
Normal file
Binary file not shown.
|
@ -29,6 +29,7 @@
|
||||||
<file alias="search.tgs">../../animations/search.tgs</file>
|
<file alias="search.tgs">../../animations/search.tgs</file>
|
||||||
<file alias="noresults.tgs">../../animations/noresults.tgs</file>
|
<file alias="noresults.tgs">../../animations/noresults.tgs</file>
|
||||||
<file alias="hello_status.tgs">../../animations/hello_status.tgs</file>
|
<file alias="hello_status.tgs">../../animations/hello_status.tgs</file>
|
||||||
|
<file alias="starref_link.tgs">../../animations/starref_link.tgs</file>
|
||||||
|
|
||||||
<file alias="dice_idle.tgs">../../animations/dice/dice_idle.tgs</file>
|
<file alias="dice_idle.tgs">../../animations/dice/dice_idle.tgs</file>
|
||||||
<file alias="dart_idle.tgs">../../animations/dice/dart_idle.tgs</file>
|
<file alias="dart_idle.tgs">../../animations/dice/dart_idle.tgs</file>
|
||||||
|
|
|
@ -9,7 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "boxes/peers/replace_boost_box.h" // CreateUserpicsTransfer.
|
#include "boxes/peers/replace_boost_box.h" // CreateUserpicsTransfer.
|
||||||
|
#include "chat_helpers/stickers_lottie.h"
|
||||||
|
#include "data/data_document.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "history/view/media/history_view_sticker.h"
|
||||||
|
#include "history/view/media/history_view_sticker_player.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
|
@ -52,6 +56,100 @@ void ConnectStarRef(
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] object_ptr<Ui::RpWidget> CreateLinkIcon(
|
||||||
|
not_null<QWidget*> parent,
|
||||||
|
not_null<UserData*> bot,
|
||||||
|
int users) {
|
||||||
|
auto result = object_ptr<Ui::RpWidget>(parent);
|
||||||
|
const auto raw = result.data();
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
not_null<DocumentData*> icon;
|
||||||
|
std::shared_ptr<Data::DocumentMedia> media;
|
||||||
|
std::shared_ptr<HistoryView::StickerPlayer> player;
|
||||||
|
int counterWidth = 0;
|
||||||
|
};
|
||||||
|
const auto outerSide = st::starrefLinkThumbOuter;
|
||||||
|
const auto outerSkip = (outerSide - st::starrefLinkThumbInner) / 2;
|
||||||
|
const auto innerSide = (outerSide - 2 * outerSkip);
|
||||||
|
const auto add = st::starrefLinkCountAdd;
|
||||||
|
const auto outer = QSize(outerSide, outerSide + add);
|
||||||
|
const auto inner = QSize(innerSide, innerSide);
|
||||||
|
const auto state = raw->lifetime().make_state<State>(State{
|
||||||
|
.icon = ChatHelpers::GenerateLocalTgsSticker(
|
||||||
|
&bot->session(),
|
||||||
|
u"starref_link"_q),
|
||||||
|
});
|
||||||
|
state->icon->overrideEmojiUsesTextColor(true);
|
||||||
|
state->media = state->icon->createMediaView();
|
||||||
|
state->player = std::make_unique<HistoryView::LottiePlayer>(
|
||||||
|
ChatHelpers::LottiePlayerFromDocument(
|
||||||
|
state->media.get(),
|
||||||
|
ChatHelpers::StickerLottieSize::MessageHistory,
|
||||||
|
inner,
|
||||||
|
Lottie::Quality::High));
|
||||||
|
const auto player = state->player.get();
|
||||||
|
player->setRepaintCallback([=] { raw->update(); });
|
||||||
|
|
||||||
|
const auto text = users
|
||||||
|
? Lang::FormatCountToShort(users).string
|
||||||
|
: QString();
|
||||||
|
const auto length = st::starrefLinkCountFont->width(text);
|
||||||
|
const auto contents = length + st::starrefLinkCountIcon.width();
|
||||||
|
const auto delta = (outer.width() - contents) / 2;
|
||||||
|
const auto badge = QRect(
|
||||||
|
delta,
|
||||||
|
outer.height() - st::starrefLinkCountFont->height - st::lineWidth,
|
||||||
|
outer.width() - 2 * delta,
|
||||||
|
st::starrefLinkCountFont->height);
|
||||||
|
const auto badgeRect = badge.marginsAdded(st::starrefLinkCountPadding);
|
||||||
|
|
||||||
|
raw->paintRequest() | rpl::start_with_next([=] {
|
||||||
|
auto p = QPainter(raw);
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
|
p.setBrush(st::windowBgActive);
|
||||||
|
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
|
||||||
|
const auto left = (raw->width() - outer.width()) / 2;
|
||||||
|
p.drawEllipse(left, 0, outerSide, outerSide);
|
||||||
|
|
||||||
|
if (!text.isEmpty()) {
|
||||||
|
const auto rect = badgeRect.translated(left, 0);
|
||||||
|
const auto textRect = badge.translated(left, 0);
|
||||||
|
const auto radius = st::starrefLinkCountFont->height / 2.;
|
||||||
|
p.setPen(st::historyPeerUserpicFg);
|
||||||
|
p.setBrush(st::historyPeer2UserpicBg2);
|
||||||
|
p.drawRoundedRect(rect, radius, radius);
|
||||||
|
|
||||||
|
p.setFont(st::starrefLinkCountFont);
|
||||||
|
const auto shift = QPoint(
|
||||||
|
st::starrefLinkCountIcon.width(),
|
||||||
|
st::starrefLinkCountFont->ascent);
|
||||||
|
st::starrefLinkCountIcon.paint(
|
||||||
|
p,
|
||||||
|
textRect.topLeft() + st::starrefLinkCountIconPosition,
|
||||||
|
raw->width());
|
||||||
|
p.drawText(textRect.topLeft() + shift, text);
|
||||||
|
}
|
||||||
|
if (player->ready()) {
|
||||||
|
const auto now = crl::now();
|
||||||
|
const auto color = st::windowFgActive->c;
|
||||||
|
auto info = player->frame(inner, color, false, now, false);
|
||||||
|
p.drawImage(
|
||||||
|
QRect(QPoint(left + outerSkip, outerSkip), inner),
|
||||||
|
info.image);
|
||||||
|
if (info.index + 1 < player->framesCount()) {
|
||||||
|
player->markFrameShown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, raw->lifetime());
|
||||||
|
|
||||||
|
raw->resize(outer);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
QString FormatCommission(ushort commission) {
|
QString FormatCommission(ushort commission) {
|
||||||
|
@ -225,11 +323,7 @@ object_ptr<Ui::BoxContent> StarRefLinkBox(
|
||||||
});
|
});
|
||||||
|
|
||||||
box->addRow(
|
box->addRow(
|
||||||
CreateUserpicsTransfer(
|
CreateLinkIcon(box, bot, row.state.users),
|
||||||
box,
|
|
||||||
rpl::single(std::vector{ not_null<PeerData*>(bot) }),
|
|
||||||
peer,
|
|
||||||
UserpicsTransferType::StarRefJoin),
|
|
||||||
st::boxRowPadding + st::starrefJoinUserpicsPadding);
|
st::boxRowPadding + st::starrefJoinUserpicsPadding);
|
||||||
box->addRow(
|
box->addRow(
|
||||||
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
||||||
|
|
|
@ -463,3 +463,10 @@ starrefBottomButtonLabelTop: 5px;
|
||||||
starrefBottomButtonSublabelTop: 23px;
|
starrefBottomButtonSublabelTop: 23px;
|
||||||
starrefEndBulletSize: 6px;
|
starrefEndBulletSize: 6px;
|
||||||
starrefEndBulletTop: 8px;
|
starrefEndBulletTop: 8px;
|
||||||
|
starrefLinkThumbOuter: 64px;
|
||||||
|
starrefLinkThumbInner: 48px;
|
||||||
|
starrefLinkCountAdd: 6px;
|
||||||
|
starrefLinkCountIcon: icon{{ "chat/mini_subscribers", historyPeerUserpicFg }};
|
||||||
|
starrefLinkCountIconPosition: point(0px, 1px);
|
||||||
|
starrefLinkCountFont: font(10px bold);
|
||||||
|
starrefLinkCountPadding: margins(2px, 0px, 3px, 1px);
|
Loading…
Add table
Reference in a new issue