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

View file

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

View file

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

View file

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

View file

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

View file

@ -25,28 +25,31 @@ MiniStars::MiniStars(
Fn<void(const QRect &r)> updateCallback,
bool opaque,
Type type)
: _availableAngles((type != Type::SlowStars)
? std::vector<Interval>{
Interval{ -10, 40 },
Interval{ 180 + 10 - 40, 40 },
Interval{ 180 + 15, 50 },
Interval{ -15 - 50, 50 },
}
: std::vector<Interval>{ Interval{ -90, 180 }, Interval{ 90, 180 } })
, _lifeLength((type != Type::SlowStars)
: _availableAngles((type != Type::SlowStars && type != Type::SlowDiamondStars)
? std::vector<Interval>{
Interval{ -10, 40 },
Interval{ 180 + 10 - 40, 40 },
Interval{ 180 + 15, 50 },
Interval{ -15 - 50, 50 },
}
: std::vector<Interval>{ Interval{ -90, 180 }, Interval{ 90, 180 } })
, _lifeLength((type != Type::SlowStars && type != Type::SlowDiamondStars)
? Interval{ 150 / 5, 200 / 5 }
: Interval{ 150 * 2, 200 * 2 })
, _deathTime((type != Type::SlowStars)
, _deathTime((type != Type::SlowStars && type != Type::SlowDiamondStars)
? Interval{ 1500, 2000 }
: Interval{ 1500 * 2, 2000 * 2 })
, _size({ 5, 10 })
, _alpha({ opaque ? 100 : 40, opaque ? 100 : 60 })
, _sinFactor({ 10, 190 })
, _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)
, _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/star.svg"_q)
, _animation([=](crl::time now) {

View file

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