Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Container for a single chat message composed of multiple functional parts. More...
#include <CompositeChat.h>
Classes | |
struct | BasePart |
struct | ClientTranslatedPart |
struct | CommandPart |
struct | RunCommandPart |
struct | ShowAchievementPart |
struct | SuggestCommandPart |
struct | TextPart |
struct | UrlPart |
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="na") |
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="nb") |
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="nc") |
Adds a part that opens an URL when clicked. More... | |
cCompositeChat (const AString &a_ParseText, eMessageType a_MessageType=mtCustom) | |
Creates a new chat message and parses the text into parts. More... | |
cCompositeChat (void) | |
Creates a new empty chat message. 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 auto & | GetParts (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... | |
Static Public Member Functions | |
static eLogLevel | MessageTypeToLogLevel (eMessageType a_MessageType) |
Converts the MessageType to a LogLevel value. 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... | |
std::vector< std::variant< TextPart, ClientTranslatedPart, UrlPart, RunCommandPart, SuggestCommandPart, ShowAchievementPart > > | m_Parts |
All the parts that. More... | |
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 33 of file CompositeChat.h.
cCompositeChat::cCompositeChat | ( | void | ) |
Creates a new empty chat message.
Exported manually due to the other overload needing a manual export.
Definition at line 18 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 &format-character. Uses ParseText() for the actual parsing. Exported manually due to ToLua++ generating extra output parameter.
Definition at line 27 of file CompositeChat.cpp.
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 381 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 55 of file CompositeChat.cpp.
void cCompositeChat::AddRunCommandPart | ( | const AString & | a_Text, |
const AString & | a_Command, | ||
const AString & | a_Style = "na" |
||
) |
Adds a part that runs a command when clicked.
The default style is underlined light green text.
Definition at line 73 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 91 of file CompositeChat.cpp.
void cCompositeChat::AddSuggestCommandPart | ( | const AString & | a_Text, |
const AString & | a_SuggestedCommand, | ||
const AString & | a_Style = "nb" |
||
) |
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 82 of file CompositeChat.cpp.
Adds a plain text part, with optional style.
The default style is plain white text.
Definition at line 46 of file CompositeChat.cpp.
void cCompositeChat::AddUrlPart | ( | const AString & | a_Text, |
const AString & | a_Url, | ||
const AString & | a_Style = "nc" |
||
) |
Adds a part that opens an URL when clicked.
The default style is underlined light blue text.
Definition at line 64 of file CompositeChat.cpp.
void cCompositeChat::Clear | ( | void | ) |
Removes all parts from the object.
Definition at line 37 of file CompositeChat.cpp.
AString cCompositeChat::CreateJsonString | ( | bool | a_ShouldUseChatPrefixes = true | ) | const |
Definition at line 283 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 237 of file CompositeChat.cpp.
|
inline |
Returns additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.
Definition at line 158 of file CompositeChat.h.
|
inline |
Returns the message type set previously by SetMessageType().
Definition at line 155 of file CompositeChat.h.
|
inline |
Definition at line 169 of file CompositeChat.h.
|
static |
Converts the MessageType to a LogLevel value.
Used by the logging bindings when logging a cCompositeChat object.
Definition at line 259 of file CompositeChat.cpp.
void cCompositeChat::ParseText | ( | const AString & | a_ParseText | ) |
Parses text into various parts, adds those.
Parse the input message to add colors or link then add it to the object.
Recognizes "http:" and "https:" URLs and &color-codes.
It detects every & of the message and the next character for it to colorize. It detect : in the text to detect link structures.
a_ParseText | The input text to parse |
Definition at line 107 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 207 of file CompositeChat.cpp.
void cCompositeChat::UnderlineUrls | ( | void | ) |
Adds the "underline" style to each part that is an URL.
Definition at line 217 of file CompositeChat.cpp.
|
protected |
Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.
Definition at line 187 of file CompositeChat.h.
|
protected |
The message type, as indicated by prefixes.
Definition at line 184 of file CompositeChat.h.
|
protected |
All the parts that.
Definition at line 181 of file CompositeChat.h.