From 3803535bd51878dfa18a5c4f5631eb0b173ab683 Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 12 Jun 2017 08:01:23 +0800 Subject: [PATCH] [General] Implement CleanChat() --- apps/openmw-mp/Script/Functions/Chat.cpp | 15 ++++++++++++++- apps/openmw-mp/Script/ScriptFunctions.hpp | 4 +++- apps/openmw/mwmp/GUI/GUIChat.cpp | 15 ++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Chat.cpp b/apps/openmw-mp/Script/Functions/Chat.cpp index ad3bad9c0..143421e5b 100644 --- a/apps/openmw-mp/Script/Functions/Chat.cpp +++ b/apps/openmw-mp/Script/Functions/Chat.cpp @@ -22,12 +22,25 @@ void ScriptFunctions::SendMessage(unsigned short pid, const char *message, bool mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->Send(true); } -void ScriptFunctions::CleanChat(unsigned short pid) +void ScriptFunctions::CleanChatByPid(unsigned short pid) { + Player *player; + GET_PLAYER(pid, player,); + + player->chatMessage.clear(); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->setPlayer(player); + + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->Send(false); } void ScriptFunctions::CleanChat() { + for (auto player : *Players::getPlayers()) + { + player.second->chatMessage.clear(); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->setPlayer(player.second); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE)->Send(false); + } } diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index cc7246549..db660b9fb 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -48,7 +48,7 @@ public: static boost::any CallPublic(const char *name, ...) noexcept; static void SendMessage(unsigned short pid, const char *message, bool broadcast) noexcept; - static void CleanChat(unsigned short pid); + static void CleanChatByPid(unsigned short pid); static void CleanChat(); /** @@ -100,6 +100,8 @@ public: {"SetServerPassword", ScriptFunctions::SetServerPassword}, {"SetRuleString", ScriptFunctions::SetRuleString}, {"SetRuleValue", ScriptFunctions::SetRuleValue}, + {"CleanChatByPid", ScriptFunctions::CleanChatByPid}, + {"CleanChat", ScriptFunctions::CleanChat}, POSITIONAPI, CELLAPI, diff --git a/apps/openmw/mwmp/GUI/GUIChat.cpp b/apps/openmw/mwmp/GUI/GUIChat.cpp index 31af443d4..8ded6456a 100644 --- a/apps/openmw/mwmp/GUI/GUIChat.cpp +++ b/apps/openmw/mwmp/GUI/GUIChat.cpp @@ -114,8 +114,17 @@ namespace mwmp { setVisible(true); } - mHistory->addText(color+msg); - LOG_MESSAGE_SIMPLE(Log::LOG_INFO, msg.c_str()); + + if(msg.size() == 0) + { + clean(); + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Chat cleaned"); + } + else + { + mHistory->addText(color + msg); + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, msg.c_str()); + } } void GUIChat::printOK(const std::string &msg) @@ -142,7 +151,7 @@ namespace mwmp void GUIChat::clean() { - mHistory->clearUserStrings(); + mHistory->setCaption(""); } void GUIChat::pressedChatMode()