1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-16 10:19:47 +02:00
vcmi/client/globalLobby/GlobalLobbyWindow.cpp
2024-01-28 00:04:54 +02:00

92 lines
2.3 KiB
C++

/*
* GlobalLobbyWindow.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 "GlobalLobbyWindow.h"
#include "GlobalLobbyClient.h"
#include "GlobalLobbyServerSetup.h"
#include "GlobalLobbyWidget.h"
#include "../CServerHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/WindowHandler.h"
#include "../widgets/TextControls.h"
#include "../widgets/ObjectLists.h"
#include "../../lib/CConfigHandler.h"
#include "../../lib/MetaString.h"
GlobalLobbyWindow::GlobalLobbyWindow()
: CWindowObject(BORDERED)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
widget = std::make_shared<GlobalLobbyWidget>(this);
pos = widget->pos;
center();
widget->getAccountNameLabel()->setText(settings["lobby"]["displayName"].String());
}
void GlobalLobbyWindow::doSendChatMessage()
{
std::string messageText = widget->getMessageInput()->getText();
JsonNode toSend;
toSend["type"].String() = "sendChatMessage";
toSend["messageText"].String() = messageText;
CSH->getGlobalLobby().sendMessage(toSend);
widget->getMessageInput()->setText("");
}
void GlobalLobbyWindow::doCreateGameRoom()
{
GH.windows().createAndPushWindow<GlobalLobbyServerSetup>();
}
void GlobalLobbyWindow::doInviteAccount(const std::string & accountID)
{
assert(0); // TODO
}
void GlobalLobbyWindow::doJoinRoom(const std::string & roomID)
{
JsonNode toSend;
toSend["type"].String() = "joinGameRoom";
toSend["gameRoomID"].String() = roomID;
CSH->getGlobalLobby().sendMessage(toSend);
}
void GlobalLobbyWindow::onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when)
{
MetaString chatMessageFormatted;
chatMessageFormatted.appendRawString("[%s] {%s}: %s\n");
chatMessageFormatted.replaceRawString(when);
chatMessageFormatted.replaceRawString(sender);
chatMessageFormatted.replaceRawString(message);
chatHistory += chatMessageFormatted.toString();
widget->getGameChat()->setText(chatHistory);
}
void GlobalLobbyWindow::onActiveAccounts(const std::vector<GlobalLobbyAccount> & accounts)
{
widget->getAccountList()->reset();
}
void GlobalLobbyWindow::onActiveRooms(const std::vector<GlobalLobbyRoom> & rooms)
{
widget->getRoomList()->reset();
}