mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[Client] Add option to use game time in game log timestamps (#2202)
Game log timestamps showed the local clock time, which is meaningless in a replay or in a log read after the fact — nobody can tell when a play happened relative to the game. Add a "Use game time instead of local time in game logs" setting. When enabled, the message log stamps entries with the elapsed game time (HH:MM:SS since the game started); regular chat views keep the local clock.
This commit is contained in:
parent
0f003eabf9
commit
9dac371ead
12 changed files with 63 additions and 8 deletions
|
|
@ -29,13 +29,17 @@ void GameState::incrementGameTime()
|
|||
void GameState::setGameTime(int _secondsElapsed)
|
||||
{
|
||||
secondsElapsed = _secondsElapsed;
|
||||
emit updateTimeElapsedLabel(formatElapsedTime(_secondsElapsed));
|
||||
}
|
||||
|
||||
QString GameState::formatElapsedTime(int _secondsElapsed)
|
||||
{
|
||||
int seconds = _secondsElapsed;
|
||||
int minutes = seconds / 60;
|
||||
seconds -= minutes * 60;
|
||||
int hours = minutes / 60;
|
||||
minutes -= hours * 60;
|
||||
|
||||
emit updateTimeElapsedLabel(QString::number(hours).rightJustified(2, '0') + ":" +
|
||||
QString::number(minutes).rightJustified(2, '0') + ":" +
|
||||
QString::number(seconds).rightJustified(2, '0'));
|
||||
return QString::number(hours).rightJustified(2, '0') + ":" + QString::number(minutes).rightJustified(2, '0') + ":" +
|
||||
QString::number(seconds).rightJustified(2, '0');
|
||||
}
|
||||
|
|
@ -110,6 +110,11 @@ public:
|
|||
return hostId;
|
||||
}
|
||||
|
||||
int getSecondsElapsed() const
|
||||
{
|
||||
return secondsElapsed;
|
||||
}
|
||||
|
||||
signals:
|
||||
void updateTimeElapsedLabel(QString newTime);
|
||||
void gameStarted(bool resuming);
|
||||
|
|
@ -120,6 +125,7 @@ signals:
|
|||
public slots:
|
||||
void incrementGameTime();
|
||||
void setGameTime(int _secondsElapsed);
|
||||
static QString formatElapsedTime(int _secondsElapsed);
|
||||
|
||||
private:
|
||||
QTimer *gameTimer;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#include "message_log_widget.h"
|
||||
|
||||
#include "../../client/settings/cache_settings.h"
|
||||
#include "../../client/settings/card_counter_settings.h"
|
||||
#include "../../client/sound_engine.h"
|
||||
#include "../../game/game_state.h"
|
||||
#include "../../game/phase.h"
|
||||
#include "../../game/player/player_logic.h"
|
||||
#include "../../interface/widgets/tabs/tab_game.h"
|
||||
|
|
@ -10,6 +12,7 @@
|
|||
|
||||
#include <libcockatrice/protocol/pb/context_move_card.pb.h>
|
||||
#include <libcockatrice/protocol/pb/context_mulligan.pb.h>
|
||||
#include <libcockatrice/settings/chat_settings.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
#include <utility>
|
||||
|
||||
|
|
@ -826,6 +829,14 @@ void MessageLogWidget::appendHtmlServerMessage(const QString &html, bool optiona
|
|||
ChatView::appendHtmlServerMessage(messagePrefix + html + messageSuffix, optionalIsBold, optionalFontColor);
|
||||
}
|
||||
|
||||
QString MessageLogWidget::getCurrentTime() const
|
||||
{
|
||||
if (SettingsCache::instance().chat().getUseGameTime()) {
|
||||
return "[" + GameState::formatElapsedTime(game->getGameState()->getSecondsElapsed()) + "] ";
|
||||
}
|
||||
return ChatView::getCurrentTime();
|
||||
}
|
||||
|
||||
void MessageLogWidget::connectToPlayerEventHandler(PlayerEventHandler *playerEventHandler)
|
||||
{
|
||||
connect(playerEventHandler, &PlayerEventHandler::logSay, this, &MessageLogWidget::logSay);
|
||||
|
|
|
|||
|
|
@ -104,6 +104,9 @@ public slots:
|
|||
void appendHtmlServerMessage(const QString &html,
|
||||
bool optionalIsBold = false,
|
||||
QString optionalFontColor = QString()) override;
|
||||
|
||||
private:
|
||||
[[nodiscard]] QString getCurrentTime() const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ void ChatView::appendHtmlServerMessage(const QString &html, bool optionalIsBold,
|
|||
|
||||
QString htmlText =
|
||||
"<font color=" + ((optionalFontColor.size() > 0) ? optionalFontColor : serverMessageColor.name()) + ">" +
|
||||
QDateTime::currentDateTime().toString("[hh:mm:ss] ") + html + "</font>";
|
||||
getCurrentTime() + html + "</font>";
|
||||
|
||||
if (optionalIsBold) {
|
||||
htmlText = "<b>" + htmlText + "</b>";
|
||||
|
|
@ -179,6 +179,11 @@ void ChatView::appendHtmlServerMessage(const QString &html, bool optionalIsBold,
|
|||
}
|
||||
}
|
||||
|
||||
QString ChatView::getCurrentTime() const
|
||||
{
|
||||
return QDateTime::currentDateTime().toString("[hh:mm:ss] ");
|
||||
}
|
||||
|
||||
void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName)
|
||||
{
|
||||
QTextCharFormat oldFormat = cursor.charFormat();
|
||||
|
|
@ -290,7 +295,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
|
||||
|
|
|
|||
|
|
@ -107,9 +107,8 @@ public:
|
|||
ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _showTimestamps, QWidget *parent = nullptr);
|
||||
void retranslateUi();
|
||||
void appendHtml(const QString &html);
|
||||
void virtual appendHtmlServerMessage(const QString &html,
|
||||
bool optionalIsBold = false,
|
||||
QString optionalFontColor = QString());
|
||||
virtual void
|
||||
appendHtmlServerMessage(const QString &html, bool optionalIsBold = false, QString optionalFontColor = QString());
|
||||
void appendMessage(QString message,
|
||||
RoomMessageTypeFlags messageType = {},
|
||||
const ServerInfo_User &userInfo = {},
|
||||
|
|
@ -119,6 +118,7 @@ public:
|
|||
QString getRecentChatLog(int maxMessages = 50) const;
|
||||
|
||||
protected:
|
||||
[[nodiscard]] virtual QString getCurrentTime() const;
|
||||
void enterEvent(QEnterEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@ MessagesSettingsPage::MessagesSettingsPage()
|
|||
connect(&roomHistory, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance().chat(),
|
||||
&ChatSettings::setRoomHistory);
|
||||
|
||||
useGameTimeCheckBox.setChecked(SettingsCache::instance().chat().getUseGameTime());
|
||||
connect(&useGameTimeCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance().chat(),
|
||||
&ChatSettings::setUseGameTime);
|
||||
|
||||
customAlertString = new QLineEdit();
|
||||
customAlertString->setText(SettingsCache::instance().chat().getHighlightWords());
|
||||
connect(customAlertString, &QLineEdit::textChanged, &SettingsCache::instance().chat(),
|
||||
|
|
@ -76,6 +80,7 @@ MessagesSettingsPage::MessagesSettingsPage()
|
|||
chatGrid->addWidget(&messagePopups, 5, 0);
|
||||
chatGrid->addWidget(&mentionPopups, 6, 0);
|
||||
chatGrid->addWidget(&roomHistory, 7, 0);
|
||||
chatGrid->addWidget(&useGameTimeCheckBox, 8, 0);
|
||||
chatGroupBox = new QGroupBox;
|
||||
chatGroupBox->setLayout(chatGrid);
|
||||
|
||||
|
|
@ -256,6 +261,7 @@ void MessagesSettingsPage::retranslateUi()
|
|||
messagePopups.setText(tr("Enable desktop notifications for private messages"));
|
||||
mentionPopups.setText(tr("Enable desktop notification for mentions"));
|
||||
roomHistory.setText(tr("Enable room message history on join"));
|
||||
useGameTimeCheckBox.setText(tr("Use game time instead of local time in game logs"));
|
||||
hexLabel.setText(tr("(Color is hexadecimal)"));
|
||||
hexHighlightLabel.setText(tr("(Color is hexadecimal)"));
|
||||
customAlertStringLabel.setText(tr("Separate words with a space, alphanumeric characters only"));
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ private:
|
|||
QCheckBox messagePopups;
|
||||
QCheckBox mentionPopups;
|
||||
QCheckBox roomHistory;
|
||||
QCheckBox useGameTimeCheckBox;
|
||||
QGroupBox *chatGroupBox;
|
||||
QGroupBox *highlightGroupBox;
|
||||
QGroupBox *messageGroupBox;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
[[nodiscard]] virtual bool getShowMessagePopup() const = 0;
|
||||
[[nodiscard]] virtual bool getShowMentionPopup() const = 0;
|
||||
[[nodiscard]] virtual bool getRoomHistory() const = 0;
|
||||
[[nodiscard]] virtual bool getUseGameTime() const = 0;
|
||||
[[nodiscard]] virtual QString getHighlightWords() const = 0;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,11 @@ bool ChatSettings::getRoomHistory() const
|
|||
return getValue("roomHistory", QString(), QString(), true).toBool();
|
||||
}
|
||||
|
||||
bool ChatSettings::getUseGameTime() const
|
||||
{
|
||||
return getValue("useGameTime", QString(), QString(), false).toBool();
|
||||
}
|
||||
|
||||
QString ChatSettings::getHighlightWords() const
|
||||
{
|
||||
return getValue("highlightWords").toString();
|
||||
|
|
@ -131,6 +136,11 @@ void ChatSettings::setRoomHistory(bool _roomHistory)
|
|||
setValue(_roomHistory, "roomHistory");
|
||||
}
|
||||
|
||||
void ChatSettings::setUseGameTime(bool _useGameTime)
|
||||
{
|
||||
setValue(_useGameTime, "useGameTime");
|
||||
}
|
||||
|
||||
void ChatSettings::setHighlightWords(const QString &_highlightWords)
|
||||
{
|
||||
setValue(_highlightWords, "highlightWords");
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public:
|
|||
[[nodiscard]] bool getShowMessagePopup() const override;
|
||||
[[nodiscard]] bool getShowMentionPopup() const override;
|
||||
[[nodiscard]] bool getRoomHistory() const override;
|
||||
[[nodiscard]] bool getUseGameTime() const override;
|
||||
[[nodiscard]] QString getHighlightWords() const override;
|
||||
|
||||
void setChatMention(bool _chatMention);
|
||||
|
|
@ -37,6 +38,7 @@ public:
|
|||
void setShowMessagePopups(bool _showMessagePopups);
|
||||
void setShowMentionPopups(bool _showMentionPopups);
|
||||
void setRoomHistory(bool _roomHistory);
|
||||
void setUseGameTime(bool _useGameTime);
|
||||
void setHighlightWords(const QString &_highlightWords);
|
||||
|
||||
signals:
|
||||
|
|
|
|||
|
|
@ -300,6 +300,12 @@ TEST_F(SettingsDefaultsTest, Chat_RoomHistory_Default)
|
|||
ASSERT_EQ(s.getRoomHistory(), true);
|
||||
}
|
||||
|
||||
TEST_F(SettingsDefaultsTest, Chat_UseGameTime_Default)
|
||||
{
|
||||
ChatSettings s(settingsPath, nullptr);
|
||||
ASSERT_EQ(s.getUseGameTime(), false);
|
||||
}
|
||||
|
||||
// --- PersonalSettings ---
|
||||
|
||||
TEST_F(SettingsDefaultsTest, Personal_Lang_Default)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue