2023-11-11 16:43:58 +02:00
|
|
|
/*
|
|
|
|
* LobbyWindow.h, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../gui/InterfaceObjectConfigurable.h"
|
|
|
|
#include "../windows/CWindowObject.h"
|
|
|
|
|
2023-11-18 16:34:18 +02:00
|
|
|
#include "../../lib/network/NetworkListener.h"
|
2023-11-11 16:43:58 +02:00
|
|
|
|
2023-12-27 17:07:44 +02:00
|
|
|
class GlobalLobbyWindow;
|
2023-11-12 15:32:54 +02:00
|
|
|
|
2023-12-27 17:07:44 +02:00
|
|
|
class GlobalLobbyWidget : public InterfaceObjectConfigurable
|
2023-11-11 16:43:58 +02:00
|
|
|
{
|
2023-12-27 17:07:44 +02:00
|
|
|
GlobalLobbyWindow * window;
|
2023-11-11 16:43:58 +02:00
|
|
|
public:
|
2023-12-27 17:07:44 +02:00
|
|
|
GlobalLobbyWidget(GlobalLobbyWindow * window);
|
2023-11-12 15:32:54 +02:00
|
|
|
|
2023-11-12 21:23:42 +02:00
|
|
|
std::shared_ptr<CLabel> getAccountNameLabel();
|
2023-11-12 15:32:54 +02:00
|
|
|
std::shared_ptr<CTextInput> getMessageInput();
|
2023-11-12 16:35:53 +02:00
|
|
|
std::shared_ptr<CTextBox> getGameChat();
|
2023-11-11 16:43:58 +02:00
|
|
|
};
|
|
|
|
|
2023-12-27 17:07:44 +02:00
|
|
|
class GlobalLobbyClient : public INetworkClientListener
|
2023-11-11 16:43:58 +02:00
|
|
|
{
|
2023-11-18 16:34:18 +02:00
|
|
|
std::unique_ptr<NetworkClient> networkClient;
|
2023-12-27 17:07:44 +02:00
|
|
|
GlobalLobbyWindow * window;
|
2023-11-12 15:32:54 +02:00
|
|
|
|
2023-12-25 21:23:27 +02:00
|
|
|
void onPacketReceived(const std::shared_ptr<NetworkConnection> &, const std::vector<uint8_t> & message) override;
|
2023-11-12 13:27:22 +02:00
|
|
|
void onConnectionFailed(const std::string & errorMessage) override;
|
2023-12-25 21:23:27 +02:00
|
|
|
void onConnectionEstablished(const std::shared_ptr<NetworkConnection> &) override;
|
|
|
|
void onDisconnected(const std::shared_ptr<NetworkConnection> &) override;
|
2023-12-26 18:30:37 +02:00
|
|
|
void onTimer() override;
|
2023-11-12 15:32:54 +02:00
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
public:
|
2023-12-27 17:07:44 +02:00
|
|
|
explicit GlobalLobbyClient(GlobalLobbyWindow * window);
|
2023-11-12 15:32:54 +02:00
|
|
|
|
|
|
|
void sendMessage(const JsonNode & data);
|
2023-11-18 16:34:18 +02:00
|
|
|
void start(const std::string & host, uint16_t port);
|
|
|
|
void run();
|
|
|
|
void poll();
|
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
};
|
|
|
|
|
2023-12-27 17:07:44 +02:00
|
|
|
class GlobalLobbyWindow : public CWindowObject
|
2023-11-11 16:43:58 +02:00
|
|
|
{
|
2023-11-12 16:35:53 +02:00
|
|
|
std::string chatHistory;
|
|
|
|
|
2023-12-27 17:07:44 +02:00
|
|
|
std::shared_ptr<GlobalLobbyWidget> widget;
|
|
|
|
std::shared_ptr<GlobalLobbyClient> connection;
|
2023-11-11 16:43:58 +02:00
|
|
|
|
2023-11-12 13:27:22 +02:00
|
|
|
void tick(uint32_t msPassed);
|
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
public:
|
2023-12-27 17:07:44 +02:00
|
|
|
GlobalLobbyWindow();
|
2023-11-12 15:32:54 +02:00
|
|
|
|
|
|
|
void doSendChatMessage();
|
|
|
|
|
2023-11-12 16:35:53 +02:00
|
|
|
void onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when);
|
2023-11-11 16:43:58 +02:00
|
|
|
};
|