1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/GameChatHandler.cpp

110 lines
3.2 KiB
C++
Raw Normal View History

/*
* GameChatHandler.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "GameChatHandler.h"
#include "CServerHandler.h"
#include "CPlayerInterface.h"
#include "PlayerLocalState.h"
2024-03-20 18:40:37 +02:00
#include "globalLobby/GlobalLobbyClient.h"
#include "lobby/CLobbyScreen.h"
#include "adventureMap/CInGameConsole.h"
#include "../CCallback.h"
#include "../lib/networkPacks/PacksForLobby.h"
#include "../lib/mapObjects/CArmedInstance.h"
#include "../lib/CConfigHandler.h"
2024-05-01 15:00:36 +02:00
#include "../lib/VCMI_Lib.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include "../lib/texts/TextOperations.h"
const std::vector<GameChatMessage> & GameChatHandler::getChatHistory() const
{
return chatHistory;
}
void GameChatHandler::resetMatchState()
{
chatHistory.clear();
}
void GameChatHandler::sendMessageGameplay(const std::string & messageText)
{
LOCPLINT->cb->sendMessage(messageText, LOCPLINT->localState->getCurrentArmy());
2024-03-20 18:40:37 +02:00
CSH->getGlobalLobby().sendMatchChatMessage(messageText);
}
void GameChatHandler::sendMessageLobby(const std::string & senderName, const std::string & messageText)
{
LobbyChatMessage lcm;
2024-05-02 21:03:23 +02:00
MetaString txt;
txt.appendRawString(messageText);
lcm.message = txt;
lcm.playerName = senderName;
CSH->sendLobbyPack(lcm);
2024-03-20 18:40:37 +02:00
CSH->getGlobalLobby().sendMatchChatMessage(messageText);
}
void GameChatHandler::onNewLobbyMessageReceived(const std::string & senderName, const std::string & messageText)
{
2024-03-20 18:40:37 +02:00
if (!SEL)
{
logGlobal->debug("Received chat message for lobby but lobby not yet exists!");
return;
}
auto * lobby = dynamic_cast<CLobbyScreen*>(SEL);
// FIXME: when can this happen?
assert(lobby);
assert(lobby->card);
if(lobby && lobby->card)
{
MetaString formatted = MetaString::createFromRawString("[%s] %s: %s");
formatted.replaceRawString(TextOperations::getCurrentFormattedTimeLocal());
formatted.replaceRawString(senderName);
2024-05-02 21:03:23 +02:00
formatted.replaceRawString(messageText);
lobby->card->chat->addNewMessage(formatted.toString());
2024-04-30 21:52:04 +02:00
if (!lobby->card->showChat)
lobby->toggleChat();
}
2024-05-02 21:03:23 +02:00
chatHistory.push_back({senderName, messageText, TextOperations::getCurrentFormattedTimeLocal()});
}
void GameChatHandler::onNewGameMessageReceived(PlayerColor sender, const std::string & messageText)
{
std::string timeFormatted = TextOperations::getCurrentFormattedTimeLocal();
std::string playerName = "<UNKNOWN>";
if (sender.isValidPlayer())
playerName = LOCPLINT->cb->getStartInfo()->playerInfos.at(sender).name;
if (sender.isSpectator())
2024-12-01 20:00:24 +02:00
playerName = VLC->generaltexth->translate("vcmi.lobby.login.spectator");
2024-05-02 21:03:23 +02:00
chatHistory.push_back({playerName, messageText, timeFormatted});
2024-05-02 21:03:23 +02:00
LOCPLINT->cingconsole->addMessage(timeFormatted, playerName, messageText);
}
void GameChatHandler::onNewSystemMessageReceived(const std::string & messageText)
{
2024-05-02 21:03:23 +02:00
chatHistory.push_back({"System", messageText, TextOperations::getCurrentFormattedTimeLocal()});
if(LOCPLINT && !settings["session"]["hideSystemMessages"].Bool())
2024-05-02 21:03:23 +02:00
LOCPLINT->cingconsole->addMessage(TextOperations::getCurrentFormattedTimeLocal(), "System", messageText);
2024-05-01 15:00:36 +02:00
}