Slightly improved mini stars for button in history view premium gifts.

This commit is contained in:
23rd 2025-07-02 10:27:41 +03:00 committed by John Preston
parent 1dd4f62ece
commit 37093c9f33
7 changed files with 32 additions and 22 deletions

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_sending.h" #include "api/api_sending.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "base/random.h" #include "base/random.h"
#include "ui/effects/premium_stars.h"
#include "boxes/premium_preview_box.h" #include "boxes/premium_preview_box.h"
#include "chat_helpers/stickers_lottie.h" #include "chat_helpers/stickers_lottie.h"
#include "core/click_handler_types.h" #include "core/click_handler_types.h"
@ -75,7 +76,7 @@ public:
TextWithEntities subtitle() override; TextWithEntities subtitle() override;
int buttonSkip() override; int buttonSkip() override;
rpl::producer<QString> button() override; rpl::producer<QString> button() override;
bool buttonMinistars() override; std::optional<Ui::Premium::MiniStarsType> buttonMinistars() override;
void draw( void draw(
Painter &p, Painter &p,
const PaintContext &context, const PaintContext &context,
@ -432,8 +433,9 @@ rpl::producer<QString> EmptyChatLockedBox::button() {
: tr::lng_send_charges_stars_go(); : tr::lng_send_charges_stars_go();
} }
bool EmptyChatLockedBox::buttonMinistars() { auto EmptyChatLockedBox::buttonMinistars()
return true; -> std::optional<Ui::Premium::MiniStarsType> {
return Ui::Premium::MiniStarsType::SlowStars;
} }
TextWithEntities EmptyChatLockedBox::subtitle() { TextWithEntities EmptyChatLockedBox::subtitle() {

View file

@ -246,8 +246,10 @@ rpl::producer<QString> PremiumGift::button() {
: tr::lng_prize_open(); : tr::lng_prize_open();
} }
bool PremiumGift::buttonMinistars() { std::optional<Ui::Premium::MiniStarsType> PremiumGift::buttonMinistars() {
return true; return tonGift()
? Ui::Premium::MiniStarsType::SlowDiamondStars
: Ui::Premium::MiniStarsType::SlowStars;
} }
ClickHandlerPtr PremiumGift::createViewLink() { ClickHandlerPtr PremiumGift::createViewLink() {

View file

@ -31,7 +31,7 @@ public:
TextWithEntities title() override; TextWithEntities title() override;
TextWithEntities subtitle() override; TextWithEntities subtitle() override;
rpl::producer<QString> button() override; rpl::producer<QString> button() override;
bool buttonMinistars() override; std::optional<Ui::Premium::MiniStarsType> buttonMinistars() override;
QImage cornerTag(const PaintContext &context) override; QImage cornerTag(const PaintContext &context) override;
int buttonSkip() override; int buttonSkip() override;
void draw( void draw(

View file

@ -104,10 +104,10 @@ ServiceBox::ServiceBox(
} }
}, _lifetime); }, _lifetime);
} }
if (_content->buttonMinistars()) { if (const auto type = _content->buttonMinistars()) {
_button.stars = std::make_unique<Ui::Premium::ColoredMiniStars>( _button.stars = std::make_unique<Ui::Premium::ColoredMiniStars>(
[=](const QRect &) { repaint(); }, [=](const QRect &) { repaint(); },
Ui::Premium::MiniStarsType::SlowStars); *type);
_button.lastFg = std::make_unique<QColor>(); _button.lastFg = std::make_unique<QColor>();
} }
} }

View file

@ -15,6 +15,7 @@ class RippleAnimation;
namespace Ui::Premium { namespace Ui::Premium {
class ColoredMiniStars; class ColoredMiniStars;
enum class MiniStarsType;
} // namespace Ui::Premium } // namespace Ui::Premium
namespace HistoryView { namespace HistoryView {
@ -32,8 +33,9 @@ public:
return top(); return top();
} }
[[nodiscard]] virtual rpl::producer<QString> button() = 0; [[nodiscard]] virtual rpl::producer<QString> button() = 0;
[[nodiscard]] virtual bool buttonMinistars() { [[nodiscard]] virtual auto buttonMinistars()
return false; -> std::optional<Ui::Premium::MiniStarsType> {
return std::nullopt;
} }
[[nodiscard]] virtual QImage cornerTag(const PaintContext &context) { [[nodiscard]] virtual QImage cornerTag(const PaintContext &context) {
return {}; return {};

View file

@ -25,28 +25,31 @@ MiniStars::MiniStars(
Fn<void(const QRect &r)> updateCallback, Fn<void(const QRect &r)> updateCallback,
bool opaque, bool opaque,
Type type) Type type)
: _availableAngles((type != Type::SlowStars) : _availableAngles((type != Type::SlowStars && type != Type::SlowDiamondStars)
? std::vector<Interval>{ ? std::vector<Interval>{
Interval{ -10, 40 }, Interval{ -10, 40 },
Interval{ 180 + 10 - 40, 40 }, Interval{ 180 + 10 - 40, 40 },
Interval{ 180 + 15, 50 }, Interval{ 180 + 15, 50 },
Interval{ -15 - 50, 50 }, Interval{ -15 - 50, 50 },
} }
: std::vector<Interval>{ Interval{ -90, 180 }, Interval{ 90, 180 } }) : std::vector<Interval>{ Interval{ -90, 180 }, Interval{ 90, 180 } })
, _lifeLength((type != Type::SlowStars) , _lifeLength((type != Type::SlowStars && type != Type::SlowDiamondStars)
? Interval{ 150 / 5, 200 / 5 } ? Interval{ 150 / 5, 200 / 5 }
: Interval{ 150 * 2, 200 * 2 }) : Interval{ 150 * 2, 200 * 2 })
, _deathTime((type != Type::SlowStars) , _deathTime((type != Type::SlowStars && type != Type::SlowDiamondStars)
? Interval{ 1500, 2000 } ? Interval{ 1500, 2000 }
: Interval{ 1500 * 2, 2000 * 2 }) : Interval{ 1500 * 2, 2000 * 2 })
, _size({ 5, 10 }) , _size({ 5, 10 })
, _alpha({ opaque ? 100 : 40, opaque ? 100 : 60 }) , _alpha({ opaque ? 100 : 40, opaque ? 100 : 60 })
, _sinFactor({ 10, 190 }) , _sinFactor({ 10, 190 })
, _spritesCount({ 0, ((type == Type::MonoStars) ? 1 : 2) }) , _spritesCount({ 0, ((type == Type::MonoStars) ? 1 : 2) })
, _appearProgressTill((type != Type::SlowStars) ? 0.2 : 0.01) , _appearProgressTill((type != Type::SlowStars
&& type != Type::SlowDiamondStars)
? 0.2
: 0.01)
, _disappearProgressAfter(0.8) , _disappearProgressAfter(0.8)
, _distanceProgressStart(0.5) , _distanceProgressStart(0.5)
, _sprite((type == Type::DiamondStars) , _sprite((type == Type::DiamondStars || type == Type::SlowDiamondStars)
? u":/gui/icons/settings/starmini.svg"_q ? u":/gui/icons/settings/starmini.svg"_q
: u":/gui/icons/settings/star.svg"_q) : u":/gui/icons/settings/star.svg"_q)
, _animation([=](crl::time now) { , _animation([=](crl::time now) {

View file

@ -19,6 +19,7 @@ enum class MiniStarsType {
BiStars, BiStars,
SlowStars, SlowStars,
DiamondStars, DiamondStars,
SlowDiamondStars,
}; };
class MiniStars final { class MiniStars final {