Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
sessionview.cpp
1#include "sessionview.h"
2#include "ui_sessionview.h"
3
4SessionView::SessionView(QWidget *parent)
5 : QMainWindow(parent), ui(new Ui::SessionView) {
6 ui->setupUi(this);
7 connect(ui->roleComboBox, SIGNAL(currentIndexChanged(int)), this,
8 SLOT(repeaterCurrentIndexChanged(int)));
9}
10
11SessionView::~SessionView() {
12 delete ui;
13}
14
15void SessionView::repeaterCurrentIndexChanged(int index) {
16 if (index == -1 || ui->roleComboBox->itemData(index).toInt() == ourRole) {
17 // displayEmpty();
18 return;
19 }
20 // qDebug() << "Chosen: " << ui->roleComboBox->itemText(index);
21 qDebug() << "Got new role index: "
22 << ui->roleComboBox->itemData(index).toInt();
23 emit newRoleChosen(ui->roleComboBox->itemData(index).toInt());
24}
25
26void SessionView::updateStatus(CreatingGameStatus newStatus) {
27 ui->statusLabel->setText(STATUS.at(newStatus));
28 ui->currentPlayersHLabel->setHidden(newStatus != CreatingGameStatus::DONE);
29 ui->playersListWidget->setHidden(newStatus != CreatingGameStatus::DONE);
30}
31
32void SessionView::updateSessionInfo(const SessionInfo &sessionInfo) {
33 ui->playersListWidget->clear();
34 for (const auto &player : sessionInfo.players) {
35 ui->playersListWidget->addItem(player.user.display_name);
36 }
37 if (sessionInfo.isHost) {
38 show_as_host();
39 } else {
40 show_as_guest();
41 }
42 if (sessionInfo.status == SessionInfo::Status::RUNNING) {
43 this->close();
44 emit joinedCreatedGame();
45 }
46}
47
48void SessionView::updateValidationResult(
49 const ValidationResult &validationResult) {
50 ui->startGameButton->setEnabled(validationResult.success);
51 ui->joinErrorLabel->setText(validationResult.message);
52}
53
54void SessionView::on_startGameButton_clicked() {
55 emit createdGame();
56}
57
58void SessionView::clear() {
59 ui->currentPlayersHLabel->hide();
60 ui->playersListWidget->hide();
61
62 ui->gameNameLabel->setText("Unknown");
63}
64
65void SessionView::on_backButton_clicked() {
66 this->clear();
67 this->close();
68 qDebug() << "Pressed Back From Session";
69 emit leftSession();
70 emit shownRoomView();
71}
72void SessionView::updateGameName(const QString &gameName) {
73 ui->gameNameLabel->setText(gameName);
74}
75void SessionView::gotRolesListUpdate(const std::vector<Role> &newRolesList) {
76 // Some bad way to check whether list actually updated
77 // TODO: implement it
78
79 ourRole = newRolesList.front().id;
80 ui->roleComboBox->clear();
81 for (const auto &roleIdAndName : newRolesList) {
82 ui->roleComboBox->addItem(roleIdAndName.name, roleIdAndName.id);
83 }
84 if (ui->roleComboBox->count() > 0) {
85 ui->roleComboBox->setCurrentIndex(0);
86 } else {
87 ui->roleComboBox->setCurrentIndex(-1);
88 }
89}
90void SessionView::show_as_host() {
91 ui->waitForHostLabel->hide();
92 ui->joinErrorLabel->show();
93 ui->startGameButton->show();
94}
95void SessionView::show_as_guest() {
96 ui->waitForHostLabel->show();
97 ui->joinErrorLabel->hide();
98 ui->startGameButton->hide();
99}