2#include <Cyrus/Classes/ControlText.h>
3#include <Cyrus/Classes/Window.h>
7std::vector<std::wstring> split(std::wstring s,
wchar_t delimiter) {
8 std::vector<std::wstring> parts;
9 std::wstringstream wss(s);
10 std::wstring temp = L
"";
11 while (std::getline(wss, temp, delimiter)) {
12 parts.push_back(temp);
17int countSubstring(
const std::wstring &str,
const std::wstring &sub) {
18 if (sub.length() == 0)
21 for (
size_t offset = str.find(sub); offset != std::string::npos;
22 offset = str.find(sub, offset + sub.length())) {
39 std::wstring
GID = L
"";
52 std::wstring serialize() {
53 std::wstring ret = L
"";
54 ret += L
"<color;" + msg.
color + L
"><image;" + img.
path + L
";" +
56 if (!player.
GID.empty()) {
57 ret += L
"<link;GID:" + player.
GID + L
"," + player.
name + L
"," +
58 player.
level + L
">" + player.
link + L
"</link>";
60 ret += msg.
message + L
"</color>";
65 std::vector<class_msg_t> messages;
70 if (line.size() == 0) {
75 auto splitted = split(line, L
';');
76 if (splitted.size() < 6) {
81 ret.msg.
color = splitted[1].substr(0, splitted[1].find(L
">"));
82 ret.img.
size_x = splitted[3];
83 ret.img.
size_y = splitted[4];
84 ret.img.
color = splitted[5].substr(0, splitted[5].find(L
">"));
86 const auto link = line.find(L
"<link;");
87 if (link != std::wstring::npos) {
88 const auto gid_loc = line.find(L
"GID:") +
sizeof(
"GID");
89 const auto first_comma = line.find(L
",", gid_loc);
90 ret.player.
GID = line.substr(gid_loc, first_comma - gid_loc);
92 const auto second_comma = line.find(L
",", first_comma + 1);
94 line.substr(first_comma + 1, second_comma - first_comma - 1);
96 auto tag_end = line.find(L
">", second_comma + 1);
98 line.substr(second_comma + 1, tag_end - second_comma - 1);
101 auto link_end = line.find(L
"</link>", tag_end);
102 ret.player.
link = line.substr(tag_end, link_end - tag_end);
104 link_end +=
sizeof(
"</link>");
105 const auto message = line.substr(
106 link_end - 1, line.find(L
"</color>", link_end) - link_end + 1);
109 ret.img.
path = L
"Art/Art_Chat_Say.dds";
114 std::wstring type = L
"none";
115 if (countSubstring(line, L
"<image;") == 2) {
116 auto offset = line.find(L
"<image;", line.find(L
"<image;") + 1);
117 type = line.substr(offset +
sizeof(
"<image"),
118 line.find(L
">", offset) -
sizeof(
"<image") - offset);
119 std::wstring::size_type i = line.find(L
" <image;" + type + L
">");
120 line.erase(i,
sizeof(
"<image;>") + type.length());
123 if (type != L
"none") {
124 ret.img.
path = L
"QuestPage/Art_Quest_" + type + L
".dds";
126 ret.img.
path = splitted[2];
132 splitted[5].substr(splitted[5].find(L
">") + 1,
133 splitted[5].find(L
"<") - splitted[5].find(L
">") - 1);
134 if (ret.msg.
color == L
"AA00AA")
136 ret.img.
path = L
"Art/Art_Quest_XP.dds";
137 }
else if (ret.msg.
color == L
"00FFFF") {
138 ret.img.
path = L
"QuestPage/Art_Quest_Pet.dds";
139 }
else if (ret.msg.
color == L
"D9ABF8") {
140 ret.img.
path = L
"QuestPage/Art_Quest_Emote.dds";
141 }
else if (message.find(L
"You have earned") != std::wstring::npos &&
142 message.find(L
"gold!") != std::wstring::npos) {
143 ret.msg.
color = L
"00CCFE";
144 ret.img.
path = L
"QuestPage/Art_Quest_Gold.dds";
151 const auto split_lines = split(chatLog->
getText(), L
'\n');
152 for (
auto line : split_lines) {
155 messages.push_back(ret);
161 std::wstring ret = L
"";
162 for (
auto i = 0; i < messages.size(); i++) {
163 ret += messages[i].serialize() + (i == messages.size() - 1 ? L
"" : L
"\n");
169 for (
auto i = 0; i < messages.size(); i++) {
170 messages[i].msg.color = L
"00CCFE";
175 const auto history = chatLog->
getText();
176 if (history.size() > 0 && history.find(L
"DBGM") == std::wstring::npos &&
177 history.find(L
"DBGL") == std::wstring::npos &&
178 history.find(L
"WARN") == std::wstring::npos &&
179 history.find(L
"ERRO") == std::wstring::npos &&
180 history.find(L
"STAT") == std::wstring::npos) {
A class that represents a text-based control element in a window.
Definition ControlText.h:22
void setText(const std::wstring &text)
Set the text of the control.
Definition ControlText.h:46
std::wstring getText() const
Get the text of the control.
Definition ControlText.h:39
Definition ChatStyle.h:28
void test()
Definition ChatStyle.h:168
void stylize(int padding=0)
Definition ChatStyle.h:174
std::wstring serialize()
Definition ChatStyle.h:160
class_msg_t process_line(std::wstring line)
Definition ChatStyle.h:68
chat_msg_parser_t(ControlText *chatLog)
Definition ChatStyle.h:150
Definition ChatStyle.h:45
std::wstring path
Definition ChatStyle.h:46
std::wstring size_y
Definition ChatStyle.h:48
std::wstring size_x
Definition ChatStyle.h:47
std::wstring color
Definition ChatStyle.h:49
Definition ChatStyle.h:33
std::wstring message
Definition ChatStyle.h:35
std::wstring color
Definition ChatStyle.h:34
Definition ChatStyle.h:38
std::wstring name
Definition ChatStyle.h:40
std::wstring level
Definition ChatStyle.h:41
std::wstring link
Definition ChatStyle.h:42
std::wstring GID
Definition ChatStyle.h:39