MessageVector

Store a list of chat messages.

Inherit:
SimObject

Description

This is responsible for managing messages which appear in the chat HUD, not the actual control rendered to the screen

Example:

// Declare ChatHud, which is what will display the actual chat from a MessageVectornewGuiMessageVectorCtrl(ChatHud) {
   profile = "ChatHudMessageProfile";
   horizSizing = "width";
   vertSizing = "height";
   position = "1 1";
   extent = "252 16";
   minExtent = "8 8";
   visible = "1";
   helpTag = "0";
   lineSpacing = "0";
   lineContinuedIndex = "10";
   matchColor = "0 0 255 255";
   maxColorIndex = "5";
};

// All messages are stored in this HudMessageVector, the actual// MainChatHud only displays the contents of this vector.newMessageVector(HudMessageVector);

// Attach the MessageVector to the chat control
chatHud.attach(HudMessageVector);

Methods

void MessageVector::clear()

Clear all messages in the vector.

Example:

HudMessageVector.clear();
bool MessageVector::deleteLine(int deletePos)

Delete the line at the specified position.

Parameters:deletePos – Position in the vector containing the line to be deleted
Returns:False if deletePos is greater than the number of lines in the current vector

Example:

// Delete the first line (index 0) in the vector...
HudMessageVector.deleteLine(0);
void MessageVector::dump(string filename)

Dump the message vector to a file without a header.

Parameters:filename – Name and path of file to dump text to.

Example:

// Dump the entire chat log to a text file
HudMessageVector.dump("./chatLog.txt");
void MessageVector::dump(string filename, string header)

Dump the message vector to a file with a header.

Parameters:
  • filename – Name and path of file to dump text to.
  • header – Prefix information for write out

Example:

// Arbitrary header data
%headerInfo = "Ars Moriendi Chat Log";

// Dump the entire chat log to a text file
HudMessageVector.dump("./chatLog.txt", %headerInfo);
int MessageVector::getLineIndexByTag(int tag)

Scan through the vector, returning the line number of the first line that matches the specified tag; else returns -1 if no match was found.

Parameters:tag – Numerical value assigned to a message when it was added or inserted
Returns:Line with matching tag, other wise -1

Example:

// Locate a line of text tagged with the value "1", then delete it.
%taggedLine = HudMessageVector.getLineIndexByTag(1);
HudMessageVector.deleteLine(%taggedLine);
int MessageVector::getLineTag(int pos)

Get the tag of a specified line.

Parameters:pos – Position in vector to grab tag from
Returns:Tag value of a given line, if the position is greater than the number of lines return 0

Example:

// Remove all lines that do not have a tag value of 1.while( HudMessageVector.getNumLines())
{
   %tag = HudMessageVector.getLineTag(1);
   if(%tag != 1)
      %tag.delete();
   HudMessageVector.popFrontLine();
}
string MessageVector::getLineText(int pos)

Get the text at a specified line.

Parameters:pos – Position in vector to grab text from
Returns:Text at specified line, if the position is greater than the number of lines return “”

Example:

// Print a line of text at position 1.
%text = HudMessageVector.getLineText(1);
echo(%text);
string MessageVector::getLineTextByTag(int tag)

Scan through the lines in the vector, returning the first line that has a matching tag.

Parameters:tag – Numerical value assigned to a message when it was added or inserted
Returns:Text from a line with matching tag, other wise “”

Example:

// Locate text in the vector tagged with the value "1", then print it
%taggedText = HudMessageVector.getLineTextByTag(1);
echo(%taggedText);
int MessageVector::getNumLines()

Get the number of lines in the vector.

Example:

// Find out how many lines have been stored in HudMessageVector
%chatLines = HudMessageVector.getNumLines();
echo(%chatLines);
bool MessageVector::insertLine(int insertPos, string msg, int tag)

Push a line onto the back of the list.

Parameters:
  • msg – Text that makes up the message
  • tag – Numerical value associated with this message, useful for searching.
Returns:

False if insertPos is greater than the number of lines in the current vector

Example:

// Add the message...
HudMessageVector.insertLine(1, "Hello World", 0);
bool MessageVector::popBackLine()

Pop a line from the back of the list; destroys the line.

Returns:False if there are no lines to pop (underflow), true otherwise

Example:

HudMessageVector.popBackLine();
bool MessageVector::popFrontLine()

Pop a line from the front of the vector, destroying the line.

Returns:False if there are no lines to pop (underflow), true otherwise

Example:

HudMessageVector.popFrontLine();
void MessageVector::pushBackLine(string msg, int tag)

Push a line onto the back of the list.

Parameters:
  • msg – Text that makes up the message
  • tag – Numerical value associated with this message, useful for searching.

Example:

// Add the message...
HudMessageVector.pushBackLine("Hello World", 0);
void MessageVector::pushFrontLine(string msg, int tag)

Push a line onto the front of the vector.

Parameters:
  • msg – Text that makes up the message
  • tag – Numerical value associated with this message, useful for searching.

Example:

// Add the message...
HudMessageVector.pushFrontLine("Hello World", 0);