2004-07-17 08:14:23 +02:00
|
|
|
/***************************************************************************************
|
|
|
|
AUTHOR: John M. Mena
|
|
|
|
EMAIL: JohnMMena@hotmail.com
|
|
|
|
FILE: CConsole.h
|
|
|
|
CREATED: 12/3/03
|
|
|
|
COMPLETED: NULL
|
|
|
|
|
|
|
|
DESCRIPTION: The class CConsole provides an interface to the
|
|
|
|
scripting abilities of an engine.
|
|
|
|
****************************************************************************************/
|
|
|
|
|
|
|
|
|
2004-06-02 22:40:07 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string>
|
|
|
|
#include <deque>
|
|
|
|
#include <map>
|
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
#include "res/unifont.h"
|
2004-06-02 22:40:07 +02:00
|
|
|
#include "ogl.h"
|
|
|
|
#include "lib.h"
|
|
|
|
#include "sdl.h"
|
2005-05-10 09:13:25 +02:00
|
|
|
#include "CStr.h"
|
2004-06-02 22:40:07 +02:00
|
|
|
|
|
|
|
#ifndef CCONSOLE_H
|
|
|
|
#define CCONSOLE_H
|
|
|
|
|
2005-03-31 00:33:10 +02:00
|
|
|
#define CONSOLE_BUFFER_SIZE 1024 // for text being typed into the console
|
2004-08-14 13:40:40 +02:00
|
|
|
#define CONSOLE_MESSAGE_SIZE 1024 // for messages being printed into the console
|
2004-06-02 22:40:07 +02:00
|
|
|
|
|
|
|
typedef void(*fptr)(void);
|
|
|
|
|
|
|
|
class CConsole
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
float m_fX;
|
|
|
|
float m_fY;
|
|
|
|
|
|
|
|
float m_fHeight;
|
|
|
|
float m_fWidth;
|
|
|
|
|
2004-06-03 03:42:40 +02:00
|
|
|
// "position" in show/hide animation, how visible the console is (0..1).
|
|
|
|
// allows implementing other animations than sliding, e.g. fading in/out.
|
|
|
|
float m_fVisibleFrac;
|
2004-06-03 02:19:22 +02:00
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
std::map<std::wstring, fptr> m_mapFuncList;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
std::deque<std::wstring> m_deqMsgHistory;
|
|
|
|
std::deque<std::wstring> m_deqBufHistory;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
|
|
|
int m_iMsgHistPos;
|
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
wchar_t* m_szBuffer;
|
2004-06-02 22:40:07 +02:00
|
|
|
int m_iBufferPos;
|
|
|
|
int m_iBufferLength;
|
|
|
|
|
2005-05-10 09:13:25 +02:00
|
|
|
CStr m_sHistoryFile;
|
|
|
|
unsigned int m_iHistorySize;
|
|
|
|
|
2004-06-02 22:40:07 +02:00
|
|
|
bool m_bFocus;
|
2004-06-03 03:42:40 +02:00
|
|
|
bool m_bVisible; // console is to be drawn
|
|
|
|
bool m_bToggle; // show/hide animation is currently active
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
void ToLower(wchar_t* szMessage, uint iSize = 0);
|
|
|
|
void Trim(wchar_t* szMessage, const wchar_t cChar = 32, uint iSize = 0);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
|
|
|
void DrawHistory(void);
|
|
|
|
void DrawWindow(void);
|
|
|
|
void DrawBuffer(void);
|
|
|
|
void DrawCursor(void);
|
|
|
|
|
|
|
|
bool IsEOB(void) {return (m_iBufferPos == m_iBufferLength);}; //Is end of Buffer?
|
|
|
|
bool IsBOB(void) {return (m_iBufferPos == 0);}; //Is beginning of Buffer?
|
2004-08-14 13:40:40 +02:00
|
|
|
bool IsFull(void) {return (m_iBufferLength == CONSOLE_BUFFER_SIZE);};
|
2004-06-02 22:40:07 +02:00
|
|
|
bool IsEmpty(void) {return (m_iBufferLength == 0);};
|
|
|
|
|
2004-07-12 14:25:27 +02:00
|
|
|
void InsertBuffer(void){InsertMessage(L"%ls", m_szBuffer);};
|
2004-06-16 17:42:48 +02:00
|
|
|
void ProcessBuffer(const wchar_t* szLine);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2005-05-10 09:13:25 +02:00
|
|
|
void LoadHistory();
|
|
|
|
void SaveHistory();
|
|
|
|
|
2004-06-02 22:40:07 +02:00
|
|
|
public:
|
2004-07-11 18:03:26 +02:00
|
|
|
CConsole();
|
2004-06-02 22:40:07 +02:00
|
|
|
~CConsole();
|
|
|
|
|
2004-07-11 18:03:26 +02:00
|
|
|
void SetSize(float X = 300, float Y = 0, float W = 800, float H = 600);
|
2005-07-03 18:25:48 +02:00
|
|
|
void UpdateScreenSize(int w, int h);
|
2004-07-11 18:03:26 +02:00
|
|
|
|
2004-07-13 23:09:55 +02:00
|
|
|
void ToggleVisible();
|
2004-08-03 01:14:54 +02:00
|
|
|
void SetVisible( bool visible );
|
2004-07-13 23:09:55 +02:00
|
|
|
|
2004-06-02 22:40:07 +02:00
|
|
|
void Update(float DeltaTime);
|
|
|
|
|
|
|
|
void Render();
|
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
void InsertMessage(const wchar_t* szMessage, ...);
|
2004-06-21 18:29:47 +02:00
|
|
|
void InsertChar(const int szChar, const wchar_t cooked);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2004-08-16 17:19:17 +02:00
|
|
|
void SendChatMessage(const wchar_t *szMessage);
|
|
|
|
void ReceivedChatMessage(const wchar_t *pSender, const wchar_t *szMessage);
|
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
void SetBuffer(const wchar_t* szMessage, ...);
|
2004-08-03 01:14:54 +02:00
|
|
|
|
2005-05-10 09:13:25 +02:00
|
|
|
void UseHistoryFile( CStr filename, unsigned int historysize );
|
|
|
|
|
2004-08-03 01:14:54 +02:00
|
|
|
// Only returns a pointer to the buffer; copy out of here if you want to keep it.
|
|
|
|
const wchar_t* GetBuffer();
|
2004-06-02 22:40:07 +02:00
|
|
|
void FlushBuffer();
|
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
void RegisterFunc(fptr F, const wchar_t* szName);
|
2004-06-03 02:19:22 +02:00
|
|
|
|
|
|
|
bool IsActive() { return m_bVisible; }
|
2004-06-16 17:42:48 +02:00
|
|
|
|
|
|
|
int m_iFontHeight;
|
|
|
|
int m_iFontOffset; // distance to move up before drawing
|
2004-06-02 22:40:07 +02:00
|
|
|
};
|
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
extern CConsole* g_Console;
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
#endif
|