mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 23:27:09 +02:00
Improve slot machine animations.
This commit is contained in:
parent
a532ae81b3
commit
de459fa1fe
3 changed files with 25 additions and 6 deletions
|
@ -29,8 +29,8 @@ constexpr auto kBarIndex = 2;
|
|||
constexpr auto kBerriesIndex = 3;
|
||||
constexpr auto kLemonIndex = 4;
|
||||
constexpr auto kStartIndex = 5;
|
||||
|
||||
constexpr auto kWinValue = 64;
|
||||
constexpr auto kSkipFramesBeforeWinEnding = 90;
|
||||
|
||||
const auto &kEmoji = ::Stickers::DicePacks::kSlotString;
|
||||
|
||||
|
@ -162,6 +162,7 @@ void SlotMachine::draw(Painter &p, const QRect &r, bool selected) {
|
|||
const auto pullReady = _pull && _pull->readyToDrawLottie();
|
||||
const auto paintReady = [&] {
|
||||
auto result = pullReady;
|
||||
auto allPlayedEnough = true;
|
||||
for (auto i = 1; i != 4; ++i) {
|
||||
if (!_end[i] || !_end[i]->readyToDrawLottie()) {
|
||||
switchedToEnd[i] = false;
|
||||
|
@ -170,8 +171,14 @@ void SlotMachine::draw(Painter &p, const QRect &r, bool selected) {
|
|||
&& (!_start[i] || !_start[i]->readyToDrawLottie())) {
|
||||
result = false;
|
||||
}
|
||||
const auto playedTillFrame = !switchedToEnd[i]
|
||||
? 0
|
||||
: _end[i]->frameIndex().value_or(0);
|
||||
if (playedTillFrame < kSkipFramesBeforeWinEnding) {
|
||||
allPlayedEnough = false;
|
||||
}
|
||||
}
|
||||
if (!_end[0] || !_end[0]->readyToDrawLottie()) {
|
||||
if (!_end[0] || !_end[0]->readyToDrawLottie() || !allPlayedEnough) {
|
||||
switchedToEnd[0] = false;
|
||||
}
|
||||
if (ranges::contains(switchedToEnd, false)
|
||||
|
|
|
@ -196,11 +196,12 @@ void Sticker::paintLottie(Painter &p, const QRect &r, bool selected) {
|
|||
: (isEmojiSticker()
|
||||
|| !Core::App().settings().loopAnimatedStickers());
|
||||
const auto count = _lottie->information().framesCount;
|
||||
_atTheEnd = (frame.index + 1 == count);
|
||||
_frameIndex = frame.index;
|
||||
_framesCount = count;
|
||||
_nextLastDiceFrame = !paused
|
||||
&& (_diceIndex > 0)
|
||||
&& (frame.index + 2 == count);
|
||||
const auto lastDiceFrame = (_diceIndex > 0) && _atTheEnd;
|
||||
const auto lastDiceFrame = (_diceIndex > 0) && atTheEnd();
|
||||
const auto switchToNext = !playOnce
|
||||
|| (!lastDiceFrame && (frame.index != 0 || !_lottieOncePlayed));
|
||||
if (!paused
|
||||
|
|
|
@ -61,7 +61,17 @@ public:
|
|||
|
||||
void setDiceIndex(const QString &emoji, int index);
|
||||
[[nodiscard]] bool atTheEnd() const {
|
||||
return _atTheEnd;
|
||||
return (_frameIndex >= 0) && (_frameIndex + 1 == _framesCount);
|
||||
}
|
||||
[[nodiscard]] std::optional<int> frameIndex() const {
|
||||
return (_frameIndex >= 0)
|
||||
? std::make_optional(_frameIndex)
|
||||
: std::nullopt;
|
||||
}
|
||||
[[nodiscard]] std::optional<int> framesCount() const {
|
||||
return (_framesCount > 0)
|
||||
? std::make_optional(_framesCount)
|
||||
: std::nullopt;
|
||||
}
|
||||
[[nodiscard]] bool readyToDrawLottie();
|
||||
|
||||
|
@ -94,8 +104,9 @@ private:
|
|||
QImage _lastDiceFrame;
|
||||
QString _diceEmoji;
|
||||
int _diceIndex = -1;
|
||||
mutable int _frameIndex = -1;
|
||||
mutable int _framesCount = -1;
|
||||
mutable bool _lottieOncePlayed = false;
|
||||
mutable bool _atTheEnd = false;
|
||||
mutable bool _nextLastDiceFrame = false;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
|
Loading…
Add table
Reference in a new issue