Mindshifter.GameConsole Class Reference

GameConsole is a simple console game component that displays a log of text to the screen and allows the user to enter input (which is also logged). Handling user input can be done in two ways, the first by registering a delegate to the console's 'TextEntered' event, which will trigger any delegates registered to it when the user enters text into the console. Both the text input and current GameTime are passed to the delegate for processing, and the function can handle the raw input any way it wishes to. The second method for handling input is to register a ConsoleCommandHandler with the console through the 'BindCommandHandler' method. ConsoleCommandHandler delegates are registered for a specific command string, and are triggered when that particular string is entered into the console. Any text after the command is considered to be a set of arguments separated by spaces. These arguments are passed to the ConsoleCommandHandler delegate when it is triggered. More...

Inherits Mindshifter.IGameConsole.

Inheritance diagram for Mindshifter.GameConsole:

Inheritance graph
[legend]
Collaboration diagram for Mindshifter.GameConsole:

Collaboration graph
[legend]
List of all members.

Public Member Functions

override void Update (GameTime gameTime)
 Updates any input to the console.
override void Draw (GameTime gameTime)
 Draws the console to the screen if the console is currently open.
void BindCommandHandler (string command, ConsoleCommandHandler handler, params char[] argumentSeparators)
 Binds a ConsoleCommandHandler to the specified command.
ConsoleCommandHandler UnbindCommandHandler (string command)
 Unbinds the ConsoleCommandHandler for the specified command.
void Open (Keys closeKey)
 Displays the console.
void Log (string message, uint level)
 Logs a message with the specified log level to the console.
void Log (string message)
 Logs a message with log level 0 to the console.
void SetLogLevelCustomColor (uint level, Color color)
 Sets the custom display color of text for the specified log level.
Color GetLogLevelCustomColor (uint level)
 Gets the custom display color of text for the specified log level, or returns the default text color if a custom color is not set for the level.
void UnsetLogLevelCustomColor (uint level)
 Unsets the custom display color of text for the specified log level.

Static Public Member Functions

static void Initialize (Game game, string font, Color textColor, Color backgroundColor, float backgroundAlpha, int lineCount)
 Initializes the Console, adding an instance of the Console class to the specified Game's component and service lists. The IInputManager service may then be retrieved using the Game's GetService function.

Public Attributes

event ConsoleInputHandler TextEntered
 Event triggered when text is entered into the console.
event ConsoleLogHandler MessageLogged
 Event triggered when a message is logged to the console.

Protected Member Functions

override void LoadContent ()
 Loads managed resources used by the console.

Properties

Color TextColor [get, set]
 Gets or sets the console's text color.
Color BackgroundColor [get, set]
 Gets or sets the console's background color.
float BackgroundAlpha [get, set]
 Gets or sets the console's background alpha translucency.
ConsoleDisplayOptions DisplayOptions [get, set]
 Gets or sets the console's display options.
string TimestampFormat [get, set]
 Gets or sets the timestamp format for message timestamps. The following symblols are replaced with their corresponding values when the timestamp for each message is constructed: {Hr} - Hour (in 24 hour format) {Min} - Minute {Sec} - Second {Ms} - Millisecond.
string Prompt [get, set]
 Gets or sets the prompt used on the input line of the console.
int VisibleLineCount [get, set]
 Gets or sets the number of text lines visible in the console.
float VerticalLineSpacing [get, set]
 Gets or sets the vertical spacing between text lines in the console.
float HorizontalPadding [get, set]
 Gets or sets the amount by which text in the console will be right offset from the leftmost side of the screen.
bool AutoScrollOnOutput [get, set]
 Gets or sets a value indicating whether or not the console should automatically scroll to the last line of the message log whenever a message is output to the console.
bool AlertOnUnrecognizedCommand [get, set]
 Gets or sets a value indicating whether or not the console will output the warning "Unrecognized Command" if the user inputs a command not registered with a command handler.
bool EchoEnabled [get, set]
 Gets or sets a value indicating whether or not the console should automatically echo and input it receives from the user to the console log.
uint EchoLogLevel [get, set]
 Gets or sets the log level of messages echoed automatically if the EchoEnabled property is set to true.
uint DefaultLogLevel [get, set]
 Gets or sets the console's default log level which will be assigned to messages logged to the console with no log level defined.
int LogLevelThreshold [get, set]
 Gets or sets the console's log level threshold. If a message's whose log level is higher than the threshold is logged to the console, it will be ignored. However, if the value is negative then all messages will be logged regardless of their log level.
int DisplayLevelThreshold [get, set]
 Gets or sets the console's display level threshold. The console will only display messages in the log with log levels lower or equal to the display level threshold. However, if the value is negative, then all messages will be displayed regardless of their threshold.
bool CursorEnabled [get, set]
 Gets or sets a value indicating whether or not the input cursor is enabled. If enabled, the user can use the arrow keys to navigate the edit position within the current input string.
float CursorBlinkSpeed [get, set]
 Gets or sets the blink interval of the input cursor, in seconds. The cursor will not blink if this value is set to 0.
float NotifyBlinkSpeed [get, set]
 Gets or sets the blink interval of the notifier that is displayed when the console's current line is not the last line of the log, that is: when the user has used PageUp/Up to scroll upward in the console. The notifier will not blink if this value is set to 0.
ReadOnlyCollection< ConsoleMessageMessageLog [get]
 Gets the console log of messages.
bool IsOpen [get]
 Gets a value indicating whether or not the console is currently open.

Private Member Functions

internal GameConsole (Game game, string font, Color textColor, Color bgColor, float bgAlpha, int lineCount)
 Creates a new instance of Console.
List< string > GetLines (float screenWidth, string text)
 Breaks the specified text into multiple lines if neccessary, based on the specified screen width.

Private Attributes

Dictionary< string, ConsoleCommandHandlerInfomCommandHandlers
SpriteBatch mSpriteBatch
SpriteFont mFont
BasicEffect mEffect
VertexDeclaration mVertexDeclaration
ConsoleDisplayOptions mDisplayOptions
string mTimestampFormat
Dictionary< char, Vector2 > mCharSizeLut
float mFontHeight
float mHorizontalPadding
int mVisibleLineCount
float mVerticalSpacing
int mCurrentLine
bool mAutoScrollOnOutput
bool mAlertOnUnrecognizedCommand
string mFontName
Color mDefaultTextColor
Dictionary< uint, Color > mTextColors
Color mBackgroundColor
float mBackgroundAlpha
bool mEchoEnabled
uint mEchoLogLevel
uint mDefaultLogLevel
int mLogLevelThreshold
int mDisplayLevelThreshold
int mInputPosition
bool mCursorEnabled
float mCursorBlinkSpeed
float mCursorTimer
bool mDrawCursor
float mNotifyBlinkSpeed
float mNotifyTimer
bool mDrawNotify
List< ConsoleMessagemLog
StringBuilder mCurrentText
string mInputPrompt
GameTime mCurrentTime
KeyboardState mLastKeyboardState
Keys mCloseKey

Classes

class  ConsoleCommandHandlerInfo
 Describes a ConsoleCommandHandler entry and the argument separators it requires. More...

Detailed Description

GameConsole is a simple console game component that displays a log of text to the screen and allows the user to enter input (which is also logged). Handling user input can be done in two ways, the first by registering a delegate to the console's 'TextEntered' event, which will trigger any delegates registered to it when the user enters text into the console. Both the text input and current GameTime are passed to the delegate for processing, and the function can handle the raw input any way it wishes to. The second method for handling input is to register a ConsoleCommandHandler with the console through the 'BindCommandHandler' method. ConsoleCommandHandler delegates are registered for a specific command string, and are triggered when that particular string is entered into the console. Any text after the command is considered to be a set of arguments separated by spaces. These arguments are passed to the ConsoleCommandHandler delegate when it is triggered.


Constructor & Destructor Documentation

internal Mindshifter.GameConsole.GameConsole ( Game  game,
string  font,
Color  textColor,
Color  bgColor,
float  bgAlpha,
int  lineCount 
) [private]

Creates a new instance of Console.

Parameters:
game The XNA Game with which to register the Console component and IConsole service
font The path to the SpriteFont used to draw text to the console
textColor The color of the console text
bgColor The color of the console background
bgAlpha The alpha translucency of the console background
lineCount The maximum number of text lines visible in the console at any given time


Member Function Documentation

static void Mindshifter.GameConsole.Initialize ( Game  game,
string  font,
Color  textColor,
Color  backgroundColor,
float  backgroundAlpha,
int  lineCount 
) [static]

Initializes the Console, adding an instance of the Console class to the specified Game's component and service lists. The IInputManager service may then be retrieved using the Game's GetService function.

Parameters:
game The XNA Game with which to register the Console component and IConsole service
font The path to the SpriteFont used to draw text to the console
textColor The color of the console text
backgroundColor The color of the console background
backgroundAlpha The alpha translucency of the console background
lineCount The maximum number of text lines visible in the console at any given time

override void Mindshifter.GameConsole.LoadContent (  )  [protected]

Loads managed resources used by the console.

override void Mindshifter.GameConsole.Update ( GameTime  gameTime  ) 

Updates any input to the console.

Parameters:
gameTime The current game time

List<string> Mindshifter.GameConsole.GetLines ( float  screenWidth,
string  text 
) [private]

Breaks the specified text into multiple lines if neccessary, based on the specified screen width.

Parameters:
screenWidth The width of the current viewport
text The text to process
Returns:
The set of lines for the specified text that will fit visibly into the console display area

override void Mindshifter.GameConsole.Draw ( GameTime  gameTime  ) 

Draws the console to the screen if the console is currently open.

Parameters:
gameTime The current game time

void Mindshifter.GameConsole.BindCommandHandler ( string  command,
ConsoleCommandHandler  handler,
params char[]  argumentSeparators 
)

Binds a ConsoleCommandHandler to the specified command.

Parameters:
command The command to which the command handler will be bound
handler The command handler to bind to the specified command
argumentSeparators The characters with which the command argument string will be split into separate arguments

Implements Mindshifter.IGameConsole.

ConsoleCommandHandler Mindshifter.GameConsole.UnbindCommandHandler ( string  command  ) 

Unbinds the ConsoleCommandHandler for the specified command.

Parameters:
command The command for which to unbind the current command handler
Returns:
The command handler previously bound to the specified command, or null if no handler was bound

Implements Mindshifter.IGameConsole.

void Mindshifter.GameConsole.Open ( Keys  closeKey  ) 

Displays the console.

Parameters:
closeKey The key that should deactivate the console when pressed

Implements Mindshifter.IGameConsole.

void Mindshifter.GameConsole.Log ( string  message,
uint  level 
)

Logs a message with the specified log level to the console.

Parameters:
message The message to output to the console
level The log level of the message

Implements Mindshifter.IGameConsole.

void Mindshifter.GameConsole.Log ( string  message  ) 

Logs a message with log level 0 to the console.

Parameters:
message The message to output to the console

Implements Mindshifter.IGameConsole.

void Mindshifter.GameConsole.SetLogLevelCustomColor ( uint  level,
Color  color 
)

Sets the custom display color of text for the specified log level.

Parameters:
level The log level for which to set the custom text display color
color The custom color with which to display text for the specified log level

Implements Mindshifter.IGameConsole.

Color Mindshifter.GameConsole.GetLogLevelCustomColor ( uint  level  ) 

Gets the custom display color of text for the specified log level, or returns the default text color if a custom color is not set for the level.

Parameters:
level The log level for which to get the custom display color
Returns:
The custom display color of text for the specified log level, or the default text color if no custom color is set for the level

Implements Mindshifter.IGameConsole.

void Mindshifter.GameConsole.UnsetLogLevelCustomColor ( uint  level  ) 

Unsets the custom display color of text for the specified log level.

Parameters:
level The log level for which to unset the custom text color

Implements Mindshifter.IGameConsole.


Member Data Documentation

event ConsoleInputHandler Mindshifter.GameConsole.TextEntered

Event triggered when text is entered into the console.

Implements Mindshifter.IGameConsole.

event ConsoleLogHandler Mindshifter.GameConsole.MessageLogged

Event triggered when a message is logged to the console.

Implements Mindshifter.IGameConsole.

Dictionary<string, ConsoleCommandHandlerInfo> Mindshifter.GameConsole.mCommandHandlers [private]

SpriteBatch Mindshifter.GameConsole.mSpriteBatch [private]

SpriteFont Mindshifter.GameConsole.mFont [private]

BasicEffect Mindshifter.GameConsole.mEffect [private]

VertexDeclaration Mindshifter.GameConsole.mVertexDeclaration [private]

ConsoleDisplayOptions Mindshifter.GameConsole.mDisplayOptions [private]

string Mindshifter.GameConsole.mTimestampFormat [private]

Dictionary<char, Vector2> Mindshifter.GameConsole.mCharSizeLut [private]

float Mindshifter.GameConsole.mFontHeight [private]

float Mindshifter.GameConsole.mHorizontalPadding [private]

int Mindshifter.GameConsole.mVisibleLineCount [private]

float Mindshifter.GameConsole.mVerticalSpacing [private]

int Mindshifter.GameConsole.mCurrentLine [private]

bool Mindshifter.GameConsole.mAutoScrollOnOutput [private]

bool Mindshifter.GameConsole.mAlertOnUnrecognizedCommand [private]

string Mindshifter.GameConsole.mFontName [private]

Color Mindshifter.GameConsole.mDefaultTextColor [private]

Dictionary<uint, Color> Mindshifter.GameConsole.mTextColors [private]

Color Mindshifter.GameConsole.mBackgroundColor [private]

float Mindshifter.GameConsole.mBackgroundAlpha [private]

bool Mindshifter.GameConsole.mEchoEnabled [private]

uint Mindshifter.GameConsole.mEchoLogLevel [private]

uint Mindshifter.GameConsole.mDefaultLogLevel [private]

int Mindshifter.GameConsole.mLogLevelThreshold [private]

int Mindshifter.GameConsole.mDisplayLevelThreshold [private]

int Mindshifter.GameConsole.mInputPosition [private]

bool Mindshifter.GameConsole.mCursorEnabled [private]

float Mindshifter.GameConsole.mCursorBlinkSpeed [private]

float Mindshifter.GameConsole.mCursorTimer [private]

bool Mindshifter.GameConsole.mDrawCursor [private]

float Mindshifter.GameConsole.mNotifyBlinkSpeed [private]

float Mindshifter.GameConsole.mNotifyTimer [private]

bool Mindshifter.GameConsole.mDrawNotify [private]

List<ConsoleMessage> Mindshifter.GameConsole.mLog [private]

StringBuilder Mindshifter.GameConsole.mCurrentText [private]

string Mindshifter.GameConsole.mInputPrompt [private]

GameTime Mindshifter.GameConsole.mCurrentTime [private]

KeyboardState Mindshifter.GameConsole.mLastKeyboardState [private]

Keys Mindshifter.GameConsole.mCloseKey [private]


Property Documentation

Color Mindshifter.GameConsole.TextColor [get, set]

Gets or sets the console's text color.

Implements Mindshifter.IGameConsole.

Color Mindshifter.GameConsole.BackgroundColor [get, set]

Gets or sets the console's background color.

Implements Mindshifter.IGameConsole.

float Mindshifter.GameConsole.BackgroundAlpha [get, set]

Gets or sets the console's background alpha translucency.

Implements Mindshifter.IGameConsole.

ConsoleDisplayOptions Mindshifter.GameConsole.DisplayOptions [get, set]

Gets or sets the console's display options.

Implements Mindshifter.IGameConsole.

string Mindshifter.GameConsole.TimestampFormat [get, set]

Gets or sets the timestamp format for message timestamps. The following symblols are replaced with their corresponding values when the timestamp for each message is constructed: {Hr} - Hour (in 24 hour format) {Min} - Minute {Sec} - Second {Ms} - Millisecond.

Sample timestamp strings: "{Hr}:{Min}:{Sec}" "[{Hr}:{Min}:{Sec}:{Ms}]"

Implements Mindshifter.IGameConsole.

string Mindshifter.GameConsole.Prompt [get, set]

Gets or sets the prompt used on the input line of the console.

Implements Mindshifter.IGameConsole.

int Mindshifter.GameConsole.VisibleLineCount [get, set]

Gets or sets the number of text lines visible in the console.

Implements Mindshifter.IGameConsole.

float Mindshifter.GameConsole.VerticalLineSpacing [get, set]

Gets or sets the vertical spacing between text lines in the console.

Implements Mindshifter.IGameConsole.

float Mindshifter.GameConsole.HorizontalPadding [get, set]

Gets or sets the amount by which text in the console will be right offset from the leftmost side of the screen.

Implements Mindshifter.IGameConsole.

bool Mindshifter.GameConsole.AutoScrollOnOutput [get, set]

Gets or sets a value indicating whether or not the console should automatically scroll to the last line of the message log whenever a message is output to the console.

Implements Mindshifter.IGameConsole.

bool Mindshifter.GameConsole.AlertOnUnrecognizedCommand [get, set]

Gets or sets a value indicating whether or not the console will output the warning "Unrecognized Command" if the user inputs a command not registered with a command handler.

Implements Mindshifter.IGameConsole.

bool Mindshifter.GameConsole.EchoEnabled [get, set]

Gets or sets a value indicating whether or not the console should automatically echo and input it receives from the user to the console log.

Implements Mindshifter.IGameConsole.

uint Mindshifter.GameConsole.EchoLogLevel [get, set]

Gets or sets the log level of messages echoed automatically if the EchoEnabled property is set to true.

Implements Mindshifter.IGameConsole.

uint Mindshifter.GameConsole.DefaultLogLevel [get, set]

Gets or sets the console's default log level which will be assigned to messages logged to the console with no log level defined.

Implements Mindshifter.IGameConsole.

int Mindshifter.GameConsole.LogLevelThreshold [get, set]

Gets or sets the console's log level threshold. If a message's whose log level is higher than the threshold is logged to the console, it will be ignored. However, if the value is negative then all messages will be logged regardless of their log level.

Implements Mindshifter.IGameConsole.

int Mindshifter.GameConsole.DisplayLevelThreshold [get, set]

Gets or sets the console's display level threshold. The console will only display messages in the log with log levels lower or equal to the display level threshold. However, if the value is negative, then all messages will be displayed regardless of their threshold.

Implements Mindshifter.IGameConsole.

bool Mindshifter.GameConsole.CursorEnabled [get, set]

Gets or sets a value indicating whether or not the input cursor is enabled. If enabled, the user can use the arrow keys to navigate the edit position within the current input string.

Implements Mindshifter.IGameConsole.

float Mindshifter.GameConsole.CursorBlinkSpeed [get, set]

Gets or sets the blink interval of the input cursor, in seconds. The cursor will not blink if this value is set to 0.

Implements Mindshifter.IGameConsole.

float Mindshifter.GameConsole.NotifyBlinkSpeed [get, set]

Gets or sets the blink interval of the notifier that is displayed when the console's current line is not the last line of the log, that is: when the user has used PageUp/Up to scroll upward in the console. The notifier will not blink if this value is set to 0.

Implements Mindshifter.IGameConsole.

ReadOnlyCollection<ConsoleMessage> Mindshifter.GameConsole.MessageLog [get]

Gets the console log of messages.

Implements Mindshifter.IGameConsole.

bool Mindshifter.GameConsole.IsOpen [get]

Gets a value indicating whether or not the console is currently open.

Implements Mindshifter.IGameConsole.


The documentation for this class was generated from the following file:
Generated on Wed Apr 2 17:18:46 2008 for GameConsole by  doxygen 1.5.1-p1