2#include "ui_roomview.h"
4RoomView::RoomView(QWidget *parent)
5 : QMainWindow(parent), ui(new Ui::
RoomView) {
13void RoomView::updateStatus(CreatingSessionStatus newStatus) {
15 ui->waitForHostLabel->setText(STATUS.at(status));
16 ui->joinSessionButton->setEnabled(status ==
17 CreatingSessionStatus::NOW_YOU_CAN_JOIN);
20void RoomView::updateRoomInfo(
const RoomInfo &roomInfo) {
21 sessionId = roomInfo.session_id;
22 is_host = roomInfo.isHost;
23 ui->roomNameLabel->setText(roomInfo.display_name);
24 ui->inviteCodeLabel->setText(roomInfo.invite_code);
25 ui->membersListWidget->clear();
26 for (
const auto &member : roomInfo.members) {
27 ui->membersListWidget->addItem(member.display_name);
30 if (!sessionId.isEmpty()) {
31 requestedSessionUpdate(sessionId);
37void RoomView::updateSessionInfo(
const SessionInfo &sessionInfo) {
39 ui->sessionGameLabel->hide();
40 ui->sessionGameComboBox->hide();
41 ui->createSessionButton->hide();
42 ui->joinSessionButton->show();
43 ui->joinSessionButton->setEnabled(sessionInfo.status !=
44 SessionInfo::Status::FINISHED);
45 updateStatus(sessionInfo.status != SessionInfo::Status::FINISHED
46 ? CreatingSessionStatus::NOW_YOU_CAN_JOIN
47 : CreatingSessionStatus::WAIT_FOR_THE_HOST);
50 if (sessionInfo.status != SessionInfo::Status::FINISHED) {
51 ui->createSessionButton->hide();
52 ui->joinSessionButton->show();
53 ui->joinSessionButton->setEnabled(
true);
54 ui->sessionGameLabel->hide();
55 ui->sessionGameComboBox->hide();
56 updateStatus(CreatingSessionStatus::NOW_YOU_CAN_JOIN);
58 ui->createSessionButton->show();
59 ui->joinSessionButton->hide();
60 ui->createSessionButton->setEnabled(
true);
61 ui->sessionGameLabel->show();
62 ui->sessionGameComboBox->show();
63 updateStatus(CreatingSessionStatus::YOU_CAN_CREATE);
67void RoomView::gotGamesListUpdate(
const std::vector<GameInfo> &newGamesList) {
68 ui->sessionGameComboBox->clear();
69 for (
const auto &gameInfo : newGamesList) {
70 ui->sessionGameComboBox->addItem(gameInfo.display_name, gameInfo.id);
72 if (ui->sessionGameComboBox->count() > 0) {
73 ui->sessionGameComboBox->setCurrentIndex(0);
75 ui->sessionGameComboBox->setCurrentIndex(-1);
79void RoomView::clear() {
80 updateStatus(CreatingSessionStatus::UNKNOWN);
81 ui->roomNameLabel->setText(
"<room_name>");
82 ui->inviteCodeLabel->setText(
"<invite_code>");
83 ui->membersListWidget->clear();
86void RoomView::on_backButton_clicked() {
90 emit shownStartView();
93void RoomView::on_joinSessionButton_clicked() {
94 emit joinedSession(sessionId);
97void RoomView::on_createSessionButton_clicked() {
98 if (ui->sessionGameComboBox->currentData().toString().isEmpty()) {
101 emit createdSession(ui->sessionGameComboBox->currentData().toString());