From bef61bdf6a1a288632bb763e71b5854083fdff6d Mon Sep 17 00:00:00 2001 From: Gwilherm Baudic Date: Tue, 7 Apr 2020 21:06:08 +0200 Subject: [PATCH] [ui] Introducing LobbyView #18 --- src/context.cpp | 1 + src/views/lobbyview.cpp | 95 +++++++++++++++++++++++++++++++++++++++++ src/views/lobbyview.hpp | 62 +++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 src/views/lobbyview.cpp create mode 100644 src/views/lobbyview.hpp diff --git a/src/context.cpp b/src/context.cpp index 1833c4d..d602609 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -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 diff --git a/src/views/lobbyview.cpp b/src/views/lobbyview.cpp new file mode 100644 index 0000000..8ae001d --- /dev/null +++ b/src/views/lobbyview.cpp @@ -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 +#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 +} + + diff --git a/src/views/lobbyview.hpp b/src/views/lobbyview.hpp new file mode 100644 index 0000000..857b054 --- /dev/null +++ b/src/views/lobbyview.hpp @@ -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 +#include +#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_ +