![]() |
Plasma Engine
2.0
|
A Quake-style console for in-game configuration of plCVar and plConsoleFunction. More...
#include <QuakeConsole.h>
Public Member Functions | |
Configuration | |
void | SetMaxConsoleStrings (plUInt32 uiMax) |
Adjusts how many strings the console will keep in memory at maximum. | |
plUInt32 | 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 plGlobalLog is displayed in the console. Enabled by default. | |
virtual void | SaveState (plStreamWriter &inout_stream) const |
Writes the state of the console (history, bound keys) to the stream. | |
virtual void | LoadState (plStreamReader &inout_stream) |
Reads the state of the console (history, bound keys) from the stream. | |
Command Processing | |
virtual void | ExecuteCommand (plStringView sInput) override |
Executes the given command using the current command interpreter. | |
void | BindKey (plStringView sKey, plStringView sCommand) |
Binds szCommand to szKey. Calling ExecuteBoundKey() with this key will then run that command. | |
void | UnbindKey (plStringView sKey) |
Removes the key binding. | |
void | ExecuteBoundKey (plStringView sKey) |
Executes the command that was bound to this key. | |
Input Handling | |
void | AddInputCharacter (plUInt32 uiChar) |
Inserts one character at the caret position into the console input line. | |
void | ClearInputLine () |
Clears the input line of the console. | |
plStringView | GetInputLine () const |
Returns the current content of the input line. | |
plInt32 | GetCaretPosition () const |
Returns the position (in characters) of the caret. | |
void | MoveCaret (plInt32 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 (plInt32 iLines) |
Scrolls the contents of the console up or down. Will be clamped to the available range. | |
plUInt32 | 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 plInputManager) for the console. | |
Console Content | |
virtual void | AddConsoleString (plStringView sText, plConsoleString::Type type=plConsoleString::Type::Default) override |
Adds a string to the console. | |
const plDeque< plConsoleString > & | 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. | |
![]() | |
const plEvent< const plConsoleEvent & > & | Events () const |
Grants access to subscribe and unsubscribe from console events. | |
plMutex & | GetMutex () const |
Returns the mutex that's used to prevent multi-threaded access. | |
void | SetCommandInterpreter (const plSharedPtr< plCommandInterpreter > &pInterpreter) |
Replaces the current command interpreter. | |
const plSharedPtr< plCommandInterpreter > & | GetCommandInterpreter () const |
Returns the currently used command interpreter. | |
virtual bool | AutoComplete (plStringBuilder &ref_sText) |
Auto-completes the given text. | |
void | AddToInputHistory (plStringView sText) |
Adds an item to the input history. | |
const plStaticArray< plString, 16 > & | GetInputHistory () const |
Returns the current input history. | |
void | RetrieveInputHistory (plInt32 iHistoryUp, plStringBuilder &ref_sResult) |
Replaces the input line by the next (or previous) history item. | |
plResult | SaveInputHistory (plStringView sFile) |
Writes the current input history to a text file. | |
void | LoadInputHistory (plStringView sFile) |
Reads the text file and appends all lines to the input history. | |
Static Public Member Functions | |
Helpers | |
static plString | GetFullInfoAsString (plCVar *pCVar) |
Returns a nice string containing all the important information about the cvar. | |
static const plString | GetValueAsString (plCVar *pCVar) |
Returns the value of the cvar as a string. | |
![]() | |
static void | SetMainConsole (plConsole *pConsole) |
static plConsole * | GetMainConsole () |
Protected Member Functions | |
void | RemoveCharacter (plUInt32 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 plLoggingEventData &data) |
The function that is used to read plGlobalLog messages. | |
virtual bool | ProcessInputCharacter (plUInt32 uiChar) |
virtual bool | FilterInputCharacter (plUInt32 uiChar) |
virtual void | InputStringChanged () |
Protected Attributes | |
plInt32 | m_iCaretPosition |
plStringBuilder | m_sInputLine |
plDeque< plConsoleString > | m_ConsoleStrings |
bool | m_bUseFilteredStrings = false |
plDeque< plConsoleString > | m_FilteredConsoleStrings |
plUInt32 | m_uiMaxConsoleStrings |
plInt32 | m_iScrollPosition |
bool | m_bLogOutputEnabled |
bool | m_bDefaultInputHandlingInitialized |
plMap< plString, plString > | m_BoundKeys |
![]() | |
plEvent< const plConsoleEvent & > | m_Events |
The console event variable, to attach to. | |
plMutex | m_Mutex |
plSharedPtr< plCommandInterpreter > | m_pCommandInterpreter |
plInt32 | m_iCurrentInputHistoryElement = -1 |
plStaticArray< plString, 16 > | m_InputHistory |
A Quake-style console for in-game configuration of plCVar and plConsoleFunction.
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 plConsoleInterpreter::Lua as the interpreter for commands typed into it. The interpreter can be replaced with custom implementations.
|
overridevirtual |
Adds a string to the console.
Reimplemented from plConsole.
void plQuakeConsole::AddInputCharacter | ( | plUInt32 | 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.
void plQuakeConsole::BindKey | ( | plStringView | sKey, |
plStringView | 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.
|
virtual |
This function implements input handling (via plInputManager) 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.
|
overridevirtual |
Executes the given command using the current command interpreter.
Reimplemented from plConsole.