diff --git a/Telegram/SourceFiles/settings/sections/settings_information.cpp b/Telegram/SourceFiles/settings/sections/settings_information.cpp index b2515c4d8b..f62ec4d711 100644 --- a/Telegram/SourceFiles/settings/sections/settings_information.cpp +++ b/Telegram/SourceFiles/settings/sections/settings_information.cpp @@ -72,6 +72,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ui/ayu_userpic.h" +#include "ayu/utils/telegram_helpers.h" +#include "styles/style_info.h" namespace Settings { @@ -109,9 +111,11 @@ private: rpl::variable _text; rpl::event_stream _unreadWidth; rpl::event_stream _premiumWidth; + rpl::event_stream _exteraWidth; QPointer _unread; Info::Profile::Badge _badge; + Info::Profile::Badge _exteraBadge; }; @@ -130,9 +134,18 @@ ComposedBadge::ComposedBadge( session, Info::Profile::BadgeContentForPeer(session->user()), nullptr, - std::move(animationPaused), + animationPaused, kPlayStatusLimit, - Info::Profile::BadgeType::Premium) { + Info::Profile::BadgeType::Premium) +, _exteraBadge( + this, + st::infoPeerBadge, + session, + ExteraBadgeTypeFromPeer(session->user()), + nullptr, + std::move(animationPaused), + 0, + Info::Profile::BadgeType::Extera | Info::Profile::BadgeType::ExteraSupporter | Info::Profile::BadgeType::ExteraCustom) { if (hasUnread) { _unread = Badge::CreateUnread(this, rpl::single( rpl::empty @@ -163,6 +176,16 @@ ComposedBadge::ComposedBadge( } }, lifetime()); + _exteraBadge.updated( + ) | rpl::on_next([=] { + if (const auto widget = _exteraBadge.widget()) { + widget->widthValue( + ) | rpl::start_to_stream(_exteraWidth, widget->lifetime()); + } else { + _exteraWidth.fire(0); + } + }, lifetime()); + auto textWidth = _text.value() | rpl::map([=] { return button->fullTextWidth(); }); @@ -171,11 +194,15 @@ ComposedBadge::ComposedBadge( _premiumWidth.events_starting_with(_badge.widget() ? _badge.widget()->width() : 0), + _exteraWidth.events_starting_with(_exteraBadge.widget() + ? _exteraBadge.widget()->width() + : 0), std::move(textWidth), button->sizeValue() ) | rpl::on_next([=]( int unreadWidth, int premiumWidth, + int exteraWidth, int textWidth, const QSize &buttonSize) { const auto &st = button->st(); @@ -183,7 +210,14 @@ ComposedBadge::ComposedBadge( const auto textRightPosition = st.padding.left() + textWidth + skip; - const auto minWidth = unreadWidth + premiumWidth + skip; + const auto exteraGap = exteraWidth + ? st::infoVerifiedCheckPosition.x() + : 0; + const auto minWidth = unreadWidth + + premiumWidth + + exteraGap + + exteraWidth + + skip; const auto maxTextWidth = buttonSize.width() - minWidth - st.padding.right(); @@ -198,6 +232,10 @@ ComposedBadge::ComposedBadge( 0, st.padding.top(), buttonSize.height() - st.padding.top()); + _exteraBadge.move( + premiumWidth, + st.padding.top(), + buttonSize.height() - st.padding.top()); if (_unread) { _unread->moveToRight( 0, diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 7886447a3f..10215b7dfd 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -322,6 +322,15 @@ MainMenu::MainMenu( [=] { return controller->isGifPausedAtLeastFor(GifPauseReason::Layer); }, kPlayStatusLimit, Info::Profile::BadgeType::Premium)) +, _exteraBadge(std::make_unique( + this, + st::infoPeerBadge, + &controller->session(), + ExteraBadgeTypeFromPeer(controller->session().user()), + nullptr, + [=] { return controller->isGifPausedAtLeastFor(GifPauseReason::Layer); }, + 0, + Info::Profile::BadgeType::Extera | Info::Profile::BadgeType::ExteraSupporter | Info::Profile::BadgeType::ExteraCustom)) , _scroll(this, st::defaultSolidScroll) , _inner(_scroll->setOwnedWidget( object_ptr(_scroll.data()))) @@ -407,13 +416,23 @@ MainMenu::MainMenu( rpl::combine( _toggleAccounts->rightSkipValue(), - rpl::single(rpl::empty) | rpl::then(_badge->updated()) + rpl::single(rpl::empty) | rpl::then(_badge->updated()), + rpl::single(rpl::empty) | rpl::then(_exteraBadge->updated()) ) | rpl::on_next([=] { moveBadge(); }, lifetime()); _badge->setPremiumClickCallback([=] { chooseEmojiStatus(); }); + { + const auto user = controller->session().user(); + const auto isCustomBadge = isCustomBadgePeer(getBareID(user)); + const auto isExtera = isExteraPeer(getBareID(user)); + const auto isSupporter = isSupporterPeer(getBareID(user)); + if (isExtera || isSupporter || isCustomBadge) { + _exteraBadge->setPremiumClickCallback(badgeClickHandler(user)); + } + } _controller->session().downloaderTaskFinished( ) | rpl::on_next([=] { @@ -464,19 +483,42 @@ MainMenu::MainMenu( MainMenu::~MainMenu() = default; void MainMenu::moveBadge() { - if (!_badge->widget()) { + const auto badgeWidth = _badge->widget() + ? _badge->widget()->width() + : 0; + const auto exteraBadgeWidth = _exteraBadge->widget() + ? _exteraBadge->widget()->width() + : 0; + if (!badgeWidth && !exteraBadgeWidth) { return; } + const auto nameGap = badgeWidth ? st::semiboldFont->spacew : 0; + const auto exteraGap = exteraBadgeWidth + ? st::infoVerifiedCheckPosition.x() + : 0; + const auto reserved = nameGap + + badgeWidth + + exteraGap + + exteraBadgeWidth; const auto available = width() - st::mainMenuCoverNameLeft - _toggleAccounts->rightSkip() - - _badge->widget()->width(); - const auto left = st::mainMenuCoverNameLeft - + std::min(_name.maxWidth() + st::semiboldFont->spacew, available); - _badge->move( - left, - st::mainMenuCoverNameTop, - st::mainMenuCoverNameTop + st::semiboldFont->height); + - reserved; + const auto nameLeft = st::mainMenuCoverNameLeft; + const auto nameEnd = nameLeft + + std::min(_name.maxWidth(), available); + if (_badge->widget()) { + _badge->move( + nameEnd + nameGap, + st::mainMenuCoverNameTop, + st::mainMenuCoverNameTop + st::semiboldFont->height); + } + if (_exteraBadge->widget()) { + _exteraBadge->move( + nameEnd + nameGap + badgeWidth, + st::mainMenuCoverNameTop, + st::mainMenuCoverNameTop + st::semiboldFont->height); + } } void MainMenu::setupArchive() { @@ -974,14 +1016,25 @@ void MainMenu::drawName(Painter &p) { } p.setFont(st::semiboldFont); p.setPen(st::windowBoldFg); + const auto badgeWidth = _badge->widget() + ? _badge->widget()->width() + : 0; + const auto exteraBadgeWidth = _exteraBadge->widget() + ? _exteraBadge->widget()->width() + : 0; + const auto nameGap = badgeWidth ? st::semiboldFont->spacew : 0; + const auto exteraGap = exteraBadgeWidth + ? st::infoVerifiedCheckPosition.x() + : 0; + const auto reserved = nameGap + + badgeWidth + + exteraGap + + exteraBadgeWidth; _name.drawLeftElided( p, st::mainMenuCoverNameLeft, st::mainMenuCoverNameTop, - (widthText - - (_badge->widget() - ? (st::semiboldFont->spacew + _badge->widget()->width()) - : 0)), + widthText - reserved, width()); } diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index 36a3087a05..23ce957928 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -93,6 +93,7 @@ private: object_ptr _setEmojiStatus; std::unique_ptr _emojiStatusPanel; std::unique_ptr _badge; + std::unique_ptr _exteraBadge; object_ptr _resetScaleButton = { nullptr }; object_ptr _scroll; not_null _inner;