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-11-12 15:32:54 +02:00
|
|
|
class LobbyWindow;
|
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
class LobbyWidget : public InterfaceObjectConfigurable
|
|
|
|
{
|
2023-11-12 15:32:54 +02:00
|
|
|
LobbyWindow * window;
|
2023-11-11 16:43:58 +02:00
|
|
|
public:
|
2023-11-12 15:32:54 +02:00
|
|
|
LobbyWidget(LobbyWindow * window);
|
|
|
|
|
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-11-18 16:34:18 +02:00
|
|
|
class LobbyClient : public INetworkClientListener
|
2023-11-11 16:43:58 +02:00
|
|
|
{
|
2023-11-18 16:34:18 +02:00
|
|
|
std::unique_ptr<NetworkClient> networkClient;
|
2023-11-12 15:32:54 +02:00
|
|
|
LobbyWindow * window;
|
|
|
|
|
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-11-12 15:32:54 +02:00
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
public:
|
2023-11-12 15:32:54 +02:00
|
|
|
explicit LobbyClient(LobbyWindow * window);
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
class LobbyWindow : public CWindowObject
|
|
|
|
{
|
2023-11-12 16:35:53 +02:00
|
|
|
std::string chatHistory;
|
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
std::shared_ptr<LobbyWidget> widget;
|
|
|
|
std::shared_ptr<LobbyClient> connection;
|
|
|
|
|
2023-11-12 13:27:22 +02:00
|
|
|
void tick(uint32_t msPassed);
|
|
|
|
|
2023-11-11 16:43:58 +02:00
|
|
|
public:
|
|
|
|
LobbyWindow();
|
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
|
|
|
};
|