From 50d6d6809dcabe6076d4da8f1d6060a45b8d2b8c Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Sat, 22 Nov 2025 20:50:20 +0100 Subject: [PATCH] Initial commit --- Client/core/CClientVariables.cpp | 1 + Client/core/CConsole.cpp | 17 +++++++++++++++-- Client/core/CGUI.cpp | 23 +++++++++++++++++++++-- Client/core/CSettings.cpp | 12 ++++++++++++ Client/core/CSettings.h | 1 + 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/Client/core/CClientVariables.cpp b/Client/core/CClientVariables.cpp index 7a14efb9bb1..b33a8189007 100644 --- a/Client/core/CClientVariables.cpp +++ b/Client/core/CClientVariables.cpp @@ -323,6 +323,7 @@ void CClientVariables::LoadDefaults() DEFAULT("chat_text_alignment", Chat::Text::Align::LEFT); // chatbox horizontal text alignment DEFAULT("server_can_flash_window", true); // allow server to flash the window DEFAULT("allow_tray_notifications", true); // allow scripts to create tray balloon notifications + DEFAULT("show_time_in_chat", false); // show time prefix in chat messages DEFAULT("text_scale", 1.0f); // text scale DEFAULT("invert_mouse", false); // mouse inverting DEFAULT("fly_with_mouse", false); // flying with mouse controls diff --git a/Client/core/CConsole.cpp b/Client/core/CConsole.cpp index 340187f1d84..89456ac9184 100644 --- a/Client/core/CConsole.cpp +++ b/Client/core/CConsole.cpp @@ -66,8 +66,21 @@ CConsole::~CConsole() void CConsole::Echo(const char* szText) { - // Add to add buffer - m_strPendingAdd += szText; + std::string finalMessage = szText; + + // Prepend timestamp for console display + if (g_pCore->GetCVars()->GetValue("show_time_in_chat", true)) + { + char szTime[16]; // HH:MM:SS + std::time_t t = std::time(nullptr); + std::tm* tm_info = std::localtime(&t); + std::strftime(szTime, sizeof(szTime), "%H:%M:%S", tm_info); + + finalMessage = std::string("[") + szTime + "] " + szText; + } + + // Add to console buffer + m_strPendingAdd += finalMessage; if (!m_strPendingAdd.EndsWith("\n")) m_strPendingAdd += "\n"; diff --git a/Client/core/CGUI.cpp b/Client/core/CGUI.cpp index 486afc1e59f..0f468626eec 100644 --- a/Client/core/CGUI.cpp +++ b/Client/core/CGUI.cpp @@ -584,10 +584,29 @@ bool CLocalGUI::IsChatBoxInputEnabled() void CLocalGUI::EchoChat(const char* szText, bool bColorCoded) { - if (m_pChat) + if (!m_pChat) + return; + + std::string finalMessage; + + if (g_pCore->GetCVars()->GetValue("show_time_in_chat", true)) { - m_pChat->Output(szText, bColorCoded); + // Get current time + char szTime[16]; + std::time_t t = std::time(nullptr); + std::tm* tm_info = std::localtime(&t); + std::strftime(szTime, sizeof(szTime), "%H:%M:%S", tm_info); + + // Prepend timestamp to the message + finalMessage = std::string("[") + szTime + "] " + szText; } + else + { + finalMessage = szText; + } + + // Output to chat + m_pChat->Output(finalMessage.c_str(), bColorCoded); } bool CLocalGUI::IsWebRequestGUIVisible() diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 9cd102ed38a..cb13fcce88d 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -410,6 +410,7 @@ void CSettings::ResetGuiPointers() m_pChatLineFadeout = NULL; m_pFlashWindow = NULL; m_pTrayBalloon = NULL; + m_pChatShowTimestamps = NULL; m_pLabelBrowserGeneral = NULL; m_pCheckBoxRemoteBrowser = NULL; @@ -3238,6 +3239,11 @@ void CSettings::CreateInterfaceTabGUI() m_pChatTextBlackOutline->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + fLineSizeY + fLineGapY)); m_pChatTextBlackOutline->GetPosition(vecTemp); m_pChatTextBlackOutline->AutoSize(NULL, 20.0f); + + m_pChatShowTimestamps = reinterpret_cast(pManager->CreateCheckBox(pTabOptions, _("Show timestamps in chat messages"))); + m_pChatShowTimestamps->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + fLineSizeY + fLineGapY)); + m_pChatShowTimestamps->GetPosition(vecTemp); + m_pChatShowTimestamps->AutoSize(NULL, 20.0f); } } } @@ -4156,6 +4162,8 @@ void CSettings::LoadData() m_pChatNickCompletion->SetSelected(bVar); CVARS_GET("chat_text_outline", bVar); m_pChatTextBlackOutline->SetSelected(bVar); + CVARS_GET("show_time_in_chat", bVar); + m_pChatShowTimestamps->SetSelected(bVar); { int iVar; @@ -4190,6 +4198,8 @@ void CSettings::LoadData() m_pFlashWindow->SetSelected(bVar); CVARS_GET("allow_tray_notifications", bVar); m_pTrayBalloon->SetSelected(bVar); + CVARS_GET("show_time_in_chat", bVar); + m_pChatShowTimestamps->SetSelected(bVar); // Browser CVARS_GET("browser_remote_websites", bVar); @@ -4622,6 +4632,7 @@ void CSettings::SaveData() CVARS_SET("chat_text_outline", m_pChatTextBlackOutline->GetSelected()); CVARS_SET("chat_line_life", GetMilliseconds(m_pChatLineLife)); CVARS_SET("chat_line_fade_out", GetMilliseconds(m_pChatLineFadeout)); + CVARS_SET("show_time_in_chat", m_pChatShowTimestamps->GetSelected()); CVARS_SET("chat_position_offset_x", m_pChatOffsetX->GetText()); CVARS_SET("chat_position_offset_y", m_pChatOffsetY->GetText()); @@ -4644,6 +4655,7 @@ void CSettings::SaveData() // Interface CVARS_SET("server_can_flash_window", m_pFlashWindow->GetSelected()); CVARS_SET("allow_tray_notifications", m_pTrayBalloon->GetSelected()); + CVARS_SET("show_time_in_chat", m_pChatShowTimestamps->GetSelected()); // Set our new skin last, as it'll destroy all our GUI pItem = m_pInterfaceSkinSelector->GetSelectedItem(); diff --git a/Client/core/CSettings.h b/Client/core/CSettings.h index 4390bc44262..b2aafa78ac2 100644 --- a/Client/core/CSettings.h +++ b/Client/core/CSettings.h @@ -355,6 +355,7 @@ class CSettings CGUIEdit* m_pChatLineFadeout; CGUICheckBox* m_pFlashWindow; CGUICheckBox* m_pTrayBalloon; + CGUICheckBox* m_pChatShowTimestamps; CGUILabel* m_pLabelBrowserGeneral; CGUICheckBox* m_pCheckBoxRemoteBrowser;