2020-03-04 09:21:19 +00:00
|
|
|
/*
|
|
|
|
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 "history/view/media/history_view_dice.h"
|
|
|
|
|
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "chat_helpers/stickers_dice_pack.h"
|
|
|
|
#include "history/history.h"
|
|
|
|
#include "history/history_item.h"
|
2020-03-06 09:48:29 +00:00
|
|
|
#include "history/history_item_components.h"
|
2020-03-04 09:21:19 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
2020-03-30 11:21:16 +00:00
|
|
|
#include "ui/toast/toast.h"
|
|
|
|
#include "lang/lang_keys.h"
|
2020-03-04 09:21:19 +00:00
|
|
|
#include "main/main_session.h"
|
|
|
|
|
|
|
|
namespace HistoryView {
|
|
|
|
namespace {
|
|
|
|
|
2020-04-06 09:07:49 +00:00
|
|
|
[[nodiscard]] DocumentData *Lookup(
|
|
|
|
not_null<Element*> view,
|
|
|
|
const QString &emoji,
|
|
|
|
int value) {
|
2020-03-04 09:21:19 +00:00
|
|
|
const auto &session = view->data()->history()->session();
|
2020-04-06 09:07:49 +00:00
|
|
|
return session.diceStickersPacks().lookup(emoji, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] ClickHandlerPtr MakeDiceHandler(const QString &emoji) {
|
|
|
|
return std::make_shared<LambdaClickHandler>([=] {
|
|
|
|
auto config = Ui::Toast::Config();
|
|
|
|
config.multiline = true;
|
|
|
|
config.minWidth = st::msgMinWidth;
|
|
|
|
config.text = { tr::lng_about_random(tr::now, lt_emoji, emoji) };
|
|
|
|
Ui::Toast::Show(config);
|
|
|
|
});
|
2020-03-04 09:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-03-06 12:12:03 +00:00
|
|
|
Dice::Dice(not_null<Element*> parent, not_null<Data::MediaDice*> dice)
|
2020-03-04 09:21:19 +00:00
|
|
|
: _parent(parent)
|
2020-03-06 12:12:03 +00:00
|
|
|
, _dice(dice)
|
2020-04-06 09:07:49 +00:00
|
|
|
, _link(_parent->data()->Has<HistoryMessageForwarded>()
|
|
|
|
? nullptr
|
|
|
|
: MakeDiceHandler(dice->emoji()))
|
|
|
|
, _start(parent, Lookup(parent, dice->emoji(), 0)) {
|
2020-03-06 09:48:29 +00:00
|
|
|
_showLastFrame = _parent->data()->Has<HistoryMessageForwarded>();
|
2020-04-06 09:07:49 +00:00
|
|
|
_start.setDiceIndex(_dice->emoji(), 0);
|
2020-03-06 09:48:29 +00:00
|
|
|
if (_showLastFrame) {
|
|
|
|
_drawingEnd = true;
|
|
|
|
}
|
2020-03-04 09:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Dice::~Dice() = default;
|
|
|
|
|
|
|
|
QSize Dice::size() {
|
|
|
|
return _start.size();
|
|
|
|
}
|
|
|
|
|
2020-03-30 11:21:16 +00:00
|
|
|
ClickHandlerPtr Dice::link() {
|
2020-04-06 09:07:49 +00:00
|
|
|
return _link;
|
2020-03-30 11:21:16 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 09:21:19 +00:00
|
|
|
void Dice::draw(Painter &p, const QRect &r, bool selected) {
|
2020-04-06 09:07:49 +00:00
|
|
|
if (const auto value = _end ? 0 : _dice->value()) {
|
|
|
|
if (const auto document = Lookup(_parent, _dice->emoji(), value)) {
|
2020-03-06 09:48:29 +00:00
|
|
|
_end.emplace(_parent, document);
|
2020-04-06 09:07:49 +00:00
|
|
|
_end->setDiceIndex(_dice->emoji(), value);
|
2020-03-06 09:48:29 +00:00
|
|
|
_end->initSize();
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 08:06:28 +00:00
|
|
|
if (!_end) {
|
|
|
|
_drawingEnd = false;
|
|
|
|
}
|
2020-03-04 09:21:19 +00:00
|
|
|
if (_drawingEnd) {
|
|
|
|
_end->draw(p, r, selected);
|
|
|
|
} else {
|
|
|
|
_start.draw(p, r, selected);
|
|
|
|
if (_end && _end->readyToDrawLottie() && _start.atTheEnd()) {
|
|
|
|
_drawingEnd = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace HistoryView
|