Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
gameslistview.cpp
1#include "gameslistview.h"
2#include "ui_gameslistview.h"
3
4GamesListView::GamesListView(QWidget *parent)
5 : QMainWindow(parent), ui(new Ui::GamesListView) {
6 ui->setupUi(this);
7 connect(ui->gameNameComboBox, SIGNAL(currentIndexChanged(int)), this,
8 SLOT(repeaterCurrentIndexChanged(int)));
9}
10
11void GamesListView::repeaterCurrentIndexChanged(int index) {
12 if (index == -1) {
13 displayEmpty();
14 return;
15 }
16 emit currentIndexChanged(index);
17 emit requestGameStatistics(ui->gameNameComboBox->currentData().toString());
18}
19
20GamesListView::~GamesListView() {
21 delete ui;
22}
23
24void GamesListView::on_backButton_clicked() {
25 this->close();
26 emit shownStartView();
27}
28
29void GamesListView::on_downloadQmlButton_clicked() {
30 emit requestedDownloadGame(ui->gameNameComboBox->currentIndex());
31}
32
33void GamesListView::gotGamesListUpdate(
34 const std::vector<GameInfo> &newGamesList) {
35 ui->gameNameComboBox->clear();
36 for (const auto &gameInfo : newGamesList) {
37 ui->gameNameComboBox->addItem(gameInfo.display_name, gameInfo.id);
38 }
39}
40
41void GamesListView::gotNewSelectedGame(const GameInfo &gameInfo) {
42 ui->gameDescriptionTextBrowser->setText(gameInfo.description);
43 ui->playersAllowedLabel->setText(QString::number(gameInfo.players_num));
44}
45
46void GamesListView::gotNewGameStatistics(const GameStatistics &gameStatistics) {
47 ui->averageDurationLabel->setText(
48 QString::number(gameStatistics.average_duration_sec));
49 ui->averagePlayersLabel->setText(
50 QString::number(gameStatistics.average_players_count));
51 ui->totalTimePlayedLabel->setText(
52 QString::number(gameStatistics.total_time_played_sec));
53 ui->totalGamesPlayedLabel->setText(
54 QString::number(gameStatistics.total_games_played));
55}
56
57void GamesListView::displayEmpty() {
58 ui->gameDescriptionTextBrowser->clear();
59 ui->playersAllowedLabel->clear();
60}