Implemented server selection interface
This commit is contained in:
+43
-14
@@ -20,17 +20,19 @@ Lobby::Lobby(ConfigUtility* cUtil, SurfaceManager* sMgr, UDPNetworkUtility* nUti
|
|||||||
|
|
||||||
//members
|
//members
|
||||||
font.SetSurface(surfaceMgr->Get("font"));
|
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
|
buttonMap["ping"] = new Button(50, 50 , surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Refresh");
|
||||||
//generate the server list
|
buttonMap["join"] = new Button(50, 100, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Join");
|
||||||
//eventually
|
buttonMap["back"] = new Button(50, 150, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Back");
|
||||||
|
|
||||||
|
//ping the network
|
||||||
|
PingNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
Lobby::~Lobby() {
|
Lobby::~Lobby() {
|
||||||
|
for (auto it : buttonMap) {
|
||||||
|
delete it.second;
|
||||||
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "leaving Lobby" << endl;
|
cout << "leaving Lobby" << endl;
|
||||||
#endif
|
#endif
|
||||||
@@ -67,9 +69,16 @@ void Lobby::Receive() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::Render(SDL_Surface* const screen) {
|
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++) {
|
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) {
|
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) {
|
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) {
|
void Lobby::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
if (pingButton.MouseButtonUp(button) == Button::State::HOVER) {
|
if (buttonMap["ping"]->MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
PingNetwork();
|
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) {
|
void Lobby::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
switch(key.keysym.sym) {
|
switch(key.keysym.sym) {
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
QuitEvent();
|
SetNextScene(SceneList::MAINMENU);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,7 +142,7 @@ void Lobby::PingNetwork() {
|
|||||||
packet.type = PacketList::PING;
|
packet.type = PacketList::PING;
|
||||||
netUtil->Send("255.255.255.255", configUtil->Integer("server.port"), reinterpret_cast<void*>(&packet), sizeof(Packet));
|
netUtil->Send("255.255.255.255", configUtil->Integer("server.port"), reinterpret_cast<void*>(&packet), sizeof(Packet));
|
||||||
//reset the server list
|
//reset the server list
|
||||||
serverVector.clear();
|
// serverVector.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::PushServer(Packet* packet) {
|
void Lobby::PushServer(Packet* packet) {
|
||||||
|
|||||||
+4
-1
@@ -12,6 +12,7 @@
|
|||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct Server {
|
struct Server {
|
||||||
@@ -43,6 +44,7 @@ protected:
|
|||||||
//utilities
|
//utilities
|
||||||
void PingNetwork();
|
void PingNetwork();
|
||||||
void PushServer(Packet*);
|
void PushServer(Packet*);
|
||||||
|
typedef std::map<std::string, Button*> ButtonMap;
|
||||||
|
|
||||||
//members
|
//members
|
||||||
ConfigUtility* configUtil = nullptr;
|
ConfigUtility* configUtil = nullptr;
|
||||||
@@ -50,9 +52,10 @@ protected:
|
|||||||
UDPNetworkUtility* netUtil = nullptr;
|
UDPNetworkUtility* netUtil = nullptr;
|
||||||
|
|
||||||
RasterFont font;
|
RasterFont font;
|
||||||
Button pingButton;
|
ButtonMap buttonMap;
|
||||||
|
|
||||||
std::vector<Server> serverVector;
|
std::vector<Server> serverVector;
|
||||||
|
Server* selectedServer = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ MainMenu::MainMenu(ConfigUtility* cUtil, SurfaceManager* sMgr) {
|
|||||||
configUtil = cUtil;
|
configUtil = cUtil;
|
||||||
surfaceMgr = sMgr;
|
surfaceMgr = sMgr;
|
||||||
|
|
||||||
buttonMap["start"] = new Button(50, 50, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "start");
|
buttonMap["start"] = new Button(50, 50, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Start");
|
||||||
buttonMap["options"] = new Button(50, 100, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "options");
|
buttonMap["options"] = new Button(50, 100, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Options");
|
||||||
buttonMap["quit"] = new Button(50, 150, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "quit");
|
buttonMap["quit"] = new Button(50, 150, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
MainMenu::~MainMenu() {
|
MainMenu::~MainMenu() {
|
||||||
@@ -69,18 +69,13 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
|||||||
|
|
||||||
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
if (buttonMap["start"]->MouseButtonUp(button) == Button::State::HOVER) {
|
if (buttonMap["start"]->MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
//TODO
|
|
||||||
SetNextScene(SceneList::LOBBY);
|
SetNextScene(SceneList::LOBBY);
|
||||||
cout << "start" << endl;
|
|
||||||
}
|
}
|
||||||
if (buttonMap["options"]->MouseButtonUp(button) == Button::State::HOVER) {
|
if (buttonMap["options"]->MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
//TODO
|
//TODO
|
||||||
cout << "options" << endl;
|
|
||||||
}
|
}
|
||||||
if (buttonMap["quit"]->MouseButtonUp(button) == Button::State::HOVER) {
|
if (buttonMap["quit"]->MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
//TODO
|
|
||||||
QuitEvent();
|
QuitEvent();
|
||||||
cout << "quit" << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 5.9 KiB |
Reference in New Issue
Block a user