-
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
158 additions
and
0 deletions.
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,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 | ||
} | ||
|
||
|
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,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_ | ||
|