2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef GAME_CLIENT_COMPONENTS_CONSOLE_H
|
|
|
|
#define GAME_CLIENT_COMPONENTS_CONSOLE_H
|
|
|
|
#include <engine/shared/ringbuffer.h>
|
|
|
|
#include <game/client/component.h>
|
|
|
|
#include <game/client/lineinput.h>
|
|
|
|
|
2021-07-12 09:29:59 +00:00
|
|
|
#include <engine/console.h>
|
|
|
|
|
2022-04-22 23:04:48 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
2015-07-23 23:28:15 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CONSOLE_CLOSED,
|
|
|
|
CONSOLE_OPENING,
|
|
|
|
CONSOLE_OPEN,
|
|
|
|
CONSOLE_CLOSING,
|
|
|
|
};
|
|
|
|
|
2022-04-22 23:04:48 +00:00
|
|
|
class CConsoleLogger;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CGameConsole : public CComponent
|
|
|
|
{
|
2022-04-22 23:04:48 +00:00
|
|
|
friend class CConsoleLogger;
|
2010-05-29 07:25:38 +00:00
|
|
|
class CInstance
|
|
|
|
{
|
|
|
|
public:
|
2010-10-16 08:32:56 +00:00
|
|
|
struct CBacklogEntry
|
|
|
|
{
|
|
|
|
float m_YOffset;
|
2021-03-08 00:08:38 +00:00
|
|
|
ColorRGBA m_PrintColor;
|
2010-10-16 08:32:56 +00:00
|
|
|
char m_aText[1];
|
|
|
|
};
|
2022-04-22 23:04:48 +00:00
|
|
|
std::mutex m_BacklogLock;
|
2021-11-15 22:26:17 +00:00
|
|
|
CStaticRingBuffer<CBacklogEntry, 1024 * 1024, CRingBufferBase::FLAG_RECYCLE> m_Backlog;
|
2020-10-27 17:57:14 +00:00
|
|
|
CStaticRingBuffer<char, 64 * 1024, CRingBufferBase::FLAG_RECYCLE> m_History;
|
2010-05-29 07:25:38 +00:00
|
|
|
char *m_pHistoryEntry;
|
|
|
|
|
|
|
|
CLineInput m_Input;
|
2022-08-09 14:41:00 +00:00
|
|
|
const char *m_pName;
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_Type;
|
|
|
|
int m_CompletionEnumerationCount;
|
2022-04-01 16:32:51 +00:00
|
|
|
int m_BacklogCurPage;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CGameConsole *m_pGameConsole;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
char m_aCompletionBuffer[128];
|
2021-09-14 11:15:09 +00:00
|
|
|
bool m_CompletionUsed;
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_CompletionChosen;
|
|
|
|
int m_CompletionFlagmask;
|
2010-06-19 11:48:01 +00:00
|
|
|
float m_CompletionRenderOffset;
|
2014-10-06 21:37:35 +00:00
|
|
|
bool m_ReverseTAB;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2017-03-02 15:16:50 +00:00
|
|
|
char m_aUser[32];
|
2017-03-06 12:49:08 +00:00
|
|
|
bool m_UserGot;
|
2017-07-24 19:43:55 +00:00
|
|
|
bool m_UsernameReq;
|
2017-03-02 15:16:50 +00:00
|
|
|
|
2011-07-14 20:07:21 +00:00
|
|
|
bool m_IsCommand;
|
|
|
|
char m_aCommandName[IConsole::TEMPCMD_NAME_LENGTH];
|
|
|
|
char m_aCommandHelp[IConsole::TEMPCMD_HELP_LENGTH];
|
|
|
|
char m_aCommandParams[IConsole::TEMPCMD_PARAMS_LENGTH];
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2010-06-05 11:38:08 +00:00
|
|
|
CInstance(int t);
|
|
|
|
void Init(CGameConsole *pGameConsole);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2010-06-19 18:51:54 +00:00
|
|
|
void ClearBacklog();
|
2022-01-14 21:36:41 +00:00
|
|
|
void ClearBacklogYOffsets();
|
2010-10-10 22:30:56 +00:00
|
|
|
void ClearHistory();
|
2010-06-19 18:51:54 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void ExecuteLine(const char *pLine);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void OnInput(IInput::CEvent Event);
|
2022-04-22 23:04:48 +00:00
|
|
|
void PrintLine(const char *pLine, int Len, ColorRGBA PrintColor);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
const char *GetString() const { return m_Input.GetString(); }
|
|
|
|
static void PossibleCommandsCompleteCallback(const char *pStr, void *pUser);
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class IConsole *m_pConsole;
|
2022-04-22 23:04:48 +00:00
|
|
|
CConsoleLogger *m_pConsoleLogger = nullptr;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CInstance m_LocalConsole;
|
|
|
|
CInstance m_RemoteConsole;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CInstance *CurrentConsole();
|
|
|
|
float TimeNow();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_ConsoleType;
|
|
|
|
int m_ConsoleState;
|
|
|
|
float m_StateChangeEnd;
|
|
|
|
float m_StateChangeDuration;
|
|
|
|
|
2021-09-12 17:32:00 +00:00
|
|
|
bool m_MouseIsPress = false;
|
|
|
|
int m_MousePressX = 0;
|
|
|
|
int m_MousePressY = 0;
|
|
|
|
int m_MouseCurX = 0;
|
|
|
|
int m_MouseCurY = 0;
|
|
|
|
int m_CurSelStart = 0;
|
|
|
|
int m_CurSelEnd = 0;
|
|
|
|
bool m_HasSelection = false;
|
|
|
|
int m_NewLineCounter = 0;
|
|
|
|
|
2021-10-25 17:28:38 +00:00
|
|
|
int m_LastInputLineCount = 0;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void Toggle(int Type);
|
2010-06-20 12:12:59 +00:00
|
|
|
void Dump(int Type);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
static void PossibleCommandsRenderCallback(const char *pStr, void *pUser);
|
|
|
|
static void ConToggleLocalConsole(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConToggleRemoteConsole(IConsole::IResult *pResult, void *pUserData);
|
2010-06-19 18:51:54 +00:00
|
|
|
static void ConClearLocalConsole(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConClearRemoteConsole(IConsole::IResult *pResult, void *pUserData);
|
2010-06-20 12:12:59 +00:00
|
|
|
static void ConDumpLocalConsole(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConDumpRemoteConsole(IConsole::IResult *pResult, void *pUserData);
|
2018-06-03 09:48:08 +00:00
|
|
|
static void ConConsolePageUp(IConsole::IResult *pResult, void *pUserData);
|
|
|
|
static void ConConsolePageDown(IConsole::IResult *pResult, void *pUserData);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
2010-11-17 12:01:46 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
CONSOLETYPE_LOCAL = 0,
|
2010-11-17 12:01:46 +00:00
|
|
|
CONSOLETYPE_REMOTE,
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CGameConsole();
|
2022-04-22 23:04:48 +00:00
|
|
|
~CGameConsole();
|
2022-01-31 02:11:47 +00:00
|
|
|
virtual int Sizeof() const override { return sizeof(*this); }
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
void PrintLine(int Type, const char *pLine);
|
2017-07-24 19:43:55 +00:00
|
|
|
void RequireUsername(bool UsernameReq);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-01-30 23:43:56 +00:00
|
|
|
virtual void OnStateChange(int NewState, int OldState) override;
|
|
|
|
virtual void OnConsoleInit() override;
|
|
|
|
virtual void OnInit() override;
|
|
|
|
virtual void OnReset() override;
|
|
|
|
virtual void OnRender() override;
|
|
|
|
virtual void OnMessage(int MsgType, void *pRawMsg) override;
|
|
|
|
virtual bool OnInput(IInput::CEvent Events) override;
|
2015-07-23 23:28:15 +00:00
|
|
|
|
|
|
|
bool IsClosed() { return m_ConsoleState == CONSOLE_CLOSED; }
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
#endif
|