diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index a80af5d2c..691b3d576 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -65,6 +65,7 @@ #include "..\Minecraft.World\DurangoStats.h" #include "..\Minecraft.World\GenericStats.h" #endif +#include ClientConnection::ClientConnection(Minecraft *minecraft, const wstring& ip, int port) { @@ -1546,17 +1547,36 @@ void ClientConnection::handleChat(shared_ptr packet) bool replaceEntitySource = false; bool replaceItem = false; + static std::wregex IDS_Pattern(LR"(\{\*IDS_(\d+)\*\})"); //maybe theres a better way to do translateable IDS + + int stringArgsSize = packet->m_stringArgs.size(); + wstring playerDisplayName = L""; wstring sourceDisplayName = L""; // On platforms other than Xbox One this just sets display name to gamertag - if (packet->m_stringArgs.size() >= 1) playerDisplayName = GetDisplayNameByGamertag(packet->m_stringArgs[0]); - if (packet->m_stringArgs.size() >= 2) sourceDisplayName = GetDisplayNameByGamertag(packet->m_stringArgs[1]); + if (stringArgsSize >= 1) playerDisplayName = GetDisplayNameByGamertag(packet->m_stringArgs[0]); + if (stringArgsSize >= 2) sourceDisplayName = GetDisplayNameByGamertag(packet->m_stringArgs[1]); switch(packet->m_messageType) { case ChatPacket::e_ChatCustom: - message = (packet->m_stringArgs.size() >= 1) ? packet->m_stringArgs[0] : L""; + if (stringArgsSize > 1) { + message = packet->m_stringArgs[0]; + + for (int i = 1; i < stringArgsSize; i++) { //skip the first string index, thats main message + message = replaceAll(message, L"{*ARGS_" + std::to_wstring(i) + L"*}", packet->m_stringArgs[i]); + } + + std::wsmatch match; + while (std::regex_search(message, match, IDS_Pattern)) { + message = replaceAll(message, match[0], app.GetString(std::stoi(match[1].str()))); + } + + message = app.FormatHTMLString(m_userIndex, message); + } else if (packet->m_stringArgs.size() == 1) { + message = (packet->m_stringArgs.size() >= 1) ? packet->m_stringArgs[0] : L""; + } break; case ChatPacket::e_ChatBedOccupied: message = app.GetString(IDS_TILE_BED_OCCUPIED); @@ -1906,7 +1926,7 @@ void ClientConnection::handleChat(shared_ptr packet) if(replacePlayer) { - message = replaceAll(message,L"{*PLAYER*}",playerDisplayName); + message = replaceAll(message,L"{*PLAYER*}", playerDisplayName); } if(replaceEntitySource) @@ -1941,7 +1961,7 @@ void ClientConnection::handleChat(shared_ptr packet) // flag that a message is a death message bool bIsDeathMessage = (packet->m_messageType>=ChatPacket::e_ChatDeathInFire) && (packet->m_messageType<=ChatPacket::e_ChatDeathIndirectMagicItem); - if( displayOnGui ) minecraft->gui->addMessage(message,m_userIndex, bIsDeathMessage); + if( displayOnGui ) minecraft->gui->addMessage(message, m_userIndex, bIsDeathMessage); } void ClientConnection::handleAnimate(shared_ptr packet) diff --git a/Minecraft.Client/Common/UI/UIScene_HUD.cpp b/Minecraft.Client/Common/UI/UIScene_HUD.cpp index 213caa8dc..06aea4fa2 100644 --- a/Minecraft.Client/Common/UI/UIScene_HUD.cpp +++ b/Minecraft.Client/Common/UI/UIScene_HUD.cpp @@ -23,6 +23,7 @@ UIScene_HUD::UIScene_HUD(int iPad, void *initData, UILayer *parentLayer) : UISce for(unsigned int i = 0; i < CHAT_LINES_COUNT; ++i) { m_labelChatText[i].init(L""); + IggyValueSetBooleanRS(m_labelChatText[i].getIggyValuePath(), 0, "m_bUseHtmlText", true); } m_labelJukebox.init(L""); diff --git a/Minecraft.Client/Common/UI/UIScene_HUD.h b/Minecraft.Client/Common/UI/UIScene_HUD.h index 04468c8ec..caadb50af 100644 --- a/Minecraft.Client/Common/UI/UIScene_HUD.h +++ b/Minecraft.Client/Common/UI/UIScene_HUD.h @@ -11,7 +11,7 @@ private: bool m_bSplitscreen; protected: - UIControl_Label m_labelChatText[CHAT_LINES_COUNT]; + UIControl_HTMLLabel m_labelChatText[CHAT_LINES_COUNT]; UIControl_Label m_labelJukebox; UIControl m_controlLabelBackground[CHAT_LINES_COUNT]; UIControl_Label m_labelDisplayName; diff --git a/Minecraft.Client/PlayerConnection.cpp b/Minecraft.Client/PlayerConnection.cpp index 1fb7c3988..546b77d82 100644 --- a/Minecraft.Client/PlayerConnection.cpp +++ b/Minecraft.Client/PlayerConnection.cpp @@ -678,7 +678,7 @@ void PlayerConnection::handleChat(shared_ptr packet) handleCommand(message); return; } - wstring formatted = L"<" + player->name + L"> " + message; + wstring formatted = L"<" + player->name + L"> " + message; server->getPlayers()->broadcastAll(shared_ptr(new ChatPacket(formatted))); chatSpamTickCount += SharedConstants::TICKS_PER_SECOND; if (chatSpamTickCount > SharedConstants::TICKS_PER_SECOND * 10)