-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||
* If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* | ||
* This Source Code Form is “Incompatible With Secondary Licenses”, | ||
* as defined by the Mozilla Public License, v. 2.0. | ||
*/ | ||
|
||
#include "../protocol.hpp" | ||
#include "../utils.hpp" | ||
#include "serverlist.hpp" | ||
using namespace std; | ||
|
||
ServerList::ServerList(ContextName name, gcn::Container * p) : Context(name, p), | ||
btn_back("< Back"), btn_manualIP("Enter IP"), btn_rescan("Rescan local network") | ||
{ | ||
|
||
if (name == ContextName::SERVER_LIST_WEB) { | ||
btn_rescan.setVisible(false); | ||
} | ||
|
||
addWidgets(); | ||
} | ||
|
||
ServerList::~ServerList() { | ||
// Cleanup our surfaces | ||
if (background) { | ||
SDL_FreeSurface(background); | ||
} | ||
if (backTexture) { | ||
SDL_DestroyTexture(backTexture); | ||
} | ||
} | ||
|
||
void ServerList::action(const gcn::ActionEvent & actionEvent) { | ||
if (actionEvent.getId() == "back") { | ||
setNextContext(ContextName::MAIN_MENU); | ||
} | ||
else if (actionEvent.getId() == "ip") { | ||
// Open the InputBox | ||
} | ||
else if (actionEvent.getId() == "rescan") { | ||
scanNetwork(); | ||
} | ||
} | ||
|
||
void ServerList::drawBackground(SDL_Renderer * screen) { | ||
if (!backTexture) { | ||
backTexture = SDL_CreateTextureFromSurface(screen, background); | ||
} | ||
SDL_RenderCopy(screen, backTexture, NULL, NULL); | ||
} | ||
|
||
void ServerList::processMessage(const Uint8 code, const std::string & message) { | ||
switch (code) { | ||
case SERVER_INFO: | ||
// Analyze message and create button | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void ServerList::addWidgets() { | ||
addWidget(&btn_back, 40, background->h - 40); | ||
addWidget(&btn_manualIP, 700, background->h / 2); | ||
addWidget(&btn_rescan, 700, btn_manualIP.getY() + 40); | ||
} | ||
|
||
/** | ||
* Send a broadcast message to find other servers | ||
*/ | ||
void ServerList::scanNetwork() { | ||
// TBD | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | ||
* If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* | ||
* This Source Code Form is “Incompatible With Secondary Licenses”, | ||
* as defined by the Mozilla Public License, v. 2.0. | ||
*/ | ||
|
||
#ifndef _H_SERVERLIST_ | ||
#define _H_SERVERLIST_ | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <guisan.hpp> | ||
#include <SDL2/SDL.h> | ||
#include "../context.hpp" | ||
|
||
class ServerList : public Context, public gcn::ActionListener { | ||
public: | ||
ServerList(ContextName name, gcn::Container *p); | ||
virtual ~ServerList(); | ||
void action(const gcn::ActionEvent &actionEvent) override; | ||
|
||
virtual void drawBackground(SDL_Renderer *screen) override; | ||
virtual void processMessage(const Uint8 code, const std::string &message) override; | ||
virtual void drawOverlay(SDL_Renderer *screen) override { | ||
// There will never be any overlays in ServerList | ||
}; | ||
|
||
virtual void processEvent(SDL_Event &event) override { | ||
// No specific handling to be done here, GUI handles everything | ||
}; | ||
|
||
private: | ||
gcn::Button btn_back; | ||
gcn::Button btn_manualIP; | ||
gcn::Button btn_rescan; | ||
// gcn::InputBox input_ip; | ||
|
||
SDL_Texture *backTexture = nullptr; | ||
SDL_Surface *background = nullptr; | ||
|
||
void addWidgets(); | ||
void scanNetwork(); | ||
}; | ||
|
||
#endif // !_H_SERVERLIST_ |