disable join if spec disabled (#2605)

This commit is contained in:
Zach H 2017-04-20 03:01:28 -04:00 committed by GitHub
parent dd36187864
commit e2e9c5ab96
2 changed files with 20 additions and 1 deletions

View file

@ -98,6 +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, SIGNAL(activated(const QModelIndex &)), this, SLOT(actJoin()));
}
@ -144,7 +145,7 @@ void GameSelector::checkResponse(const Response &response)
if (createButton)
createButton->setEnabled(true);
joinButton->setEnabled(true);
spectateButton->setEnabled(true);
switch (response.response_code()) {
case Response::RespNotInRoom: QMessageBox::critical(this, tr("Error"), tr("Please join the appropriate room first.")); break;
@ -157,6 +158,9 @@ void GameSelector::checkResponse(const Response &response)
case Response::RespInIgnoreList: QMessageBox::critical(this, tr("Error"), tr("You are being ignored by the creator of this game.")); break;
default: ;
}
if (response.response_code() != Response::RespSpectatorsNotAllowed)
spectateButton->setEnabled(true);
}
void GameSelector::actJoin()
@ -212,3 +216,17 @@ void GameSelector::processGameInfo(const ServerInfo_Game &info)
{
gameListModel->updateGameList(info);
}
void GameSelector::updateButtonChoices(const QModelIndex &index)
{
if (!index.isValid())
return;
const ServerInfo_Game &game = gameListModel->getGame(index.data(Qt::UserRole).toInt());
bool overrideRestrictions = !tabSupervisor->getAdminLocked();
if (game.spectators_allowed() || overrideRestrictions)
spectateButton->setEnabled(true);
else
spectateButton->setEnabled(false);
}

View file

@ -23,6 +23,7 @@ private slots:
void actCreate();
void actJoin();
void checkResponse(const Response &response);
void updateButtonChoices(const QModelIndex &);
signals:
void gameJoined(int gameId);
private: