The serverlist is displayed when pressing connect button.
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
#include "../Rendering/IRenderer.h"
|
#include "../Rendering/IRenderer.h"
|
||||||
#include "../Core/ResourceManager.h"
|
#include "../Core/ResourceManager.h"
|
||||||
#include "../Core/Event.h"
|
#include "../Core/Event.h"
|
||||||
|
#include "../Network/ESearchForServers.h"
|
||||||
|
#include "../Network/EDisplayServerlist.h"
|
||||||
|
|
||||||
#include "EButtonClicked.h"
|
#include "EButtonClicked.h"
|
||||||
#include "EButtonPressed.h"
|
#include "EButtonPressed.h"
|
||||||
@@ -27,6 +28,8 @@ private:
|
|||||||
bool OnButtonRelease(const Events::ButtonReleased& e);
|
bool OnButtonRelease(const Events::ButtonReleased& e);
|
||||||
EventRelay<MainMenuSystem, Events::ButtonPressed> m_EPressed;
|
EventRelay<MainMenuSystem, Events::ButtonPressed> m_EPressed;
|
||||||
bool OnButtonPress(const Events::ButtonPressed& e);
|
bool OnButtonPress(const Events::ButtonPressed& e);
|
||||||
|
EventRelay<MainMenuSystem, Events::DisplayServerlist> m_EDisplayServerlist;
|
||||||
|
bool OnDisplayServerlist(const Events::DisplayServerlist& e);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,18 +25,7 @@
|
|||||||
#include "Network/SnapshotFilter.h"
|
#include "Network/SnapshotFilter.h"
|
||||||
#include "Core/EPlayerSpawned.h"
|
#include "Core/EPlayerSpawned.h"
|
||||||
#include "Network/ESearchForServers.h"
|
#include "Network/ESearchForServers.h"
|
||||||
|
#include "Network/EDisplayServerlist.h"
|
||||||
struct ServerInfo
|
|
||||||
{
|
|
||||||
ServerInfo(std::string a, int b, std::string c, int d)
|
|
||||||
{
|
|
||||||
Address = a; Port = b; Name = c; PlayersConnected = d;
|
|
||||||
}
|
|
||||||
std::string Address = "";
|
|
||||||
int Port = 0;
|
|
||||||
std::string Name = "";
|
|
||||||
int PlayersConnected = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Client : public Network
|
class Client : public Network
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef Events_DisplayServerlist_h__
|
||||||
|
#define Events_DisplayServerlist_h__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "Core/Event.h"
|
||||||
|
|
||||||
|
struct ServerInfo
|
||||||
|
{
|
||||||
|
ServerInfo(std::string address, int port, std::string name, int players)
|
||||||
|
{
|
||||||
|
Address = address; Port = port; Name = name; PlayersConnected = players;
|
||||||
|
}
|
||||||
|
std::string Address = "";
|
||||||
|
int Port = 0;
|
||||||
|
std::string Name = "";
|
||||||
|
int PlayersConnected = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct DisplayServerlist : public Event
|
||||||
|
{
|
||||||
|
std::vector<ServerInfo> Serverlist;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -8,6 +8,7 @@ MainMenuSystem::MainMenuSystem(SystemParams params, IRenderer* renderer)
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_EPressed, &MainMenuSystem::OnButtonPress);
|
EVENT_SUBSCRIBE_MEMBER(m_EPressed, &MainMenuSystem::OnButtonPress);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EReleased, &MainMenuSystem::OnButtonRelease);
|
EVENT_SUBSCRIBE_MEMBER(m_EReleased, &MainMenuSystem::OnButtonRelease);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EClicked, &MainMenuSystem::OnButtonClick);
|
EVENT_SUBSCRIBE_MEMBER(m_EClicked, &MainMenuSystem::OnButtonClick);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EDisplayServerlist, &MainMenuSystem::OnDisplayServerlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenuSystem::Update(double dt)
|
void MainMenuSystem::Update(double dt)
|
||||||
@@ -19,8 +20,9 @@ bool MainMenuSystem::OnButtonClick(const Events::ButtonClicked& e)
|
|||||||
{
|
{
|
||||||
if(e.EntityName == "Play") {
|
if(e.EntityName == "Play") {
|
||||||
//Run play code
|
//Run play code
|
||||||
} else if(e.EntityName == "Connect") {
|
} else if(e.EntityName == "Connecting") {
|
||||||
//Run connect code
|
LOG_INFO("Searching for LAN servers...");
|
||||||
|
m_EventBroker->Publish(Events::SearchForServers());
|
||||||
} else if(e.EntityName == "Host") {
|
} else if(e.EntityName == "Host") {
|
||||||
//Run host code
|
//Run host code
|
||||||
} else if(e.EntityName == "Quit") {
|
} else if(e.EntityName == "Quit") {
|
||||||
@@ -55,3 +57,17 @@ bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MainMenuSystem::OnDisplayServerlist(const Events::DisplayServerlist& e)
|
||||||
|
{
|
||||||
|
LOG_INFO("This is a serverlist V2!");
|
||||||
|
for (int i = 0; i < e.Serverlist.size(); i++) {
|
||||||
|
LOG_INFO("%s:%i\t%s\t%i/8"
|
||||||
|
, e.Serverlist[i].Address
|
||||||
|
, e.Serverlist[i].Port
|
||||||
|
, e.Serverlist[i].Name
|
||||||
|
, e.Serverlist[i].PlayersConnected
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,10 @@ void Client::Update()
|
|||||||
if (m_SearchingForServers) {
|
if (m_SearchingForServers) {
|
||||||
if (m_SearchingTime < (1000* (std::clock() - m_StartSearchTime) / (double)CLOCKS_PER_SEC)) {
|
if (m_SearchingTime < (1000* (std::clock() - m_StartSearchTime) / (double)CLOCKS_PER_SEC)) {
|
||||||
m_SearchingForServers = false;
|
m_SearchingForServers = false;
|
||||||
displayServerlist();
|
//displayServerlist();
|
||||||
|
Events::DisplayServerlist e;
|
||||||
|
e.Serverlist = m_Serverlist;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,12 +422,6 @@ void Client::disconnect()
|
|||||||
|
|
||||||
bool Client::OnInputCommand(const Events::InputCommand & e)
|
bool Client::OnInputCommand(const Events::InputCommand & e)
|
||||||
{
|
{
|
||||||
// TEMP
|
|
||||||
if (e.Command == "SearchForServers" && e.Value > 0) {
|
|
||||||
Events::SearchForServers e;
|
|
||||||
m_EventBroker->Publish(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.PlayerID != -1) {
|
if (e.PlayerID != -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -492,7 +489,6 @@ bool Client::OnSearchForServers(const Events::SearchForServers& e)
|
|||||||
m_SearchingForServers = true;
|
m_SearchingForServers = true;
|
||||||
m_StartSearchTime = std::clock();
|
m_StartSearchTime = std::clock();
|
||||||
m_Serverlist.clear();
|
m_Serverlist.clear();
|
||||||
LOG_INFO("Searching for LAN servers...\n");
|
|
||||||
Packet packet(MessageType::ServerlistRequest);
|
Packet packet(MessageType::ServerlistRequest);
|
||||||
m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config
|
m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user