mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Start UI of the new gift sending box.
This commit is contained in:
parent
e3bc4dab85
commit
761617c1ce
6 changed files with 567 additions and 63 deletions
|
@ -2981,6 +2981,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_gift_stars_incoming" = "Use Stars to unlock content and services on Telegram.";
|
"lng_gift_stars_incoming" = "Use Stars to unlock content and services on Telegram.";
|
||||||
"lng_gift_until" = "Until";
|
"lng_gift_until" = "Until";
|
||||||
|
|
||||||
|
"lng_gift_premium_subtitle" = "Gift Premium";
|
||||||
|
"lng_gift_premium_about" = "Give {name} access to exclusive features with Telegram Premium. {features}";
|
||||||
|
"lng_gift_premium_features" = "See Features >";
|
||||||
|
"lng_gift_premium_label" = "Premium";
|
||||||
|
"lng_gift_stars_subtitle" = "Gift Stars";
|
||||||
|
"lng_gift_stars_about" = "Give {name} gifts that can be kept on your profile or converted to Stars. {link}";
|
||||||
|
"lng_gift_stars_link" = "What are Stars >";
|
||||||
|
"lng_gift_stars_limited" = "limited";
|
||||||
|
"lng_gift_stars_tabs_all" = "All Gifts";
|
||||||
|
"lng_gift_stars_tabs_limited" = "Limited";
|
||||||
|
|
||||||
"lng_accounts_limit_title" = "Limit Reached";
|
"lng_accounts_limit_title" = "Limit Reached";
|
||||||
"lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected account.";
|
"lng_accounts_limit1#one" = "You have reached the limit of **{count}** connected account.";
|
||||||
"lng_accounts_limit1#other" = "You have reached the limit of **{count}** connected accounts.";
|
"lng_accounts_limit1#other" = "You have reached the limit of **{count}** connected accounts.";
|
||||||
|
|
|
@ -550,6 +550,24 @@ Payments::InvoicePremiumGiftCode PremiumGiftCodeOptions::invoice(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<GiftOptionData> PremiumGiftCodeOptions::optionsForPeer() const {
|
||||||
|
auto result = std::vector<GiftOptionData>();
|
||||||
|
|
||||||
|
if (!_optionsForOnePerson.currency.isEmpty()) {
|
||||||
|
const auto count = int(_optionsForOnePerson.months.size());
|
||||||
|
result.reserve(count);
|
||||||
|
for (auto i = 0; i != count; ++i) {
|
||||||
|
Assert(i < _optionsForOnePerson.totalCosts.size());
|
||||||
|
result.push_back({
|
||||||
|
.cost = _optionsForOnePerson.totalCosts[i],
|
||||||
|
.currency = _optionsForOnePerson.currency,
|
||||||
|
.months = _optionsForOnePerson.months[i],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
Data::PremiumSubscriptionOptions PremiumGiftCodeOptions::options(int amount) {
|
Data::PremiumSubscriptionOptions PremiumGiftCodeOptions::options(int amount) {
|
||||||
const auto it = _subscriptionOptions.find(amount);
|
const auto it = _subscriptionOptions.find(amount);
|
||||||
if (it != end(_subscriptionOptions)) {
|
if (it != end(_subscriptionOptions)) {
|
||||||
|
|
|
@ -67,6 +67,12 @@ struct GiveawayInfo {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GiftOptionData {
|
||||||
|
int64 cost = 0;
|
||||||
|
QString currency;
|
||||||
|
int months = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class Premium final {
|
class Premium final {
|
||||||
public:
|
public:
|
||||||
explicit Premium(not_null<ApiWrap*> api);
|
explicit Premium(not_null<ApiWrap*> api);
|
||||||
|
@ -171,6 +177,7 @@ public:
|
||||||
PremiumGiftCodeOptions(not_null<PeerData*> peer);
|
PremiumGiftCodeOptions(not_null<PeerData*> peer);
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
||||||
|
[[nodiscard]] std::vector<GiftOptionData> optionsForPeer() const;
|
||||||
[[nodiscard]] Data::PremiumSubscriptionOptions options(int amount);
|
[[nodiscard]] Data::PremiumSubscriptionOptions options(int amount);
|
||||||
[[nodiscard]] const std::vector<int> &availablePresets() const;
|
[[nodiscard]] const std::vector<int> &availablePresets() const;
|
||||||
[[nodiscard]] int monthsFromPreset(int monthsIndex);
|
[[nodiscard]] int monthsFromPreset(int monthsIndex);
|
||||||
|
@ -206,7 +213,7 @@ private:
|
||||||
base::flat_map<Amount, PremiumSubscriptionOptions> _subscriptionOptions;
|
base::flat_map<Amount, PremiumSubscriptionOptions> _subscriptionOptions;
|
||||||
struct {
|
struct {
|
||||||
std::vector<int> months;
|
std::vector<int> months;
|
||||||
std::vector<float64> totalCosts;
|
std::vector<int64> totalCosts;
|
||||||
QString currency;
|
QString currency;
|
||||||
} _optionsForOnePerson;
|
} _optionsForOnePerson;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/gift_credits_box.h"
|
#include "boxes/gift_credits_box.h"
|
||||||
|
|
||||||
#include "api/api_credits.h"
|
#include "api/api_credits.h"
|
||||||
|
#include "api/api_premium.h"
|
||||||
#include "boxes/peer_list_controllers.h"
|
#include "boxes/peer_list_controllers.h"
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -15,11 +16,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/stickers/data_custom_emoji.h"
|
#include "data/stickers/data_custom_emoji.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/session/session_show.h"
|
#include "main/session/session_show.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
#include "settings/settings_credits_graphics.h"
|
#include "settings/settings_credits_graphics.h"
|
||||||
|
#include "settings/settings_credits.h"
|
||||||
|
#include "settings/settings_premium.h"
|
||||||
#include "ui/controls/userpic_button.h"
|
#include "ui/controls/userpic_button.h"
|
||||||
#include "ui/effects/premium_graphics.h"
|
#include "ui/effects/premium_graphics.h"
|
||||||
#include "ui/effects/premium_stars_colored.h"
|
#include "ui/effects/premium_stars_colored.h"
|
||||||
|
#include "ui/effects/ripple_animation.h"
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
|
#include "ui/painter.h"
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/vertical_list.h"
|
#include "ui/vertical_list.h"
|
||||||
|
@ -33,39 +39,485 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_premium.h"
|
#include "styles/style_premium.h"
|
||||||
|
|
||||||
namespace Ui {
|
#include "data/stickers/data_stickers.h"
|
||||||
|
#include "data/data_document.h"
|
||||||
|
|
||||||
void GiftCreditsBox(
|
namespace Ui {
|
||||||
not_null<Ui::GenericBox*> box,
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kPriceTabAll = 0;
|
||||||
|
constexpr auto kPriceTabLimited = -1;
|
||||||
|
|
||||||
|
struct GiftTypePremium {
|
||||||
|
int64 cost = 0;
|
||||||
|
QString currency;
|
||||||
|
int months = 0;
|
||||||
|
int discountPercent = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] friend inline bool operator==(
|
||||||
|
const GiftTypePremium &,
|
||||||
|
const GiftTypePremium &) = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GiftTypeStars {
|
||||||
|
DocumentData *document = nullptr;
|
||||||
|
int stars = 0;
|
||||||
|
bool limited = false;
|
||||||
|
|
||||||
|
[[nodiscard]] friend inline bool operator==(
|
||||||
|
const GiftTypeStars&,
|
||||||
|
const GiftTypeStars&) = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GiftDescriptor : std::variant<GiftTypePremium, GiftTypeStars> {
|
||||||
|
using variant::variant;
|
||||||
|
|
||||||
|
[[nodiscard]] friend inline bool operator==(
|
||||||
|
const GiftDescriptor&,
|
||||||
|
const GiftDescriptor&) = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<std::vector<GiftTypePremium>> GiftsPremium(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
not_null<PeerData*> peer) {
|
||||||
|
struct Session {
|
||||||
|
std::vector<GiftTypePremium> last;
|
||||||
|
};
|
||||||
|
static auto Map = base::flat_map<not_null<Main::Session*>, Session>();
|
||||||
|
return [=](auto consumer) {
|
||||||
|
auto lifetime = rpl::lifetime();
|
||||||
|
|
||||||
|
auto i = Map.find(session);
|
||||||
|
if (i == end(Map)) {
|
||||||
|
i = Map.emplace(session, Session()).first;
|
||||||
|
session->lifetime().add([=] { Map.remove(session); });
|
||||||
|
}
|
||||||
|
if (!i->second.last.empty()) {
|
||||||
|
consumer.put_next_copy(i->second.last);
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace Api;
|
||||||
|
const auto api = lifetime.make_state<PremiumGiftCodeOptions>(peer);
|
||||||
|
api->request() | rpl::start_with_error_done([=](QString error) {
|
||||||
|
consumer.put_next({});
|
||||||
|
}, [=] {
|
||||||
|
const auto &options = api->optionsForPeer();
|
||||||
|
auto list = std::vector<GiftTypePremium>();
|
||||||
|
list.reserve(options.size());
|
||||||
|
auto minMonthsGift = GiftTypePremium();
|
||||||
|
for (const auto &option : options) {
|
||||||
|
list.push_back({
|
||||||
|
.cost = option.cost,
|
||||||
|
.currency = option.currency,
|
||||||
|
.months = option.months,
|
||||||
|
});
|
||||||
|
if (!minMonthsGift.months
|
||||||
|
|| option.months < minMonthsGift.months) {
|
||||||
|
minMonthsGift = list.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto &gift : list) {
|
||||||
|
if (gift.months > minMonthsGift.months
|
||||||
|
&& gift.currency == minMonthsGift.currency) {
|
||||||
|
const auto costPerMonth = gift.cost / gift.months;
|
||||||
|
const auto maxCostPerMonth = minMonthsGift.cost
|
||||||
|
/ minMonthsGift.months;
|
||||||
|
const auto costRatio = costPerMonth / maxCostPerMonth;
|
||||||
|
const auto discount = 1. - costRatio;
|
||||||
|
const auto discountPercent = 100 * discount;
|
||||||
|
const auto value = int(base::SafeRound(discountPercent));
|
||||||
|
if (value > 0 && value < 100) {
|
||||||
|
gift.discountPercent = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map[session].last = list;
|
||||||
|
consumer.put_next_copy(list);
|
||||||
|
}, lifetime);
|
||||||
|
|
||||||
|
return lifetime;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<std::vector<GiftTypeStars>> GiftsStars(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
not_null<PeerData*> peer) {
|
||||||
|
//struct Session {
|
||||||
|
// std::vector<GiftTypeStars> last;
|
||||||
|
//};
|
||||||
|
//static auto Map = base::flat_map<not_null<Main::Session*>, Session>();
|
||||||
|
return [=](auto consumer) {
|
||||||
|
auto lifetime = rpl::lifetime();
|
||||||
|
|
||||||
|
auto list = std::vector<GiftTypeStars>();
|
||||||
|
|
||||||
|
const auto add = [&](uint64 setId, int price, bool limited) {
|
||||||
|
auto &sets = session->data().stickers().setsRef();
|
||||||
|
const auto i = sets.find(setId);
|
||||||
|
if (i != end(sets)) {
|
||||||
|
for (const auto document : i->second->stickers) {
|
||||||
|
price = document->isPremiumSticker() ? 1000 : price;
|
||||||
|
list.push_back({
|
||||||
|
.document = document,
|
||||||
|
.stars = price,
|
||||||
|
.limited = limited,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
add(Data::Stickers::CloudRecentSetId, 100, false);
|
||||||
|
add(Data::Stickers::RecentSetId, 250, false);
|
||||||
|
add(Data::Stickers::FavedSetId, 50, true);
|
||||||
|
|
||||||
|
consumer.put_next(std::move(list));
|
||||||
|
|
||||||
|
return lifetime;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Text::String TabTextForPrice(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
int price) {
|
||||||
|
const auto simple = [](const QString &text) {
|
||||||
|
return Text::String(st::semiboldTextStyle, text);
|
||||||
|
};
|
||||||
|
if (price == kPriceTabAll) {
|
||||||
|
return simple(tr::lng_gift_stars_tabs_all(tr::now));
|
||||||
|
} else if (price == kPriceTabLimited) {
|
||||||
|
return simple(tr::lng_gift_stars_tabs_limited(tr::now));
|
||||||
|
}
|
||||||
|
auto &manager = session->data().customEmojiManager();
|
||||||
|
auto result = Text::String();
|
||||||
|
const auto context = Core::MarkedTextContext{
|
||||||
|
.session = session,
|
||||||
|
.customEmojiRepaint = [] {},
|
||||||
|
};
|
||||||
|
result.setMarkedText(
|
||||||
|
st::semiboldTextStyle,
|
||||||
|
manager.creditsEmoji().append(QString::number(price)),
|
||||||
|
kMarkupTextOptions,
|
||||||
|
context);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GiftPriceTabs {
|
||||||
|
rpl::producer<int> priceTab;
|
||||||
|
object_ptr<RpWidget> widget;
|
||||||
|
};
|
||||||
|
[[nodiscard]] GiftPriceTabs MakeGiftsPriceTabs(
|
||||||
|
not_null<Window::SessionController*> window,
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
rpl::producer<std::vector<GiftTypeStars>> gifts) {
|
||||||
|
auto widget = object_ptr<RpWidget>((QWidget*)nullptr);
|
||||||
|
const auto raw = widget.data();
|
||||||
|
|
||||||
|
struct Button {
|
||||||
|
QRect geometry;
|
||||||
|
Text::String text;
|
||||||
|
int price = 0;
|
||||||
|
bool active = false;
|
||||||
|
};
|
||||||
|
struct State {
|
||||||
|
rpl::variable<std::vector<int>> prices;
|
||||||
|
rpl::variable<int> priceTab = kPriceTabAll;
|
||||||
|
std::vector<Button> buttons;
|
||||||
|
int selected = -1;
|
||||||
|
int active = -1;
|
||||||
|
};
|
||||||
|
const auto state = raw->lifetime().make_state<State>();
|
||||||
|
state->prices = std::move(
|
||||||
|
gifts
|
||||||
|
) | rpl::map([](const std::vector<GiftTypeStars> &gifts) {
|
||||||
|
auto result = std::vector<int>();
|
||||||
|
result.push_back(kPriceTabAll);
|
||||||
|
auto same = true;
|
||||||
|
auto sameKey = 0;
|
||||||
|
for (const auto &gift : gifts) {
|
||||||
|
if (same) {
|
||||||
|
const auto key = gift.stars * (gift.limited ? -1 : 1);
|
||||||
|
if (!sameKey) {
|
||||||
|
sameKey = key;
|
||||||
|
} else if (sameKey != key) {
|
||||||
|
same = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gift.limited
|
||||||
|
&& (result.size() < 2 || result[1] != kPriceTabLimited)) {
|
||||||
|
result.insert(begin(result) + 1, kPriceTabLimited);
|
||||||
|
}
|
||||||
|
if (!ranges::contains(result, gift.stars)) {
|
||||||
|
result.push_back(gift.stars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (same) {
|
||||||
|
return std::vector<int>();
|
||||||
|
}
|
||||||
|
ranges::sort(begin(result) + 1, end(result));
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
|
const auto setSelected = [=](int index) {
|
||||||
|
const auto was = (state->selected >= 0);
|
||||||
|
const auto now = (index >= 0);
|
||||||
|
state->selected = index;
|
||||||
|
if (was != now) {
|
||||||
|
raw->setCursor(now ? style::cur_pointer : style::cur_default);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const auto setActive = [=](int index) {
|
||||||
|
const auto was = state->active;
|
||||||
|
if (was == index) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (was >= 0 && was < state->buttons.size()) {
|
||||||
|
state->buttons[was].active = false;
|
||||||
|
}
|
||||||
|
state->active = index;
|
||||||
|
state->buttons[index].active = true;
|
||||||
|
raw->update();
|
||||||
|
|
||||||
|
state->priceTab = state->buttons[index].price;
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto session = &peer->session();
|
||||||
|
state->prices.value(
|
||||||
|
) | rpl::start_with_next([=](const std::vector<int> &prices) {
|
||||||
|
auto x = st::giftBoxTabsMargin.left();
|
||||||
|
auto y = st::giftBoxTabsMargin.top();
|
||||||
|
|
||||||
|
setSelected(-1);
|
||||||
|
state->buttons.resize(prices.size());
|
||||||
|
const auto padding = st::giftBoxTabPadding;
|
||||||
|
auto currentPrice = state->priceTab.current();
|
||||||
|
if (!ranges::contains(prices, currentPrice)) {
|
||||||
|
currentPrice = kPriceTabAll;
|
||||||
|
}
|
||||||
|
state->active = -1;
|
||||||
|
for (auto i = 0, count = int(prices.size()); i != count; ++i) {
|
||||||
|
const auto price = prices[i];
|
||||||
|
auto &button = state->buttons[i];
|
||||||
|
if (button.text.isEmpty() || button.price != price) {
|
||||||
|
button.price = price;
|
||||||
|
button.text = TabTextForPrice(session, price);
|
||||||
|
}
|
||||||
|
button.active = (price == currentPrice);
|
||||||
|
if (button.active) {
|
||||||
|
state->active = i;
|
||||||
|
}
|
||||||
|
const auto width = button.text.maxWidth();
|
||||||
|
const auto height = st::giftBoxTabStyle.font->height;
|
||||||
|
const auto r = QRect(0, 0, width, height).marginsAdded(padding);
|
||||||
|
button.geometry = QRect(QPoint(x, y), r.size());
|
||||||
|
x += r.width() + st::giftBoxTabSkip;
|
||||||
|
}
|
||||||
|
const auto height = state->buttons.empty()
|
||||||
|
? 0
|
||||||
|
: (y
|
||||||
|
+ state->buttons.back().geometry.height()
|
||||||
|
+ st::giftBoxTabsMargin.bottom());
|
||||||
|
raw->resize(raw->width(), height);
|
||||||
|
raw->update();
|
||||||
|
}, raw->lifetime());
|
||||||
|
|
||||||
|
raw->setMouseTracking(true);
|
||||||
|
raw->events() | rpl::start_with_next([=](not_null<QEvent*> e) {
|
||||||
|
const auto type = e->type();
|
||||||
|
switch (type) {
|
||||||
|
case QEvent::Leave: setSelected(-1); break;
|
||||||
|
case QEvent::MouseMove: {
|
||||||
|
const auto position = static_cast<QMouseEvent*>(e.get())->pos();
|
||||||
|
for (auto i = 0, c = int(state->buttons.size()); i != c; ++i) {
|
||||||
|
if (state->buttons[i].geometry.contains(position)) {
|
||||||
|
setSelected(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case QEvent::MouseButtonPress: {
|
||||||
|
const auto me = static_cast<QMouseEvent*>(e.get());
|
||||||
|
if (me->button() != Qt::LeftButton) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const auto position = me->pos();
|
||||||
|
for (auto i = 0, c = int(state->buttons.size()); i != c; ++i) {
|
||||||
|
if (state->buttons[i].geometry.contains(position)) {
|
||||||
|
setActive(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}, raw->lifetime());
|
||||||
|
|
||||||
|
raw->paintRequest() | rpl::start_with_next([=] {
|
||||||
|
auto p = QPainter(raw);
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
const auto padding = st::giftBoxTabPadding;
|
||||||
|
for (const auto &button : state->buttons) {
|
||||||
|
const auto geometry = button.geometry;
|
||||||
|
if (button.active) {
|
||||||
|
p.setBrush(st::giftBoxTabBgActive);
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
|
const auto radius = geometry.height() / 2.;
|
||||||
|
p.drawRoundedRect(geometry, radius, radius);
|
||||||
|
p.setPen(st::giftBoxTabFgActive);
|
||||||
|
} else {
|
||||||
|
p.setPen(st::giftBoxTabFg);
|
||||||
|
}
|
||||||
|
button.text.draw(p, {
|
||||||
|
.position = geometry.marginsRemoved(padding).topLeft(),
|
||||||
|
.availableWidth = button.text.maxWidth(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, raw->lifetime());
|
||||||
|
|
||||||
|
return {
|
||||||
|
.priceTab = state->priceTab.value(),
|
||||||
|
.widget = std::move(widget),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] object_ptr<RpWidget> MakeGiftsList(
|
||||||
|
not_null<Window::SessionController*> window,
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
rpl::producer<std::vector<GiftDescriptor>> gifts) {
|
||||||
|
auto result = object_ptr<RpWidget>((QWidget*)nullptr);
|
||||||
|
const auto raw = result.data();
|
||||||
|
|
||||||
|
raw->paintRequest() | rpl::start_with_next([=] {
|
||||||
|
|
||||||
|
}, raw->lifetime());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FillBg(not_null<RpWidget*> box) {
|
||||||
|
box->paintRequest() | rpl::start_with_next([=] {
|
||||||
|
auto p = QPainter(box);
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
|
||||||
|
const auto radius = st::boxRadius;
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
|
p.setBrush(st::boxDividerBg);
|
||||||
|
p.drawRoundedRect(
|
||||||
|
box->rect().marginsAdded({ 0, 0, 0, 2 * radius }),
|
||||||
|
radius,
|
||||||
|
radius);
|
||||||
|
}, box->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AddBlockArgs {
|
||||||
|
rpl::producer<QString> subtitle;
|
||||||
|
rpl::producer<TextWithEntities> about;
|
||||||
|
Fn<bool(const ClickHandlerPtr&, Qt::MouseButton)> aboutFilter;
|
||||||
|
object_ptr<RpWidget> content;
|
||||||
|
};
|
||||||
|
|
||||||
|
void AddBlock(
|
||||||
|
not_null<VerticalLayout*> content,
|
||||||
|
not_null<Window::SessionController*> window,
|
||||||
|
AddBlockArgs &&args) {
|
||||||
|
content->add(
|
||||||
|
object_ptr<FlatLabel>(
|
||||||
|
content,
|
||||||
|
std::move(args.subtitle),
|
||||||
|
st::giftBoxSubtitle),
|
||||||
|
st::giftBoxSubtitleMargin);
|
||||||
|
const auto about = content->add(
|
||||||
|
object_ptr<FlatLabel>(
|
||||||
|
content,
|
||||||
|
std::move(args.about),
|
||||||
|
st::giftBoxAbout),
|
||||||
|
st::giftBoxAboutMargin);
|
||||||
|
about->setClickHandlerFilter(std::move(args.aboutFilter));
|
||||||
|
content->add(std::move(args.content));
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] object_ptr<RpWidget> MakePremiumGifts(
|
||||||
|
not_null<Window::SessionController*> window,
|
||||||
|
not_null<PeerData*> peer) {
|
||||||
|
auto result = object_ptr<RpWidget>((QWidget*)nullptr);
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
rpl::variable<std::vector<GiftDescriptor>> gifts;
|
||||||
|
};
|
||||||
|
const auto state = std::make_unique<State>();
|
||||||
|
|
||||||
|
state->gifts = GiftsPremium(&window->session(), peer) | rpl::map([=](
|
||||||
|
const std::vector<GiftTypePremium> &gifts) {
|
||||||
|
return gifts | ranges::to<std::vector<GiftDescriptor>>;
|
||||||
|
});
|
||||||
|
|
||||||
|
return MakeGiftsList(window, peer, state->gifts.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] object_ptr<RpWidget> MakeStarsGifts(
|
||||||
|
not_null<Window::SessionController*> window,
|
||||||
|
not_null<PeerData*> peer) {
|
||||||
|
auto result = object_ptr<VerticalLayout>((QWidget*)nullptr);
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
rpl::variable<std::vector<GiftTypeStars>> gifts;
|
||||||
|
rpl::variable<int> priceTab = kPriceTabAll;
|
||||||
|
};
|
||||||
|
const auto state = result->lifetime().make_state<State>();
|
||||||
|
|
||||||
|
state->gifts = GiftsStars(&window->session(), peer);
|
||||||
|
|
||||||
|
auto tabs = MakeGiftsPriceTabs(window, peer, state->gifts.value());
|
||||||
|
state->priceTab = std::move(tabs.priceTab);
|
||||||
|
result->add(std::move(tabs.widget));
|
||||||
|
result->add(MakeGiftsList(window, peer, rpl::combine(
|
||||||
|
state->gifts.value(),
|
||||||
|
state->priceTab.value()
|
||||||
|
) | rpl::map([=](std::vector<GiftTypeStars> &&gifts, int price) {
|
||||||
|
gifts.erase(ranges::remove_if(gifts, [&](const GiftTypeStars &gift) {
|
||||||
|
return (price == kPriceTabLimited)
|
||||||
|
? (!gift.limited)
|
||||||
|
: (price && gift.stars != price);
|
||||||
|
}), end(gifts));
|
||||||
|
return gifts | ranges::to<std::vector<GiftDescriptor>>();
|
||||||
|
})));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GiftBox(
|
||||||
|
not_null<GenericBox*> box,
|
||||||
|
not_null<Window::SessionController*> window,
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
Fn<void()> gifted) {
|
Fn<void()> gifted) {
|
||||||
box->setWidth(st::boxWideWidth);
|
box->setWidth(st::boxWideWidth);
|
||||||
box->setStyle(st::creditsGiftBox);
|
box->setStyle(st::creditsGiftBox);
|
||||||
box->setNoContentMargin(true);
|
box->setNoContentMargin(true);
|
||||||
|
box->setCustomCornersFilling(RectPart::FullTop);
|
||||||
box->addButton(tr::lng_create_group_back(), [=] { box->closeBox(); });
|
box->addButton(tr::lng_create_group_back(), [=] { box->closeBox(); });
|
||||||
|
|
||||||
const auto content = box->setPinnedToTopContent(
|
FillBg(box);
|
||||||
object_ptr<Ui::VerticalLayout>(box));
|
|
||||||
|
|
||||||
Ui::AddSkip(content);
|
|
||||||
Ui::AddSkip(content);
|
|
||||||
const auto &stUser = st::premiumGiftsUserpicButton;
|
const auto &stUser = st::premiumGiftsUserpicButton;
|
||||||
const auto userpicWrap = content->add(
|
const auto content = box->verticalLayout();
|
||||||
object_ptr<Ui::CenterWrap<>>(
|
|
||||||
|
AddSkip(content);
|
||||||
|
AddSkip(content);
|
||||||
|
|
||||||
|
content->add(
|
||||||
|
object_ptr<CenterWrap<>>(
|
||||||
content,
|
content,
|
||||||
object_ptr<Ui::UserpicButton>(content, peer, stUser)));
|
object_ptr<UserpicButton>(content, peer, stUser))
|
||||||
userpicWrap->setAttribute(Qt::WA_TransparentForMouseEvents);
|
)->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
Ui::AddSkip(content);
|
AddSkip(content);
|
||||||
Ui::AddSkip(content);
|
AddSkip(content);
|
||||||
|
|
||||||
{
|
{
|
||||||
const auto widget = Ui::CreateChild<Ui::RpWidget>(content);
|
const auto widget = CreateChild<RpWidget>(content);
|
||||||
using ColoredMiniStars = Ui::Premium::ColoredMiniStars;
|
using ColoredMiniStars = Premium::ColoredMiniStars;
|
||||||
const auto stars = widget->lifetime().make_state<ColoredMiniStars>(
|
const auto stars = widget->lifetime().make_state<ColoredMiniStars>(
|
||||||
widget,
|
widget,
|
||||||
false,
|
false,
|
||||||
Ui::Premium::MiniStars::Type::BiStars);
|
Premium::MiniStars::Type::BiStars);
|
||||||
stars->setColorOverride(Ui::Premium::CreditsIconGradientStops());
|
stars->setColorOverride(Premium::CreditsIconGradientStops());
|
||||||
widget->resize(
|
widget->resize(
|
||||||
st::boxWidth - stUser.photoSize,
|
st::boxWidth - stUser.photoSize,
|
||||||
stUser.photoSize * 2);
|
stUser.photoSize * 2);
|
||||||
|
@ -84,51 +536,43 @@ void GiftCreditsBox(
|
||||||
stars->paint(p);
|
stars->paint(p);
|
||||||
}, widget->lifetime());
|
}, widget->lifetime());
|
||||||
}
|
}
|
||||||
{
|
AddSkip(content);
|
||||||
Ui::AddSkip(content);
|
AddSkip(box->verticalLayout());
|
||||||
const auto arrow = Ui::Text::SingleCustomEmoji(
|
|
||||||
peer->owner().customEmojiManager().registerInternalEmoji(
|
|
||||||
st::topicButtonArrow,
|
|
||||||
st::channelEarnLearnArrowMargins,
|
|
||||||
false));
|
|
||||||
auto link = tr::lng_credits_box_history_entry_gift_about_link(
|
|
||||||
lt_emoji,
|
|
||||||
rpl::single(arrow),
|
|
||||||
Ui::Text::RichLangValue
|
|
||||||
) | rpl::map([](TextWithEntities text) {
|
|
||||||
return Ui::Text::Link(
|
|
||||||
std::move(text),
|
|
||||||
u"internal:stars_examples"_q);
|
|
||||||
});
|
|
||||||
content->add(
|
|
||||||
object_ptr<Ui::CenterWrap<>>(
|
|
||||||
content,
|
|
||||||
Ui::CreateLabelWithCustomEmoji(
|
|
||||||
content,
|
|
||||||
tr::lng_credits_box_history_entry_gift_out_about(
|
|
||||||
lt_user,
|
|
||||||
rpl::single(TextWithEntities{ peer->shortName() }),
|
|
||||||
lt_link,
|
|
||||||
std::move(link),
|
|
||||||
Ui::Text::RichLangValue),
|
|
||||||
{ .session = &peer->session() },
|
|
||||||
st::creditsBoxAbout)),
|
|
||||||
st::boxRowPadding);
|
|
||||||
}
|
|
||||||
Ui::AddSkip(content);
|
|
||||||
Ui::AddSkip(box->verticalLayout());
|
|
||||||
|
|
||||||
Settings::FillCreditOptions(
|
const auto premiumClickHandlerFilter = [=](const auto &...) {
|
||||||
Main::MakeSessionShow(box->uiShow(), &peer->session()),
|
Settings::ShowPremium(window, u"gift_send"_q);
|
||||||
box->verticalLayout(),
|
return false;
|
||||||
peer,
|
};
|
||||||
0,
|
const auto starsClickHandlerFilter = [=](const auto &...) {
|
||||||
[=] { gifted(); box->uiShow()->hideLayer(); });
|
window->showSettings(Settings::CreditsId());
|
||||||
|
return false;
|
||||||
box->setPinnedToBottomContent(
|
};
|
||||||
object_ptr<Ui::VerticalLayout>(box));
|
AddBlock(content, window, {
|
||||||
|
.subtitle = tr::lng_gift_premium_subtitle(),
|
||||||
|
.about = tr::lng_gift_premium_about(
|
||||||
|
lt_name,
|
||||||
|
rpl::single(Text::Bold(peer->shortName())),
|
||||||
|
lt_features,
|
||||||
|
tr::lng_gift_premium_features() | Text::ToLink(),
|
||||||
|
Text::WithEntities),
|
||||||
|
.aboutFilter = premiumClickHandlerFilter,
|
||||||
|
.content = MakePremiumGifts(window, peer),
|
||||||
|
});
|
||||||
|
AddBlock(content, window, {
|
||||||
|
.subtitle = tr::lng_gift_stars_subtitle(),
|
||||||
|
.about = tr::lng_gift_stars_about(
|
||||||
|
lt_name,
|
||||||
|
rpl::single(Text::Bold(peer->shortName())),
|
||||||
|
lt_link,
|
||||||
|
tr::lng_gift_stars_link() | Text::ToLink(),
|
||||||
|
Text::WithEntities),
|
||||||
|
.aboutFilter = starsClickHandlerFilter,
|
||||||
|
.content = MakeStarsGifts(window, peer),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void ShowGiftCreditsBox(
|
void ShowGiftCreditsBox(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
Fn<void()> gifted) {
|
Fn<void()> gifted) {
|
||||||
|
@ -171,11 +615,11 @@ void ShowGiftCreditsBox(
|
||||||
auto listController = std::make_unique<Controller>(
|
auto listController = std::make_unique<Controller>(
|
||||||
&controller->session(),
|
&controller->session(),
|
||||||
[=](not_null<PeerData*> peer) {
|
[=](not_null<PeerData*> peer) {
|
||||||
show->showBox(Box(GiftCreditsBox, peer, gifted));
|
show->showBox(Box(GiftBox, controller, peer, gifted));
|
||||||
});
|
});
|
||||||
show->showBox(
|
show->showBox(
|
||||||
Box<PeerListBox>(std::move(listController), std::move(initBox)),
|
Box<PeerListBox>(std::move(listController), std::move(initBox)),
|
||||||
Ui::LayerOption::KeepOther);
|
LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
|
@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/language_box.h"
|
#include "boxes/language_box.h"
|
||||||
#include "boxes/username_box.h"
|
#include "boxes/username_box.h"
|
||||||
#include "boxes/about_box.h"
|
#include "boxes/about_box.h"
|
||||||
|
#include "boxes/gift_credits_box.h"
|
||||||
#include "ui/basic_click_handlers.h"
|
#include "ui/basic_click_handlers.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "ui/controls/userpic_button.h"
|
#include "ui/controls/userpic_button.h"
|
||||||
|
@ -527,7 +528,8 @@ void SetupPremium(
|
||||||
{ .icon = &st::menuIconGiftPremium }
|
{ .icon = &st::menuIconGiftPremium }
|
||||||
);
|
);
|
||||||
button->addClickHandler([=] {
|
button->addClickHandler([=] {
|
||||||
controller->showGiftPremiumsBox(u"gift"_q);
|
Ui::ShowGiftCreditsBox(controller, [=] {
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
|
|
|
@ -57,3 +57,25 @@ creditsHistoryEntryGiftStickerSpace: 105px;
|
||||||
creditsGiftBox: Box(defaultBox) {
|
creditsGiftBox: Box(defaultBox) {
|
||||||
shadowIgnoreTopSkip: true;
|
shadowIgnoreTopSkip: true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
giftBoxSubtitle: FlatLabel(defaultFlatLabel) {
|
||||||
|
style: TextStyle(defaultTextStyle) {
|
||||||
|
font: boxTitleFont;
|
||||||
|
}
|
||||||
|
textFg: windowBoldFg;
|
||||||
|
align: align(top);
|
||||||
|
minWidth: 200px;
|
||||||
|
}
|
||||||
|
giftBoxSubtitleMargin: margins(22px, 4px, 22px, 4px);
|
||||||
|
giftBoxAbout: FlatLabel(defaultFlatLabel) {
|
||||||
|
align: align(top);
|
||||||
|
minWidth: 200px;
|
||||||
|
}
|
||||||
|
giftBoxAboutMargin: margins(20px, 4px, 20px, 4px);
|
||||||
|
giftBoxTabsMargin: margins(20px, 4px, 20px, 4px);
|
||||||
|
giftBoxTabPadding: margins(8px, 2px, 8px, 2px);
|
||||||
|
giftBoxTabSkip: 2px;
|
||||||
|
giftBoxTabStyle: semiboldTextStyle;
|
||||||
|
giftBoxTabFg: windowSubTextFg;
|
||||||
|
giftBoxTabFgActive: windowBoldFg;
|
||||||
|
giftBoxTabBgActive: windowBgRipple;
|
||||||
|
|
Loading…
Add table
Reference in a new issue