Implemented server selection interface
This commit is contained in:
+43
-14
@@ -20,17 +20,19 @@ Lobby::Lobby(ConfigUtility* cUtil, SurfaceManager* sMgr, UDPNetworkUtility* nUti
|
||||
|
||||
//members
|
||||
font.SetSurface(surfaceMgr->Get("font"));
|
||||
pingButton.SetSurfaces(surfaceMgr->Get("button"), surfaceMgr->Get("font"));
|
||||
pingButton.SetText("Refresh");
|
||||
pingButton.SetX(50);
|
||||
pingButton.SetY(50);
|
||||
|
||||
//ping the network, ping the preset "phone home" servers
|
||||
//generate the server list
|
||||
//eventually
|
||||
buttonMap["ping"] = new Button(50, 50 , surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Refresh");
|
||||
buttonMap["join"] = new Button(50, 100, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Join");
|
||||
buttonMap["back"] = new Button(50, 150, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Back");
|
||||
|
||||
//ping the network
|
||||
PingNetwork();
|
||||
}
|
||||
|
||||
Lobby::~Lobby() {
|
||||
for (auto it : buttonMap) {
|
||||
delete it.second;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
cout << "leaving Lobby" << endl;
|
||||
#endif
|
||||
@@ -67,9 +69,16 @@ void Lobby::Receive() {
|
||||
}
|
||||
|
||||
void Lobby::Render(SDL_Surface* const screen) {
|
||||
pingButton.DrawTo(screen);
|
||||
for (auto it : buttonMap) {
|
||||
it.second->DrawTo(screen);
|
||||
}
|
||||
//draw the server list, highlighting the selected server
|
||||
for (int i = 0; i < serverVector.size(); i++) {
|
||||
font.DrawStringTo(serverVector[i].name, screen, 50, 16*i + 100);
|
||||
if (selectedServer && selectedServer == &serverVector[i]) {
|
||||
SDL_Rect clip = {250, Sint16(16*i + 50), Uint16(screen->w - 250), 16};
|
||||
SDL_FillRect(screen, &clip, SDL_MapRGB(screen->format, 255, 127, 39));
|
||||
}
|
||||
font.DrawStringTo(serverVector[i].name, screen, 250, 16*i + 50);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,23 +87,43 @@ void Lobby::Render(SDL_Surface* const screen) {
|
||||
//-------------------------
|
||||
|
||||
void Lobby::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
pingButton.MouseMotion(motion);
|
||||
for (auto it : buttonMap) {
|
||||
it.second->MouseMotion(motion);
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
pingButton.MouseButtonDown(button);
|
||||
for (auto it : buttonMap) {
|
||||
it.second->MouseButtonDown(button);
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
if (pingButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
if (buttonMap["ping"]->MouseButtonUp(button) == Button::State::HOVER) {
|
||||
PingNetwork();
|
||||
}
|
||||
if (buttonMap["join"]->MouseButtonUp(button) == Button::State::HOVER) {
|
||||
//join...
|
||||
if (selectedServer) {
|
||||
cout << "joining server: " << selectedServer->name << endl;
|
||||
}
|
||||
}
|
||||
if (buttonMap["back"]->MouseButtonUp(button) == Button::State::HOVER) {
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
}
|
||||
//select a server
|
||||
if (button.x >= 250 && button.y >= 50 && button.y < serverVector.size() * 16 + 50) {
|
||||
selectedServer = &serverVector[(button.y-50)/16];
|
||||
}
|
||||
else {
|
||||
selectedServer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
switch(key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
QuitEvent();
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -113,7 +142,7 @@ void Lobby::PingNetwork() {
|
||||
packet.type = PacketList::PING;
|
||||
netUtil->Send("255.255.255.255", configUtil->Integer("server.port"), reinterpret_cast<void*>(&packet), sizeof(Packet));
|
||||
//reset the server list
|
||||
serverVector.clear();
|
||||
// serverVector.clear();
|
||||
}
|
||||
|
||||
void Lobby::PushServer(Packet* packet) {
|
||||
|
||||
Reference in New Issue
Block a user