mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Return gift_credits_box with gifting stars.
This commit is contained in:
parent
d361d5f3b2
commit
cf1d274b0d
10 changed files with 216 additions and 18 deletions
|
@ -276,6 +276,8 @@ PRIVATE
|
|||
boxes/edit_caption_box.h
|
||||
boxes/edit_privacy_box.cpp
|
||||
boxes/edit_privacy_box.h
|
||||
boxes/gift_credits_box.cpp
|
||||
boxes/gift_credits_box.h
|
||||
boxes/gift_premium_box.cpp
|
||||
boxes/gift_premium_box.h
|
||||
boxes/language_box.cpp
|
||||
|
|
181
Telegram/SourceFiles/boxes/gift_credits_box.cpp
Normal file
181
Telegram/SourceFiles/boxes/gift_credits_box.cpp
Normal file
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
#include "boxes/gift_credits_box.h"
|
||||
|
||||
#include "api/api_credits.h"
|
||||
#include "boxes/peer_list_controllers.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/stickers/data_custom_emoji.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/session/session_show.h"
|
||||
#include "settings/settings_credits_graphics.h"
|
||||
#include "ui/controls/userpic_button.h"
|
||||
#include "ui/effects/premium_graphics.h"
|
||||
#include "ui/effects/premium_stars_colored.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/widgets/label_with_custom_emoji.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_channel_earn.h"
|
||||
#include "styles/style_chat.h"
|
||||
#include "styles/style_credits.h"
|
||||
#include "styles/style_giveaway.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_premium.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
void GiftCreditsBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void()> gifted) {
|
||||
box->setWidth(st::boxWideWidth);
|
||||
box->setStyle(st::creditsGiftBox);
|
||||
box->setNoContentMargin(true);
|
||||
box->addButton(tr::lng_create_group_back(), [=] { box->closeBox(); });
|
||||
|
||||
const auto content = box->setPinnedToTopContent(
|
||||
object_ptr<Ui::VerticalLayout>(box));
|
||||
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
const auto &stUser = st::premiumGiftsUserpicButton;
|
||||
const auto userpicWrap = content->add(
|
||||
object_ptr<Ui::CenterWrap<>>(
|
||||
content,
|
||||
object_ptr<Ui::UserpicButton>(content, peer, stUser)));
|
||||
userpicWrap->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
|
||||
{
|
||||
const auto widget = Ui::CreateChild<Ui::RpWidget>(content);
|
||||
using ColoredMiniStars = Ui::Premium::ColoredMiniStars;
|
||||
const auto stars = widget->lifetime().make_state<ColoredMiniStars>(
|
||||
widget,
|
||||
false,
|
||||
Ui::Premium::MiniStars::Type::BiStars);
|
||||
stars->setColorOverride(Ui::Premium::CreditsIconGradientStops());
|
||||
widget->resize(
|
||||
st::boxWidth - stUser.photoSize,
|
||||
stUser.photoSize * 2);
|
||||
content->sizeValue(
|
||||
) | rpl::start_with_next([=](const QSize &size) {
|
||||
widget->moveToLeft(stUser.photoSize / 2, 0);
|
||||
const auto starsRect = Rect(widget->size());
|
||||
stars->setPosition(starsRect.topLeft());
|
||||
stars->setSize(starsRect.size());
|
||||
widget->lower();
|
||||
}, widget->lifetime());
|
||||
widget->paintRequest(
|
||||
) | rpl::start_with_next([=](const QRect &r) {
|
||||
auto p = QPainter(widget);
|
||||
p.fillRect(r, Qt::transparent);
|
||||
stars->paint(p);
|
||||
}, widget->lifetime());
|
||||
}
|
||||
{
|
||||
Ui::AddSkip(content);
|
||||
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(
|
||||
Main::MakeSessionShow(box->uiShow(), &peer->session()),
|
||||
box->verticalLayout(),
|
||||
peer,
|
||||
0,
|
||||
[=] { gifted(); box->uiShow()->hideLayer(); });
|
||||
|
||||
box->setPinnedToBottomContent(
|
||||
object_ptr<Ui::VerticalLayout>(box));
|
||||
}
|
||||
|
||||
void ShowGiftCreditsBox(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void()> gifted) {
|
||||
|
||||
class Controller final : public ContactsBoxController {
|
||||
public:
|
||||
Controller(
|
||||
not_null<Main::Session*> session,
|
||||
Fn<void(not_null<PeerData*>)> choose)
|
||||
: ContactsBoxController(session)
|
||||
, _choose(std::move(choose)) {
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<PeerListRow> createRow(
|
||||
not_null<UserData*> user) override {
|
||||
if (user->isSelf()
|
||||
|| user->isBot()
|
||||
|| user->isServiceUser()
|
||||
|| user->isInaccessible()) {
|
||||
return nullptr;
|
||||
}
|
||||
return ContactsBoxController::createRow(user);
|
||||
}
|
||||
|
||||
void rowClicked(not_null<PeerListRow*> row) override {
|
||||
_choose(row->peer());
|
||||
}
|
||||
|
||||
private:
|
||||
const Fn<void(not_null<PeerData*>)> _choose;
|
||||
|
||||
};
|
||||
auto initBox = [=](not_null<PeerListBox*> peersBox) {
|
||||
peersBox->setTitle(tr::lng_credits_gift_title());
|
||||
peersBox->addButton(tr::lng_cancel(), [=] { peersBox->closeBox(); });
|
||||
};
|
||||
|
||||
const auto show = controller->uiShow();
|
||||
auto listController = std::make_unique<Controller>(
|
||||
&controller->session(),
|
||||
[=](not_null<PeerData*> peer) {
|
||||
show->showBox(Box(GiftCreditsBox, peer, gifted));
|
||||
});
|
||||
show->showBox(
|
||||
Box<PeerListBox>(std::move(listController), std::move(initBox)),
|
||||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
} // namespace Ui
|
20
Telegram/SourceFiles/boxes/gift_credits_box.h
Normal file
20
Telegram/SourceFiles/boxes/gift_credits_box.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
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
|
||||
|
||||
namespace Window {
|
||||
class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace Ui {
|
||||
|
||||
void ShowGiftCreditsBox(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void()> gifted);
|
||||
|
||||
} // namespace Ui
|
|
@ -1168,8 +1168,7 @@ void AddBlock(
|
|||
void GiftBox(
|
||||
not_null<GenericBox*> box,
|
||||
not_null<Window::SessionController*> window,
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void()> gifted) {
|
||||
not_null<PeerData*> peer) {
|
||||
box->setWidth(st::boxWideWidth);
|
||||
box->setStyle(st::creditsGiftBox);
|
||||
box->setNoContentMargin(true);
|
||||
|
@ -1255,9 +1254,7 @@ void GiftBox(
|
|||
} // namespace
|
||||
|
||||
void ChooseStarGiftRecipient(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void()> gifted) {
|
||||
|
||||
not_null<Window::SessionController*> controller) {
|
||||
class Controller final : public ContactsBoxController {
|
||||
public:
|
||||
Controller(
|
||||
|
@ -1295,7 +1292,7 @@ void ChooseStarGiftRecipient(
|
|||
auto listController = std::make_unique<Controller>(
|
||||
&controller->session(),
|
||||
[=](not_null<PeerData*> peer) {
|
||||
ShowStarGiftBox(controller, peer, gifted);
|
||||
ShowStarGiftBox(controller, peer);
|
||||
});
|
||||
controller->show(
|
||||
Box<PeerListBox>(std::move(listController), std::move(initBox)),
|
||||
|
@ -1304,9 +1301,8 @@ void ChooseStarGiftRecipient(
|
|||
|
||||
void ShowStarGiftBox(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void()> gifted) {
|
||||
controller->show(Box(GiftBox, controller, peer, gifted));
|
||||
not_null<PeerData*> peer) {
|
||||
controller->show(Box(GiftBox, controller, peer));
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -14,12 +14,10 @@ class SessionController;
|
|||
namespace Ui {
|
||||
|
||||
void ChooseStarGiftRecipient(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void()> gifted);
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
void ShowStarGiftBox(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void()> gifted);
|
||||
not_null<PeerData*> peer);
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -1133,7 +1133,7 @@ bool ResolvePremiumMultigift(
|
|||
if (!controller) {
|
||||
return false;
|
||||
}
|
||||
Ui::ChooseStarGiftRecipient(controller, [] {});
|
||||
Ui::ChooseStarGiftRecipient(controller);
|
||||
controller->window().activate();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -706,7 +706,7 @@ base::options::toggle ShowPeerIdBelowAbout({
|
|||
|
||||
button->setClickedCallback([=] {
|
||||
if (!button->isDisabled()) {
|
||||
Ui::ShowStarGiftBox(controller, user, [] {});
|
||||
Ui::ShowStarGiftBox(controller, user);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "api/api_credits.h"
|
||||
#include "boxes/star_gift_box.h"
|
||||
#include "boxes/gift_credits_box.h"
|
||||
#include "boxes/gift_premium_box.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "data/components/credits.h"
|
||||
|
@ -360,7 +361,7 @@ void Credits::setupContent() {
|
|||
Ui::AddSkip(content);
|
||||
Ui::AddDivider(content);
|
||||
giftButton->setClickedCallback([=] {
|
||||
Ui::ChooseStarGiftRecipient(_controller, paid);
|
||||
Ui::ShowGiftCreditsBox(_controller, paid);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -528,7 +528,7 @@ void SetupPremium(
|
|||
{ .icon = &st::menuIconGiftPremium }
|
||||
);
|
||||
button->addClickHandler([=] {
|
||||
Ui::ChooseStarGiftRecipient(controller, [] {});
|
||||
Ui::ChooseStarGiftRecipient(controller);
|
||||
});
|
||||
}
|
||||
Ui::AddSkip(container);
|
||||
|
|
|
@ -1240,7 +1240,7 @@ void Filler::addGiftPremium() {
|
|||
|
||||
const auto navigation = _controller;
|
||||
_addAction(tr::lng_profile_gift_premium(tr::now), [=] {
|
||||
Ui::ChooseStarGiftRecipient(navigation, [] {});
|
||||
Ui::ChooseStarGiftRecipient(navigation);
|
||||
}, &st::menuIconGiftPremium);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue