From acb40bc738982d6fcb5169edb28414ab2a0fa645 Mon Sep 17 00:00:00 2001 From: ctrlaltca Date: Mon, 24 Apr 2017 22:20:44 +0200 Subject: [PATCH] Fix #2608; fix #2609; fix #2611 (#2636) --- cockatrice/src/gameselector.cpp | 15 ++++++--------- cockatrice/src/gameselector.h | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index bb4541ca..0a745f5e 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -98,7 +98,7 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin())); connect(spectateButton, SIGNAL(clicked()), this, SLOT(actJoin())); - connect(gameListView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(updateButtonChoices(const QModelIndex &))); + connect(gameListView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(actSelectedGameChanged(const QModelIndex &, const QModelIndex &))); connect(gameListView, SIGNAL(activated(const QModelIndex &)), this, SLOT(actJoin())); } @@ -146,7 +146,6 @@ void GameSelector::checkResponse(const Response &response) createButton->setEnabled(true); joinButton->setEnabled(true); - switch (response.response_code()) { case Response::RespNotInRoom: QMessageBox::critical(this, tr("Error"), tr("Please join the appropriate room first.")); break; case Response::RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Wrong password.")); break; @@ -217,16 +216,14 @@ void GameSelector::processGameInfo(const ServerInfo_Game &info) gameListModel->updateGameList(info); } -void GameSelector::updateButtonChoices(const QModelIndex &index) +void GameSelector::actSelectedGameChanged(const QModelIndex ¤t, const QModelIndex & /* previous */) { - if (!index.isValid()) + if (!current.isValid()) return; - const ServerInfo_Game &game = gameListModel->getGame(index.data(Qt::UserRole).toInt()); + const ServerInfo_Game &game = gameListModel->getGame(current.data(Qt::UserRole).toInt()); bool overrideRestrictions = !tabSupervisor->getAdminLocked(); - if (game.spectators_allowed() || overrideRestrictions) - spectateButton->setEnabled(true); - else - spectateButton->setEnabled(false); + spectateButton->setEnabled(game.spectators_allowed() || overrideRestrictions); + joinButton->setEnabled( game.player_count() < game.max_players() || overrideRestrictions); } diff --git a/cockatrice/src/gameselector.h b/cockatrice/src/gameselector.h index 421726e1..69d22dc3 100644 --- a/cockatrice/src/gameselector.h +++ b/cockatrice/src/gameselector.h @@ -22,8 +22,8 @@ private slots: void actClearFilter(); void actCreate(); void actJoin(); + void actSelectedGameChanged(const QModelIndex ¤t, const QModelIndex &previous); void checkResponse(const Response &response); - void updateButtonChoices(const QModelIndex &); signals: void gameJoined(int gameId); private: