Skip to content

Commit 50d6d68

Browse files
committed
Initial commit
1 parent 3466e0f commit 50d6d68

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

Client/core/CClientVariables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ void CClientVariables::LoadDefaults()
323323
DEFAULT("chat_text_alignment", Chat::Text::Align::LEFT); // chatbox horizontal text alignment
324324
DEFAULT("server_can_flash_window", true); // allow server to flash the window
325325
DEFAULT("allow_tray_notifications", true); // allow scripts to create tray balloon notifications
326+
DEFAULT("show_time_in_chat", false); // show time prefix in chat messages
326327
DEFAULT("text_scale", 1.0f); // text scale
327328
DEFAULT("invert_mouse", false); // mouse inverting
328329
DEFAULT("fly_with_mouse", false); // flying with mouse controls

Client/core/CConsole.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,21 @@ CConsole::~CConsole()
6666

6767
void CConsole::Echo(const char* szText)
6868
{
69-
// Add to add buffer
70-
m_strPendingAdd += szText;
69+
std::string finalMessage = szText;
70+
71+
// Prepend timestamp for console display
72+
if (g_pCore->GetCVars()->GetValue<bool>("show_time_in_chat", true))
73+
{
74+
char szTime[16]; // HH:MM:SS
75+
std::time_t t = std::time(nullptr);
76+
std::tm* tm_info = std::localtime(&t);
77+
std::strftime(szTime, sizeof(szTime), "%H:%M:%S", tm_info);
78+
79+
finalMessage = std::string("[") + szTime + "] " + szText;
80+
}
81+
82+
// Add to console buffer
83+
m_strPendingAdd += finalMessage;
7184
if (!m_strPendingAdd.EndsWith("\n"))
7285
m_strPendingAdd += "\n";
7386

Client/core/CGUI.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,29 @@ bool CLocalGUI::IsChatBoxInputEnabled()
584584

585585
void CLocalGUI::EchoChat(const char* szText, bool bColorCoded)
586586
{
587-
if (m_pChat)
587+
if (!m_pChat)
588+
return;
589+
590+
std::string finalMessage;
591+
592+
if (g_pCore->GetCVars()->GetValue<bool>("show_time_in_chat", true))
588593
{
589-
m_pChat->Output(szText, bColorCoded);
594+
// Get current time
595+
char szTime[16];
596+
std::time_t t = std::time(nullptr);
597+
std::tm* tm_info = std::localtime(&t);
598+
std::strftime(szTime, sizeof(szTime), "%H:%M:%S", tm_info);
599+
600+
// Prepend timestamp to the message
601+
finalMessage = std::string("[") + szTime + "] " + szText;
590602
}
603+
else
604+
{
605+
finalMessage = szText;
606+
}
607+
608+
// Output to chat
609+
m_pChat->Output(finalMessage.c_str(), bColorCoded);
591610
}
592611

593612
bool CLocalGUI::IsWebRequestGUIVisible()

Client/core/CSettings.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ void CSettings::ResetGuiPointers()
410410
m_pChatLineFadeout = NULL;
411411
m_pFlashWindow = NULL;
412412
m_pTrayBalloon = NULL;
413+
m_pChatShowTimestamps = NULL;
413414

414415
m_pLabelBrowserGeneral = NULL;
415416
m_pCheckBoxRemoteBrowser = NULL;
@@ -3238,6 +3239,11 @@ void CSettings::CreateInterfaceTabGUI()
32383239
m_pChatTextBlackOutline->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + fLineSizeY + fLineGapY));
32393240
m_pChatTextBlackOutline->GetPosition(vecTemp);
32403241
m_pChatTextBlackOutline->AutoSize(NULL, 20.0f);
3242+
3243+
m_pChatShowTimestamps = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabOptions, _("Show timestamps in chat messages")));
3244+
m_pChatShowTimestamps->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + fLineSizeY + fLineGapY));
3245+
m_pChatShowTimestamps->GetPosition(vecTemp);
3246+
m_pChatShowTimestamps->AutoSize(NULL, 20.0f);
32413247
}
32423248
}
32433249
}
@@ -4156,6 +4162,8 @@ void CSettings::LoadData()
41564162
m_pChatNickCompletion->SetSelected(bVar);
41574163
CVARS_GET("chat_text_outline", bVar);
41584164
m_pChatTextBlackOutline->SetSelected(bVar);
4165+
CVARS_GET("show_time_in_chat", bVar);
4166+
m_pChatShowTimestamps->SetSelected(bVar);
41594167

41604168
{
41614169
int iVar;
@@ -4190,6 +4198,8 @@ void CSettings::LoadData()
41904198
m_pFlashWindow->SetSelected(bVar);
41914199
CVARS_GET("allow_tray_notifications", bVar);
41924200
m_pTrayBalloon->SetSelected(bVar);
4201+
CVARS_GET("show_time_in_chat", bVar);
4202+
m_pChatShowTimestamps->SetSelected(bVar);
41934203

41944204
// Browser
41954205
CVARS_GET("browser_remote_websites", bVar);
@@ -4622,6 +4632,7 @@ void CSettings::SaveData()
46224632
CVARS_SET("chat_text_outline", m_pChatTextBlackOutline->GetSelected());
46234633
CVARS_SET("chat_line_life", GetMilliseconds(m_pChatLineLife));
46244634
CVARS_SET("chat_line_fade_out", GetMilliseconds(m_pChatLineFadeout));
4635+
CVARS_SET("show_time_in_chat", m_pChatShowTimestamps->GetSelected());
46254636

46264637
CVARS_SET("chat_position_offset_x", m_pChatOffsetX->GetText());
46274638
CVARS_SET("chat_position_offset_y", m_pChatOffsetY->GetText());
@@ -4644,6 +4655,7 @@ void CSettings::SaveData()
46444655
// Interface
46454656
CVARS_SET("server_can_flash_window", m_pFlashWindow->GetSelected());
46464657
CVARS_SET("allow_tray_notifications", m_pTrayBalloon->GetSelected());
4658+
CVARS_SET("show_time_in_chat", m_pChatShowTimestamps->GetSelected());
46474659

46484660
// Set our new skin last, as it'll destroy all our GUI
46494661
pItem = m_pInterfaceSkinSelector->GetSelectedItem();

Client/core/CSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ class CSettings
355355
CGUIEdit* m_pChatLineFadeout;
356356
CGUICheckBox* m_pFlashWindow;
357357
CGUICheckBox* m_pTrayBalloon;
358+
CGUICheckBox* m_pChatShowTimestamps;
358359

359360
CGUILabel* m_pLabelBrowserGeneral;
360361
CGUICheckBox* m_pCheckBoxRemoteBrowser;

0 commit comments

Comments
 (0)