2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Implement multiboost reassign box.

This commit is contained in:
John Preston
2023-11-08 13:31:01 +04:00
parent a41bbd27c8
commit c5d1739e95
18 changed files with 844 additions and 213 deletions

View File

@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/boxes/boost_box.h"
#include "lang/lang_keys.h"
#include "ui/boxes/confirm_box.h"
#include "ui/effects/fireworks_animation.h"
#include "ui/effects/premium_graphics.h"
#include "ui/layers/generic_box.h"
@@ -177,9 +178,10 @@ void BoostBox(
(st::boxRowPadding
+ QMargins(0, st::boostTextSkip, 0, st::boostBottomSkip)));
const auto allowMulti = data.allowMulti;
auto submit = state->data.value(
) | rpl::map([=](BoostCounters counters) {
return !counters.nextLevelBoosts
return (!counters.nextLevelBoosts || (counters.mine && !allowMulti))
? tr::lng_box_ok()
: (counters.mine > 0)
? tr::lng_boost_again_button()
@@ -189,7 +191,8 @@ void BoostBox(
const auto button = box->addButton(rpl::duplicate(submit), [=] {
if (state->submitted) {
return;
} else if (state->data.current().nextLevelBoosts > 0) {
} else if (state->data.current().nextLevelBoosts > 0
&& (allowMulti || !state->data.current().mine)) {
state->submitted = true;
const auto was = state->data.current().mine;
@@ -346,6 +349,49 @@ object_ptr<Ui::RpWidget> MakeLinkLabel(
return result;
}
void BoostBoxAlready(not_null<GenericBox*> box) {
ConfirmBox(box, {
.text = tr::lng_boost_error_already_text(Text::RichLangValue),
.title = tr::lng_boost_error_already_title(),
.inform = true,
});
}
void GiftForBoostsBox(
not_null<GenericBox*> box,
QString channel,
int receive,
bool again) {
ConfirmBox(box, {
.text = (again
? tr::lng_boost_need_more_again
: tr::lng_boost_need_more_text)(
lt_count,
rpl::single(receive) | tr::to_count(),
lt_channel,
rpl::single(TextWithEntities{ channel }),
Text::RichLangValue),
.title = tr::lng_boost_need_more(),
.inform = true,
});
}
void GiftedNoBoostsBox(not_null<GenericBox*> box) {
InformBox(box, {
.text = tr::lng_boost_error_gifted_text(Text::RichLangValue),
.title = tr::lng_boost_error_gifted_title(),
});
}
void PremiumForBoostsBox(not_null<GenericBox*> box, Fn<void()> buyPremium) {
ConfirmBox(box, {
.text = tr::lng_boost_error_premium_text(Text::RichLangValue),
.confirmed = buyPremium,
.confirmText = tr::lng_boost_error_premium_yes(),
.title = tr::lng_boost_error_premium_title(),
});
}
void AskBoostBox(
not_null<GenericBox*> box,
AskBoostBoxData data,

View File

@@ -33,6 +33,7 @@ struct BoostCounters {
struct BoostBoxData {
QString name;
BoostCounters boost;
bool allowMulti = false;
};
void BoostBox(
@@ -40,6 +41,15 @@ void BoostBox(
BoostBoxData data,
Fn<void(Fn<void(BoostCounters)>)> boost);
void BoostBoxAlready(not_null<GenericBox*> box);
void GiftForBoostsBox(
not_null<GenericBox*> box,
QString channel,
int receive,
bool again);
void GiftedNoBoostsBox(not_null<GenericBox*> box);
void PremiumForBoostsBox(not_null<GenericBox*> box, Fn<void()> buyPremium);
struct AskBoostBoxData {
QString link;
BoostCounters boost;

View File

@@ -100,11 +100,4 @@ object_ptr<Ui::GenericBox> MakeConfirmBox(ConfirmBoxArgs &&args) {
return Box(ConfirmBox, std::move(args));
}
object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text) {
return MakeConfirmBox({
.text = std::move(text),
.inform = true,
});
}
} // namespace Ui

View File

@@ -40,10 +40,24 @@ struct ConfirmBoxArgs {
bool strictCancel = false;
};
void ConfirmBox(not_null<Ui::GenericBox*> box, ConfirmBoxArgs &&args);
void ConfirmBox(not_null<GenericBox*> box, ConfirmBoxArgs &&args);
[[nodiscard]] object_ptr<Ui::GenericBox> MakeConfirmBox(
ConfirmBoxArgs &&args);
[[nodiscard]] object_ptr<Ui::GenericBox> MakeInformBox(v::text::data text);
inline void InformBox(not_null<GenericBox*> box, ConfirmBoxArgs &&args) {
args.inform = true;
ConfirmBox(box, std::move(args));
}
[[nodiscard]] object_ptr<GenericBox> MakeConfirmBox(ConfirmBoxArgs &&args);
[[nodiscard]] inline object_ptr<GenericBox> MakeInformBox(
ConfirmBoxArgs &&args) {
args.inform = true;
return MakeConfirmBox(std::move(args));
}
[[nodiscard]] inline object_ptr<GenericBox> MakeInformBox(
v::text::data text) {
return MakeInformBox({ .text = std::move(text) });
}
} // namespace Ui

View File

@@ -1108,57 +1108,4 @@ not_null<Ui::UserpicButton*> CreateUploadSubButton(
return upload;
}
object_ptr<Ui::RpWidget> CreateBoostReplaceUserpics(
not_null<Ui::RpWidget*> parent,
not_null<PeerData*> from,
not_null<PeerData*> to) {
const auto full = st::boostReplaceUserpic.size.height()
+ st::boostReplaceIconAdd.y()
+ st::lineWidth;
auto result = object_ptr<FixedHeightWidget>(parent, full);
const auto raw = result.data();
const auto &st = st::boostReplaceUserpic;
const auto left = CreateChild<UserpicButton>(raw, from, st);
const auto right = CreateChild<UserpicButton>(raw, to, st);
const auto overlay = CreateChild<RpWidget>(raw);
raw->widthValue(
) | rpl::start_with_next([=](int width) {
const auto skip = st::boostReplaceUserpicsSkip;
const auto total = left->width() + skip + right->width();
left->moveToLeft((width - total) / 2, 0);
right->moveToLeft(left->x() + left->width() + skip, 0);
overlay->setGeometry(QRect(0, 0, width, raw->height()));
}, raw->lifetime());
overlay->paintRequest(
) | rpl::start_with_next([=] {
const auto outerw = overlay->width();
const auto add = st::boostReplaceIconAdd;
const auto skip = st::boostReplaceIconSkip;
const auto w = st::boostReplaceIcon.width() + 2 * skip;
const auto h = st::boostReplaceIcon.height() + 2 * skip;
const auto x = left->x() + left->width() - w + add.x();
const auto y = left->y() + left->height() - h + add.y();
const auto stroke = st::boostReplaceIconOutline;
const auto half = stroke / 2.;
auto p = QPainter(overlay);
auto hq = PainterHighQualityEnabler(p);
auto pen = st::windowBg->p;
pen.setWidthF(stroke);
p.setPen(pen);
auto brush = QLinearGradient(QPointF(x + w, y + h), QPointF(x, y));
brush.setStops(Premium::ButtonGradientStops());
p.setBrush(brush);
p.drawEllipse(x - half, y - half, w + stroke, h + stroke);
st::boostReplaceIcon.paint(p, x + skip, y + skip, outerw);
const auto size = st::boostReplaceArrow.size();
st::boostReplaceArrow.paint(
p,
(outerw - size.width()) / 2,
(left->height() - size.height()) / 2,
outerw);
}, overlay->lifetime());
return result;
}
} // namespace Ui

View File

@@ -204,9 +204,4 @@ private:
not_null<UserData*> contact,
not_null<Window::SessionController*> controller);
[[nodiscard]] object_ptr<Ui::RpWidget> CreateBoostReplaceUserpics(
not_null<Ui::RpWidget*> parent,
not_null<PeerData*> from,
not_null<PeerData*> to);
} // namespace Ui

View File

@@ -247,7 +247,6 @@ boostTitleSkip: 32px;
boostTitle: FlatLabel(defaultFlatLabel) {
minWidth: 40px;
textFg: windowBoldFg;
align: align(top);
maxHeight: 24px;
style: TextStyle(boxTextStyle) {
font: font(17px semibold);
@@ -258,6 +257,10 @@ boostText: FlatLabel(defaultFlatLabel) {
minWidth: 40px;
align: align(top);
}
boostReassignText: FlatLabel(defaultFlatLabel) {
minWidth: 40px;
align: align(top);
}
boostBottomSkip: 6px;
boostBox: Box(premiumPreviewDoubledLimitsBox) {
buttonPadding: margins(22px, 22px, 22px, 22px);
@@ -271,11 +274,12 @@ boostBox: Box(premiumPreviewDoubledLimitsBox) {
boostReplaceUserpicsPadding: margins(0px, 18px, 0px, 20px);
boostReplaceUserpicsSkip: 42px;
boostReplaceUserpicsShift: 24px;
boostReplaceUserpic: UserpicButton(defaultUserpicButton) {
size: size(60px, 60px);
photoSize: 60px;
}
boostReplaceIcon: icon{{ "stories/boost_mini", windowBg }};
boostReplaceIcon: icon{{ "stories/boost_mini", premiumButtonFg }};
boostReplaceIconSkip: 3px;
boostReplaceIconOutline: 2px;
boostReplaceIconAdd: point(4px, 2px);