Cuberite
A lightweight, fast and extensible game server for Minecraft
CompositeChat.h
Go to the documentation of this file.
1 
2 // CompositeChat.h
3 
4 // Declares the cCompositeChat class used to wrap a chat message with multiple parts (text, url, cmd)
5 
6 #pragma once
7 
8 #include "Defines.h"
9 #include "json/json.h"
10 
11 
12 
13 
14 
15 // tolua_begin
34 {
35 public:
36  // tolua_end
37 
38 
39  struct BasePart
40  {
44  } ;
45 
46 
47 
48  struct TextPart:
49  public BasePart
50  {
51  } ;
52 
53 
54 
56  public BasePart
57  {
59  } ;
60 
61 
62 
63  struct UrlPart:
64  public BasePart
65  {
67  } ;
68 
69 
70 
71  struct CommandPart:
72  public BasePart
73  {
75  } ;
76 
77 
78 
80  public CommandPart
81  {
82  } ;
83 
84 
85 
87  public CommandPart
88  {
89  } ;
90 
91 
92 
94  public BasePart
95  {
97  } ;
98 
99 
100 
103  cCompositeChat(void);
104 
109  cCompositeChat(const AString & a_ParseText, eMessageType a_MessageType = mtCustom);
110 
111  // The following are exported in ManualBindings in order to support chaining - they return "self" in Lua (#755)
112 
114  void Clear(void);
115 
118  void AddTextPart(const AString & a_Message, const AString & a_Style = "");
119 
121  void AddClientTranslatedPart(const AString & a_TranslationID, const AStringVector & a_Parameters, const AString & a_Style = "");
122 
125  void AddUrlPart(const AString & a_Text, const AString & a_Url, const AString & a_Style = "nc");
126 
129  void AddRunCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = "na");
130 
133  void AddSuggestCommandPart(const AString & a_Text, const AString & a_SuggestedCommand, const AString & a_Style = "nb");
134 
138  void AddShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style = "");
139 
142  void ParseText(const AString & a_ParseText);
143 
145  void UnderlineUrls(void);
146 
150  void SetMessageType(eMessageType a_MessageType, const AString & a_AdditionalMessageTypeData = "");
151 
152  // tolua_begin
153 
155  eMessageType GetMessageType(void) const { return m_MessageType; }
156 
159 
163  AString ExtractText(void) const;
164 
165  AString CreateJsonString(bool a_ShouldUseChatPrefixes = true) const;
166 
167  // tolua_end
168 
169  const auto & GetParts(void) const { return m_Parts; }
170 
173  static eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType);
174 
176  void AddChatPartStyle(Json::Value & a_Value, const AString & a_PartStyle) const;
177 
178 protected:
179 
181  std::vector<std::variant<TextPart, ClientTranslatedPart, UrlPart, RunCommandPart, SuggestCommandPart, ShowAchievementPart>> m_Parts;
182 
185 
188 
189 } ; // tolua_export
eMessageType
Definition: Defines.h:352
@ mtCustom
Definition: Defines.h:356
eLogLevel
Definition: LoggerSimple.h:6
std::vector< AString > AStringVector
Definition: StringUtils.h:12
std::string AString
Definition: StringUtils.h:11
Container for a single chat message composed of multiple functional parts.
Definition: CompositeChat.h:34
void Clear(void)
Removes all parts from the object.
AString CreateJsonString(bool a_ShouldUseChatPrefixes=true) const
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 UnderlineUrls(void)
Adds the "underline" style to each part that is an URL.
void AddUrlPart(const AString &a_Text, const AString &a_Url, const AString &a_Style="nc")
Adds a part that opens an URL when clicked.
AString ExtractText(void) const
Returns the text from the parts that comprises the human-readable data.
AString m_AdditionalMessageTypeData
Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.
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 cli...
void ParseText(const AString &a_ParseText)
Parses text into various parts, adds those.
const auto & GetParts(void) const
eMessageType GetMessageType(void) const
Returns the message type set previously by SetMessageType().
void AddTextPart(const AString &a_Message, const AString &a_Style="")
Adds a plain text part, with optional 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.
cCompositeChat(void)
Creates a new empty chat message.
void AddRunCommandPart(const AString &a_Text, const AString &a_Command, const AString &a_Style="na")
Adds a part that runs a command when clicked.
eMessageType m_MessageType
The message type, as indicated by prefixes.
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.
std::vector< std::variant< TextPart, ClientTranslatedPart, UrlPart, RunCommandPart, SuggestCommandPart, ShowAchievementPart > > m_Parts
All the parts that.
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 GetAdditionalMessageTypeData(void) const
Returns additional data pertaining to message type, for example, the name of a mtPrivateMsg sender.
static eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType)
Converts the MessageType to a LogLevel value.