minor improvements

This commit is contained in:
Max-Wilhelm Bruker 2009-04-14 19:18:46 +02:00
parent 3388804e8f
commit 99ff7fd15f
23 changed files with 114 additions and 95 deletions

View file

@ -130,7 +130,7 @@ void Client::readLine()
// XXX Parametergültigkeit überprüfen
if (!prefix.compare("list_games"))
gamelist << new ServerGame(val[0], val[1], val[2].toInt(), val[3].toInt(), val[4].toInt());
gamelist << new ServerGame(val[0].toInt(), val[5], val[1], val[2].toInt(), val[3].toInt(), val[4].toInt());
else if (!prefix.compare("list_players"))
playerlist << new ServerPlayer(val[0].toInt(), val[1]);
else if (!prefix.compare("list_counters"))
@ -215,14 +215,14 @@ int Client::listPlayers()
return cmd("list_players");
}
int Client::createGame(const QString &name, const QString &description, const QString &password, unsigned int maxPlayers)
int Client::createGame(const QString &description, const QString &password, unsigned int maxPlayers)
{
return cmd(QString("create_game|%1|%2|%3|%4").arg(name).arg(description).arg(password).arg(maxPlayers));
return cmd(QString("create_game|%1|%2|%3").arg(description).arg(password).arg(maxPlayers));
}
int Client::joinGame(const QString &name, const QString &password)
int Client::joinGame(int gameId, const QString &password)
{
return cmd(QString("join_game|%1|%2").arg(name).arg(password));
return cmd(QString("join_game|%1|%2").arg(gameId).arg(password));
}
int Client::leaveGame()

View file

@ -64,8 +64,8 @@ public:
void disconnectFromServer();
int listGames();
int listPlayers();
int createGame(const QString &name, const QString &description, const QString &password, unsigned int maxPlayers);
int joinGame(const QString &name, const QString &password);
int createGame(const QString &description, const QString &password, unsigned int maxPlayers);
int joinGame(int gameId, const QString &password);
int leaveGame();
int login(const QString &name, const QString &pass);
int say(const QString &s);

View file

@ -2,14 +2,8 @@
#include "dlg_creategame.h"
DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
: QDialog(parent), client(_client)
: QDialog(parent), client(_client), msgid(0)
{
msgid = 0;
nameLabel = new QLabel(tr("&Name:"));
nameEdit = new QLineEdit;
nameLabel->setBuddy(nameEdit);
descriptionLabel = new QLabel(tr("&Description:"));
descriptionEdit = new QLineEdit;
descriptionLabel->setBuddy(descriptionEdit);
@ -18,19 +12,17 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
passwordEdit = new QLineEdit;
passwordLabel->setBuddy(passwordEdit);
maxPlayersLabel = new QLabel(tr("&Max Players:"));
maxPlayersLabel = new QLabel(tr("P&layers:"));
maxPlayersEdit = new QLineEdit("2");
maxPlayersLabel->setBuddy(maxPlayersEdit);
QGridLayout *grid = new QGridLayout;
grid->addWidget(nameLabel, 0, 0);
grid->addWidget(nameEdit, 0, 1);
grid->addWidget(descriptionLabel, 1, 0);
grid->addWidget(descriptionEdit, 1, 1);
grid->addWidget(passwordLabel, 2, 0);
grid->addWidget(passwordEdit, 2, 1);
grid->addWidget(maxPlayersLabel, 3, 0);
grid->addWidget(maxPlayersEdit, 3, 1);
grid->addWidget(descriptionLabel, 0, 0);
grid->addWidget(descriptionEdit, 0, 1);
grid->addWidget(passwordLabel, 1, 0);
grid->addWidget(passwordEdit, 1, 1);
grid->addWidget(maxPlayersLabel, 2, 0);
grid->addWidget(maxPlayersEdit, 2, 1);
okButton = new QPushButton(tr("&OK"));
okButton->setDefault(true);
@ -65,8 +57,7 @@ void DlgCreateGame::actOK()
QMessageBox::critical(this, tr("Error"), tr("Invalid number of players."));
return;
}
msgid = client->createGame(nameEdit->text(),
descriptionEdit->text(),
msgid = client->createGame(descriptionEdit->text(),
passwordEdit->text(),
maxPlayers);
}

View file

@ -19,8 +19,8 @@ private:
Client *client;
int msgid;
QLabel *nameLabel, *descriptionLabel, *passwordLabel, *maxPlayersLabel;
QLineEdit *nameEdit, *descriptionEdit, *passwordEdit, *maxPlayersEdit;
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
QLineEdit *descriptionEdit, *passwordEdit, *maxPlayersEdit;
QPushButton *okButton, *cancelButton;
};

View file

@ -3,10 +3,8 @@
#include "dlg_creategame.h"
DlgGames::DlgGames(Client *_client, QWidget *parent)
: QDialog(parent), client(_client)
: QDialog(parent), client(_client), msgid(0)
{
msgid = 0;
tableView = new QTreeView;
tableModel = new GamesModel(this);
tableView->setModel(tableModel);
@ -28,8 +26,8 @@ DlgGames::DlgGames(Client *_client, QWidget *parent)
setLayout(mainLayout);
setWindowTitle(tr("Games"));
setMinimumWidth(sizeHint().width());
setMinimumWidth(tableView->columnWidth(0) * tableModel->columnCount());
connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate()));
connect(refreshButton, SIGNAL(clicked()), this, SLOT(actRefresh()));
connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin()));
@ -78,7 +76,7 @@ void DlgGames::actJoin()
}
connect(client, SIGNAL(responseReceived(ServerResponse *)), this, SLOT(checkResponse(ServerResponse *)));
msgid = client->joinGame(game->getName(), password);
msgid = client->joinGame(game->getGameId(), password);
}
void DlgGames::gameListReceived(QList<ServerGame *> _gameList)

View file

@ -73,12 +73,11 @@ signals:
void logSetCounter(QString playerName, QString counterName, int value, int oldValue);
void logSetDoesntUntap(QString playerName, QString cardName, bool doesntUntap);
void logDumpZone(QString playerName, QString zoneName, QString zoneOwner, int numberCards);
public slots:
void restartGameDialog();
public:
Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName);
~Game();
Player *getLocalPlayer() const { return localPlayer; }
void restartGameDialog();
};
#endif

View file

@ -13,14 +13,14 @@ int GamesModel::rowCount(const QModelIndex &parent) const
int GamesModel::columnCount(const QModelIndex &parent) const
{
return 4;
return 5;
}
QVariant GamesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if ((index.row() >= gameList.size()) || (index.column() >= 4))
if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
return QVariant();
if (role != Qt::DisplayRole)
@ -28,10 +28,11 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
ServerGame *g = gameList.at(index.row());
switch (index.column()) {
case 0: return g->getName();
case 1: return g->getDescription();
case 2: return QString(g->getHasPassword() ? "yes" : "no");
case 3: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
case 0: return g->getGameId();
case 1: return g->getCreator();
case 2: return g->getDescription();
case 3: return QString(g->getHasPassword() ? "yes" : "no");
case 4: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
default: return QVariant();
}
}
@ -43,10 +44,11 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
if (orientation != Qt::Horizontal)
return QVariant();
switch (section) {
case 0: return QString("Name");
case 1: return QString("Description");
case 2: return QString("Password");
case 3: return QString("Players");
case 0: return QString("Game ID");
case 1: return QString("Creator");
case 2: return QString("Description");
case 3: return QString("Password");
case 4: return QString("Players");
default: return QVariant();
}
}

View file

@ -276,7 +276,6 @@ void Player::gameEvent(ServerEventData *event)
int colorValue = data[1].toInt();
int value = data[2].toInt();
QColor color(colorValue / 65536, (colorValue % 65536) / 256, colorValue % 256);
qDebug(QString("%1 / %2 / %3").arg(color.red()).arg(color.green()).arg(color.blue()).toLatin1());
area->addCounter(counterName, color, value);
break;
}

View file

@ -3,15 +3,17 @@
class ServerGame {
private:
QString name;
int gameId;
QString creator;
QString description;
bool hasPassword;
unsigned char playerCount;
unsigned char maxPlayers;
public:
ServerGame(const QString &_name, const QString &_description, bool _hasPassword, unsigned char _playerCount, unsigned char _maxPlayers)
: name(_name), description(_description), hasPassword(_hasPassword), playerCount(_playerCount), maxPlayers(_maxPlayers) { }
QString getName() { return name; }
ServerGame(int _gameId, const QString &_creator, const QString &_description, bool _hasPassword, unsigned char _playerCount, unsigned char _maxPlayers)
: gameId(_gameId), creator(_creator), description(_description), hasPassword(_hasPassword), playerCount(_playerCount), maxPlayers(_maxPlayers) { }
int getGameId() { return gameId; }
QString getCreator() { return creator; }
QString getDescription() { return description; }
bool getHasPassword() { return hasPassword; }
unsigned char getPlayerCount() { return playerCount; }

View file

@ -96,8 +96,15 @@ void MainWindow::actGames()
dlg.exec();
}
void MainWindow::actRestartGame()
{
zoneLayout->clear();
game->restartGameDialog();
}
void MainWindow::actLeaveGame()
{
zoneLayout->clear();
client->leaveGame();
delete game;
game = 0;
@ -145,7 +152,6 @@ void MainWindow::playerIdReceived(int id, QString name)
connect(game, SIGNAL(hoverCard(QString)), this, SLOT(hoverCard(QString)));
connect(game, SIGNAL(playerAdded(Player *)), this, SLOT(playerAdded(Player *)));
connect(game, SIGNAL(playerRemoved(Player *)), this, SLOT(playerRemoved(Player *)));
connect(aRestartGame, SIGNAL(triggered()), game, SLOT(restartGameDialog()));
playerAdded(game->getLocalPlayer());
messageLog->connectToGame(game);
@ -174,6 +180,7 @@ void MainWindow::createActions()
aRestartGame = new QAction(tr("&Restart game..."), this);
aRestartGame->setShortcut(tr("F2"));
aRestartGame->setEnabled(false);
connect(aRestartGame, SIGNAL(triggered()), this, SLOT(actRestartGame()));
aLeaveGame = new QAction(tr("&Leave game"), this);
aLeaveGame->setEnabled(false);
connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame()));

View file

@ -53,6 +53,7 @@ private slots:
void actConnect();
void actDisconnect();
void actGames();
void actRestartGame();
void actLeaveGame();
void actDeckEditor();
void actExit();

View file

@ -52,3 +52,9 @@ void ZoneViewLayout::closeMostRecentZoneView()
return;
views.at(views.size() - 1)->close();
}
void ZoneViewLayout::clear()
{
for (int i = views.size() - 1; i >= 0; i--)
views.at(i)->close();
}

View file

@ -21,6 +21,7 @@ public slots:
void addItem(Player *player, const QString &zoneName, int numberCards = 0);
void removeItem(ZoneViewWidget *item);
void closeMostRecentZoneView();
void clear();
};
#endif