mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-19 15:47:11 +02:00
Show additional prize in giveaway message.
This commit is contained in:
parent
19f38f3c6f
commit
e854f0b60c
4 changed files with 75 additions and 3 deletions
|
@ -2198,6 +2198,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
"lng_prizes_title#one" = "Giveaway Prize";
|
||||
"lng_prizes_title#other" = "Giveaway Prizes";
|
||||
"lng_prizes_additional#one" = "**{count}** {prize}";
|
||||
"lng_prizes_additional#other" = "**{count}** {prize}";
|
||||
"lng_prizes_additional_with" = "with";
|
||||
"lng_prizes_about#one" = "**{count}** Telegram Premium Subscription {duration}.";
|
||||
"lng_prizes_about#other" = "**{count}** Telegram Premium Subscriptions {duration}.";
|
||||
"lng_prizes_participants" = "Participants";
|
||||
|
|
|
@ -35,6 +35,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace HistoryView {
|
||||
namespace {
|
||||
|
||||
constexpr auto kAdditionalPrizesWithLineOpacity = 0.6;
|
||||
|
||||
[[nodiscard]] QSize CountOptimalTextSize(
|
||||
const Ui::Text::String &text,
|
||||
int minWidth,
|
||||
|
@ -80,6 +82,24 @@ void Giveaway::fillFromData(not_null<Data::Giveaway*> giveaway) {
|
|||
tr::lng_prizes_title(tr::now, lt_count, _quantity),
|
||||
kDefaultTextOptions);
|
||||
|
||||
if (giveaway->additionalPrize.isEmpty()) {
|
||||
_additional.clear();
|
||||
_with.clear();
|
||||
} else {
|
||||
_additional.setMarkedText(
|
||||
st::defaultTextStyle,
|
||||
tr::lng_prizes_additional(
|
||||
tr::now,
|
||||
lt_count,
|
||||
_quantity,
|
||||
lt_prize,
|
||||
TextWithEntities{ giveaway->additionalPrize },
|
||||
Ui::Text::RichLangValue));
|
||||
_with.setText(
|
||||
st::defaultTextStyle,
|
||||
tr::lng_prizes_additional_with(tr::now));
|
||||
}
|
||||
|
||||
_prizes.setMarkedText(
|
||||
st::defaultTextStyle,
|
||||
tr::lng_prizes_about(
|
||||
|
@ -88,8 +108,7 @@ void Giveaway::fillFromData(not_null<Data::Giveaway*> giveaway) {
|
|||
_quantity,
|
||||
lt_duration,
|
||||
Ui::Text::Bold(GiftDuration(_months)),
|
||||
Ui::Text::RichLangValue),
|
||||
kDefaultTextOptions);
|
||||
Ui::Text::RichLangValue));
|
||||
_participantsTitle.setText(
|
||||
st::semiboldTextStyle,
|
||||
tr::lng_prizes_participants(tr::now),
|
||||
|
@ -163,9 +182,25 @@ QSize Giveaway::countOptimalSize() {
|
|||
_prizesTitleTop = _stickerTop
|
||||
+ st::msgServiceGiftBoxStickerSize.height()
|
||||
+ st::chatGiveawayPrizesTop;
|
||||
_prizesTop = _prizesTitleTop
|
||||
_additionalTop = _prizesTitleTop
|
||||
+ _prizesTitle.countHeight(available)
|
||||
+ st::chatGiveawayPrizesSkip;
|
||||
if (!_additional.isEmpty()) {
|
||||
const auto additionalSize = CountOptimalTextSize(
|
||||
_additional,
|
||||
st::msgMinWidth,
|
||||
available);
|
||||
_additionalWidth = additionalSize.width();
|
||||
_withTop = _additionalTop
|
||||
+ additionalSize.height()
|
||||
+ st::chatGiveawayPrizesWithPadding.top();
|
||||
_prizesTop = _withTop
|
||||
+ st::normalFont->height
|
||||
+ st::chatGiveawayPrizesWithPadding.bottom();
|
||||
} else {
|
||||
_additionalWidth = 0;
|
||||
_prizesTop = _withTop = _additionalTop;
|
||||
}
|
||||
const auto prizesSize = CountOptimalTextSize(
|
||||
_prizes,
|
||||
st::msgMinWidth,
|
||||
|
@ -285,6 +320,33 @@ void Giveaway::draw(Painter &p, const PaintContext &context) const {
|
|||
});
|
||||
};
|
||||
paintText(_prizesTitle, _prizesTitleTop, paintw);
|
||||
if (!_additional.isEmpty()) {
|
||||
paintText(_additional, _additionalTop, _additionalWidth);
|
||||
p.setPen(stm->msgDateFg);
|
||||
_with.draw(p, {
|
||||
.position = { padding.left(), _withTop },
|
||||
.outerWidth = outer,
|
||||
.availableWidth = paintw,
|
||||
.align = style::al_top,
|
||||
.palette = &stm->textPalette,
|
||||
.now = context.now,
|
||||
.elisionLines = 1,
|
||||
});
|
||||
const auto skip = st::chatGiveawayPrizesWithPadding;
|
||||
const auto inner = outer - 2 * (skip.left() + skip.right());
|
||||
const auto sub = _with.maxWidth();
|
||||
if (inner > sub + 1) {
|
||||
const auto fill = (inner - sub) / 2;
|
||||
const auto stroke = st::lineWidth;
|
||||
const auto top = _withTop
|
||||
+ st::chatGiveawayPrizesWithTop;
|
||||
p.setOpacity(kAdditionalPrizesWithLineOpacity);
|
||||
p.fillRect(skip.left(), top, fill, stroke, stm->msgDateFg);
|
||||
const auto start = outer - skip.left() - fill;
|
||||
p.fillRect(start, top, fill, stroke, stm->msgDateFg);
|
||||
p.setOpacity(1.);
|
||||
}
|
||||
}
|
||||
paintText(_prizes, _prizesTop, _prizesWidth);
|
||||
paintText(_participantsTitle, _participantsTitleTop, paintw);
|
||||
paintText(_participants, _participantsTop, _participantsWidth);
|
||||
|
|
|
@ -89,6 +89,8 @@ private:
|
|||
mutable std::optional<Sticker> _sticker;
|
||||
|
||||
Ui::Text::String _prizesTitle;
|
||||
Ui::Text::String _additional;
|
||||
Ui::Text::String _with;
|
||||
Ui::Text::String _prizes;
|
||||
Ui::Text::String _participantsTitle;
|
||||
Ui::Text::String _participants;
|
||||
|
@ -107,6 +109,9 @@ private:
|
|||
int _quantity = 0;
|
||||
int _stickerTop = 0;
|
||||
int _prizesTitleTop = 0;
|
||||
int _additionalTop = 0;
|
||||
int _additionalWidth = 0;
|
||||
int _withTop = 0;
|
||||
int _prizesTop = 0;
|
||||
int _prizesWidth = 0;
|
||||
int _participantsTitleTop = 0;
|
||||
|
|
|
@ -980,6 +980,8 @@ chatGiveawayBadgePadding: margins(7px, 1px, 5px, 3px);
|
|||
chatGiveawayBadgeStroke: 2px;
|
||||
chatGiveawayPrizesTop: 16px;
|
||||
chatGiveawayPrizesSkip: 4px;
|
||||
chatGiveawayPrizesWithPadding: margins(22px, 2px, 8px, 2px);
|
||||
chatGiveawayPrizesWithTop: 9px;
|
||||
chatGiveawayParticipantsTop: 16px;
|
||||
chatGiveawayParticipantsSkip: 4px;
|
||||
chatGiveawayChannelTop: 6px;
|
||||
|
|
Loading…
Add table
Reference in a new issue