mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-26 15:33:02 +02:00
Support correct sitckers for TON gifts.
This commit is contained in:
parent
7b870edefa
commit
f083180401
13 changed files with 158 additions and 138 deletions
|
@ -458,7 +458,7 @@ auto GenerateGiftMedia(
|
||||||
.sticker = sticker,
|
.sticker = sticker,
|
||||||
.size = st::chatIntroStickerSize,
|
.size = st::chatIntroStickerSize,
|
||||||
.cacheTag = Tag::ChatIntroHelloSticker,
|
.cacheTag = Tag::ChatIntroHelloSticker,
|
||||||
.singleTimePlayback = v::is<GiftTypePremium>(descriptor),
|
.stopOnLastFrame = v::is<GiftTypePremium>(descriptor),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
push(std::make_unique<StickerInBubblePart>(
|
push(std::make_unique<StickerInBubblePart>(
|
||||||
|
|
|
@ -16,14 +16,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Stickers {
|
namespace Stickers {
|
||||||
|
|
||||||
GiftBoxPack::GiftBoxPack(not_null<Main::Session*> session)
|
GiftBoxPack::GiftBoxPack(not_null<Main::Session*> session)
|
||||||
: _session(session)
|
: _session(session) {
|
||||||
, _localMonths({ 1, 3, 6, 12, 24 }) {
|
_premium.dividers = { 1, 3, 6, 12, 24 };
|
||||||
|
_ton.dividers = { 0, 10, 50 };
|
||||||
}
|
}
|
||||||
|
|
||||||
GiftBoxPack::~GiftBoxPack() = default;
|
GiftBoxPack::~GiftBoxPack() = default;
|
||||||
|
|
||||||
rpl::producer<> GiftBoxPack::updated() const {
|
rpl::producer<> GiftBoxPack::updated() const {
|
||||||
return _updated.events();
|
return _premium.updated.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> GiftBoxPack::tonUpdated() const {
|
||||||
|
return _ton.updated.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GiftBoxPack::monthsForStars(int stars) const {
|
int GiftBoxPack::monthsForStars(int stars) const {
|
||||||
|
@ -36,89 +41,90 @@ int GiftBoxPack::monthsForStars(int stars) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentData *GiftBoxPack::lookup(int months, Type type) const {
|
DocumentData *GiftBoxPack::lookup(int months) const {
|
||||||
const auto it = _setsData.find(type);
|
return lookup(_premium, months, false);
|
||||||
if (it == _setsData.end() || it->second.documents.empty()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& documents = it->second.documents;
|
DocumentData *GiftBoxPack::tonLookup(int amount) const {
|
||||||
const auto itMonths = ranges::lower_bound(_localMonths, months);
|
return lookup(_ton, amount, true);
|
||||||
const auto fallback = documents[0];
|
}
|
||||||
|
|
||||||
if (itMonths == begin(_localMonths)) {
|
DocumentData *GiftBoxPack::lookup(
|
||||||
|
const Pack &pack,
|
||||||
|
int divider,
|
||||||
|
bool exact) const {
|
||||||
|
const auto it = ranges::lower_bound(pack.dividers, divider);
|
||||||
|
const auto fallback = pack.documents.empty()
|
||||||
|
? nullptr
|
||||||
|
: pack.documents.front();
|
||||||
|
if (it == begin(pack.dividers)) {
|
||||||
return fallback;
|
return fallback;
|
||||||
} else if (itMonths == end(_localMonths)) {
|
} else if (it == end(pack.dividers)) {
|
||||||
return documents.back();
|
return pack.documents.back();
|
||||||
}
|
}
|
||||||
|
const auto shift = exact
|
||||||
const auto left = *(itMonths - 1);
|
? ((*it > divider) ? 1 : 0)
|
||||||
const auto right = *itMonths;
|
: (std::abs(divider - (*(it - 1))) < std::abs(divider - (*it)))
|
||||||
const auto shift = (std::abs(months - left) < std::abs(months - right))
|
|
||||||
? -1
|
? -1
|
||||||
: 0;
|
: 0;
|
||||||
const auto index = int(
|
const auto index = int(std::distance(begin(pack.dividers), it - shift));
|
||||||
std::distance(begin(_localMonths), itMonths - shift));
|
return (index >= pack.documents.size())
|
||||||
return (index >= documents.size()) ? fallback : documents[index];
|
? fallback
|
||||||
|
: pack.documents[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
Data::FileOrigin GiftBoxPack::origin(Type type) const {
|
Data::FileOrigin GiftBoxPack::origin() const {
|
||||||
const auto it = _setsData.find(type);
|
return Data::FileOriginStickerSet(_premium.id, _premium.accessHash);
|
||||||
if (it == _setsData.end()) {
|
|
||||||
return Data::FileOrigin();
|
|
||||||
}
|
|
||||||
return Data::FileOriginStickerSet(
|
|
||||||
it->second.setId,
|
|
||||||
it->second.accessHash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GiftBoxPack::load(Type type) {
|
Data::FileOrigin GiftBoxPack::tonOrigin() const {
|
||||||
if (_requestId) {
|
return Data::FileOriginStickerSet(_ton.id, _ton.accessHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GiftBoxPack::load() {
|
||||||
|
load(_premium, MTP_inputStickerSetPremiumGifts());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GiftBoxPack::tonLoad() {
|
||||||
|
load(_ton, MTP_inputStickerSetTonGifts());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GiftBoxPack::load(Pack &pack, const MTPInputStickerSet &set) {
|
||||||
|
if (pack.requestId || !pack.documents.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
pack.requestId = _session->api().request(MTPmessages_GetStickerSet(
|
||||||
const auto it = _setsData.find(type);
|
set,
|
||||||
if (it != _setsData.end() && !it->second.documents.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_requestId = _session->api().request(MTPmessages_GetStickerSet(
|
|
||||||
type == Type::Currency
|
|
||||||
? MTP_inputStickerSetTonGifts()
|
|
||||||
: MTP_inputStickerSetPremiumGifts(),
|
|
||||||
MTP_int(0) // Hash.
|
MTP_int(0) // Hash.
|
||||||
)).done([=](const MTPmessages_StickerSet &result) {
|
)).done([=, &pack](const MTPmessages_StickerSet &result) {
|
||||||
_requestId = 0;
|
pack.requestId = 0;
|
||||||
result.match([&](const MTPDmessages_stickerSet &data) {
|
result.match([&](const MTPDmessages_stickerSet &data) {
|
||||||
applySet(data, type);
|
applySet(pack, data);
|
||||||
}, [](const MTPDmessages_stickerSetNotModified &) {
|
}, [](const MTPDmessages_stickerSetNotModified &) {
|
||||||
LOG(("API Error: Unexpected messages.stickerSetNotModified."));
|
LOG(("API Error: Unexpected messages.stickerSetNotModified."));
|
||||||
});
|
});
|
||||||
}).fail([=] {
|
}).fail([=, &pack] {
|
||||||
_requestId = 0;
|
pack.requestId = 0;
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GiftBoxPack::applySet(const MTPDmessages_stickerSet &data, Type type) {
|
void GiftBoxPack::applySet(Pack &pack, const MTPDmessages_stickerSet &data) {
|
||||||
auto setData = SetData();
|
pack.id = data.vset().data().vid().v;
|
||||||
setData.setId = data.vset().data().vid().v;
|
pack.accessHash = data.vset().data().vaccess_hash().v;
|
||||||
setData.accessHash = data.vset().data().vaccess_hash().v;
|
|
||||||
|
|
||||||
auto documents = base::flat_map<DocumentId, not_null<DocumentData*>>();
|
auto documents = base::flat_map<DocumentId, not_null<DocumentData*>>();
|
||||||
for (const auto &sticker : data.vdocuments().v) {
|
for (const auto &sticker : data.vdocuments().v) {
|
||||||
const auto document = _session->data().processDocument(sticker);
|
const auto document = _session->data().processDocument(sticker);
|
||||||
if (document->sticker()) {
|
if (document->sticker()) {
|
||||||
documents.emplace(document->id, document);
|
documents.emplace(document->id, document);
|
||||||
if (setData.documents.empty()) {
|
if (pack.documents.empty()) {
|
||||||
// Fallback.
|
// Fallback.
|
||||||
setData.documents.resize(1);
|
pack.documents.resize(1);
|
||||||
setData.documents[0] = document;
|
pack.documents[0] = document;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (const auto &info : data.vpacks().v) {
|
||||||
for (const auto &pack : data.vpacks().v) {
|
const auto &data = info.data();
|
||||||
pack.match([&](const MTPDstickerPack &data) {
|
|
||||||
const auto emoji = qs(data.vemoticon());
|
const auto emoji = qs(data.vemoticon());
|
||||||
if (emoji.isEmpty()) {
|
if (emoji.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -129,22 +135,19 @@ void GiftBoxPack::applySet(const MTPDmessages_stickerSet &data, Type type) {
|
||||||
if (!sticker->alt.isEmpty()) {
|
if (!sticker->alt.isEmpty()) {
|
||||||
const auto ch = int(sticker->alt[0].unicode());
|
const auto ch = int(sticker->alt[0].unicode());
|
||||||
const auto index = (ch - '1'); // [0, 4];
|
const auto index = (ch - '1'); // [0, 4];
|
||||||
if (index < 0 || index >= _localMonths.size()) {
|
if (index < 0 || index >= pack.dividers.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((index + 1) > setData.documents.size()) {
|
if ((index + 1) > pack.documents.size()) {
|
||||||
setData.documents.resize((index + 1));
|
pack.documents.resize((index + 1));
|
||||||
}
|
}
|
||||||
setData.documents[index] = (*document);
|
pack.documents[index] = (*document);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
pack.updated.fire({});
|
||||||
_setsData[type] = std::move(setData);
|
|
||||||
_updated.fire({});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Stickers
|
} // namespace Stickers
|
||||||
|
|
|
@ -21,38 +21,45 @@ namespace Stickers {
|
||||||
|
|
||||||
class GiftBoxPack final {
|
class GiftBoxPack final {
|
||||||
public:
|
public:
|
||||||
enum class Type {
|
|
||||||
Gifts,
|
|
||||||
Currency,
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit GiftBoxPack(not_null<Main::Session*> session);
|
explicit GiftBoxPack(not_null<Main::Session*> session);
|
||||||
~GiftBoxPack();
|
~GiftBoxPack();
|
||||||
|
|
||||||
void load(Type type = Type::Gifts);
|
void load();
|
||||||
[[nodiscard]] int monthsForStars(int stars) const;
|
[[nodiscard]] int monthsForStars(int stars) const;
|
||||||
[[nodiscard]] DocumentData *lookup(
|
[[nodiscard]] DocumentData *lookup(int months) const;
|
||||||
int months,
|
[[nodiscard]] Data::FileOrigin origin() const;
|
||||||
Type type = Type::Gifts) const;
|
|
||||||
[[nodiscard]] Data::FileOrigin origin(Type type = Type::Gifts) const;
|
|
||||||
[[nodiscard]] rpl::producer<> updated() const;
|
[[nodiscard]] rpl::producer<> updated() const;
|
||||||
|
|
||||||
|
void tonLoad();
|
||||||
|
[[nodiscard]] DocumentData *tonLookup(int amount) const;
|
||||||
|
[[nodiscard]] Data::FileOrigin tonOrigin() const;
|
||||||
|
[[nodiscard]] rpl::producer<> tonUpdated() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using SetId = uint64;
|
using SetId = uint64;
|
||||||
struct SetData {
|
|
||||||
SetId setId = 0;
|
struct Pack {
|
||||||
|
SetId id = 0;
|
||||||
uint64 accessHash = 0;
|
uint64 accessHash = 0;
|
||||||
std::vector<DocumentData*> documents;
|
std::vector<DocumentData*> documents;
|
||||||
|
mtpRequestId requestId = 0;
|
||||||
|
std::vector<int> dividers;
|
||||||
|
rpl::event_stream<> updated;
|
||||||
};
|
};
|
||||||
|
|
||||||
void applySet(const MTPDmessages_stickerSet &data, Type type);
|
void load(Pack &pack, const MTPInputStickerSet &set);
|
||||||
|
void applySet(Pack &pack, const MTPDmessages_stickerSet &data);
|
||||||
|
[[nodiscard]] DocumentData *lookup(
|
||||||
|
const Pack &pack,
|
||||||
|
int divider,
|
||||||
|
bool exact) const;
|
||||||
|
|
||||||
const not_null<Main::Session*> _session;
|
const not_null<Main::Session*> _session;
|
||||||
const std::vector<int> _localMonths;
|
const std::vector<int> _localMonths;
|
||||||
|
const std::vector<int> _localTonAmounts;
|
||||||
|
|
||||||
rpl::event_stream<> _updated;
|
Pack _premium;
|
||||||
base::flat_map<Type, SetData> _setsData;
|
Pack _ton;
|
||||||
mtpRequestId _requestId = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5768,6 +5768,7 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) {
|
||||||
auto result = PreparedServiceText();
|
auto result = PreparedServiceText();
|
||||||
const auto isSelf = (_from->id == _from->session().userPeerId());
|
const auto isSelf = (_from->id == _from->session().userPeerId());
|
||||||
const auto peer = isSelf ? _history->peer : _from;
|
const auto peer = isSelf ? _history->peer : _from;
|
||||||
|
_history->session().giftBoxStickersPacks().tonLoad();
|
||||||
const auto amount = action.vamount().v;
|
const auto amount = action.vamount().v;
|
||||||
const auto currency = qs(action.vcurrency());
|
const auto currency = qs(action.vcurrency());
|
||||||
const auto cost = AmountAndStarCurrency(
|
const auto cost = AmountAndStarCurrency(
|
||||||
|
|
|
@ -48,7 +48,7 @@ auto GenerateGiveawayStart(
|
||||||
return Data{
|
return Data{
|
||||||
.sticker = packs.lookup(months),
|
.sticker = packs.lookup(months),
|
||||||
.size = st::msgServiceGiftBoxStickerSize,
|
.size = st::msgServiceGiftBoxStickerSize,
|
||||||
.singleTimePlayback = true,
|
.stopOnLastFrame = true,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
push(std::make_unique<StickerWithBadgePart>(
|
push(std::make_unique<StickerWithBadgePart>(
|
||||||
|
@ -222,7 +222,7 @@ auto GenerateGiveawayResults(
|
||||||
.sticker = packs.lookup(emoji, 0),
|
.sticker = packs.lookup(emoji, 0),
|
||||||
.skipTop = st::chatGiveawayWinnersTopSkip,
|
.skipTop = st::chatGiveawayWinnersTopSkip,
|
||||||
.size = st::maxAnimatedEmojiSize,
|
.size = st::maxAnimatedEmojiSize,
|
||||||
.singleTimePlayback = true,
|
.stopOnLastFrame = true,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
push(std::make_unique<StickerWithBadgePart>(
|
push(std::make_unique<StickerWithBadgePart>(
|
||||||
|
|
|
@ -474,8 +474,8 @@ void StickerInBubblePart::ensureCreated(Element *replacing) const {
|
||||||
_link = data.link;
|
_link = data.link;
|
||||||
_skipTop = data.skipTop;
|
_skipTop = data.skipTop;
|
||||||
_sticker.emplace(_parent, sticker, skipPremiumEffect, replacing);
|
_sticker.emplace(_parent, sticker, skipPremiumEffect, replacing);
|
||||||
if (data.singleTimePlayback) {
|
if (data.stopOnLastFrame) {
|
||||||
_sticker->setPlayingOnce(true);
|
_sticker->setStopOnLastFrame(true);
|
||||||
}
|
}
|
||||||
_sticker->initSize(data.size);
|
_sticker->initSize(data.size);
|
||||||
_sticker->setCustomCachingTag(data.cacheTag);
|
_sticker->setCustomCachingTag(data.cacheTag);
|
||||||
|
|
|
@ -197,7 +197,7 @@ public:
|
||||||
int skipTop = 0;
|
int skipTop = 0;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
ChatHelpers::StickerLottieSize cacheTag = {};
|
ChatHelpers::StickerLottieSize cacheTag = {};
|
||||||
bool singleTimePlayback = false;
|
bool stopOnLastFrame = false;
|
||||||
ClickHandlerPtr link;
|
ClickHandlerPtr link;
|
||||||
|
|
||||||
explicit operator bool() const {
|
explicit operator bool() const {
|
||||||
|
|
|
@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "boxes/gift_premium_box.h" // ResolveGiftCode
|
#include "boxes/gift_premium_box.h" // ResolveGiftCode
|
||||||
#include "chat_helpers/stickers_gift_box_pack.h"
|
#include "chat_helpers/stickers_gift_box_pack.h"
|
||||||
#include "chat_helpers/stickers_lottie.h"
|
|
||||||
#include "core/click_handler_types.h" // ClickHandlerContext
|
#include "core/click_handler_types.h" // ClickHandlerContext
|
||||||
#include "data/stickers/data_custom_emoji.h"
|
#include "data/stickers/data_custom_emoji.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
|
@ -30,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "settings/settings_credits_graphics.h" // GiftedCreditsBox
|
#include "settings/settings_credits_graphics.h" // GiftedCreditsBox
|
||||||
#include "settings/settings_premium.h" // Settings::ShowGiftPremium
|
#include "settings/settings_premium.h" // Settings::ShowGiftPremium
|
||||||
#include "ui/chat/chat_style.h"
|
#include "ui/chat/chat_style.h"
|
||||||
|
#include "ui/controls/ton_common.h" // kNanosInOne
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
|
@ -416,15 +416,17 @@ void PremiumGift::ensureStickerCreated() const {
|
||||||
if (_sticker) {
|
if (_sticker) {
|
||||||
return;
|
return;
|
||||||
} else if (tonGift()) {
|
} else if (tonGift()) {
|
||||||
const auto document = ChatHelpers::GenerateLocalTgsSticker(
|
const auto &session = _parent->history()->session();
|
||||||
&_parent->history()->session(),
|
auto &packs = session.giftBoxStickersPacks();
|
||||||
"diamond");
|
const auto count = _data.count / Ui::kNanosInOne;
|
||||||
const auto sticker = document->sticker();
|
if (const auto document = packs.tonLookup(count)) {
|
||||||
Assert(sticker != nullptr);
|
if (document->sticker()) {
|
||||||
_sticker.emplace(_parent, document, false, _parent);
|
const auto skipPremiumEffect = false;
|
||||||
_sticker->setPlayingOnce(true);
|
_sticker.emplace(_parent, document, skipPremiumEffect, _parent);
|
||||||
_sticker->initSize(st::msgServiceStarGiftStickerSize);
|
_sticker->setStopOnLastFrame(true);
|
||||||
_parent->repaint();
|
_sticker->initSize(st::msgServiceGiftBoxStickerSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else if (const auto document = _data.document) {
|
} else if (const auto document = _data.document) {
|
||||||
const auto sticker = document->sticker();
|
const auto sticker = document->sticker();
|
||||||
|
@ -443,7 +445,7 @@ void PremiumGift::ensureStickerCreated() const {
|
||||||
if (document->sticker()) {
|
if (document->sticker()) {
|
||||||
const auto skipPremiumEffect = false;
|
const auto skipPremiumEffect = false;
|
||||||
_sticker.emplace(_parent, document, skipPremiumEffect, _parent);
|
_sticker.emplace(_parent, document, skipPremiumEffect, _parent);
|
||||||
_sticker->setPlayingOnce(true);
|
_sticker->setStopOnLastFrame(true);
|
||||||
_sticker->initSize(st::msgServiceGiftBoxStickerSize);
|
_sticker->initSize(st::msgServiceGiftBoxStickerSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ QSize Sticker::countOptimalSize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sticker::readyToDrawAnimationFrame() {
|
bool Sticker::readyToDrawAnimationFrame() {
|
||||||
if (!_lastDiceFrame.isNull()) {
|
if (!_lastFrameCached.isNull()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const auto sticker = _data->sticker();
|
const auto sticker = _data->sticker();
|
||||||
|
@ -261,7 +261,7 @@ void Sticker::paintAnimationFrame(
|
||||||
const QRect &r) {
|
const QRect &r) {
|
||||||
const auto colored = (customEmojiPart() && _data->emojiUsesTextColor())
|
const auto colored = (customEmojiPart() && _data->emojiUsesTextColor())
|
||||||
? ComputeEmojiTextColor(context)
|
? ComputeEmojiTextColor(context)
|
||||||
: (context.selected() && !_nextLastDiceFrame)
|
: (context.selected() && !_nextLastFrame)
|
||||||
? context.st->msgStickerOverlay()->c
|
? context.st->msgStickerOverlay()->c
|
||||||
: QColor(0, 0, 0, 0);
|
: QColor(0, 0, 0, 0);
|
||||||
const auto powerSavingFlag = (emojiSticker() || _diceIndex >= 0)
|
const auto powerSavingFlag = (emojiSticker() || _diceIndex >= 0)
|
||||||
|
@ -276,14 +276,16 @@ void Sticker::paintAnimationFrame(
|
||||||
context.now,
|
context.now,
|
||||||
paused)
|
paused)
|
||||||
: StickerPlayer::FrameInfo();
|
: StickerPlayer::FrameInfo();
|
||||||
if (_nextLastDiceFrame) {
|
if (_nextLastFrame) {
|
||||||
_nextLastDiceFrame = false;
|
_nextLastFrame = false;
|
||||||
_lastDiceFrame = CacheDiceImage(_diceEmoji, _diceIndex, frame.image);
|
_lastFrameCached = (_diceIndex > 0)
|
||||||
|
? CacheDiceImage(_diceEmoji, _diceIndex, frame.image)
|
||||||
|
: frame.image;
|
||||||
}
|
}
|
||||||
const auto &image = _lastDiceFrame.isNull()
|
const auto &image = _lastFrameCached.isNull()
|
||||||
? frame.image
|
? frame.image
|
||||||
: _lastDiceFrame;
|
: _lastFrameCached;
|
||||||
const auto prepared = (!_lastDiceFrame.isNull() && context.selected())
|
const auto prepared = (!_lastFrameCached.isNull() && context.selected())
|
||||||
? Images::Colored(
|
? Images::Colored(
|
||||||
base::duplicate(image),
|
base::duplicate(image),
|
||||||
context.st->msgStickerOverlay()->c)
|
context.st->msgStickerOverlay()->c)
|
||||||
|
@ -296,25 +298,25 @@ void Sticker::paintAnimationFrame(
|
||||||
r.y() + (r.height() - size.height()) / 2),
|
r.y() + (r.height() - size.height()) / 2),
|
||||||
size),
|
size),
|
||||||
prepared);
|
prepared);
|
||||||
if (!_lastDiceFrame.isNull()) {
|
if (!_lastFrameCached.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto count = _player->framesCount();
|
const auto count = _player->framesCount();
|
||||||
_frameIndex = frame.index;
|
_frameIndex = frame.index;
|
||||||
_framesCount = count;
|
_framesCount = count;
|
||||||
_nextLastDiceFrame = !paused
|
_nextLastFrame = !paused
|
||||||
&& (_diceIndex > 0)
|
&& _stopOnLastFrame
|
||||||
&& (_frameIndex + 2 == count);
|
&& (_frameIndex + 2 == count);
|
||||||
const auto playOnce = (_playingOnce || _diceIndex > 0)
|
const auto playOnce = _playingOnce
|
||||||
? true
|
? true
|
||||||
: (_diceIndex == 0)
|
: (_diceIndex == 0)
|
||||||
? false
|
? false
|
||||||
: ((!customEmojiPart() && emojiSticker())
|
: ((!customEmojiPart() && emojiSticker())
|
||||||
|| !Core::App().settings().loopAnimatedStickers());
|
|| !Core::App().settings().loopAnimatedStickers());
|
||||||
const auto lastDiceFrame = (_diceIndex > 0) && atTheEnd();
|
const auto lastFrame = _stopOnLastFrame && atTheEnd();
|
||||||
const auto switchToNext = !playOnce
|
const auto switchToNext = !playOnce
|
||||||
|| (!lastDiceFrame && (_frameIndex != 0 || !_oncePlayed));
|
|| (!lastFrame && (_frameIndex != 0 || !_oncePlayed));
|
||||||
if (!paused
|
if (!paused
|
||||||
&& switchToNext
|
&& switchToNext
|
||||||
&& _player->markFrameShown()
|
&& _player->markFrameShown()
|
||||||
|
@ -519,12 +521,19 @@ void Sticker::dataMediaCreated() const {
|
||||||
void Sticker::setDiceIndex(const QString &emoji, int index) {
|
void Sticker::setDiceIndex(const QString &emoji, int index) {
|
||||||
_diceEmoji = emoji;
|
_diceEmoji = emoji;
|
||||||
_diceIndex = index;
|
_diceIndex = index;
|
||||||
|
_playingOnce = (index >= 0);
|
||||||
|
_stopOnLastFrame = (index > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sticker::setPlayingOnce(bool once) {
|
void Sticker::setPlayingOnce(bool once) {
|
||||||
_playingOnce = once;
|
_playingOnce = once;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sticker::setStopOnLastFrame(bool stop) {
|
||||||
|
_stopOnLastFrame = stop;
|
||||||
|
_playingOnce = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Sticker::setCustomCachingTag(ChatHelpers::StickerLottieSize tag) {
|
void Sticker::setCustomCachingTag(ChatHelpers::StickerLottieSize tag) {
|
||||||
_cachingTag = tag;
|
_cachingTag = tag;
|
||||||
}
|
}
|
||||||
|
@ -595,8 +604,8 @@ void Sticker::unloadPlayer() {
|
||||||
if (!_player) {
|
if (!_player) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_diceIndex > 0 && _lastDiceFrame.isNull()) {
|
if (_stopOnLastFrame && _lastFrameCached.isNull()) {
|
||||||
_nextLastDiceFrame = false;
|
_nextLastFrame = false;
|
||||||
_oncePlayed = false;
|
_oncePlayed = false;
|
||||||
}
|
}
|
||||||
_player = nullptr;
|
_player = nullptr;
|
||||||
|
|
|
@ -67,6 +67,7 @@ public:
|
||||||
|
|
||||||
void setDiceIndex(const QString &emoji, int index);
|
void setDiceIndex(const QString &emoji, int index);
|
||||||
void setPlayingOnce(bool once);
|
void setPlayingOnce(bool once);
|
||||||
|
void setStopOnLastFrame(bool stop);
|
||||||
void setCustomCachingTag(ChatHelpers::StickerLottieSize tag);
|
void setCustomCachingTag(ChatHelpers::StickerLottieSize tag);
|
||||||
void setCustomEmojiPart();
|
void setCustomEmojiPart();
|
||||||
void setEmojiSticker();
|
void setEmojiSticker();
|
||||||
|
@ -128,7 +129,7 @@ private:
|
||||||
mutable std::shared_ptr<Data::DocumentMedia> _dataMedia;
|
mutable std::shared_ptr<Data::DocumentMedia> _dataMedia;
|
||||||
ClickHandlerPtr _link;
|
ClickHandlerPtr _link;
|
||||||
QSize _size;
|
QSize _size;
|
||||||
QImage _lastDiceFrame;
|
QImage _lastFrameCached;
|
||||||
QString _diceEmoji;
|
QString _diceEmoji;
|
||||||
int _diceIndex = -1;
|
int _diceIndex = -1;
|
||||||
mutable int _frameIndex = -1;
|
mutable int _frameIndex = -1;
|
||||||
|
@ -137,12 +138,13 @@ private:
|
||||||
mutable bool _oncePlayed : 1 = false;
|
mutable bool _oncePlayed : 1 = false;
|
||||||
mutable bool _premiumEffectPlayed : 1 = false;
|
mutable bool _premiumEffectPlayed : 1 = false;
|
||||||
mutable bool _premiumEffectSkipped : 1 = false;
|
mutable bool _premiumEffectSkipped : 1 = false;
|
||||||
mutable bool _nextLastDiceFrame : 1 = false;
|
mutable bool _nextLastFrame : 1 = false;
|
||||||
bool _skipPremiumEffect : 1 = false;
|
bool _skipPremiumEffect : 1 = false;
|
||||||
bool _customEmojiPart : 1 = false;
|
bool _customEmojiPart : 1 = false;
|
||||||
bool _emojiSticker : 1 = false;
|
bool _emojiSticker : 1 = false;
|
||||||
bool _webpagePart : 1 = false;
|
bool _webpagePart : 1 = false;
|
||||||
bool _playingOnce : 1 = false;
|
bool _playingOnce : 1 = false;
|
||||||
|
bool _stopOnLastFrame : 1 = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,6 @@ QString ToUsd(
|
||||||
int afterFloat) {
|
int afterFloat) {
|
||||||
constexpr auto kApproximately = QChar(0x2248);
|
constexpr auto kApproximately = QChar(0x2248);
|
||||||
|
|
||||||
const auto result = int64(base::SafeRound(value.value() * rate));
|
|
||||||
return QString(kApproximately)
|
return QString(kApproximately)
|
||||||
+ QChar('$')
|
+ QChar('$')
|
||||||
+ QString::number(
|
+ QString::number(
|
||||||
|
|
|
@ -121,8 +121,7 @@ Credits::Credits(
|
||||||
st::tonFieldIconSize,
|
st::tonFieldIconSize,
|
||||||
st::currencyFg->c)
|
st::currencyFg->c)
|
||||||
: Ui::GenerateStars(st::creditsBalanceStarHeight, 1)) {
|
: Ui::GenerateStars(st::creditsBalanceStarHeight, 1)) {
|
||||||
_controller->session().giftBoxStickersPacks().load(
|
_controller->session().giftBoxStickersPacks().tonLoad();
|
||||||
Stickers::GiftBoxPack::Type::Currency);
|
|
||||||
setupContent();
|
setupContent();
|
||||||
|
|
||||||
_controller->session().premiumPossibleValue(
|
_controller->session().premiumPossibleValue(
|
||||||
|
@ -418,7 +417,6 @@ void Credits::setupContent() {
|
||||||
};
|
};
|
||||||
const auto state = content->lifetime().make_state<State>();
|
const auto state = content->lifetime().make_state<State>();
|
||||||
|
|
||||||
const auto paddings = rect::m::sum::h(st::boxRowPadding);
|
|
||||||
{
|
{
|
||||||
const auto button = content->add(
|
const auto button = content->add(
|
||||||
object_ptr<Ui::CenterWrap<Ui::RoundButton>>(
|
object_ptr<Ui::CenterWrap<Ui::RoundButton>>(
|
||||||
|
@ -623,13 +621,13 @@ QPointer<Ui::RpWidget> Credits::createPinnedToTop(
|
||||||
st::creditsPremiumCover,
|
st::creditsPremiumCover,
|
||||||
Ui::Premium::TopBarDescriptor{
|
Ui::Premium::TopBarDescriptor{
|
||||||
.clickContextOther = clickContextOther,
|
.clickContextOther = clickContextOther,
|
||||||
|
.logo = isCurrency ? u"diamond"_q : QString(),
|
||||||
.title = title(),
|
.title = title(),
|
||||||
.about = (isCurrency
|
.about = (isCurrency
|
||||||
? tr::lng_credits_currency_summary_about
|
? tr::lng_credits_currency_summary_about
|
||||||
: tr::lng_credits_summary_about)(
|
: tr::lng_credits_summary_about)(
|
||||||
TextWithEntities::Simple),
|
TextWithEntities::Simple),
|
||||||
.light = true,
|
.light = true,
|
||||||
.logo = isCurrency ? u"diamond"_q : QString(),
|
|
||||||
.gradientStops = Ui::Premium::CreditsIconGradientStops(),
|
.gradientStops = Ui::Premium::CreditsIconGradientStops(),
|
||||||
});
|
});
|
||||||
}();
|
}();
|
||||||
|
|
|
@ -1311,13 +1311,12 @@ void GenericCreditsEntryBox(
|
||||||
auto &packs = session->giftBoxStickersPacks();
|
auto &packs = session->giftBoxStickersPacks();
|
||||||
const auto document = starGiftSticker
|
const auto document = starGiftSticker
|
||||||
? starGiftSticker
|
? starGiftSticker
|
||||||
|
: e.credits.ton()
|
||||||
|
? packs.tonLookup(e.credits.whole())
|
||||||
: packs.lookup(
|
: packs.lookup(
|
||||||
e.premiumMonthsForStars
|
e.premiumMonthsForStars
|
||||||
? e.premiumMonthsForStars
|
? e.premiumMonthsForStars
|
||||||
: packs.monthsForStars(e.credits.whole()),
|
: packs.monthsForStars(e.credits.whole()));
|
||||||
e.credits.stars()
|
|
||||||
? Stickers::GiftBoxPack::Type::Gifts
|
|
||||||
: Stickers::GiftBoxPack::Type::Currency);
|
|
||||||
if (document && document->sticker()) {
|
if (document && document->sticker()) {
|
||||||
state->sticker = document;
|
state->sticker = document;
|
||||||
state->media = document->createMediaView();
|
state->media = document->createMediaView();
|
||||||
|
|
Loading…
Add table
Reference in a new issue