mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Renamed new LobbyXXX classes to GlobaLobbyXXX
This commit is contained in:
parent
ee797cb245
commit
20a38d8514
@ -467,7 +467,7 @@ CMultiMode::CMultiMode(ESelectionScreen ScreenType)
|
|||||||
void CMultiMode::openLobby()
|
void CMultiMode::openLobby()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
GH.windows().createAndPushWindow<LobbyWindow>();
|
GH.windows().createAndPushWindow<GlobalLobbyWindow>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMultiMode::hostTCP()
|
void CMultiMode::hostTCP()
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
#include "../../lib/network/NetworkClient.h"
|
#include "../../lib/network/NetworkClient.h"
|
||||||
|
|
||||||
LobbyClient::LobbyClient(LobbyWindow * window)
|
GlobalLobbyClient::GlobalLobbyClient(GlobalLobbyWindow * window)
|
||||||
: networkClient(std::make_unique<NetworkClient>(*this))
|
: networkClient(std::make_unique<NetworkClient>(*this))
|
||||||
, window(window)
|
, window(window)
|
||||||
{}
|
{}
|
||||||
@ -42,7 +42,7 @@ static std::string getCurrentTimeFormatted(int timeOffsetSeconds = 0)
|
|||||||
return timeFormatted.toString();
|
return timeFormatted.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyClient::onPacketReceived(const std::shared_ptr<NetworkConnection> &, const std::vector<uint8_t> & message)
|
void GlobalLobbyClient::onPacketReceived(const std::shared_ptr<NetworkConnection> &, const std::vector<uint8_t> & message)
|
||||||
{
|
{
|
||||||
// FIXME: find better approach
|
// FIXME: find better approach
|
||||||
const char * payloadBegin = reinterpret_cast<const char*>(message.data());
|
const char * payloadBegin = reinterpret_cast<const char*>(message.data());
|
||||||
@ -69,7 +69,7 @@ void LobbyClient::onPacketReceived(const std::shared_ptr<NetworkConnection> &, c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyClient::onConnectionEstablished(const std::shared_ptr<NetworkConnection> &)
|
void GlobalLobbyClient::onConnectionEstablished(const std::shared_ptr<NetworkConnection> &)
|
||||||
{
|
{
|
||||||
JsonNode toSend;
|
JsonNode toSend;
|
||||||
toSend["type"].String() = "authentication";
|
toSend["type"].String() = "authentication";
|
||||||
@ -78,24 +78,24 @@ void LobbyClient::onConnectionEstablished(const std::shared_ptr<NetworkConnectio
|
|||||||
sendMessage(toSend);
|
sendMessage(toSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyClient::onConnectionFailed(const std::string & errorMessage)
|
void GlobalLobbyClient::onConnectionFailed(const std::string & errorMessage)
|
||||||
{
|
{
|
||||||
GH.windows().popWindows(1);
|
GH.windows().popWindows(1);
|
||||||
CInfoWindow::showInfoDialog("Failed to connect to game lobby!\n" + errorMessage, {});
|
CInfoWindow::showInfoDialog("Failed to connect to game lobby!\n" + errorMessage, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyClient::onDisconnected(const std::shared_ptr<NetworkConnection> &)
|
void GlobalLobbyClient::onDisconnected(const std::shared_ptr<NetworkConnection> &)
|
||||||
{
|
{
|
||||||
GH.windows().popWindows(1);
|
GH.windows().popWindows(1);
|
||||||
CInfoWindow::showInfoDialog("Connection to game lobby was lost!", {});
|
CInfoWindow::showInfoDialog("Connection to game lobby was lost!", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyClient::onTimer()
|
void GlobalLobbyClient::onTimer()
|
||||||
{
|
{
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyClient::sendMessage(const JsonNode & data)
|
void GlobalLobbyClient::sendMessage(const JsonNode & data)
|
||||||
{
|
{
|
||||||
std::string payloadString = data.toJson(true);
|
std::string payloadString = data.toJson(true);
|
||||||
|
|
||||||
@ -108,22 +108,22 @@ void LobbyClient::sendMessage(const JsonNode & data)
|
|||||||
networkClient->sendPacket(payloadBuffer);
|
networkClient->sendPacket(payloadBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyClient::start(const std::string & host, uint16_t port)
|
void GlobalLobbyClient::start(const std::string & host, uint16_t port)
|
||||||
{
|
{
|
||||||
networkClient->start(host, port);
|
networkClient->start(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyClient::run()
|
void GlobalLobbyClient::run()
|
||||||
{
|
{
|
||||||
networkClient->run();
|
networkClient->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyClient::poll()
|
void GlobalLobbyClient::poll()
|
||||||
{
|
{
|
||||||
networkClient->poll();
|
networkClient->poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
LobbyWidget::LobbyWidget(LobbyWindow * window)
|
GlobalLobbyWidget::GlobalLobbyWidget(GlobalLobbyWindow * window)
|
||||||
: window(window)
|
: window(window)
|
||||||
{
|
{
|
||||||
addCallback("closeWindow", [](int) { GH.windows().popWindows(1); });
|
addCallback("closeWindow", [](int) { GH.windows().popWindows(1); });
|
||||||
@ -133,29 +133,29 @@ LobbyWidget::LobbyWidget(LobbyWindow * window)
|
|||||||
build(config);
|
build(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CLabel> LobbyWidget::getAccountNameLabel()
|
std::shared_ptr<CLabel> GlobalLobbyWidget::getAccountNameLabel()
|
||||||
{
|
{
|
||||||
return widget<CLabel>("accountNameLabel");
|
return widget<CLabel>("accountNameLabel");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CTextInput> LobbyWidget::getMessageInput()
|
std::shared_ptr<CTextInput> GlobalLobbyWidget::getMessageInput()
|
||||||
{
|
{
|
||||||
return widget<CTextInput>("messageInput");
|
return widget<CTextInput>("messageInput");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CTextBox> LobbyWidget::getGameChat()
|
std::shared_ptr<CTextBox> GlobalLobbyWidget::getGameChat()
|
||||||
{
|
{
|
||||||
return widget<CTextBox>("gameChat");
|
return widget<CTextBox>("gameChat");
|
||||||
}
|
}
|
||||||
|
|
||||||
LobbyWindow::LobbyWindow():
|
GlobalLobbyWindow::GlobalLobbyWindow():
|
||||||
CWindowObject(BORDERED)
|
CWindowObject(BORDERED)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||||
widget = std::make_shared<LobbyWidget>(this);
|
widget = std::make_shared<GlobalLobbyWidget>(this);
|
||||||
pos = widget->pos;
|
pos = widget->pos;
|
||||||
center();
|
center();
|
||||||
connection = std::make_shared<LobbyClient>(this);
|
connection = std::make_shared<GlobalLobbyClient>(this);
|
||||||
|
|
||||||
connection->start("127.0.0.1", 30303);
|
connection->start("127.0.0.1", 30303);
|
||||||
widget->getAccountNameLabel()->setText(settings["general"]["playerName"].String());
|
widget->getAccountNameLabel()->setText(settings["general"]["playerName"].String());
|
||||||
@ -163,12 +163,12 @@ LobbyWindow::LobbyWindow():
|
|||||||
addUsedEvents(TIME);
|
addUsedEvents(TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyWindow::tick(uint32_t msPassed)
|
void GlobalLobbyWindow::tick(uint32_t msPassed)
|
||||||
{
|
{
|
||||||
connection->poll();
|
connection->poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyWindow::doSendChatMessage()
|
void GlobalLobbyWindow::doSendChatMessage()
|
||||||
{
|
{
|
||||||
std::string messageText = widget->getMessageInput()->getText();
|
std::string messageText = widget->getMessageInput()->getText();
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ void LobbyWindow::doSendChatMessage()
|
|||||||
widget->getMessageInput()->setText("");
|
widget->getMessageInput()->setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyWindow::onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when)
|
void GlobalLobbyWindow::onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when)
|
||||||
{
|
{
|
||||||
MetaString chatMessageFormatted;
|
MetaString chatMessageFormatted;
|
||||||
chatMessageFormatted.appendRawString("[%s] {%s}: %s\n");
|
chatMessageFormatted.appendRawString("[%s] {%s}: %s\n");
|
||||||
|
@ -14,23 +14,23 @@
|
|||||||
|
|
||||||
#include "../../lib/network/NetworkListener.h"
|
#include "../../lib/network/NetworkListener.h"
|
||||||
|
|
||||||
class LobbyWindow;
|
class GlobalLobbyWindow;
|
||||||
|
|
||||||
class LobbyWidget : public InterfaceObjectConfigurable
|
class GlobalLobbyWidget : public InterfaceObjectConfigurable
|
||||||
{
|
{
|
||||||
LobbyWindow * window;
|
GlobalLobbyWindow * window;
|
||||||
public:
|
public:
|
||||||
LobbyWidget(LobbyWindow * window);
|
GlobalLobbyWidget(GlobalLobbyWindow * window);
|
||||||
|
|
||||||
std::shared_ptr<CLabel> getAccountNameLabel();
|
std::shared_ptr<CLabel> getAccountNameLabel();
|
||||||
std::shared_ptr<CTextInput> getMessageInput();
|
std::shared_ptr<CTextInput> getMessageInput();
|
||||||
std::shared_ptr<CTextBox> getGameChat();
|
std::shared_ptr<CTextBox> getGameChat();
|
||||||
};
|
};
|
||||||
|
|
||||||
class LobbyClient : public INetworkClientListener
|
class GlobalLobbyClient : public INetworkClientListener
|
||||||
{
|
{
|
||||||
std::unique_ptr<NetworkClient> networkClient;
|
std::unique_ptr<NetworkClient> networkClient;
|
||||||
LobbyWindow * window;
|
GlobalLobbyWindow * window;
|
||||||
|
|
||||||
void onPacketReceived(const std::shared_ptr<NetworkConnection> &, const std::vector<uint8_t> & message) override;
|
void onPacketReceived(const std::shared_ptr<NetworkConnection> &, const std::vector<uint8_t> & message) override;
|
||||||
void onConnectionFailed(const std::string & errorMessage) override;
|
void onConnectionFailed(const std::string & errorMessage) override;
|
||||||
@ -39,7 +39,7 @@ class LobbyClient : public INetworkClientListener
|
|||||||
void onTimer() override;
|
void onTimer() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LobbyClient(LobbyWindow * window);
|
explicit GlobalLobbyClient(GlobalLobbyWindow * window);
|
||||||
|
|
||||||
void sendMessage(const JsonNode & data);
|
void sendMessage(const JsonNode & data);
|
||||||
void start(const std::string & host, uint16_t port);
|
void start(const std::string & host, uint16_t port);
|
||||||
@ -48,17 +48,17 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class LobbyWindow : public CWindowObject
|
class GlobalLobbyWindow : public CWindowObject
|
||||||
{
|
{
|
||||||
std::string chatHistory;
|
std::string chatHistory;
|
||||||
|
|
||||||
std::shared_ptr<LobbyWidget> widget;
|
std::shared_ptr<GlobalLobbyWidget> widget;
|
||||||
std::shared_ptr<LobbyClient> connection;
|
std::shared_ptr<GlobalLobbyClient> connection;
|
||||||
|
|
||||||
void tick(uint32_t msPassed);
|
void tick(uint32_t msPassed);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LobbyWindow();
|
GlobalLobbyWindow();
|
||||||
|
|
||||||
void doSendChatMessage();
|
void doSendChatMessage();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user