From a2d1579ae5aaabe0d7e7ab4665f8dcb0637026b7 Mon Sep 17 00:00:00 2001
From: Lily <112970249+lilyhuang-github@users.noreply.github.com>
Date: Tue, 11 Mar 2025 15:42:09 -0400
Subject: [PATCH] Implement game time
---
cockatrice/src/server/chat_view/chat_view.cpp | 44 ++++++++++++++++---
cockatrice/src/server/chat_view/chat_view.h | 4 +-
cockatrice/src/server/message_log_widget.cpp | 3 +-
3 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/cockatrice/src/server/chat_view/chat_view.cpp b/cockatrice/src/server/chat_view/chat_view.cpp
index 33249829d..8a6a7afe8 100644
--- a/cockatrice/src/server/chat_view/chat_view.cpp
+++ b/cockatrice/src/server/chat_view/chat_view.cpp
@@ -43,7 +43,6 @@ ChatView::ChatView(TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTime
)");
linkColor = palette().link().color();
}
-
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
@@ -102,11 +101,19 @@ void ChatView::appendHtml(const QString &html)
void ChatView::appendHtmlServerMessage(const QString &html, bool optionalIsBold, QString optionalFontColor)
{
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
-
- QString htmlText =
+ QString htmlText;
+ /*QString htmlText =
"" +
- QDateTime::currentDateTime().toString("[hh:mm:ss] ") + html + "";
+ QDateTime::currentDateTime().toString("[hh:mm:ss] ") + html + "";*/
+ if (elapsedSeconds != nullptr) {
+ htmlText =
+ "" +
+ getCurrentTime() + html + "";
+ } else {
+ htmlText = "" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") + html + "";
+ }
if (optionalIsBold)
htmlText = "" + htmlText + "";
@@ -168,7 +175,14 @@ void ChatView::appendMessage(QString message,
timeFormat.setForeground(serverMessageColor);
timeFormat.setFontWeight(QFont::Bold);
cursor.setCharFormat(timeFormat);
- cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm:ss] "));
+
+ //cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm:ss] "));
+ if (elapsedSeconds != nullptr) {
+
+ cursor.insertText(getCurrentTime());
+ } else {
+ cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm:ss] "));
+ }
}
// nickname
@@ -457,6 +471,21 @@ bool ChatView::isModeratorSendingGlobal(QFlags u
(userLevel & ServerInfo_User::IsModerator || userLevel & ServerInfo_User::IsAdmin));
}
+QString ChatView::getCurrentTime()
+{
+
+ 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'));
+
+}
+
void ChatView::actMessageClicked()
{
emit messageClickedSignal();
@@ -535,6 +564,11 @@ 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 586ba90b3..d2d9baf52 100644
--- a/cockatrice/src/server/chat_view/chat_view.h
+++ b/cockatrice/src/server/chat_view/chat_view.h
@@ -44,6 +44,7 @@ private:
HoveredCard,
HoveredUser
};
+ int *elapsedSeconds{};
const UserListProxy *const userListProxy;
UserContextMenu *userContextMenu;
QString lastSender;
@@ -77,7 +78,7 @@ 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();
@@ -103,6 +104,7 @@ 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;
diff --git a/cockatrice/src/server/message_log_widget.cpp b/cockatrice/src/server/message_log_widget.cpp
index b09f75a05..153433980 100644
--- a/cockatrice/src/server/message_log_widget.cpp
+++ b/cockatrice/src/server/message_log_widget.cpp
@@ -875,8 +875,9 @@ void MessageLogWidget::connectToPlayer(Player *player)
}
MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, int *seconds, QWidget *parent)
- : ChatView(_tabSupervisor, _game, true,seconds, parent), mulliganNumber(0), currentContext(MessageContext_None)
+ : ChatView(_tabSupervisor, _game, true, parent), mulliganNumber(0), currentContext(MessageContext_None)
{
elapsedSeconds = seconds;
+ ChatView::setTime(seconds);
}