Skip to content

Commit

Permalink
[ui] Introducing LobbyView #18
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaudic committed Apr 7, 2020
1 parent 17f6bf9 commit bef61bd
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "views/serverlist.hpp"
#include "views/serverview.hpp"
#include "views/roomview.hpp"
#include "views/lobbyview.hpp"
using namespace std;

// Init of static class members
Expand Down
95 changes: 95 additions & 0 deletions src/views/lobbyview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* \file lobbyview.cpp
* \brief Implementation for the Lobby view
* \author G. B.
* \version 0.1a
* \date 07/04/2020
*/
/* 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 <regex>
#include "lobbyview.hpp"
using namespace gcn;

LobbyView::LobbyView(): Context(ContextName::ROOM_LOBBY) {

btn_back.setActionEventId("back");
btn_back.addActionListener(this);
btn_ready.setActionEventId("ready");
btn_ready.addActionListener(this);
btn_editName.setActionEventId("editname");
btn_editName.addActionListener(this);
btn_editConfig.setActionEventId("config");
btn_editConfig.addActionListener(this);
btn_teamSwitch.setActionEventId("switch");
btn_teamSwitch.addActionListener(this);
tf_message.setActionEventId("message");
tf_message.addActionListener(this);

pg_loading.setVisible(false);
}

void LobbyView::action(const gcn::ActionEvent& actionEvent) {
if (actionEvent.getId() == "editname" && isCurrentPlayerAdmin) {
// TODO open edit box
} else if (actionEvent.getId() == "config" && isCurrentPlayerAdmin) {
// TODO open specific edition box
} else if (actionEvent.getId() == "message") {
std::string msg = tf_message.getText();
// Handle special processing of commands
std::regex pattern{ "^(/kick|/mute)\\s+" };
if (std::regex_match(msg, pattern)) {
// TODO send as command
} else {
// Send as text message
}
}
}

void LobbyView::updateRoomInfo() {
// TBD
}

void LobbyView::updatePlayerInfo() {
// TBD
}

void LobbyView::updateItemInfo() {
// TBD
}

void LobbyView::addMessage(std::string user, std::string message, bool showBalloon) {
tb_messages.addRow(user + "] " + message);
if (showBalloon) {
// Reset the balloon for this user
}
}

void LobbyView::addWidgets() {
addWidget(&lbl_number, 5, 5);
addWidget(&lbl_name, 20, 5);
addWidget(&btn_editName, 100, 5);

addWidget(&btn_back, 5, getHeight() - 2 * btn_back.getHeight());
addWidget(&btn_ready, getWidth() - 5 - btn_ready.getWidth(), getHeight() - 2 * btn_back.getHeight());
}

void LobbyView::drawBackground(SDL_Renderer* screen) {
// TBD
}

void LobbyView::processMessage(const Uint8 code, const std::string& message) {
// TBD
}

void LobbyView::drawOverlay(SDL_Renderer* screen) {
// TBD
}


62 changes: 62 additions & 0 deletions src/views/lobbyview.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* \file lobbyview.hpp
* \brief Implementation for the Lobby view
* \author G. B.
* \version 0.1a
* \date 07/04/2020
*/
/* 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_LOBBYVIEW_
#define _H_LOBBYVIEW_

#include <string>
#include <guisan.hpp>
#include "../context.hpp"
#include "../common/commonroom.hpp"
#include "../common/messages.hpp"

class LobbyView : public Context, public gcn::ActionListener {
public:
LobbyView();
void action(const gcn::ActionEvent& actionEvent) override;

void updateRoomInfo();
void updatePlayerInfo();
void updateItemInfo();
void addMessage(std::string user, std::string message, bool showBalloon = true);

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;
virtual void processEvent(SDL_Event& event) override {
// No specific handling to be done here, GUI handles everything
};

private:
gcn::Label lbl_number;
gcn::Label lbl_name;

gcn::Button btn_back{ "< Back" };
gcn::Button btn_ready{ "Ready" };
gcn::Button btn_editName{ "Edit name" };
gcn::Button btn_editConfig{ "Edit config" };
gcn::Button btn_teamSwitch{ "Change team" };
gcn::ProgressBar pg_loading;
gcn::TabbedArea tabs;
gcn::TextField tf_message;
gcn::TextBox tb_messages;

bool isCurrentPlayerAdmin = false;

void addWidgets();
};

#endif // !_H_LOBBYVIEW_

0 comments on commit bef61bd

Please sign in to comment.