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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SpeedyFolf's feedback is valid:

It'd be nice if chat and console were separate options, I'd like to have timestamp shown in console but not chat, I don't want to clutter chat too much but console is a bigger window

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to change Console to support toggling. (mainly because the console is implemented as simply appending raw text to m_pHistory / a CGuiMemo, and I don't want to introduce another copy of the buffer)

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toggling the setting should show/hide the time in the chat and the console.

The current implementation conditionally modifies the chat string to include the time.

Instead I suggest you save the timestamp string + message string separately, and include the timestamp string conditionally at render time.

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 @@ -411,6 +411,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 @@ -3246,6 +3247,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 @@ -4168,6 +4174,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 @@ -4202,6 +4210,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 @@ -4636,6 +4646,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 @@ -4658,6 +4669,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 @@ -356,6 +356,7 @@ class CSettings
CGUIEdit* m_pChatLineFadeout;
CGUICheckBox* m_pFlashWindow;
CGUICheckBox* m_pTrayBalloon;
CGUICheckBox* m_pChatShowTimestamps;

CGUILabel* m_pLabelBrowserGeneral;
CGUICheckBox* m_pCheckBoxRemoteBrowser;
Expand Down