Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Client/core/CClientVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions Client/core/CConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("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";

Expand Down
23 changes: 21 additions & 2 deletions Client/core/CGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("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()
Expand Down
12 changes: 12 additions & 0 deletions Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CGUICheckBox*>(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);
}
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Client/core/CSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class CSettings
CGUIEdit* m_pChatLineFadeout;
CGUICheckBox* m_pFlashWindow;
CGUICheckBox* m_pTrayBalloon;
CGUICheckBox* m_pChatShowTimestamps;

CGUILabel* m_pLabelBrowserGeneral;
CGUICheckBox* m_pCheckBoxRemoteBrowser;
Expand Down