47 for (cParts::iterator itr =
m_Parts.begin(), end =
m_Parts.end(); itr != end; ++itr)
114 size_t len = a_ParseText.length();
118 for (
size_t i = 0; i < len; i++)
120 switch (a_ParseText[i])
131 if (a_ParseText[i] ==
'@')
136 CurrentText.append(a_ParseText.c_str() + first, i - first - 1);
146 CurrentText.append(a_ParseText.c_str() + first, i - first - 1);
149 if (!CurrentText.empty())
154 AddStyle(CurrentStyle, a_ParseText.substr(i - 1, 2));
161 const char * LinkPrefixes[] =
166 for (
size_t Prefix = 0; Prefix <
ARRAYCOUNT(LinkPrefixes); Prefix++)
168 size_t PrefixLen = strlen(LinkPrefixes[Prefix]);
170 (i >= first + PrefixLen) &&
171 (strncmp(a_ParseText.c_str() + i - PrefixLen, LinkPrefixes[Prefix], PrefixLen) == 0)
175 if (i > first + PrefixLen)
177 CurrentText.append(a_ParseText.c_str() + first, i - first - PrefixLen);
178 first = i - PrefixLen;
180 if (!CurrentText.empty())
189 if (isspace(a_ParseText[i]))
194 AddUrlPart(a_ParseText.substr(first, i - first), a_ParseText.substr(first, i - first), CurrentStyle);
205 AddTextPart(a_ParseText.substr(first, len - first), CurrentStyle);
225 for (cParts::iterator itr =
m_Parts.begin(), end =
m_Parts.end(); itr != end; ++itr)
227 if ((*itr)->m_PartType ==
ptUrl)
229 (*itr)->m_Style.append(
"u");
241 for (cParts::const_iterator itr =
m_Parts.begin(), end =
m_Parts.end(); itr != end; ++itr)
243 switch ((*itr)->m_PartType)
250 Msg.append((*itr)->m_Text);
255 Msg.append((static_cast<cUrlPart *>(*itr))->m_Url);
273 switch (a_MessageType)
287 ASSERT(!
"Unhandled MessageType");
297 if (a_AddStyle.empty())
301 if (a_AddStyle[0] ==
'@')
303 size_t idx = a_Style.find(
'@');
304 if ((idx != AString::npos) && (idx != a_Style.length()))
306 a_Style.erase(idx, 2);
308 a_Style.append(a_AddStyle);
311 a_Style.append(a_AddStyle);
323 for (cCompositeChat::cParts::const_iterator itr = Parts.begin(), end = Parts.end(); itr != end; ++itr)
326 switch ((*itr)->m_PartType)
330 Part[
"text"] = (*itr)->m_Text;
338 Part[
"translate"] = p.
m_Text;
357 Url[
"action"] =
"open_url";
358 Url[
"value"] = p.
m_Url;
359 Part[
"clickEvent"] = Url;
372 Part[
"clickEvent"] = Cmd;
380 Part[
"translate"] =
"chat.type.achievement";
383 Ach[
"action"] =
"show_achievement";
386 Json::Value AchColourAndName;
387 AchColourAndName[
"color"] =
"green";
388 AchColourAndName[
"translate"] = p.
m_Text;
389 AchColourAndName[
"hoverEvent"] = Ach;
392 Extra.append(AchColourAndName);
406 msg[
"extra"].append(Part);
411 Json::FastWriter writer;
412 return writer.write(msg);
415 return msg.toStyledString();
425 size_t len = a_PartStyle.length();
426 for (
size_t i = 0; i < len; i++)
428 switch (a_PartStyle[i])
433 a_Value[
"bold"] = Json::Value(
true);
440 a_Value[
"italic"] = Json::Value(
true);
447 a_Value[
"underlined"] = Json::Value(
true);
454 a_Value[
"strikethrough"] = Json::Value(
true);
461 a_Value[
"obfuscated"] = Json::Value(
true);
474 switch (a_PartStyle[i])
476 case '0': a_Value[
"color"] = Json::Value(
"black");
break;
477 case '1': a_Value[
"color"] = Json::Value(
"dark_blue");
break;
478 case '2': a_Value[
"color"] = Json::Value(
"dark_green");
break;
479 case '3': a_Value[
"color"] = Json::Value(
"dark_aqua");
break;
480 case '4': a_Value[
"color"] = Json::Value(
"dark_red");
break;
481 case '5': a_Value[
"color"] = Json::Value(
"dark_purple");
break;
482 case '6': a_Value[
"color"] = Json::Value(
"gold");
break;
483 case '7': a_Value[
"color"] = Json::Value(
"gray");
break;
484 case '8': a_Value[
"color"] = Json::Value(
"dark_gray");
break;
485 case '9': a_Value[
"color"] = Json::Value(
"blue");
break;
486 case 'a': a_Value[
"color"] = Json::Value(
"green");
break;
487 case 'b': a_Value[
"color"] = Json::Value(
"aqua");
break;
488 case 'c': a_Value[
"color"] = Json::Value(
"red");
break;
489 case 'd': a_Value[
"color"] = Json::Value(
"light_purple");
break;
490 case 'e': a_Value[
"color"] = Json::Value(
"yellow");
break;
491 case 'f': a_Value[
"color"] = Json::Value(
"white");
break;
506 m_PartType(a_PartType),
533 m_Parameters(a_Parameters)
558 super(a_PartType, a_Text, a_Style),
595 m_PlayerName(a_PlayerName)
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.
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 opt...
void AddTextPart(const AString &a_Message, const AString &a_Style="")
Adds a plain text part, with optional style.
AStringVector m_Parameters
cUrlPart(const AString &a_Text, const AString &a_Url, const AString &a_Style="")
void UnderlineUrls(void)
Adds the "underline" style to each part that is an URL.
AString GetAdditionalMessageTypeData(void) const
Returns additional data pertaining to message type, for example, the name of a mtPrivateMsg sender...
void ParseText(const AString &a_ParseText)
Parses text into various parts, adds those.
static AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData)
Formats the type of message with the proper color and prefix for sending to the client.
AString ExtractText(void) const
Returns the text from the parts that comprises the human-readable data.
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.
void AddStyle(AString &a_Style, const AString &a_AddStyle)
Adds a_AddStyle to a_Style; overwrites the existing style if appropriate.
cClientTranslatedPart(const AString &a_TranslationID, const AStringVector &a_Parameters, const AString &a_Style="")
eMessageType GetMessageType(void) const
Returns the message type set previously by SetMessageType().
static cLogger::eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType)
Converts the MessageType to a LogLevel value.
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 cli...
std::vector< AString > AStringVector
cSuggestCommandPart(const AString &a_Text, const AString &a_Command, const AString &a_Style="")
cCompositeChat(void)
Creates a new empty chat message.
cRunCommandPart(const AString &a_Text, const AString &a_Command, const AString &a_Style="")
const cParts & GetParts(void) const
cShowAchievementPart(const AString &a_PlayerName, const AString &a_Achievement, const AString &a_Style="")
cCommandPart(ePartType a_PartType, const AString &a_Text, const AString &a_Command, const AString &a_Style="")
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...
eMessageType m_MessageType
The message type, as indicated by prefixes.
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.
AString m_AdditionalMessageTypeData
Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender...
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 achiev...
AString CreateJsonString(bool a_ShouldUseChatPrefixes=true) const
cParts m_Parts
All the parts that.
cBasePart(ePartType a_PartType, const AString &a_Text, const AString &a_Style="")
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
cTextPart(const AString &a_Text, const AString &a_Style="")
std::vector< cBasePart * > cParts
void Clear(void)
Removes all parts from the object.