Click replay timeline to seek. (#3570)

* Click replay timeline to seek.

* Fix seek for long games

* Erase log when rewinding

* zach cleanup

Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com>
This commit is contained in:
Rob Blanckaert 2019-02-08 17:32:56 -08:00 committed by Zach H
parent b065ada633
commit 612edae5f6
3 changed files with 29 additions and 12 deletions

View file

@ -22,12 +22,12 @@ void ReplayTimelineWidget::setTimeline(const QList<int> &_replayTimeline)
histogram.clear(); histogram.clear();
int binEndTime = binLength - 1; int binEndTime = binLength - 1;
int binValue = 0; int binValue = 0;
for (int i = 0; i < replayTimeline.size(); ++i) { for (int i : replayTimeline) {
if (replayTimeline[i] > binEndTime) { if (i > binEndTime) {
histogram.append(binValue); histogram.append(binValue);
if (binValue > maxBinValue) if (binValue > maxBinValue)
maxBinValue = binValue; maxBinValue = binValue;
while (replayTimeline[i] > binEndTime + binLength) { while (i > binEndTime + binLength) {
histogram.append(0); histogram.append(0);
binEndTime += binLength; binEndTime += binLength;
} }
@ -59,17 +59,30 @@ void ReplayTimelineWidget::paintEvent(QPaintEvent * /* event */)
const QColor barColor = QColor::fromHsv(120, 255, 255, 100); const QColor barColor = QColor::fromHsv(120, 255, 255, 100);
quint64 w = (quint64)(width() - 1) * (quint64)currentTime / maxTime; quint64 w = (quint64)(width() - 1) * (quint64)currentTime / maxTime;
painter.fillRect(0, 0, w, height() - 1, barColor); painter.fillRect(0, 0, static_cast<int>(w), height() - 1, barColor);
}
void ReplayTimelineWidget::mousePressEvent(QMouseEvent *event)
{
int newTime = static_cast<int>((long)maxTime * (long)event->x() / width());
if (newTime < currentTime) {
currentTime = 0;
currentEvent = 0;
emit rewound();
}
currentTime = newTime - 200; // 200 is added back in replayTimerTimeout
replayTimerTimeout();
update();
} }
QSize ReplayTimelineWidget::sizeHint() const QSize ReplayTimelineWidget::sizeHint() const
{ {
return QSize(-1, 50); return {-1, 50};
} }
QSize ReplayTimelineWidget::minimumSizeHint() const QSize ReplayTimelineWidget::minimumSizeHint() const
{ {
return QSize(400, 50); return {400, 50};
} }
void ReplayTimelineWidget::replayTimerTimeout() void ReplayTimelineWidget::replayTimerTimeout()
@ -91,12 +104,12 @@ void ReplayTimelineWidget::replayTimerTimeout()
void ReplayTimelineWidget::setTimeScaleFactor(qreal _timeScaleFactor) void ReplayTimelineWidget::setTimeScaleFactor(qreal _timeScaleFactor)
{ {
timeScaleFactor = _timeScaleFactor; timeScaleFactor = _timeScaleFactor;
replayTimer->setInterval(200 / timeScaleFactor); replayTimer->setInterval(static_cast<int>(200 / timeScaleFactor));
} }
void ReplayTimelineWidget::startReplay() void ReplayTimelineWidget::startReplay()
{ {
replayTimer->start(200 / timeScaleFactor); replayTimer->start(static_cast<int>(200 / timeScaleFactor));
} }
void ReplayTimelineWidget::stopReplay() void ReplayTimelineWidget::stopReplay()

View file

@ -2,6 +2,7 @@
#define REPLAY_TIMELINE_WIDGET #define REPLAY_TIMELINE_WIDGET
#include <QList> #include <QList>
#include <QMouseEvent>
#include <QWidget> #include <QWidget>
class QPaintEvent; class QPaintEvent;
@ -13,6 +14,7 @@ class ReplayTimelineWidget : public QWidget
signals: signals:
void processNextEvent(); void processNextEvent();
void replayFinished(); void replayFinished();
void rewound();
private: private:
QTimer *replayTimer; QTimer *replayTimer;
@ -27,10 +29,10 @@ private slots:
void replayTimerTimeout(); void replayTimerTimeout();
public: public:
ReplayTimelineWidget(QWidget *parent = 0); explicit ReplayTimelineWidget(QWidget *parent = nullptr);
void setTimeline(const QList<int> &_replayTimeline); void setTimeline(const QList<int> &_replayTimeline);
QSize sizeHint() const; QSize sizeHint() const override;
QSize minimumSizeHint() const; QSize minimumSizeHint() const override;
void setTimeScaleFactor(qreal _timeScaleFactor); void setTimeScaleFactor(qreal _timeScaleFactor);
int getCurrentEvent() const int getCurrentEvent() const
{ {
@ -41,7 +43,8 @@ public slots:
void stopReplay(); void stopReplay();
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
}; };
#endif #endif

View file

@ -1604,6 +1604,7 @@ void TabGame::createReplayDock()
timelineWidget->setTimeline(replayTimeline); timelineWidget->setTimeline(replayTimeline);
connect(timelineWidget, SIGNAL(processNextEvent()), this, SLOT(replayNextEvent())); connect(timelineWidget, SIGNAL(processNextEvent()), this, SLOT(replayNextEvent()));
connect(timelineWidget, SIGNAL(replayFinished()), this, SLOT(replayFinished())); connect(timelineWidget, SIGNAL(replayFinished()), this, SLOT(replayFinished()));
connect(timelineWidget, &ReplayTimelineWidget::rewound, messageLog, &ChatView::clearChat);
replayStartButton = new QToolButton; replayStartButton = new QToolButton;
replayStartButton->setIconSize(QSize(32, 32)); replayStartButton->setIconSize(QSize(32, 32));