2014-02-15 17:16:44 -05:00
|
|
|
|
|
|
|
// CompositeChat.h
|
|
|
|
|
|
|
|
// Declares the cCompositeChat class used to wrap a chat message with multiple parts (text, url, cmd)
|
|
|
|
|
2020-05-04 08:58:43 -04:00
|
|
|
#pragma once
|
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
#include "Defines.h"
|
2014-09-13 14:27:10 -04:00
|
|
|
#include "json/json.h"
|
2014-02-15 17:16:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// tolua_begin
|
|
|
|
/** Container for a single chat message composed of multiple functional parts.
|
|
|
|
Each part corresponds roughly to the behavior supported by the client messaging:
|
|
|
|
- plain text, optionaly colorized / styled
|
|
|
|
- clickable URLs
|
|
|
|
- clickable commands (run)
|
|
|
|
- clickable commands (suggest)
|
|
|
|
Each part has a text assigned to it that can be styled. The style is specified using a string,
|
|
|
|
each character / character combination in the string specifies the style to use:
|
|
|
|
- b = bold
|
|
|
|
- i = italic
|
|
|
|
- u = underlined
|
|
|
|
- s = strikethrough
|
|
|
|
- o = obfuscated
|
|
|
|
- @X = color X (X is 0 - 9 or a - f, same as dye meta
|
|
|
|
If the protocol version doesn't support all the features, it degrades gracefully.
|
|
|
|
*/
|
|
|
|
class cCompositeChat
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// tolua_end
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
|
2021-02-04 21:05:14 -05:00
|
|
|
struct BasePart
|
2014-02-15 17:16:44 -05:00
|
|
|
{
|
2021-02-04 21:05:14 -05:00
|
|
|
AString Text;
|
|
|
|
AString Style;
|
|
|
|
AString AdditionalStyleData;
|
2014-02-15 17:16:44 -05:00
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
|
|
|
|
|
2021-02-04 21:05:14 -05:00
|
|
|
struct TextPart:
|
|
|
|
public BasePart
|
2014-02-15 17:16:44 -05:00
|
|
|
{
|
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
|
|
|
|
|
2021-02-04 21:05:14 -05:00
|
|
|
struct ClientTranslatedPart:
|
|
|
|
public BasePart
|
2014-02-15 17:16:44 -05:00
|
|
|
{
|
2021-02-04 21:05:14 -05:00
|
|
|
AStringVector Parameters;
|
2014-02-15 17:16:44 -05:00
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
|
|
|
|
|
2021-02-04 21:05:14 -05:00
|
|
|
struct UrlPart:
|
|
|
|
public BasePart
|
2014-02-15 17:16:44 -05:00
|
|
|
{
|
2021-02-04 21:05:14 -05:00
|
|
|
AString Url;
|
2014-02-15 17:16:44 -05:00
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
|
|
|
|
|
2021-02-04 21:05:14 -05:00
|
|
|
struct CommandPart:
|
|
|
|
public BasePart
|
2014-02-15 17:16:44 -05:00
|
|
|
{
|
2021-02-04 21:05:14 -05:00
|
|
|
AString Command;
|
2014-02-15 17:16:44 -05:00
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
|
|
|
|
|
2021-02-04 21:05:14 -05:00
|
|
|
struct RunCommandPart:
|
|
|
|
public CommandPart
|
2014-02-15 17:16:44 -05:00
|
|
|
{
|
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
|
|
|
|
|
2021-02-04 21:05:14 -05:00
|
|
|
struct SuggestCommandPart:
|
|
|
|
public CommandPart
|
2014-02-15 17:16:44 -05:00
|
|
|
{
|
|
|
|
} ;
|
2014-05-19 15:40:56 -04:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
|
|
|
|
|
2021-02-04 21:05:14 -05:00
|
|
|
struct ShowAchievementPart:
|
|
|
|
public BasePart
|
2014-05-19 15:40:56 -04:00
|
|
|
{
|
2021-02-04 21:05:14 -05:00
|
|
|
AString PlayerName;
|
2014-05-19 15:40:56 -04:00
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2016-09-25 06:42:05 -04:00
|
|
|
/** Creates a new empty chat message.
|
|
|
|
Exported manually due to the other overload needing a manual export. */
|
2014-02-15 17:16:44 -05:00
|
|
|
cCompositeChat(void);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
/** Creates a new chat message and parses the text into parts.
|
|
|
|
Recognizes "http:" and "https:" links and @color-codes.
|
2016-09-25 06:42:05 -04:00
|
|
|
Uses ParseText() for the actual parsing.
|
|
|
|
Exported manually due to ToLua++ generating extra output parameter. */
|
2014-03-31 07:28:38 -04:00
|
|
|
cCompositeChat(const AString & a_ParseText, eMessageType a_MessageType = mtCustom);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2016-09-25 06:42:05 -04:00
|
|
|
// The following are exported in ManualBindings in order to support chaining - they return "self" in Lua (#755)
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
/** Removes all parts from the object. */
|
|
|
|
void Clear(void);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
/** Adds a plain text part, with optional style.
|
|
|
|
The default style is plain white text. */
|
|
|
|
void AddTextPart(const AString & a_Message, const AString & a_Style = "");
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-03-04 16:17:23 -05:00
|
|
|
/** Adds a part that is translated client-side, with the formatting parameters and optional style. */
|
2014-02-15 17:16:44 -05:00
|
|
|
void AddClientTranslatedPart(const AString & a_TranslationID, const AStringVector & a_Parameters, const AString & a_Style = "");
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
/** Adds a part that opens an URL when clicked.
|
|
|
|
The default style is underlined light blue text. */
|
|
|
|
void AddUrlPart(const AString & a_Text, const AString & a_Url, const AString & a_Style = "u@c");
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
/** Adds a part that runs a command when clicked.
|
|
|
|
The default style is underlined light green text. */
|
|
|
|
void AddRunCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = "u@a");
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
/** 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. */
|
|
|
|
void AddSuggestCommandPart(const AString & a_Text, const AString & a_SuggestedCommand, const AString & a_Style = "u@b");
|
2014-05-19 15:40:56 -04:00
|
|
|
|
|
|
|
/** 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}.
|
|
|
|
*/
|
|
|
|
void AddShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style = "");
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
/** Parses text into various parts, adds those.
|
|
|
|
Recognizes "http:" and "https:" URLs and @color-codes. */
|
|
|
|
void ParseText(const AString & a_ParseText);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2016-09-25 06:42:05 -04:00
|
|
|
/** Adds the "underline" style to each part that is an URL. */
|
|
|
|
void UnderlineUrls(void);
|
|
|
|
|
2014-05-20 17:49:21 -04:00
|
|
|
/** 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.
|
2016-09-25 06:42:05 -04:00
|
|
|
Exported manually, because ToLua++ would generate extra return values. */
|
2014-05-20 17:49:21 -04:00
|
|
|
void SetMessageType(eMessageType a_MessageType, const AString & a_AdditionalMessageTypeData = "");
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-03-04 16:17:23 -05:00
|
|
|
// tolua_begin
|
|
|
|
|
|
|
|
/** Returns the message type set previously by SetMessageType(). */
|
|
|
|
eMessageType GetMessageType(void) const { return m_MessageType; }
|
2014-05-19 16:16:29 -04:00
|
|
|
|
|
|
|
/** Returns additional data pertaining to message type, for example, the name of a mtPrivateMsg sender */
|
|
|
|
AString GetAdditionalMessageTypeData(void) const { return m_AdditionalMessageTypeData; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-03-31 16:51:14 -04:00
|
|
|
/** 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. */
|
|
|
|
AString ExtractText(void) const;
|
2014-09-13 14:27:10 -04:00
|
|
|
|
|
|
|
AString CreateJsonString(bool a_ShouldUseChatPrefixes = true) const;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
// tolua_end
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2021-02-04 21:05:14 -05:00
|
|
|
const auto & GetParts(void) const { return m_Parts; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-01 03:32:14 -04:00
|
|
|
/** Converts the MessageType to a LogLevel value.
|
|
|
|
Used by the logging bindings when logging a cCompositeChat object. */
|
2020-05-14 22:35:43 -04:00
|
|
|
static eLogLevel MessageTypeToLogLevel(eMessageType a_MessageType);
|
2014-09-13 14:27:10 -04:00
|
|
|
|
|
|
|
/** Adds the chat part's style (represented by the part's stylestring) into the Json object. */
|
|
|
|
void AddChatPartStyle(Json::Value & a_Value, const AString & a_PartStyle) const;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
protected:
|
2021-02-04 21:05:14 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
/** All the parts that */
|
2021-02-04 21:05:14 -05:00
|
|
|
std::vector<std::variant<TextPart, ClientTranslatedPart, UrlPart, RunCommandPart, SuggestCommandPart, ShowAchievementPart>> m_Parts;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-15 17:16:44 -05:00
|
|
|
/** The message type, as indicated by prefixes. */
|
|
|
|
eMessageType m_MessageType;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-05-19 16:16:29 -04:00
|
|
|
/** Additional data pertaining to message type, for example, the name of a mtPrivateMsg sender */
|
|
|
|
AString m_AdditionalMessageTypeData;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
|
|
|
|
2014-02-16 17:31:47 -05:00
|
|
|
/** 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. */
|
|
|
|
void AddStyle(AString & a_Style, const AString & a_AddStyle);
|
2014-02-15 17:16:44 -05:00
|
|
|
} ; // tolua_export
|