The serverlist is displayed when pressing connect button.
This commit is contained in:
@@ -8,6 +8,7 @@ MainMenuSystem::MainMenuSystem(SystemParams params, IRenderer* renderer)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPressed, &MainMenuSystem::OnButtonPress);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EReleased, &MainMenuSystem::OnButtonRelease);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EClicked, &MainMenuSystem::OnButtonClick);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDisplayServerlist, &MainMenuSystem::OnDisplayServerlist);
|
||||
}
|
||||
|
||||
void MainMenuSystem::Update(double dt)
|
||||
@@ -19,8 +20,9 @@ bool MainMenuSystem::OnButtonClick(const Events::ButtonClicked& e)
|
||||
{
|
||||
if(e.EntityName == "Play") {
|
||||
//Run play code
|
||||
} else if(e.EntityName == "Connect") {
|
||||
//Run connect code
|
||||
} else if(e.EntityName == "Connecting") {
|
||||
LOG_INFO("Searching for LAN servers...");
|
||||
m_EventBroker->Publish(Events::SearchForServers());
|
||||
} else if(e.EntityName == "Host") {
|
||||
//Run host code
|
||||
} else if(e.EntityName == "Quit") {
|
||||
@@ -55,3 +57,17 @@ bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
|
||||
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_SearchingTime < (1000* (std::clock() - m_StartSearchTime) / (double)CLOCKS_PER_SEC)) {
|
||||
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)
|
||||
{
|
||||
// TEMP
|
||||
if (e.Command == "SearchForServers" && e.Value > 0) {
|
||||
Events::SearchForServers e;
|
||||
m_EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
if (e.PlayerID != -1) {
|
||||
return false;
|
||||
}
|
||||
@@ -492,7 +489,6 @@ bool Client::OnSearchForServers(const Events::SearchForServers& e)
|
||||
m_SearchingForServers = true;
|
||||
m_StartSearchTime = std::clock();
|
||||
m_Serverlist.clear();
|
||||
LOG_INFO("Searching for LAN servers...\n");
|
||||
Packet packet(MessageType::ServerlistRequest);
|
||||
m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user