Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cCompositeChat Class Reference

Container for a single chat message composed of multiple functional parts. More...

#include <CompositeChat.h>

Classes

class  cBasePart
 
class  cClientTranslatedPart
 
class  cCommandPart
 
class  cRunCommandPart
 
class  cShowAchievementPart
 
class  cSuggestCommandPart
 
class  cTextPart
 
class  cUrlPart
 

Public Types

typedef std::vector< cBasePart * > cParts
 
enum  ePartType {
  ptText, ptClientTranslated, ptUrl, ptRunCommand,
  ptSuggestCommand, ptShowAchievement
}
 

Public Member Functions

void AddChatPartStyle (Json::Value &a_Value, const AString &a_PartStyle) const
 Adds the chat part's style (represented by the part's stylestring) into the Json object. More...
 
void AddClientTranslatedPart (const AString &a_TranslationID, const AStringVector &a_Parameters, const AString &a_Style="")
 Adds a part that is translated client-side, with the formatting parameters and optional style. More...
 
void AddRunCommandPart (const AString &a_Text, const AString &a_Command, const AString &a_Style="u@a")
 Adds a part that runs a command when clicked. More...
 
void AddShowAchievementPart (const AString &a_PlayerName, const AString &a_Achievement, const AString &a_Style="")
 Adds a part that fully formats a specified achievement using client translatable strings Takes achievement name and player awarded to. More...
 
void AddSuggestCommandPart (const AString &a_Text, const AString &a_SuggestedCommand, const AString &a_Style="u@b")
 Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked. More...
 
void AddTextPart (const AString &a_Message, const AString &a_Style="")
 Adds a plain text part, with optional style. More...
 
void AddUrlPart (const AString &a_Text, const AString &a_Url, const AString &a_Style="u@c")
 Adds a part that opens an URL when clicked. More...
 
 cCompositeChat (void)
 Creates a new empty chat message. More...
 
 cCompositeChat (const AString &a_ParseText, eMessageType a_MessageType=mtCustom)
 Creates a new chat message and parses the text into parts. More...
 
void Clear (void)
 Removes all parts from the object. More...
 
AString CreateJsonString (bool a_ShouldUseChatPrefixes=true) const
 
AString ExtractText (void) const
 Returns the text from the parts that comprises the human-readable data. More...
 
AString GetAdditionalMessageTypeData (void) const
 Returns additional data pertaining to message type, for example, the name of a mtPrivateMsg sender. More...
 
eMessageType GetMessageType (void) const
 Returns the message type set previously by SetMessageType(). More...
 
const cPartsGetParts (void) const
 
void ParseText (const AString &a_ParseText)
 Parses text into various parts, adds those. More...
 
void SetMessageType (eMessageType a_MessageType, const AString &a_AdditionalMessageTypeData="")
 Sets the message type, which is indicated by prefixes added to the message when serializing Takes optional AdditionalMessageTypeData to set m_AdditionalMessageTypeData. More...
 
void UnderlineUrls (void)
 Adds the "underline" style to each part that is an URL. More...
 
 ~cCompositeChat ()
 

Static Public Member Functions

static cLogger::eLogLevel MessageTypeToLogLevel (eMessageType a_MessageType)
 Converts the MessageType to a LogLevel value. More...
 

Protected Member Functions

void AddStyle (AString &a_Style, const AString &a_AddStyle)
 Adds a_AddStyle to a_Style; overwrites the existing style if appropriate. More...
 

Protected Attributes

AString m_AdditionalMessageTypeData
 Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender. More...
 
eMessageType m_MessageType
 The message type, as indicated by prefixes. More...
 
cParts m_Parts
 All the parts that. More...
 

Detailed Description

Container for a single chat message composed of multiple functional parts.

Each part corresponds roughly to the behavior supported by the client messaging:

Definition at line 31 of file CompositeChat.h.

Member Typedef Documentation

typedef std::vector<cBasePart *> cCompositeChat::cParts

Definition at line 123 of file CompositeChat.h.

Member Enumeration Documentation

Enumerator
ptText 
ptClientTranslated 
ptUrl 
ptRunCommand 
ptSuggestCommand 
ptShowAchievement 

Definition at line 36 of file CompositeChat.h.

Constructor & Destructor Documentation

cCompositeChat::cCompositeChat ( void  )

Creates a new empty chat message.

Exported manually due to the other overload needing a manual export.

Definition at line 17 of file CompositeChat.cpp.

cCompositeChat::cCompositeChat ( const AString a_ParseText,
eMessageType  a_MessageType = mtCustom 
)

Creates a new chat message and parses the text into parts.

Recognizes "http:" and "https:" links and -codes. Uses ParseText() for the actual parsing. Exported manually due to ToLua++ generating extra output parameter.

Definition at line 26 of file CompositeChat.cpp.

cCompositeChat::~cCompositeChat ( )

Definition at line 36 of file CompositeChat.cpp.

Member Function Documentation

void cCompositeChat::AddChatPartStyle ( Json::Value &  a_Value,
const AString a_PartStyle 
) const

Adds the chat part's style (represented by the part's stylestring) into the Json object.

Definition at line 423 of file CompositeChat.cpp.

void cCompositeChat::AddClientTranslatedPart ( const AString a_TranslationID,
const AStringVector a_Parameters,
const AString a_Style = "" 
)

Adds a part that is translated client-side, with the formatting parameters and optional style.

Definition at line 67 of file CompositeChat.cpp.

void cCompositeChat::AddRunCommandPart ( const AString a_Text,
const AString a_Command,
const AString a_Style = "u@a" 
)

Adds a part that runs a command when clicked.

The default style is underlined light green text.

Definition at line 85 of file CompositeChat.cpp.

void cCompositeChat::AddShowAchievementPart ( const AString a_PlayerName,
const AString a_Achievement,
const AString a_Style = "" 
)

Adds a part that fully formats a specified achievement using client translatable strings Takes achievement name and player awarded to.

Displays as {player} has earned the achievement {achievement_name}.

Definition at line 103 of file CompositeChat.cpp.

void cCompositeChat::AddStyle ( AString a_Style,
const AString a_AddStyle 
)
protected

Adds a_AddStyle to a_Style; overwrites the existing style if appropriate.

If the style already contains something that a_AddStyle overrides, it is erased first.

Definition at line 295 of file CompositeChat.cpp.

void cCompositeChat::AddSuggestCommandPart ( const AString a_Text,
const AString a_SuggestedCommand,
const AString a_Style = "u@b" 
)

Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked.

The default style is underlined yellow text.

Definition at line 94 of file CompositeChat.cpp.

void cCompositeChat::AddTextPart ( const AString a_Message,
const AString a_Style = "" 
)

Adds a plain text part, with optional style.

The default style is plain white text.

Definition at line 58 of file CompositeChat.cpp.

void cCompositeChat::AddUrlPart ( const AString a_Text,
const AString a_Url,
const AString a_Style = "u@c" 
)

Adds a part that opens an URL when clicked.

The default style is underlined light blue text.

Definition at line 76 of file CompositeChat.cpp.

void cCompositeChat::Clear ( void  )

Removes all parts from the object.

Definition at line 45 of file CompositeChat.cpp.

AString cCompositeChat::CreateJsonString ( bool  a_ShouldUseChatPrefixes = true) const

Definition at line 318 of file CompositeChat.cpp.

AString cCompositeChat::ExtractText ( void  ) const

Returns the text from the parts that comprises the human-readable data.

Used for older protocols that don't support composite chat and for console-logging.

Definition at line 238 of file CompositeChat.cpp.

AString cCompositeChat::GetAdditionalMessageTypeData ( void  ) const
inline

Returns additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.

Definition at line 184 of file CompositeChat.h.

eMessageType cCompositeChat::GetMessageType ( void  ) const
inline

Returns the message type set previously by SetMessageType().

Definition at line 181 of file CompositeChat.h.

const cParts& cCompositeChat::GetParts ( void  ) const
inline

Definition at line 195 of file CompositeChat.h.

cLogger::eLogLevel cCompositeChat::MessageTypeToLogLevel ( eMessageType  a_MessageType)
static

Converts the MessageType to a LogLevel value.

Used by the logging bindings when logging a cCompositeChat object.

Definition at line 271 of file CompositeChat.cpp.

void cCompositeChat::ParseText ( const AString a_ParseText)

Parses text into various parts, adds those.

Recognizes "http:" and "https:" URLs and -codes.

Definition at line 112 of file CompositeChat.cpp.

void cCompositeChat::SetMessageType ( eMessageType  a_MessageType,
const AString a_AdditionalMessageTypeData = "" 
)

Sets the message type, which is indicated by prefixes added to the message when serializing Takes optional AdditionalMessageTypeData to set m_AdditionalMessageTypeData.

See said variable for more documentation. Exported manually, because ToLua++ would generate extra return values.

Definition at line 213 of file CompositeChat.cpp.

void cCompositeChat::UnderlineUrls ( void  )

Adds the "underline" style to each part that is an URL.

Definition at line 223 of file CompositeChat.cpp.

Member Data Documentation

AString cCompositeChat::m_AdditionalMessageTypeData
protected

Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.

Definition at line 212 of file CompositeChat.h.

eMessageType cCompositeChat::m_MessageType
protected

The message type, as indicated by prefixes.

Definition at line 209 of file CompositeChat.h.

cParts cCompositeChat::m_Parts
protected

All the parts that.

Definition at line 206 of file CompositeChat.h.


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