From 1dade7b9f779cf496cb0521f781ef0da62d79584 Mon Sep 17 00:00:00 2001
From: Lily <112970249+lilyhuang-github@users.noreply.github.com>
Date: Tue, 11 Mar 2025 22:23:50 -0400
Subject: [PATCH] implement UI component
---
cockatrice/src/server/chat_view/chat_view.cpp | 34 ++++++++++---------
cockatrice/src/server/chat_view/chat_view.h | 1 +
cockatrice/src/server/message_log_widget.cpp | 27 +++++++++------
cockatrice/src/server/message_log_widget.h | 1 +
4 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/cockatrice/src/server/chat_view/chat_view.cpp b/cockatrice/src/server/chat_view/chat_view.cpp
index 8e0bca801..6463854a6 100644
--- a/cockatrice/src/server/chat_view/chat_view.cpp
+++ b/cockatrice/src/server/chat_view/chat_view.cpp
@@ -61,6 +61,7 @@ ChatView::ChatView(TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTime
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
setOpenLinks(false);
connect(this, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(openLink(const QUrl &)));
+ showInGameTime = SettingsCache::instance().getLocalTime();
}
void ChatView::retranslateUi()
@@ -102,11 +103,9 @@ void ChatView::appendHtml(const QString &html)
void ChatView::appendHtmlServerMessage(const QString &html, bool optionalIsBold, QString optionalFontColor)
{
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
- QString htmlText;
-
- htmlText = "" +
- QDateTime::currentDateTime().toString("[hh:mm:ss] ") + html + "";
-
+ QString htmlText = "" + getCurrentTime() + html + "";
+
if (optionalIsBold)
htmlText = "" + htmlText + "";
@@ -168,7 +167,7 @@ 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(getCurrentTime());
}
// nickname
@@ -459,16 +458,19 @@ bool ChatView::isModeratorSendingGlobal(QFlags u
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'));
+ 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] ");
+ }
}
void ChatView::actMessageClicked()
diff --git a/cockatrice/src/server/chat_view/chat_view.h b/cockatrice/src/server/chat_view/chat_view.h
index d2d9baf52..856e62eca 100644
--- a/cockatrice/src/server/chat_view/chat_view.h
+++ b/cockatrice/src/server/chat_view/chat_view.h
@@ -57,6 +57,7 @@ private:
QStringList highlightedWords;
bool evenNumber;
bool showTimestamps;
+ bool showInGameTime;
HoveredItemType hoveredItemType;
QString hoveredContent;
QAction *messageClicked;
diff --git a/cockatrice/src/server/message_log_widget.cpp b/cockatrice/src/server/message_log_widget.cpp
index 77f679581..69eb79eda 100644
--- a/cockatrice/src/server/message_log_widget.cpp
+++ b/cockatrice/src/server/message_log_widget.cpp
@@ -14,15 +14,19 @@
const QString MessageLogWidget::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'));
+ 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] ");
+ }
}
const QString &MessageLogWidget::tableConstant() const
@@ -628,13 +632,13 @@ void MessageLogWidget::logSetActivePhase(int phaseNumber)
soundEngine->playSound(phase.soundFileName);
- appendHtml("" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") +
+ appendHtml("" + getCurrentTime() +
phase.name + "");
}
void MessageLogWidget::logSetActivePlayer(Player *player)
{
- appendHtml("
" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") +
+ appendHtml("
" + getCurrentTime() +
QString(tr("%1's turn.")).arg(player->getName()) + "
");
}
@@ -874,6 +878,7 @@ void MessageLogWidget::connectToPlayer(Player *player)
MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, int *seconds, 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 b8b6dd665..833141bd1 100644
--- a/cockatrice/src/server/message_log_widget.h
+++ b/cockatrice/src/server/message_log_widget.h
@@ -26,6 +26,7 @@ private:
MessageContext currentContext;
QString messagePrefix, messageSuffix;
int *elapsedSeconds;
+ bool showInGameTime;
const QString getCurrentTime();
const QString &tableConstant() const;