Fix intro hello sticker playback in editing.

This commit is contained in:
John Preston 2024-03-20 11:59:05 +04:00
parent 191c35914f
commit 98ce91df39
8 changed files with 52 additions and 48 deletions

View file

@ -180,13 +180,10 @@ ChatIntroBox::ChatIntroBox(not_null<Element*> parent, Data::ChatIntro data)
, _data(data) { , _data(data) {
if (const auto document = data.sticker) { if (const auto document = data.sticker) {
if (const auto sticker = document->sticker()) { if (const auto sticker = document->sticker()) {
const auto skipPremiumEffect = false; const auto skipPremiumEffect = true;
_sticker.emplace(_parent, document, skipPremiumEffect, _parent); _sticker.emplace(_parent, document, skipPremiumEffect, _parent);
_sticker->setDiceIndex(sticker->alt, 0); _sticker->initSize(st::chatIntroStickerSize);
_sticker->setGiftBoxSticker(true); _sticker->setCustomCachingTag(
_sticker->initSize();
_sticker->setCustomEmojiPart(
st::chatIntroStickerSize,
ChatHelpers::StickerLottieSize::ChatIntroHelloSticker); ChatHelpers::StickerLottieSize::ChatIntroHelloSticker);
} }
} }

View file

@ -753,14 +753,16 @@ void Element::refreshMedia(Element *replacing) {
const auto emojiStickers = &history()->session().emojiStickersPack(); const auto emojiStickers = &history()->session().emojiStickersPack();
const auto skipPremiumEffect = false; const auto skipPremiumEffect = false;
if (const auto sticker = emojiStickers->stickerForEmoji(emoji)) { if (const auto sticker = emojiStickers->stickerForEmoji(emoji)) {
auto content = std::make_unique<Sticker>(
this,
sticker.document,
skipPremiumEffect,
replacing,
sticker.replacements);
content->setEmojiSticker();
_media = std::make_unique<UnwrappedMedia>( _media = std::make_unique<UnwrappedMedia>(
this, this,
std::make_unique<Sticker>( std::move(content));
this,
sticker.document,
skipPremiumEffect,
replacing,
sticker.replacements));
} else { } else {
_media = std::make_unique<UnwrappedMedia>( _media = std::make_unique<UnwrappedMedia>(
this, this,

View file

@ -128,7 +128,9 @@ std::unique_ptr<Sticker> CustomEmoji::createStickerPart(
_parent, _parent,
document, document,
skipPremiumEffect); skipPremiumEffect);
result->setCustomEmojiPart(_singleSize, _cachingTag); result->initSize(_singleSize);
result->setCustomCachingTag(_cachingTag);
result->setCustomEmojiPart();
return result; return result;
} }

View file

@ -310,10 +310,10 @@ void StickerWithBadgePart::draw(
int outerWidth) const { int outerWidth) const {
const auto stickerSize = st::msgServiceGiftBoxStickerSize; const auto stickerSize = st::msgServiceGiftBoxStickerSize;
const auto sticker = QRect( const auto sticker = QRect(
(outerWidth - stickerSize.width()) / 2, (outerWidth - stickerSize) / 2,
st::chatGiveawayStickerTop + _skipTop, st::chatGiveawayStickerTop + _skipTop,
stickerSize.width(), stickerSize,
stickerSize.height()); stickerSize);
if (_sticker) { if (_sticker) {
_sticker->draw(p, context, sticker); _sticker->draw(p, context, sticker);
@ -335,7 +335,7 @@ void StickerWithBadgePart::unloadHeavyPart() {
QSize StickerWithBadgePart::countOptimalSize() { QSize StickerWithBadgePart::countOptimalSize() {
const auto size = st::msgServiceGiftBoxStickerSize; const auto size = st::msgServiceGiftBoxStickerSize;
return { size.width(), st::chatGiveawayStickerTop + size.height() }; return { size, st::chatGiveawayStickerTop + size };
} }
QSize StickerWithBadgePart::countCurrentSize(int newWidth) { QSize StickerWithBadgePart::countCurrentSize(int newWidth) {
@ -352,8 +352,9 @@ void StickerWithBadgePart::ensureCreated() const {
_skipTop = data.skipTop; _skipTop = data.skipTop;
_sticker.emplace(_parent, document, skipPremiumEffect, _parent); _sticker.emplace(_parent, document, skipPremiumEffect, _parent);
_sticker->setDiceIndex(sticker->alt, 1); _sticker->setDiceIndex(sticker->alt, 1);
_sticker->setGiftBoxSticker(data.isGiftBoxSticker); _sticker->initSize(data.isGiftBoxSticker
_sticker->initSize(); ? st::msgServiceGiftBoxStickerSize
: 0);
} }
} }
} }

View file

@ -39,7 +39,9 @@ int PremiumGift::top() {
} }
QSize PremiumGift::size() { QSize PremiumGift::size() {
return st::msgServiceGiftBoxStickerSize; return QSize(
st::msgServiceGiftBoxStickerSize,
st::msgServiceGiftBoxStickerSize);
} }
QString PremiumGift::title() { QString PremiumGift::title() {
@ -172,8 +174,7 @@ void PremiumGift::ensureStickerCreated() const {
const auto skipPremiumEffect = false; const auto skipPremiumEffect = false;
_sticker.emplace(_parent, document, skipPremiumEffect, _parent); _sticker.emplace(_parent, document, skipPremiumEffect, _parent);
_sticker->setDiceIndex(sticker->alt, 1); _sticker->setDiceIndex(sticker->alt, 1);
_sticker->setGiftBoxSticker(true); _sticker->initSize(st::msgServiceGiftBoxStickerSize);
_sticker->initSize();
} }
} }
} }

View file

@ -130,20 +130,18 @@ bool Sticker::hasPremiumEffect() const {
} }
bool Sticker::customEmojiPart() const { bool Sticker::customEmojiPart() const {
return (_cachingTag != ChatHelpers::StickerLottieSize::MessageHistory); return _customEmojiPart;
} }
bool Sticker::isEmojiSticker() const { bool Sticker::emojiSticker() const {
return (_parent->data()->media() == nullptr); return _emojiSticker;
} }
void Sticker::initSize() { void Sticker::initSize(int customSize) {
if (isEmojiSticker() || _diceIndex >= 0) { if (customSize > 0) {
if (_giftBoxSticker) { _size = { customSize, customSize };
_size = st::msgServiceGiftBoxStickerSize; } else if (emojiSticker() || _diceIndex >= 0) {
} else { _size = EmojiSize();
_size = EmojiSize();
}
if (_diceIndex > 0) { if (_diceIndex > 0) {
[[maybe_unused]] bool result = readyToDrawAnimationFrame(); [[maybe_unused]] bool result = readyToDrawAnimationFrame();
} }
@ -252,7 +250,7 @@ void Sticker::paintAnimationFrame(
: (context.selected() && !_nextLastDiceFrame) : (context.selected() && !_nextLastDiceFrame)
? context.st->msgStickerOverlay()->c ? context.st->msgStickerOverlay()->c
: QColor(0, 0, 0, 0); : QColor(0, 0, 0, 0);
const auto powerSavingFlag = (isEmojiSticker() || _diceIndex >= 0) const auto powerSavingFlag = (emojiSticker() || _diceIndex >= 0)
? PowerSaving::kEmojiChat ? PowerSaving::kEmojiChat
: PowerSaving::kStickersChat; : PowerSaving::kStickersChat;
const auto paused = context.paused || On(powerSavingFlag); const auto paused = context.paused || On(powerSavingFlag);
@ -298,7 +296,7 @@ void Sticker::paintAnimationFrame(
? true ? true
: (_diceIndex == 0) : (_diceIndex == 0)
? false ? false
: ((!customEmojiPart() && isEmojiSticker()) : ((!customEmojiPart() && emojiSticker())
|| !Core::App().settings().loopAnimatedStickers()); || !Core::App().settings().loopAnimatedStickers());
const auto lastDiceFrame = (_diceIndex > 0) && atTheEnd(); const auto lastDiceFrame = (_diceIndex > 0) && atTheEnd();
const auto switchToNext = !playOnce const auto switchToNext = !playOnce
@ -421,7 +419,7 @@ void Sticker::refreshLink() {
return; return;
} }
const auto sticker = _data->sticker(); const auto sticker = _data->sticker();
if (isEmojiSticker()) { if (emojiSticker()) {
const auto weak = base::make_weak(this); const auto weak = base::make_weak(this);
_link = std::make_shared<LambdaClickHandler>([weak] { _link = std::make_shared<LambdaClickHandler>([weak] {
if (const auto that = weak.get()) { if (const auto that = weak.get()) {
@ -499,15 +497,16 @@ void Sticker::setDiceIndex(const QString &emoji, int index) {
_diceIndex = index; _diceIndex = index;
} }
void Sticker::setCustomEmojiPart( void Sticker::setCustomCachingTag(ChatHelpers::StickerLottieSize tag) {
int size,
ChatHelpers::StickerLottieSize tag) {
_size = { size, size };
_cachingTag = tag; _cachingTag = tag;
} }
void Sticker::setGiftBoxSticker(bool giftBoxSticker) { void Sticker::setCustomEmojiPart() {
_giftBoxSticker = giftBoxSticker; _customEmojiPart = true;
}
void Sticker::setEmojiSticker() {
_emojiSticker = true;
} }
void Sticker::setupPlayer() { void Sticker::setupPlayer() {

View file

@ -42,7 +42,7 @@ public:
const Lottie::ColorReplacements *replacements = nullptr); const Lottie::ColorReplacements *replacements = nullptr);
~Sticker(); ~Sticker();
void initSize(); void initSize(int customSize = 0);
QSize countOptimalSize() override; QSize countOptimalSize() override;
void draw( void draw(
Painter &p, Painter &p,
@ -62,12 +62,13 @@ public:
void refreshLink() override; void refreshLink() override;
bool hasTextForCopy() const override { bool hasTextForCopy() const override {
return isEmojiSticker(); return emojiSticker();
} }
void setDiceIndex(const QString &emoji, int index); void setDiceIndex(const QString &emoji, int index);
void setCustomEmojiPart(int size, ChatHelpers::StickerLottieSize tag); void setCustomCachingTag(ChatHelpers::StickerLottieSize tag);
void setGiftBoxSticker(bool giftBoxSticker); void setCustomEmojiPart();
void setEmojiSticker();
[[nodiscard]] bool atTheEnd() const { [[nodiscard]] bool atTheEnd() const {
return (_frameIndex >= 0) && (_frameIndex + 1 == _framesCount); return (_frameIndex >= 0) && (_frameIndex + 1 == _framesCount);
} }
@ -96,7 +97,7 @@ public:
private: private:
[[nodiscard]] bool hasPremiumEffect() const; [[nodiscard]] bool hasPremiumEffect() const;
[[nodiscard]] bool customEmojiPart() const; [[nodiscard]] bool customEmojiPart() const;
[[nodiscard]] bool isEmojiSticker() const; [[nodiscard]] bool emojiSticker() const;
void paintAnimationFrame( void paintAnimationFrame(
Painter &p, Painter &p,
const PaintContext &context, const PaintContext &context,
@ -134,7 +135,8 @@ private:
mutable bool _premiumEffectSkipped : 1 = false; mutable bool _premiumEffectSkipped : 1 = false;
mutable bool _nextLastDiceFrame : 1 = false; mutable bool _nextLastDiceFrame : 1 = false;
bool _skipPremiumEffect : 1 = false; bool _skipPremiumEffect : 1 = false;
bool _giftBoxSticker : 1 = false; bool _customEmojiPart : 1 = false;
bool _emojiSticker : 1 = false;
}; };

View file

@ -923,7 +923,7 @@ msgServiceGiftBoxButtonPadding: margins(2px, 0px, 2px, 0px);
msgServiceGiftBoxButtonMargins: margins(0px, 13px, 0px, 17px); msgServiceGiftBoxButtonMargins: margins(0px, 13px, 0px, 17px);
msgServiceGiftBoxTitlePadding: margins(0px, 5px, 0px, 2px); msgServiceGiftBoxTitlePadding: margins(0px, 5px, 0px, 2px);
msgServiceGiftBoxStickerTop: -19px; msgServiceGiftBoxStickerTop: -19px;
msgServiceGiftBoxStickerSize: size(140px, 140px); msgServiceGiftBoxStickerSize: 140px;
historySponsorInfoItem: FlatLabel(defaultFlatLabel) { historySponsorInfoItem: FlatLabel(defaultFlatLabel) {
style: TextStyle(defaultTextStyle) { style: TextStyle(defaultTextStyle) {