mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
implemented game types
This commit is contained in:
parent
7116382a96
commit
04742f6fb9
23 changed files with 249 additions and 127 deletions
|
|
@ -11,8 +11,8 @@
|
|||
#include "dlg_creategame.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *parent)
|
||||
: QDialog(parent), client(_client), roomId(_roomId)
|
||||
DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<int, QString> &_gameTypes, QWidget *parent)
|
||||
: QDialog(parent), client(_client), roomId(_roomId), gameTypes(_gameTypes)
|
||||
{
|
||||
descriptionLabel = new QLabel(tr("&Description:"));
|
||||
descriptionEdit = new QLineEdit;
|
||||
|
|
@ -29,6 +29,17 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *pare
|
|||
maxPlayersEdit->setValue(2);
|
||||
maxPlayersLabel->setBuddy(maxPlayersEdit);
|
||||
|
||||
QVBoxLayout *gameTypeLayout = new QVBoxLayout;
|
||||
QMapIterator<int, QString> gameTypeIterator(gameTypes);
|
||||
while (gameTypeIterator.hasNext()) {
|
||||
gameTypeIterator.next();
|
||||
QCheckBox *gameTypeCheckBox = new QCheckBox(gameTypeIterator.value());
|
||||
gameTypeLayout->addWidget(gameTypeCheckBox);
|
||||
gameTypeCheckBoxes.insert(gameTypeIterator.key(), gameTypeCheckBox);
|
||||
}
|
||||
QGroupBox *gameTypeGroupBox = new QGroupBox(tr("Game type"));
|
||||
gameTypeGroupBox->setLayout(gameTypeLayout);
|
||||
|
||||
spectatorsAllowedCheckBox = new QCheckBox(tr("&Spectators allowed"));
|
||||
spectatorsAllowedCheckBox->setChecked(true);
|
||||
connect(spectatorsAllowedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(spectatorsAllowedChanged(int)));
|
||||
|
|
@ -50,7 +61,8 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *pare
|
|||
grid->addWidget(passwordEdit, 1, 1);
|
||||
grid->addWidget(maxPlayersLabel, 2, 0);
|
||||
grid->addWidget(maxPlayersEdit, 2, 1);
|
||||
grid->addWidget(spectatorsGroupBox, 3, 0, 1, 2);
|
||||
grid->addWidget(gameTypeGroupBox, 3, 0, 1, 2);
|
||||
grid->addWidget(spectatorsGroupBox, 4, 0, 1, 2);
|
||||
|
||||
okButton = new QPushButton(tr("&OK"));
|
||||
okButton->setDefault(true);
|
||||
|
|
@ -76,11 +88,20 @@ DlgCreateGame::DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *pare
|
|||
|
||||
void DlgCreateGame::actOK()
|
||||
{
|
||||
QList<GameTypeId *> gameTypeList;
|
||||
QMapIterator<int, QCheckBox *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
|
||||
while (gameTypeCheckBoxIterator.hasNext()) {
|
||||
gameTypeCheckBoxIterator.next();
|
||||
if (gameTypeCheckBoxIterator.value()->isChecked())
|
||||
gameTypeList.append(new GameTypeId(gameTypeCheckBoxIterator.key()));
|
||||
}
|
||||
|
||||
Command_CreateGame *createCommand = new Command_CreateGame(
|
||||
roomId,
|
||||
descriptionEdit->text(),
|
||||
passwordEdit->text(),
|
||||
maxPlayersEdit->value(),
|
||||
gameTypeList,
|
||||
spectatorsAllowedCheckBox->isChecked(),
|
||||
spectatorsNeedPasswordCheckBox->isChecked(),
|
||||
spectatorsCanTalkCheckBox->isChecked(),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class QSpinBox;
|
|||
class DlgCreateGame : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DlgCreateGame(AbstractClient *_client, int _roomId, QWidget *parent = 0);
|
||||
DlgCreateGame(AbstractClient *_client, int _roomId, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
|
||||
private slots:
|
||||
void actOK();
|
||||
void checkResponse(ResponseCode response);
|
||||
|
|
@ -22,6 +22,8 @@ private slots:
|
|||
private:
|
||||
AbstractClient *client;
|
||||
int roomId;
|
||||
QMap<int, QString> gameTypes;
|
||||
QMap<int, QCheckBox *> gameTypeCheckBoxes;
|
||||
|
||||
QGroupBox *spectatorsGroupBox;
|
||||
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -9,8 +9,11 @@ class ServerInfo_Game;
|
|||
|
||||
class GamesModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<ServerInfo_Game *> gameList;
|
||||
QMap<int, QString> gameTypes;
|
||||
public:
|
||||
GamesModel(QObject *parent = 0) : QAbstractTableModel(parent) { }
|
||||
GamesModel(const QMap<int, QString> &_gameTypes, QObject *parent = 0);
|
||||
~GamesModel();
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : gameList.size(); }
|
||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 5; }
|
||||
|
|
@ -19,8 +22,6 @@ public:
|
|||
|
||||
ServerInfo_Game *getGame(int row);
|
||||
void updateGameList(ServerInfo_Game *game);
|
||||
private:
|
||||
QList<ServerInfo_Game *> gameList;
|
||||
};
|
||||
|
||||
class GamesProxyModel : public QSortFilterProxyModel {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
LocalServer::LocalServer(QObject *parent)
|
||||
: Server(parent)
|
||||
{
|
||||
addRoom(new Server_Room(0, QString(), QString(), false, QString(), this));
|
||||
addRoom(new Server_Room(0, QString(), QString(), false, QString(), QStringList(), this));
|
||||
}
|
||||
|
||||
LocalServer::~LocalServer()
|
||||
|
|
|
|||
|
|
@ -17,15 +17,16 @@
|
|||
#include "gamesmodel.h"
|
||||
#include "chatview.h"
|
||||
|
||||
GameSelector::GameSelector(AbstractClient *_client, int _roomId, QWidget *parent)
|
||||
: QGroupBox(parent), client(_client), roomId(_roomId)
|
||||
GameSelector::GameSelector(AbstractClient *_client, TabRoom *_room, QWidget *parent)
|
||||
: QGroupBox(parent), client(_client), room(_room)
|
||||
{
|
||||
gameListView = new QTreeView;
|
||||
gameListModel = new GamesModel(this);
|
||||
gameListModel = new GamesModel(room->getGameTypes(), this);
|
||||
gameListProxyModel = new GamesProxyModel(this);
|
||||
gameListProxyModel->setSourceModel(gameListModel);
|
||||
gameListView->setModel(gameListProxyModel);
|
||||
gameListView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
|
||||
gameListView->setSortingEnabled(true);
|
||||
|
||||
showFullGamesCheckBox = new QCheckBox;
|
||||
createButton = new QPushButton;
|
||||
|
|
@ -61,7 +62,7 @@ void GameSelector::showFullGamesChanged(int state)
|
|||
|
||||
void GameSelector::actCreate()
|
||||
{
|
||||
DlgCreateGame dlg(client, roomId, this);
|
||||
DlgCreateGame dlg(client, room->getRoomId(), room->getGameTypes(), this);
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +97,7 @@ void GameSelector::actJoin()
|
|||
return;
|
||||
}
|
||||
|
||||
Command_JoinGame *commandJoinGame = new Command_JoinGame(roomId, game->getGameId(), password, spectator);
|
||||
Command_JoinGame *commandJoinGame = new Command_JoinGame(room->getRoomId(), game->getGameId(), password, spectator);
|
||||
connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
|
||||
client->sendCommand(commandJoinGame);
|
||||
|
||||
|
|
@ -122,7 +123,11 @@ void GameSelector::processGameInfo(ServerInfo_Game *info)
|
|||
TabRoom::TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info)
|
||||
: Tab(), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName)
|
||||
{
|
||||
gameSelector = new GameSelector(client, roomId);
|
||||
const QList<ServerInfo_GameType *> gameTypeList = info->getGameTypeList();
|
||||
for (int i = 0; i < gameTypeList.size(); ++i)
|
||||
gameTypes.insert(gameTypeList[i]->getGameTypeId(), gameTypeList[i]->getDescription());
|
||||
|
||||
gameSelector = new GameSelector(client, this);
|
||||
userList = new UserList(client, false);
|
||||
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class Event_ListGames;
|
|||
class Event_JoinRoom;
|
||||
class Event_LeaveRoom;
|
||||
class Event_RoomSay;
|
||||
class TabRoom;
|
||||
|
||||
class GameSelector : public QGroupBox {
|
||||
Q_OBJECT
|
||||
|
|
@ -35,7 +36,7 @@ signals:
|
|||
void gameJoined(int gameId);
|
||||
private:
|
||||
AbstractClient *client;
|
||||
int roomId;
|
||||
TabRoom *room;
|
||||
|
||||
QTreeView *gameListView;
|
||||
GamesModel *gameListModel;
|
||||
|
|
@ -43,7 +44,7 @@ private:
|
|||
QPushButton *createButton, *joinButton, *spectateButton;
|
||||
QCheckBox *showFullGamesCheckBox;
|
||||
public:
|
||||
GameSelector(AbstractClient *_client, int _roomId, QWidget *parent = 0);
|
||||
GameSelector(AbstractClient *_client, TabRoom *_room, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
void processGameInfo(ServerInfo_Game *info);
|
||||
};
|
||||
|
|
@ -55,6 +56,7 @@ private:
|
|||
int roomId;
|
||||
QString roomName;
|
||||
QString ownName;
|
||||
QMap<int, QString> gameTypes;
|
||||
|
||||
GameSelector *gameSelector;
|
||||
UserList *userList;
|
||||
|
|
@ -82,6 +84,7 @@ public:
|
|||
void retranslateUi();
|
||||
void processRoomEvent(RoomEvent *event);
|
||||
int getRoomId() const { return roomId; }
|
||||
const QMap<int, QString> &getGameTypes() const { return gameTypes; }
|
||||
QString getChannelName() const { return roomName; }
|
||||
QString getTabText() const { return roomName; }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ void MainWindow::actSinglePlayer()
|
|||
}
|
||||
tabSupervisor->startLocal(localClients);
|
||||
|
||||
Command_CreateGame *createCommand = new Command_CreateGame(0, QString(), QString(), numberPlayers, false, false, false, false);
|
||||
Command_CreateGame *createCommand = new Command_CreateGame(0, QString(), QString(), numberPlayers, QList<GameTypeId *>(), false, false, false, false);
|
||||
mainClient->sendCommand(createCommand);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue