Files
AyuGramDesktop/Telegram/SourceFiles/boxes/star_gift_craft_animation.h
T
2026-02-01 23:33:57 +04:00

193 lines
4.3 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/object_ptr.h"
#include "base/unique_qptr.h"
#include "data/data_star_gift.h"
#include "ui/effects/animations.h"
#include "ui/effects/radial_animation.h"
#include "ui/text/text_custom_emoji.h"
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Main {
class Session;
} // namespace Main
namespace HistoryView {
class StickerPlayer;
} // namespace HistoryView
namespace Info::PeerGifts {
class GiftButton;
} // namespace Info::PeerGifts
namespace Ui {
class GenericBox;
class VerticalLayout;
class UniqueGiftCoverWidget;
using CraftResultCallback = Fn<void(std::shared_ptr<Data::GiftUpgradeResult>)>;
struct BackdropView {
Data::UniqueGiftBackdrop colors;
QImage gradient;
};
struct PatternView {
std::unique_ptr<Text::CustomEmoji> emoji;
base::flat_map<int, base::flat_map<float64, QImage>> emojis;
};
struct CraftState {
struct Cover {
BackdropView backdrop;
PatternView pattern;
QColor button1;
QColor button2;
Animations::Simple shownAnimation;
bool shown = false;
};
std::array<Cover, 4> covers;
rpl::variable<QColor> edgeColor;
QColor button1;
QColor button2;
bool coversAnimate = false;
bool craftingStarted = false;
QImage craftBg;
QImage topPart;
QRect topPartRect;
QImage bottomPart;
int bottomPartY = 0;
struct CornerSnapshot {
base::unique_qptr<Info::PeerGifts::GiftButton> giftButton;
mutable QImage giftFrame;
QImage percentBadge;
QImage removeButton;
QImage addButton;
QRect originalRect;
mutable bool giftFrameFinal = false;
[[nodiscard]] QImage gift(float64 progress) const;
};
std::array<CornerSnapshot, 4> corners;
QRect forgeRect;
QColor forgeBgOverlay;
QColor forgeBg1;
QColor forgeBg2;
QImage forgePercent;
struct EmptySide {
QColor bg;
QImage frame;
};
std::array<EmptySide, 6> forgeSides;
EmptySide finalSide;
Main::Session *session = nullptr;
int containerHeight = 0;
int craftingTop = 0;
int craftingBottom = 0;
int craftingAreaCenterY = 0;
int craftingOffsetY = 0;
void paint(
QPainter &p,
QSize size,
int craftingHeight,
float64 slideProgress = 0.);
void updateForGiftCount(int count, Fn<void()> repaint);
[[nodiscard]] EmptySide prepareEmptySide(int index) const;
};
struct FacePlacement {
int face = -1;
int rotation = 0;
};
struct CraftDoneAnimation {
object_ptr<UniqueGiftCoverWidget> owned;
UniqueGiftCoverWidget *widget = nullptr;
Animations::Simple shownAnimation;
Animations::Simple heightAnimation;
QImage frame;
int coverHeight = 0;
int coverShift = 0;
float64 expanded = 0.;
bool finished = false;
bool hiding = false;
};
struct CraftFailAnimation {
std::unique_ptr<HistoryView::StickerPlayer> player;
QImage frame;
DocumentData *document = nullptr;
Animations::Simple scaleAnimation;
bool scaleStarted = false;
bool playerStarted = false;
bool playerFinished = false;
rpl::lifetime lifetime;
};
struct CraftAnimationState {
std::shared_ptr<CraftState> shared;
Animations::Simple slideOutAnimation;
Animations::Basic continuousAnimation;
float64 rotationX = 0.;
float64 rotationY = 0.;
int currentlyFlying = -1;
int giftsLanded = 0;
int totalGifts = 0;
bool allGiftsLanded = false;
bool currentPhaseFinished = false;
std::array<FacePlacement, 4> giftToSide;
Animations::Simple flightAnimation;
int currentPhaseIndex = -1;
crl::time animationStartTime = 0;
crl::time animationDuration = 0;
float64 initialRotationX = 0.;
float64 initialRotationY = 0.;
int nextFaceIndex = 0;
int nextFaceRotation = 0;
bool nextFaceRevealed = false;
std::optional<std::array<QPointF, 4>> flightTargetCorners;
std::optional<std::shared_ptr<Data::GiftUpgradeResult>> craftResult;
std::unique_ptr<InfiniteRadialAnimation> loadingAnimation;
Animations::Simple loadingShownAnimation;
crl::time loadingStartedTime = 0;
bool loadingFadingOut = false;
std::unique_ptr<CraftDoneAnimation> successAnimation;
std::unique_ptr<CraftFailAnimation> failureAnimation;
};
void StartCraftAnimation(
not_null<GenericBox*> box,
std::shared_ptr<ChatHelpers::Show> show,
std::shared_ptr<CraftState> state,
Fn<void(CraftResultCallback)> startRequest,
Fn<void()> closeParent);
} // namespace Ui