[Client] Add option to use game time in game log timestamps (#7265)

* [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.

* [Game] Move formatElapsedTime helper out of public slots (#2202)

The message log needs the HH:MM:SS formatter used by the game timer, but
it lives in GameState's public slots, tying a pure formatting helper to
the signal-slot machinery.

Move formatElapsedTime into a public section of GameState so the log can
call it directly, and add the missing trailing newline to game_state.cpp.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-02 17:30:48 +02:00 • committed by GitHub
parent ffcb9094ca
commit 750d5b3c21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 68 additions and 12 deletions

View file

@ -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>
@ -626,13 +629,12 @@ void MessageLogWidget::logSetActivePhase(int phaseNumber)
soundEngine->playSound(phase.soundFileName);
appendHtml("<font color=\"" + phase.color + "\"><b>" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") +
phase.getName() + "</b></font>");
appendHtml("<font color=\"" + phase.color + "\"><b>" + getCurrentTime() + phase.getName() + "</b></font>");
}
void MessageLogWidget::logSetActivePlayer(PlayerLogic *player)
{
appendHtml("<br><font color=\"green\"><b>" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") +
appendHtml("<br><font color=\"green\"><b>" + getCurrentTime() +
QString(tr("%1's turn.")).arg(player->getPlayerInfo()->getName()) + "</b></font><br>");
}
@ -826,6 +828,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);