about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGreYFoX <GreYFoXGTi@GMaiL.CoM>2011-03-20 17:17:06 +0200
committeroy <Tom_Adams@web.de>2011-03-27 17:21:07 +0200
commiteb344c83ce082669dc3ec5495217e1bf6b76a9a4 (patch)
treebea2ae7a796a724ec44b8afccd247129e6d5936f
parent4d5443affa2cccfbf84afbd3790dcc105e5edef0 (diff)
downloadzcatch-eb344c83ce082669dc3ec5495217e1bf6b76a9a4.tar.gz
zcatch-eb344c83ce082669dc3ec5495217e1bf6b76a9a4.zip
Chat History. Closes #521
-rw-r--r--src/game/client/components/chat.cpp39
-rw-r--r--src/game/client/components/chat.h3
2 files changed, 42 insertions, 0 deletions
diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp
index fd08d9d0..8fe6b2cc 100644
--- a/src/game/client/components/chat.cpp
+++ b/src/game/client/components/chat.cpp
@@ -40,6 +40,7 @@ void CChat::OnReset()
 	m_aCompletionBuffer[0] = 0;
 	m_PlaceholderOffset = 0;
 	m_PlaceholderLength = 0;
+	m_pHistoryEntry = 0x0;
 }
 
 void CChat::OnRelease()
@@ -105,7 +106,12 @@ bool CChat::OnInput(IInput::CEvent e)
 	else if(e.m_Flags&IInput::FLAG_PRESS && (e.m_Key == KEY_RETURN || e.m_Key == KEY_KP_ENTER))
 	{
 		if(m_Input.GetString()[0])
+		{
 			Say(m_Mode == MODE_ALL ? 0 : 1, m_Input.GetString());
+			char *pEntry = m_History.Allocate(m_Input.GetLength()+1);
+			mem_copy(pEntry, m_Input.GetString(), m_Input.GetLength()+1);
+		}
+		m_pHistoryEntry = 0x0;
 		m_Mode = MODE_NONE;
 		m_pClient->OnRelease();
 	}
@@ -165,6 +171,39 @@ bool CChat::OnInput(IInput::CEvent e)
 		m_Input.ProcessInput(e);
 		m_InputUpdate = true;
 	}
+	if(e.m_Flags&IInput::FLAG_PRESS && e.m_Key == KEY_UP)
+	{
+		if (m_pHistoryEntry)
+		{
+			char *pTest = m_History.Prev(m_pHistoryEntry);
+
+			if (pTest)
+				m_pHistoryEntry = pTest;
+		}
+		else
+			m_pHistoryEntry = m_History.Last();
+
+		if (m_pHistoryEntry)
+		{
+			unsigned int Len = str_length(m_pHistoryEntry);
+			if (Len < sizeof(m_Input) - 1) // TODO: WTF?
+				m_Input.Set(m_pHistoryEntry);
+		}
+	}
+	else if (e.m_Flags&IInput::FLAG_PRESS && e.m_Key == KEY_DOWN)
+	{
+		if (m_pHistoryEntry)
+			m_pHistoryEntry = m_History.Next(m_pHistoryEntry);
+
+		if (m_pHistoryEntry)
+		{
+			unsigned int Len = str_length(m_pHistoryEntry);
+			if (Len < sizeof(m_Input) - 1) // TODO: WTF?
+				m_Input.Set(m_pHistoryEntry);
+		}
+		else
+			m_Input.Clear();
+	}
 	
 	return true;
 }
diff --git a/src/game/client/components/chat.h b/src/game/client/components/chat.h
index 652564ed..bb68d7be 100644
--- a/src/game/client/components/chat.h
+++ b/src/game/client/components/chat.h
@@ -2,6 +2,7 @@
 /* If you are missing that file, acquire a complete release at teeworlds.com.                */
 #ifndef GAME_CLIENT_COMPONENTS_CHAT_H
 #define GAME_CLIENT_COMPONENTS_CHAT_H
+#include <engine/shared/ringbuffer.h>
 #include <game/client/component.h>
 #include <game/client/lineinput.h>
 
@@ -46,6 +47,8 @@ class CChat : public CComponent
 	char m_aCompletionBuffer[256];
 	int m_PlaceholderOffset;
 	int m_PlaceholderLength;
+	char *m_pHistoryEntry;
+	TStaticRingBuffer<char, 64*1024, CRingBufferBase::FLAG_RECYCLE> m_History;
 	
 	static void ConSay(IConsole::IResult *pResult, void *pUserData);
 	static void ConSayTeam(IConsole::IResult *pResult, void *pUserData);