Support different backgrounds for paid comments.

This commit is contained in:
John Preston
2025-10-24 12:41:29 +04:00
parent 797b2a5085
commit 6b05d253a7
8 changed files with 142 additions and 27 deletions

View File

@@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/peers/prepare_short_info_box.h"
#include "boxes/premium_preview_box.h"
#include "calls/group/ui/calls_group_stars_coloring.h"
#include "calls/group/calls_group_messages.h"
#include "chat_helpers/compose/compose_show.h"
#include "chat_helpers/emoji_suggestions_widget.h"
@@ -33,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/text_utilities.h"
#include "ui/widgets/fields/input_field.h"
#include "ui/widgets/elastic_scroll.h"
#include "ui/color_int_conversion.h"
#include "ui/painter.h"
#include "ui/ui_utility.h"
#include "ui/userpic_view.h"
@@ -49,6 +51,7 @@ namespace Calls::Group {
namespace {
constexpr auto kMessageBgOpacity = 0.8;
constexpr auto kColoredMessageBgOpacity = 0.6;
[[nodiscard]] int CountMessageRadius() {
const auto minHeight = st::groupCallMessagePadding.top()
@@ -57,6 +60,10 @@ constexpr auto kMessageBgOpacity = 0.8;
return minHeight / 2;
}
[[nodiscard]] uint64 ColoringKey(const Ui::StarsColoring &value) {
return (uint64(uint32(value.bg1)) << 32) | uint64(uint32(value.bg2));
}
void ReceiveSomeMouseEvents(
not_null<Ui::ElasticScroll*> scroll,
Fn<bool(QPoint)> handleClick) {
@@ -165,6 +172,11 @@ struct MessagesUi::MessageView {
bool failed = false;
};
MessagesUi::PayedBg::PayedBg(const Ui::StarsColoring &coloring)
: color(Ui::ColorFromSerialized(coloring.bg2))
, rounded(CountMessageRadius(), color.color()) {
}
MessagesUi::MessagesUi(
not_null<QWidget*> parent,
std::shared_ptr<ChatHelpers::Show> show,
@@ -181,7 +193,6 @@ MessagesUi::MessagesUi(
return result;
})
, _messageBgRect(CountMessageRadius(), _messageBg.color())
, _payedBgRect(CountMessageRadius(), st::creditsBg3)
, _fadeHeight(st::normalFont->height)
, _streamMode(_mode == MessagesMode::VideoStream) {
setupList(std::move(messages), std::move(shown));
@@ -732,7 +743,14 @@ void MessagesUi::setupMessagesWidget() {
if (!_streamMode) {
_messageBgRect.paint(p, { x, y, width, use });
} else if (entry.stars) {
_payedBgRect.paint(p, { x, y, width, use });
const auto coloring = Ui::StarsColoringForCount(entry.stars);
auto &bg = _bgs[ColoringKey(coloring)];
if (!bg) {
bg = std::make_unique<PayedBg>(coloring);
}
p.setOpacity(kColoredMessageBgOpacity);
bg->rounded.paint(p, { x, y, width, use });
p.setOpacity(1.);
}
auto leftSkip = padding.left();

View File

@@ -29,6 +29,11 @@ class SendButton;
class RpWidget;
} // namespace Ui
namespace Calls::Group::Ui {
using namespace ::Ui;
struct StarsColoring;
} // namespace Calls::Group::Ui
namespace Calls::Group {
struct Message;
@@ -57,6 +62,12 @@ public:
private:
struct MessageView;
struct PayedBg {
PayedBg(const Ui::StarsColoring &coloring);
style::owned_color color;
Ui::RoundRect rounded;
};
void setupList(
rpl::producer<std::vector<Message>> messages,
@@ -98,7 +109,7 @@ private:
style::complex_color _messageBg;
Ui::RoundRect _messageBgRect;
Ui::RoundRect _payedBgRect;
base::flat_map<uint64, std::unique_ptr<PayedBg>> _bgs;
QPoint _reactionBasePosition;
rpl::lifetime _effectsLifetime;

View File

@@ -70,14 +70,56 @@ namespace {
} // namespace
StarsColoring StarsColoringForCount(int stars) {
//name: "Purple" [STRING],
//center_color: 11431086 [INT],
//edge_color: 8669060 [INT],
//pattern_color: 4656199 [INT],
//text_color: 15977459 [INT],
//name: "Celtic Blue" [STRING],
//center_color: 4569325 [INT],
//edge_color: 3704537 [INT],
//pattern_color: 16005 [INT],
//text_color: 12773375 [INT],
//name: "Mint Green" [STRING],
//center_color: 8309634 [INT],
//edge_color: 4562522 [INT],
//pattern_color: 158498 [INT],
//text_color: 12451788 [INT],
//name: "Pure Gold" [STRING],
//center_color: 13413185 [INT],
//edge_color: 9993010 [INT],
//pattern_color: 7355392 [INT],
//text_color: 16770475 [INT],
//name: "Orange" [STRING],
//center_color: 13736506 [INT],
//edge_color: 12611399 [INT],
//pattern_color: 10303751 [INT],
//text_color: 16769475 [INT],
//name: "Strawberry" [STRING],
//center_color: 14519919 [INT],
//edge_color: 12016224 [INT],
//pattern_color: 11078668 [INT],
//text_color: 16765907 [INT],
//name: "Steel Grey" [STRING],
//center_color: 9937580 [INT],
//edge_color: 6517372 [INT],
//pattern_color: 3360082 [INT],
//text_color: 14673128 [INT],
const auto list = std::vector<StarsColoring>{
{ st::creditsBg3->c, st::creditsBg2->c, 50, 1, 60, 1 },
{ st::creditsBg3->c, st::creditsBg2->c, 100, 1, 80, 2 },
{ st::creditsBg3->c, st::creditsBg2->c, 250, 5, 110, 3 },
{ st::creditsBg3->c, st::creditsBg2->c, 500, 10, 150, 4 },
{ st::creditsBg3->c, st::creditsBg2->c, 2000, 15, 200, 7 },
{ st::creditsBg3->c, st::creditsBg2->c, 7500, 30, 280, 10 },
{ st::creditsBg3->c, st::creditsBg2->c, 0, 60, 400, 20 },
{ 11431086, 8669060, 50, 1, 60, 1 },
{ 4569325, 3704537, 100, 1, 80, 2 },
{ 8309634, 4562522, 250, 5, 110, 3 },
{ 13413185, 9993010, 500, 10, 150, 4 },
{ 13736506, 12611399, 2000, 15, 200, 7 },
{ 14519919, 12016224, 7500, 30, 280, 10 },
{ 9937580, 6517372, 0, 60, 400, 20 },
};
for (const auto &entry : list) {
if (!entry.tillStars || stars < entry.tillStars) {

View File

@@ -16,8 +16,8 @@ namespace Calls::Group::Ui {
using namespace ::Ui;
struct StarsColoring {
QColor bg1;
QColor bg2;
int bg1 = 0;
int bg2 = 0;
int tillStars = 0;
int minutesPin = 0;
int charactersMax = 0;