mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added gift sticker to ReceiptCreditsBox for gifts.
This commit is contained in:
parent
3f2cb8f8c9
commit
e760a0983f
2 changed files with 82 additions and 18 deletions
|
@ -12,11 +12,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/timer_rpl.h"
|
#include "base/timer_rpl.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "boxes/gift_premium_box.h"
|
#include "boxes/gift_premium_box.h"
|
||||||
|
#include "chat_helpers/stickers_gift_box_pack.h"
|
||||||
|
#include "chat_helpers/stickers_lottie.h"
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
|
#include "core/click_handler_types.h" // UrlClickHandler
|
||||||
#include "core/ui_integration.h"
|
#include "core/ui_integration.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_document_media.h"
|
||||||
#include "data/data_file_origin.h"
|
#include "data/data_file_origin.h"
|
||||||
#include "core/click_handler_types.h" // UrlClickHandler
|
|
||||||
#include "data/data_photo_media.h"
|
#include "data/data_photo_media.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
@ -27,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
||||||
#include "info/statistics/info_statistics_list_controllers.h"
|
#include "info/statistics/info_statistics_list_controllers.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
#include "lottie/lottie_single_player.h"
|
||||||
#include "main/main_app_config.h"
|
#include "main/main_app_config.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "payments/payments_checkout_process.h"
|
#include "payments/payments_checkout_process.h"
|
||||||
|
@ -457,24 +461,82 @@ void ReceiptCreditsBox(
|
||||||
content,
|
content,
|
||||||
GenericEntryPhoto(content, callback, stUser.photoSize)));
|
GenericEntryPhoto(content, callback, stUser.photoSize)));
|
||||||
AddViewMediaHandler(thumb->entity(), controller, e);
|
AddViewMediaHandler(thumb->entity(), controller, e);
|
||||||
} else if (peer) {
|
} else if (peer && !e.gift) {
|
||||||
content->add(object_ptr<Ui::CenterWrap<>>(
|
content->add(object_ptr<Ui::CenterWrap<>>(
|
||||||
content,
|
content,
|
||||||
object_ptr<Ui::UserpicButton>(content, peer, stUser)));
|
object_ptr<Ui::UserpicButton>(content, peer, stUser)));
|
||||||
} else {
|
} else {
|
||||||
const auto widget = content->add(
|
if (e.gift) {
|
||||||
object_ptr<Ui::CenterWrap<>>(
|
using PlayerPtr = std::unique_ptr<Lottie::SinglePlayer>;
|
||||||
|
struct State final {
|
||||||
|
DocumentData *sticker = nullptr;
|
||||||
|
std::shared_ptr<Data::DocumentMedia> media;
|
||||||
|
std::unique_ptr<Lottie::SinglePlayer> lottie;
|
||||||
|
rpl::lifetime downloadLifetime;
|
||||||
|
};
|
||||||
|
Ui::AddSkip(
|
||||||
content,
|
content,
|
||||||
object_ptr<Ui::RpWidget>(content)))->entity();
|
st::creditsHistoryEntryGiftStickerSpace);
|
||||||
using Draw = Fn<void(Painter &, int, int, int, int)>;
|
const auto icon = Ui::CreateChild<Ui::RpWidget>(content);
|
||||||
const auto draw = widget->lifetime().make_state<Draw>(
|
icon->resize(Size(st::creditsHistoryEntryGiftStickerSize));
|
||||||
Ui::GenerateCreditsPaintUserpicCallback(e));
|
const auto state = icon->lifetime().make_state<State>();
|
||||||
widget->resize(Size(stUser.photoSize));
|
auto &packs = session->giftBoxStickersPacks();
|
||||||
widget->paintRequest(
|
const auto document = packs.lookup(1);
|
||||||
) | rpl::start_with_next([=] {
|
if (document && document->sticker()) {
|
||||||
auto p = Painter(widget);
|
state->sticker = document;
|
||||||
(*draw)(p, 0, 0, stUser.photoSize, stUser.photoSize);
|
state->media = document->createMediaView();
|
||||||
}, widget->lifetime());
|
state->media->thumbnailWanted(packs.origin());
|
||||||
|
state->media->automaticLoad(packs.origin(), nullptr);
|
||||||
|
session->downloaderTaskFinished(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
if (state->media->loaded()) {
|
||||||
|
state->lottie = ChatHelpers::LottiePlayerFromDocument(
|
||||||
|
state->media.get(),
|
||||||
|
ChatHelpers::StickerLottieSize::MessageHistory,
|
||||||
|
icon->size(),
|
||||||
|
Lottie::Quality::High);
|
||||||
|
state->lottie->updates() | rpl::start_with_next([=] {
|
||||||
|
icon->update();
|
||||||
|
}, icon->lifetime());
|
||||||
|
state->downloadLifetime.destroy();
|
||||||
|
}
|
||||||
|
}, state->downloadLifetime);
|
||||||
|
}
|
||||||
|
icon->paintRequest(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
auto p = Painter(icon);
|
||||||
|
const auto &lottie = state->lottie;
|
||||||
|
const auto frame = (lottie && lottie->ready())
|
||||||
|
? lottie->frameInfo({ .box = icon->size() })
|
||||||
|
: Lottie::Animation::FrameInfo();
|
||||||
|
if (!frame.image.isNull()) {
|
||||||
|
p.drawImage(0, 0, frame.image);
|
||||||
|
if (lottie->frameIndex() < lottie->framesCount() - 1) {
|
||||||
|
lottie->markFrameShown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, icon->lifetime());
|
||||||
|
content->sizeValue(
|
||||||
|
) | rpl::start_with_next([=](const QSize &size) {
|
||||||
|
icon->move(
|
||||||
|
(size.width() - icon->width()) / 2,
|
||||||
|
st::creditsHistoryEntryGiftStickerSkip);
|
||||||
|
}, icon->lifetime());
|
||||||
|
} else {
|
||||||
|
const auto widget = content->add(
|
||||||
|
object_ptr<Ui::CenterWrap<>>(
|
||||||
|
content,
|
||||||
|
object_ptr<Ui::RpWidget>(content)))->entity();
|
||||||
|
using Draw = Fn<void(Painter &, int, int, int, int)>;
|
||||||
|
const auto draw = widget->lifetime().make_state<Draw>(
|
||||||
|
Ui::GenerateCreditsPaintUserpicCallback(e));
|
||||||
|
widget->resize(Size(stUser.photoSize));
|
||||||
|
widget->paintRequest(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
auto p = Painter(widget);
|
||||||
|
(*draw)(p, 0, 0, stUser.photoSize, stUser.photoSize);
|
||||||
|
}, widget->lifetime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
|
@ -635,10 +697,7 @@ void ReceiptCreditsBox(
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
|
|
||||||
AddCreditsHistoryEntryTable(
|
AddCreditsHistoryEntryTable(controller, content, e);
|
||||||
controller,
|
|
||||||
box->verticalLayout(),
|
|
||||||
e);
|
|
||||||
|
|
||||||
Ui::AddSkip(content);
|
Ui::AddSkip(content);
|
||||||
|
|
||||||
|
|
|
@ -49,3 +49,8 @@ starIconSmall: icon{{ "payments/small_star", windowFg }};
|
||||||
starIconSmallPadding: margins(0px, -2px, 0px, 0px);
|
starIconSmallPadding: margins(0px, -2px, 0px, 0px);
|
||||||
|
|
||||||
creditsHistoryEntryTypeAds: icon {{ "folders/folders_channels", premiumButtonFg }};
|
creditsHistoryEntryTypeAds: icon {{ "folders/folders_channels", premiumButtonFg }};
|
||||||
|
|
||||||
|
creditsHistoryEntryGiftStickerSkip: -20px;
|
||||||
|
creditsHistoryEntryGiftStickerSize: 150px;
|
||||||
|
creditsHistoryEntryGiftStickerSpace: 105px;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue