Skip to content

Commit

Permalink
Started implementation of #11 (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaudic committed May 30, 2019
1 parent ce3b4a2 commit 22d48a7
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "context.hpp"
#include "views/menu.hpp"
#include "views/serverlist.hpp"
#include "views/serverview.hpp"
using namespace std;

// Init of static class members
Expand Down Expand Up @@ -80,6 +81,14 @@ void Context::setServerIP(const Uint32 ip) {
network.setServerInfo(ip);
}

const int Context::getHeight() const {
return top.getHeight();
}

const int Context::getWidth() const {
return top.getWidth();
}

/**
* Create and replace the current Context in the application
* Closely related to the Factory design pattern
Expand All @@ -104,6 +113,14 @@ Context * Context::getNextContext(ContextName nextName) {
currentContext = new ServerList(nextName);
currentContext->enter();
break;
case ContextName::ROOM_LIST:
if (currentContext) {
currentContext->leave();
delete currentContext;
}
currentContext = new ServerView();
currentContext->enter();
break;
default:
break;
}
Expand Down
3 changes: 3 additions & 0 deletions src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Context {
void send(const Uint8 code, const std::string & message);
void setServerIP(const Uint32 ip);

const int getHeight() const;
const int getWidth() const;

private:
static gcn::Container *parent;
ContextName name;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* \file utils.cpp
* \brief Utility functions
* \author G. B.
* \date /11/2016
* \date 01/11/2016
* \version 0.1a
*/
/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
Expand Down
2 changes: 1 addition & 1 deletion src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* \file utils.hpp
* \brief Utility functions
* \author G. B.
* \date /11/2016
* \date 01/11/2016
* \version 0.1a
*/
/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
Expand Down
45 changes: 45 additions & 0 deletions src/views/serverview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* 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 "serverview.hpp"

ServerView::ServerView() : Context(ContextName::ROOM_LIST),
btn_back("Logout"), btn_newRoom("Create room"), btn_goToShop("Item shop"),
btn_addFriend("Add friend"), btn_prevPage("<"), btn_nextPage(">"),
in_addFriend("Add friend", "Enter player id") {


addWidgets();
}

ServerView::~ServerView() {
// Cleanup our surfaces
if (background) {
SDL_FreeSurface(background);
}
if (backTexture) {
SDL_DestroyTexture(backTexture);
}
}

void ServerView::action(const gcn::ActionEvent& actionEvent) {

}

void ServerView::addWidgets() {

int xStep = getWidth() / 5;
addWidget(&btn_back, xStep - btn_back.getWidth(), getHeight() - 2 * btn_back.getHeight());
addWidget(&btn_newRoom, 2 *xStep - btn_newRoom.getWidth(), btn_back.getY());
addWidget(&btn_goToShop, 3 * xStep - btn_goToShop.getWidth(), btn_back.getY());
addWidget(&btn_addFriend, 4 * xStep - btn_addFriend.getWidth(), btn_back.getY());
}

void ServerView::drawBackground(SDL_Renderer* screen) {

}
60 changes: 60 additions & 0 deletions src/views/serverview.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* 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_SERVERVIEW_
#define _H_SERVERVIEW_

#include <map>
#include <guisan.hpp>
#include "../context.hpp"

class ServerView final : public Context, public gcn::ActionListener {
public:
ServerView();
virtual ~ServerView();

virtual void drawBackground(SDL_Renderer* screen) override;
virtual void drawOverlay(SDL_Renderer* screen) override {
// No overlays in ServerView
};
virtual void processEvent(SDL_Event& event) override {
// No specific handling to be done here, GUI handles everything
};
// Inherited via ActionListener
void action(const gcn::ActionEvent& actionEvent) override;

private:
gcn::Button btn_back;
gcn::Button btn_newRoom;
gcn::Button btn_goToShop;
gcn::Button btn_addFriend;

gcn::Button btn_prevPage;
gcn::Button btn_nextPage;

gcn::Label lbl_playerName;
gcn::Label lbl_playerTeam;
gcn::Label lbl_playerPoints;
gcn::Label lbl_playerMoney;

gcn::Label lbl_pages;

gcn::TextBox tb_chat;
gcn::ScrollArea sa_chat;
gcn::TextField tf_message;

gcn::InputBox in_addFriend;

SDL_Texture* backTexture = nullptr;
SDL_Surface* background = nullptr;
SDL_Texture* playerLvlTexture = nullptr;

void addWidgets();
};

#endif // !_H_SERVERVIEW_

0 comments on commit 22d48a7

Please sign in to comment.