diff --git a/cockatrice/src/client/tabs/tab_game.cpp b/cockatrice/src/client/tabs/tab_game.cpp index 999b5b164..60943e2bd 100644 --- a/cockatrice/src/client/tabs/tab_game.cpp +++ b/cockatrice/src/client/tabs/tab_game.cpp @@ -410,6 +410,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); @@ -448,15 +453,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) 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/dialogs/dlg_settings.cpp b/cockatrice/src/dialogs/dlg_settings.cpp index 502662c14..17b9af5c8 100644 --- a/cockatrice/src/dialogs/dlg_settings.cpp +++ b/cockatrice/src/dialogs/dlg_settings.cpp @@ -1138,6 +1138,9 @@ MessagesSettingsPage::MessagesSettingsPage() connect(&messagePopups, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), &SettingsCache::setShowMessagePopups); + localTimeCheckBox.setChecked(SettingsCache::instance().getLocalTime()); + connect(&localTimeCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), &SettingsCache::setLocalTime); + mentionPopups.setChecked(SettingsCache::instance().getShowMentionPopup()); connect(&mentionPopups, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), &SettingsCache::setShowMentionPopups); @@ -1160,6 +1163,7 @@ MessagesSettingsPage::MessagesSettingsPage() chatGrid->addWidget(&messagePopups, 4, 0); chatGrid->addWidget(&mentionPopups, 5, 0); chatGrid->addWidget(&roomHistory, 6, 0); + chatGrid->addWidget(&localTimeCheckBox, 7, 0); chatGroupBox = new QGroupBox; chatGroupBox->setLayout(chatGrid); @@ -1342,6 +1346,7 @@ void MessagesSettingsPage::retranslateUi() aAdd->setText(tr("Add New Message")); aEdit->setText(tr("Edit Message")); aRemove->setText(tr("Remove Message")); + localTimeCheckBox.setText(tr("Use Room Time over Real-Life Time")); } SoundSettingsPage::SoundSettingsPage() diff --git a/cockatrice/src/dialogs/dlg_settings.h b/cockatrice/src/dialogs/dlg_settings.h index 6c9b8b062..2f729e346 100644 --- a/cockatrice/src/dialogs/dlg_settings.h +++ b/cockatrice/src/dialogs/dlg_settings.h @@ -241,6 +241,7 @@ private: QCheckBox invertHighlightForeground; QCheckBox ignoreUnregUsersMainChat; QCheckBox ignoreUnregUserMessages; + QCheckBox localTimeCheckBox; QCheckBox messagePopups; QCheckBox mentionPopups; QCheckBox roomHistory; diff --git a/cockatrice/src/server/chat_view/chat_view.cpp b/cockatrice/src/server/chat_view/chat_view.cpp index f204ea9b4..1ffe696b4 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, &ChatView::anchorClicked, this, &ChatView::openLink); + showInGameTime = SettingsCache::instance().getLocalTime(); } void ChatView::retranslateUi() @@ -102,10 +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 = "" + - QDateTime::currentDateTime().toString("[hh:mm:ss] ") + html + ""; + getCurrentTime() + html + ""; if (optionalIsBold) htmlText = "" + htmlText + ""; @@ -168,7 +168,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 @@ -457,6 +457,15 @@ bool ChatView::isModeratorSendingGlobal(QFlags u (userLevel & ServerInfo_User::IsModerator || userLevel & ServerInfo_User::IsAdmin)); } +QString ChatView::getCurrentTime() const +{ + if (game && showInGameTime) { + return game->getCurrentInGameTime(); + } else { + return QDateTime::currentDateTime().toString("[hh:mm:ss] "); + } +} + void ChatView::actMessageClicked() { emit messageClickedSignal(); diff --git a/cockatrice/src/server/chat_view/chat_view.h b/cockatrice/src/server/chat_view/chat_view.h index 586ba90b3..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 { @@ -56,6 +56,7 @@ private: QStringList highlightedWords; bool evenNumber; bool showTimestamps; + bool showInGameTime; HoveredItemType hoveredItemType; QString hoveredContent; QAction *messageClicked; @@ -77,7 +78,6 @@ private: QColor otherUserColor = QColor(0, 65, 255); // dark blue QColor serverMessageColor = QColor(0x85, 0x15, 0x15); QColor linkColor; - private slots: void openLink(const QUrl &link); void actMessageClicked(); @@ -106,6 +106,7 @@ protected: 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 7ee275377..362611120 100644 --- a/cockatrice/src/server/message_log_widget.cpp +++ b/cockatrice/src/server/message_log_widget.cpp @@ -12,6 +12,11 @@ #include +const QString MessageLogWidget::getCurrentTime() +{ + return ChatView::getCurrentTime(); +} + const QString &MessageLogWidget::tableConstant() const { static const QString constant("table"); @@ -615,14 +620,13 @@ void MessageLogWidget::logSetActivePhase(int phaseNumber) soundEngine->playSound(phase.soundFileName); - appendHtml("" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") + - phase.getName() + ""); + appendHtml("" + getCurrentTime() + phase.getName() + ""); } void MessageLogWidget::logSetActivePlayer(Player *player) { - appendHtml("
" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") + - QString(tr("%1's turn.")).arg(player->getName()) + "
"); + appendHtml("
" + getCurrentTime() + QString(tr("%1's turn.")).arg(player->getName()) + + "
"); } void MessageLogWidget::logSetAnnotation(Player *player, CardItem *card, QString newAnnotation) diff --git a/cockatrice/src/server/message_log_widget.h b/cockatrice/src/server/message_log_widget.h index ef66f21e7..8eed1b05b 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; + const QString getCurrentTime(); const QString &tableConstant() const; const QString &graveyardConstant() const; const QString &exileConstant() const; diff --git a/cockatrice/src/settings/cache_settings.cpp b/cockatrice/src/settings/cache_settings.cpp index ba25590f3..51279ab82 100644 --- a/cockatrice/src/settings/cache_settings.cpp +++ b/cockatrice/src/settings/cache_settings.cpp @@ -342,6 +342,7 @@ SettingsCache::SettingsCache() rememberGameSettings = settings->value("game/remembergamesettings", true).toBool(); clientID = settings->value("personal/clientid", CLIENT_INFO_NOT_SET).toString(); clientVersion = settings->value("personal/clientversion", CLIENT_INFO_NOT_SET).toString(); + localTime = settings->value("chat/localtime", false).toBool(); } void SettingsCache::setUseTearOffMenus(bool _useTearOffMenus) @@ -431,6 +432,12 @@ void SettingsCache::setRoomHistory(const QT_STATE_CHANGED_T _roomHistory) settings->setValue("chat/roomhistory", roomHistory); } +void SettingsCache::setLocalTime(const QT_STATE_CHANGED_T _localTime) +{ + localTime = (bool)_localTime; + settings->setValue("chat/localtime", localTime); +} + void SettingsCache::setLang(const QString &_lang) { lang = _lang; diff --git a/cockatrice/src/settings/cache_settings.h b/cockatrice/src/settings/cache_settings.h index 78993ce4a..27b973a5a 100644 --- a/cockatrice/src/settings/cache_settings.h +++ b/cockatrice/src/settings/cache_settings.h @@ -215,6 +215,7 @@ private: bool rememberGameSettings; QList releaseChannels; bool isPortableBuild; + bool localTime; bool roundCardCorners; public: @@ -602,6 +603,10 @@ public: { return showMessagePopups; } + bool getLocalTime() const + { + return localTime; + } bool getShowMentionPopup() const { return showMentionPopups; @@ -865,6 +870,7 @@ public slots: void setCardScaling(const QT_STATE_CHANGED_T _scaleCards); void setStackCardOverlapPercent(const int _verticalCardOverlapPercent); void setShowMessagePopups(const QT_STATE_CHANGED_T _showMessagePopups); + void setLocalTime(const QT_STATE_CHANGED_T _showMessagePopups); void setShowMentionPopups(const QT_STATE_CHANGED_T _showMentionPopups); void setRoomHistory(const QT_STATE_CHANGED_T _roomHistory); void setLeftJustified(const QT_STATE_CHANGED_T _leftJustified); diff --git a/dbconverter/src/mocks.cpp b/dbconverter/src/mocks.cpp index 93048d3cf..f9d79ef82 100644 --- a/dbconverter/src/mocks.cpp +++ b/dbconverter/src/mocks.cpp @@ -88,6 +88,9 @@ void SettingsCache::setStackCardOverlapPercent(const int /* _verticalCardOverlap void SettingsCache::setShowMessagePopups(const QT_STATE_CHANGED_T /* _showMessagePopups */) { } +void SettingsCache::setLocalTime(const QT_STATE_CHANGED_T /*_LocalTime*/) +{ +} void SettingsCache::setShowMentionPopups(const QT_STATE_CHANGED_T /* _showMentionPopus */) { } diff --git a/tests/carddatabase/mocks.cpp b/tests/carddatabase/mocks.cpp index a2ca73fb1..ecaae9361 100644 --- a/tests/carddatabase/mocks.cpp +++ b/tests/carddatabase/mocks.cpp @@ -311,6 +311,9 @@ void SettingsCache::setZoneViewGroupByIndex(int /* _zoneViewGroupByIndex */) void SettingsCache::setZoneViewSortByIndex(int /* _zoneViewSortByIndex */) { } +void SettingsCache::setLocalTime(const QT_STATE_CHANGED_T /*_LocalTime*/) +{ +} void SettingsCache::setZoneViewPileView(QT_STATE_CHANGED_T /* _zoneViewPileView */) { } diff --git a/vcpkg b/vcpkg index c63619856..6f29f12e8 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit c63619856b89f0af4d77ba2049396039e4985418 +Subproject commit 6f29f12e82a8293156836ad81cc9bf5af41fe836