From bf73b542f15ce255e42f1ff5cffc0467ac1a9306 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 20 May 2013 18:54:10 +1000 Subject: [PATCH] Implemented server selection interface --- client/lobby.cpp | 57 ++++++++++++++++++++++------- client/lobby.hpp | 5 ++- client/main_menu.cpp | 11 ++---- screenshots/select your poison.png | Bin 0 -> 6047 bytes 4 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 screenshots/select your poison.png diff --git a/client/lobby.cpp b/client/lobby.cpp index 5ad8e3e..d55a4d6 100644 --- a/client/lobby.cpp +++ b/client/lobby.cpp @@ -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(&packet), sizeof(Packet)); //reset the server list - serverVector.clear(); +// serverVector.clear(); } void Lobby::PushServer(Packet* packet) { diff --git a/client/lobby.hpp b/client/lobby.hpp index dcc4ee3..5d68ff2 100644 --- a/client/lobby.hpp +++ b/client/lobby.hpp @@ -12,6 +12,7 @@ #include "button.hpp" #include +#include #include struct Server { @@ -43,6 +44,7 @@ protected: //utilities void PingNetwork(); void PushServer(Packet*); + typedef std::map ButtonMap; //members ConfigUtility* configUtil = nullptr; @@ -50,9 +52,10 @@ protected: UDPNetworkUtility* netUtil = nullptr; RasterFont font; - Button pingButton; + ButtonMap buttonMap; std::vector serverVector; + Server* selectedServer = nullptr; }; #endif diff --git a/client/main_menu.cpp b/client/main_menu.cpp index 6d7afe3..758d5fa 100644 --- a/client/main_menu.cpp +++ b/client/main_menu.cpp @@ -15,9 +15,9 @@ MainMenu::MainMenu(ConfigUtility* cUtil, SurfaceManager* sMgr) { configUtil = cUtil; surfaceMgr = sMgr; - 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["quit"] = new Button(50, 150, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "quit"); + 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["quit"] = new Button(50, 150, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Quit"); } MainMenu::~MainMenu() { @@ -69,18 +69,13 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) { void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { if (buttonMap["start"]->MouseButtonUp(button) == Button::State::HOVER) { - //TODO SetNextScene(SceneList::LOBBY); - cout << "start" << endl; } if (buttonMap["options"]->MouseButtonUp(button) == Button::State::HOVER) { //TODO - cout << "options" << endl; } if (buttonMap["quit"]->MouseButtonUp(button) == Button::State::HOVER) { - //TODO QuitEvent(); - cout << "quit" << endl; } } diff --git a/screenshots/select your poison.png b/screenshots/select your poison.png new file mode 100644 index 0000000000000000000000000000000000000000..303b3df49dfd7a0cf0c6ecb0c3e03a941e83ff81 GIT binary patch literal 6047 zcmeHLdo+~m{(m$(PCId=o1L0dY$ZgL%T8uj_L&k&6NboCV^p@rC6{p-=GU&Fo2|?g zqihvw8;m5e$!t=&OxdNGq{d|%#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