XII Release 0.1.0
Loading...
Searching...
No Matches
xiiQuakeConsole Class Referencefinal

A Quake-style console for in-game configuration of xiiCVar and xiiConsoleFunction. More...

#include <QuakeConsole.h>

Inheritance diagram for xiiQuakeConsole:
[legend]

Public Member Functions

Configuration
void SetMaxConsoleStrings (xiiUInt32 uiMax)
 Adjusts how many strings the console will keep in memory at maximum.
 
xiiUInt32 GetMaxConsoleStrings () const
 Returns how many strings the console will keep in memory at maximum.
 
virtual void EnableLogOutput (bool bEnable)
 Enables or disables that the output from xiiGlobalLog is displayed in the console. Enabled by default.
 
virtual void SaveState (xiiStreamWriter &ref_stream) const
 Writes the state of the console (history, bound keys) to the stream.
 
virtual void LoadState (xiiStreamReader &ref_stream)
 Reads the state of the console (history, bound keys) from the stream.
 
Command Processing
virtual void ExecuteCommand (xiiStringView sInput) override
 Executes the given command using the current command interpreter.
 
void BindKey (xiiStringView sKey, xiiStringView sCommand)
 Binds szCommand to szKey. Calling ExecuteBoundKey() with this key will then run that command.
 
void UnbindKey (xiiStringView sKey)
 Removes the key binding.
 
void ExecuteBoundKey (xiiStringView sKey)
 Executes the command that was bound to this key.
 
Input Handling
void AddInputCharacter (xiiUInt32 uiChar)
 Inserts one character at the caret position into the console input line.
 
void ClearInputLine ()
 Clears the input line of the console.
 
xiiStringView GetInputLine () const
 Returns the current content of the input line.
 
xiiInt32 GetCaretPosition () const
 Returns the position (in characters) of the caret.
 
void MoveCaret (xiiInt32 iMoveOffset)
 Moves the caret in the text. Its position will be clamped to the length of the current input line text.
 
void DeleteNextCharacter ()
 Deletes the character following the caret position.
 
void Scroll (xiiInt32 iLines)
 Scrolls the contents of the console up or down. Will be clamped to the available range.
 
xiiUInt32 GetScrollPosition () const
 Returns the current scroll position. This must be used during rendering to start with the proper line.
 
virtual void DoDefaultInputHandling (bool bConsoleOpen)
 This function implements input handling (via xiiInputManager) for the console.
 
Console Content
virtual void AddConsoleString (xiiStringView sText, xiiConsoleString::Type type=xiiConsoleString::Type::Default) override
 Adds a string to the console.
 
const xiiDeque< xiiConsoleString > & GetConsoleStrings () const
 Returns all current console strings. Use GetScrollPosition() to know which one should be displayed as the first one.
 
void ClearConsoleStrings ()
 Deletes all console strings, making the console empty.
 
- Public Member Functions inherited from xiiConsole
const xiiEvent< const xiiConsoleEvent & > & Events () const
 Grants access to subscribe and unsubscribe from console events.
 
xiiMutexGetMutex () const
 Returns the mutex that's used to prevent multi-threaded access.
 
void SetCommandInterpreter (const xiiSharedPtr< xiiCommandInterpreter > &pInterpreter)
 Replaces the current command interpreter.
 
const xiiSharedPtr< xiiCommandInterpreter > & GetCommandInterpreter () const
 Returns the currently used command interpreter.
 
virtual bool AutoComplete (xiiStringBuilder &ref_sText)
 Auto-completes the given text.
 
void AddToInputHistory (xiiStringView sText)
 Adds an item to the input history.
 
const xiiStaticArray< xiiString, 16 > & GetInputHistory () const
 Returns the current input history.
 
void RetrieveInputHistory (xiiInt32 iHistoryUp, xiiStringBuilder &ref_sResult)
 Replaces the input line by the next (or previous) history item.
 
xiiResult SaveInputHistory (xiiStringView sFile)
 Writes the current input history to a text file.
 
void LoadInputHistory (xiiStringView sFile)
 Reads the text file and appends all lines to the input history.
 

Static Public Member Functions

Helpers
static xiiString GetFullInfoAsString (xiiCVar *pCVar)
 Returns a nice string containing all the important information about the cvar.
 
static const xiiString GetValueAsString (xiiCVar *pCVar)
 Returns the value of the cvar as a string.
 
static void SetMainConsole (xiiConsole *pConsole)
 
static xiiConsoleGetMainConsole ()
 

Protected Member Functions

void RemoveCharacter (xiiUInt32 uiInputLinePosition)
 Deletes the character at the given position in the input line.
 
void ClampCaretPosition ()
 Makes sure the caret position is clamped to the input line length.
 
void LogHandler (const xiiLoggingEventData &data)
 The function that is used to read xiiGlobalLog messages.
 
virtual bool ProcessInputCharacter (xiiUInt32 uiChar)
 
virtual bool FilterInputCharacter (xiiUInt32 uiChar)
 
virtual void InputStringChanged ()
 

Protected Attributes

xiiInt32 m_iCaretPosition
 
xiiStringBuilder m_sInputLine
 
xiiDeque< xiiConsoleStringm_ConsoleStrings
 
bool m_bUseFilteredStrings = false
 
xiiDeque< xiiConsoleStringm_FilteredConsoleStrings
 
xiiUInt32 m_uiMaxConsoleStrings
 
xiiInt32 m_iScrollPosition
 
bool m_bLogOutputEnabled
 
bool m_bDefaultInputHandlingInitialized
 
xiiMap< xiiString, xiiStringm_BoundKeys
 
xiiEvent< const xiiConsoleEvent & > m_Events
 The console event variable, to attach to.
 
xiiMutex m_Mutex
 
xiiSharedPtr< xiiCommandInterpreterm_pCommandInterpreter
 
xiiInt32 m_iCurrentInputHistoryElement = -1
 
xiiStaticArray< xiiString, 16 > m_InputHistory
 

Detailed Description

A Quake-style console for in-game configuration of xiiCVar and xiiConsoleFunction.

The console displays the recent log activity and allows to modify cvars and call console functions. It supports auto-completion of known keywords. Additionally, 'keys' can be bound to arbitrary commands, such that useful commands can be executed easily. The default implementation uses xiiConsoleInterpreter::Lua as the interpreter for commands typed into it. The interpreter can be replaced with custom implementations.

Member Function Documentation

◆ AddConsoleString()

void xiiQuakeConsole::AddConsoleString ( xiiStringView sText,
xiiConsoleString::Type type = xiiConsoleString::Type::Default )
overridevirtual

Adds a string to the console.

Reimplemented from xiiConsole.

◆ AddInputCharacter()

void xiiQuakeConsole::AddInputCharacter ( xiiUInt32 uiChar)

Inserts one character at the caret position into the console input line.

This function also calls ProcessInputCharacter and FilterInputCharacter. By default this already reacts on Tab, Enter and ESC and filters out all non ASCII characters.

◆ BindKey()

void xiiQuakeConsole::BindKey ( xiiStringView sKey,
xiiStringView sCommand )

Binds szCommand to szKey. Calling ExecuteBoundKey() with this key will then run that command.

A key can be any arbitrary string. However, it might make sense to either use the standard ASCII characters A-Z and a-z, which allows to trigger actions by the press of any of those buttons. You can, however, also use names for input buttons, such as 'Key_Left', but then you also need to call ExecuteBoundKey() with those names. If you use such virtual key names, it makes also sense to listen to the auto-complete event and suggest those key names there.

◆ DoDefaultInputHandling()

void xiiQuakeConsole::DoDefaultInputHandling ( bool bConsoleOpen)
virtual

This function implements input handling (via xiiInputManager) for the console.

If the console is 'open' (ie. has full focus), it will handle more input for caret movement etc. However, in the 'closed' state, it will still execute bound keys and commands from the history. It is not required to call this function, you can implement input handling entirely outside the console.

If this function is used, it should be called once per frame and if the console is considered 'open', no further keyboard input should be processed, as that might lead to confusing behavior when the user types text into the console.

The state whether the console is considered open has to be managed by the application.

◆ ExecuteCommand()

void xiiQuakeConsole::ExecuteCommand ( xiiStringView sInput)
overridevirtual

Executes the given command using the current command interpreter.

Reimplemented from xiiConsole.


The documentation for this class was generated from the following files: