示例#1
0
void GamesModel::updateGameList(ServerInfo_Game *_game)
{
	ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), new ServerInfo_User(_game->getCreatorInfo()), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount());
	for (int i = 0; i < gameList.size(); i++)
		if (gameList[i]->getGameId() == game->getGameId()) {
			if (game->getPlayerCount() == 0) {
				beginRemoveRows(QModelIndex(), i, i);
				delete gameList.takeAt(i);
				endRemoveRows();
			} else {
				delete gameList[i];
				gameList[i] = game;
				emit dataChanged(index(i, 0), index(i, 4));
			}
			return;
		}
	if (game->getPlayerCount() == 0)
		return;
	beginInsertRows(QModelIndex(), gameList.size(), gameList.size());
	gameList.append(game);
	endInsertRows();
}
示例#2
0
void GameSelector::actJoin()
{
	bool spectator = sender() == spectateButton;
	
	QModelIndex ind = gameListView->currentIndex();
	if (!ind.isValid())
		return;
	ServerInfo_Game *game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
	QString password;
	if (game->getHasPassword() && !(spectator && !game->getSpectatorsNeedPassword())) {
		bool ok;
		password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
		if (!ok)
			return;
	}

	Command_JoinGame *commandJoinGame = new Command_JoinGame(roomId, game->getGameId(), password, spectator);
	connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
	client->sendCommand(commandJoinGame);

	createButton->setEnabled(false);
	joinButton->setEnabled(false);
	spectateButton->setEnabled(false);
}