mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
implemented game types
This commit is contained in:
parent
7116382a96
commit
04742f6fb9
23 changed files with 249 additions and 127 deletions
|
|
@ -1,6 +1,11 @@
|
|||
#include "gamesmodel.h"
|
||||
#include "protocol_datastructures.h"
|
||||
|
||||
GamesModel::GamesModel(const QMap<int, QString> &_gameTypes, QObject *parent)
|
||||
: QAbstractTableModel(parent), gameTypes(_gameTypes)
|
||||
{
|
||||
}
|
||||
|
||||
GamesModel::~GamesModel()
|
||||
{
|
||||
if (!gameList.isEmpty()) {
|
||||
|
|
@ -27,9 +32,16 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
|||
switch (index.column()) {
|
||||
case 0: return g->getDescription();
|
||||
case 1: return g->getCreatorInfo()->getName();
|
||||
case 2: return g->getHasPassword() ? (g->getSpectatorsNeedPassword() ? tr("yes") : tr("yes, free for spectators")) : tr("no");
|
||||
case 3: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
|
||||
case 4: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed"));
|
||||
case 2: {
|
||||
QStringList result;
|
||||
QList<GameTypeId *> gameTypeList = g->getGameTypes();
|
||||
for (int i = 0; i < gameTypeList.size(); ++i)
|
||||
result.append(gameTypes.value(gameTypeList[i]->getData()));
|
||||
return result.join(", ");
|
||||
}
|
||||
case 3: return g->getHasPassword() ? (g->getSpectatorsNeedPassword() ? tr("yes") : tr("yes, free for spectators")) : tr("no");
|
||||
case 4: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
|
||||
case 5: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed"));
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
|
@ -41,9 +53,10 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
|
|||
switch (section) {
|
||||
case 0: return tr("Description");
|
||||
case 1: return tr("Creator");
|
||||
case 2: return tr("Password");
|
||||
case 3: return tr("Players");
|
||||
case 4: return tr("Spectators");
|
||||
case 2: return tr("Game type");
|
||||
case 3: return tr("Password");
|
||||
case 4: return tr("Players");
|
||||
case 5: return tr("Spectators");
|
||||
default: return QVariant();
|
||||
}
|
||||
}
|
||||
|
|
@ -56,7 +69,11 @@ ServerInfo_Game *GamesModel::getGame(int row)
|
|||
|
||||
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());
|
||||
QList<GameTypeId *> gameTypeList, oldGameTypeList = _game->getGameTypes();
|
||||
for (int i = 0; i < oldGameTypeList.size(); ++i)
|
||||
gameTypeList.append(new GameTypeId(oldGameTypeList[i]->getData()));
|
||||
|
||||
ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), gameTypeList, 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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue