From 15c1b429fca601430ba81870ec1b1b06a6947027 Mon Sep 17 00:00:00 2001 From: Lily <112970249+lilyhuang-github@users.noreply.github.com> Date: Sat, 12 Apr 2025 12:22:21 -0400 Subject: [PATCH] update logic to tab_game, and make message_log_widet/chat_view reliant --- cockatrice/src/client/tabs/tab_game.cpp | 18 ++++++++---------- cockatrice/src/client/tabs/tab_game.h | 2 ++ cockatrice/src/server/chat_view/chat_view.cpp | 17 ++--------------- cockatrice/src/server/chat_view/chat_view.h | 6 ++---- cockatrice/src/server/message_log_widget.cpp | 19 ++----------------- cockatrice/src/server/message_log_widget.h | 4 +--- 6 files changed, 17 insertions(+), 49 deletions(-) diff --git a/cockatrice/src/client/tabs/tab_game.cpp b/cockatrice/src/client/tabs/tab_game.cpp index 4fb53d0d2..317778006 100644 --- a/cockatrice/src/client/tabs/tab_game.cpp +++ b/cockatrice/src/client/tabs/tab_game.cpp @@ -408,6 +408,11 @@ void TabGame::closeRequest(bool forced) close(); } +QString TabGame::getCurrentInGameTime() const +{ + return QTime::fromMSecsSinceStartOfDay(secondsElapsed * 1000).toString("[hh:mm:ss] "); +} + void TabGame::replayNextEvent(Player::EventProcessingOptions options) { processGameEventContainer(replay->event_list(timelineWidget->getCurrentEvent()), nullptr, options); @@ -446,15 +451,8 @@ void TabGame::replayRewind() void TabGame::incrementGameTime() { - int seconds = ++secondsElapsed; - int minutes = seconds / 60; - seconds -= minutes * 60; - int hours = minutes / 60; - minutes -= hours * 60; - - timeElapsedLabel->setText(QString::number(hours).rightJustified(2, '0') + ":" + - QString::number(minutes).rightJustified(2, '0') + ":" + - QString::number(seconds).rightJustified(2, '0')); + ++secondsElapsed; + timeElapsedLabel->setText(getCurrentInGameTime()); } void TabGame::adminLockChanged(bool lock) @@ -1679,7 +1677,7 @@ void TabGame::createPlayerListDock(bool bReplay) void TabGame::createMessageDock(bool bReplay) { - messageLog = new MessageLogWidget(tabSupervisor, this, &secondsElapsed); + messageLog = new MessageLogWidget(tabSupervisor, this); connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfoFrameWidget, SLOT(setCard(QString))); connect(messageLog, &MessageLogWidget::showCardInfoPopup, this, &TabGame::showCardInfoPopup); connect(messageLog, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString))); diff --git a/cockatrice/src/client/tabs/tab_game.h b/cockatrice/src/client/tabs/tab_game.h index 096998728..b791810c0 100644 --- a/cockatrice/src/client/tabs/tab_game.h +++ b/cockatrice/src/client/tabs/tab_game.h @@ -92,6 +92,7 @@ private: QCompleter *completer; QStringList autocompleteUserList; QStackedWidget *mainWidget; + bool showInGameTime; // Replay related members GameReplay *replay; @@ -224,6 +225,7 @@ public: void retranslateUi() override; void updatePlayerListDockTitle(); void closeRequest(bool forced = false) override; + QString getCurrentInGameTime() const; const QMap &getPlayers() const { return players; diff --git a/cockatrice/src/server/chat_view/chat_view.cpp b/cockatrice/src/server/chat_view/chat_view.cpp index 876abb300..e4d9eb14d 100644 --- a/cockatrice/src/server/chat_view/chat_view.cpp +++ b/cockatrice/src/server/chat_view/chat_view.cpp @@ -457,18 +457,10 @@ bool ChatView::isModeratorSendingGlobal(QFlags u (userLevel & ServerInfo_User::IsModerator || userLevel & ServerInfo_User::IsAdmin)); } -QString ChatView::getCurrentTime() +QString ChatView::getCurrentTime() const { if (showInGameTime) { - int seconds = *elapsedSeconds; - int minutes = seconds / 60; - seconds -= minutes * 60; - int hours = minutes / 60; - minutes -= hours * 60; - return QString("[%1:%2:%3] ") - .arg(QString::number(hours).rightJustified(2, '0')) - .arg(QString::number(minutes).rightJustified(2, '0')) - .arg(QString::number(seconds).rightJustified(2, '0')); + return game->getCurrentInGameTime(); } else { return QDateTime::currentDateTime().toString("[hh:mm:ss] "); } @@ -552,11 +544,6 @@ void ChatView::leaveEvent(QEvent * /*event*/) setMouseTracking(false); } -void ChatView::setTime(int *time) -{ - elapsedSeconds = time; -} - QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const { QTextCursor cursor(cursorForPosition(pos)); diff --git a/cockatrice/src/server/chat_view/chat_view.h b/cockatrice/src/server/chat_view/chat_view.h index 856e62eca..33488c660 100644 --- a/cockatrice/src/server/chat_view/chat_view.h +++ b/cockatrice/src/server/chat_view/chat_view.h @@ -1,6 +1,7 @@ #ifndef CHATVIEW_H #define CHATVIEW_H +#include "../../client/tabs/tab_game.h" #include "../../client/tabs/tab_supervisor.h" #include "../user/user_list_widget.h" #include "room_message_type.h" @@ -16,7 +17,6 @@ class QTextTable; class QMouseEvent; class UserContextMenu; class UserListProxy; -class TabGame; class UserMessagePosition { @@ -44,7 +44,6 @@ private: HoveredCard, HoveredUser }; - int *elapsedSeconds{}; const UserListProxy *const userListProxy; UserContextMenu *userContextMenu; QString lastSender; @@ -79,7 +78,6 @@ private: QColor otherUserColor = QColor(0, 65, 255); // dark blue QColor serverMessageColor = QColor(0x85, 0x15, 0x15); QColor linkColor; - QString getCurrentTime(); private slots: void openLink(const QUrl &link); void actMessageClicked(); @@ -105,10 +103,10 @@ protected: void enterEvent(QEvent *event) override; #endif void leaveEvent(QEvent *event) override; - void setTime(int *time); void mouseMoveEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; + QString getCurrentTime() const; signals: void openMessageDialog(const QString &userName, bool focus); void cardNameHovered(QString cardName); diff --git a/cockatrice/src/server/message_log_widget.cpp b/cockatrice/src/server/message_log_widget.cpp index 77116191f..fdaf0eafd 100644 --- a/cockatrice/src/server/message_log_widget.cpp +++ b/cockatrice/src/server/message_log_widget.cpp @@ -14,19 +14,7 @@ const QString MessageLogWidget::getCurrentTime() { - if (showInGameTime) { - int seconds = *elapsedSeconds; - int minutes = seconds / 60; - seconds -= minutes * 60; - int hours = minutes / 60; - minutes -= hours * 60; - return QString("[%1:%2:%3] ") - .arg(QString::number(hours).rightJustified(2, '0')) - .arg(QString::number(minutes).rightJustified(2, '0')) - .arg(QString::number(seconds).rightJustified(2, '0')); - } else { - return QDateTime::currentDateTime().toString("[hh:mm:ss] "); - } + return ChatView::getCurrentTime(); } const QString &MessageLogWidget::tableConstant() const @@ -874,10 +862,7 @@ void MessageLogWidget::connectToPlayer(Player *player) SLOT(logAlwaysLookAtTopCard(Player *, CardZone *, bool))); } -MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, int *seconds, QWidget *parent) +MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent) : ChatView(_tabSupervisor, _game, true, parent), mulliganNumber(0), currentContext(MessageContext_None) { - showInGameTime = SettingsCache::instance().getLocalTime(); - elapsedSeconds = seconds; - ChatView::setTime(seconds); } diff --git a/cockatrice/src/server/message_log_widget.h b/cockatrice/src/server/message_log_widget.h index 833141bd1..8eed1b05b 100644 --- a/cockatrice/src/server/message_log_widget.h +++ b/cockatrice/src/server/message_log_widget.h @@ -25,8 +25,6 @@ private: Player *mulliganPlayer; MessageContext currentContext; QString messagePrefix, messageSuffix; - int *elapsedSeconds; - bool showInGameTime; const QString getCurrentTime(); const QString &tableConstant() const; @@ -105,7 +103,7 @@ public slots: public: void connectToPlayer(Player *player); - MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, int *elapsedSeconds, QWidget *parent = nullptr); + MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent = nullptr); }; #endif