Fixed elevation of spectator rights; added some spectator options; closes bug 0000005

This commit is contained in:
Max-Wilhelm Bruker 2010-05-26 21:36:54 +02:00
parent 604d1ffa94
commit befafa28ae
26 changed files with 430 additions and 220 deletions

View file

@ -14,11 +14,25 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
passwordLabel->setBuddy(passwordEdit);
maxPlayersLabel = new QLabel(tr("P&layers:"));
maxPlayersEdit = new QLineEdit("2");
maxPlayersEdit = new QSpinBox();
maxPlayersEdit->setMinimum(1);
maxPlayersEdit->setMaximum(100);
maxPlayersEdit->setValue(2);
maxPlayersLabel->setBuddy(maxPlayersEdit);
spectatorsAllowedCheckBox = new QCheckBox(tr("&Spectators allowed"));
spectatorsAllowedCheckBox->setChecked(true);
connect(spectatorsAllowedCheckBox, SIGNAL(stateChanged(int)), this, SLOT(spectatorsAllowedChanged(int)));
spectatorsNeedPasswordCheckBox = new QCheckBox(tr("Spectators &need a password to join"));
spectatorsCanTalkCheckBox = new QCheckBox(tr("Spectators can &talk"));
spectatorsSeeEverythingCheckBox = new QCheckBox(tr("Spectators see &everything"));
QVBoxLayout *spectatorsLayout = new QVBoxLayout;
spectatorsLayout->addWidget(spectatorsAllowedCheckBox);
spectatorsLayout->addWidget(spectatorsNeedPasswordCheckBox);
spectatorsLayout->addWidget(spectatorsCanTalkCheckBox);
spectatorsLayout->addWidget(spectatorsSeeEverythingCheckBox);
spectatorsGroupBox = new QGroupBox(tr("Spectators"));
spectatorsGroupBox->setLayout(spectatorsLayout);
QGridLayout *grid = new QGridLayout;
grid->addWidget(descriptionLabel, 0, 0);
@ -27,7 +41,7 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
grid->addWidget(passwordEdit, 1, 1);
grid->addWidget(maxPlayersLabel, 2, 0);
grid->addWidget(maxPlayersEdit, 2, 1);
grid->addWidget(spectatorsAllowedCheckBox, 3, 0, 1, 2);
grid->addWidget(spectatorsGroupBox, 3, 0, 1, 2);
okButton = new QPushButton(tr("&OK"));
okButton->setDefault(true);
@ -53,13 +67,15 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
void DlgCreateGame::actOK()
{
bool ok;
int maxPlayers = maxPlayersEdit->text().toInt(&ok);
if (!ok) {
QMessageBox::critical(this, tr("Error"), tr("Invalid number of players."));
return;
}
Command_CreateGame *createCommand = new Command_CreateGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers, spectatorsAllowedCheckBox->isChecked());
Command_CreateGame *createCommand = new Command_CreateGame(
descriptionEdit->text(),
passwordEdit->text(),
maxPlayersEdit->value(),
spectatorsAllowedCheckBox->isChecked(),
spectatorsNeedPasswordCheckBox->isChecked(),
spectatorsCanTalkCheckBox->isChecked(),
spectatorsSeeEverythingCheckBox->isChecked()
);
connect(createCommand, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
client->sendCommand(createCommand);
@ -79,3 +95,10 @@ void DlgCreateGame::checkResponse(ResponseCode response)
return;
}
}
void DlgCreateGame::spectatorsAllowedChanged(int state)
{
spectatorsNeedPasswordCheckBox->setEnabled(state);
spectatorsCanTalkCheckBox->setEnabled(state);
spectatorsSeeEverythingCheckBox->setEnabled(state);
}

View file

@ -8,6 +8,8 @@ class QLabel;
class QLineEdit;
class QPushButton;
class QCheckBox;
class QGroupBox;
class QSpinBox;
class DlgCreateGame : public QDialog {
Q_OBJECT
@ -16,12 +18,15 @@ public:
private slots:
void actOK();
void checkResponse(ResponseCode response);
void spectatorsAllowedChanged(int state);
private:
Client *client;
QGroupBox *spectatorsGroupBox;
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
QLineEdit *descriptionEdit, *passwordEdit, *maxPlayersEdit;
QCheckBox *spectatorsAllowedCheckBox;
QLineEdit *descriptionEdit, *passwordEdit;
QSpinBox *maxPlayersEdit;
QCheckBox *spectatorsAllowedCheckBox, *spectatorsNeedPasswordCheckBox, *spectatorsCanTalkCheckBox, *spectatorsSeeEverythingCheckBox;
QPushButton *okButton, *cancelButton;
};

View file

@ -27,7 +27,7 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
switch (index.column()) {
case 0: return g->getDescription();
case 1: return g->getCreatorName();
case 2: return g->getHasPassword() ? tr("yes") : tr("no");
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"));
default: return QVariant();
@ -56,7 +56,7 @@ 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(), _game->getCreatorName(), _game->getSpectatorsAllowed(), _game->getSpectatorCount());
ServerInfo_Game *game = new ServerInfo_Game(_game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), _game->getCreatorName(), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount());
for (int i = 0; i < gameList.size(); i++)
if (gameList[i]->getGameId() == game->getGameId()) {
if (game->getPlayerCount() == 0) {

View file

@ -5,8 +5,8 @@
#include "protocol_items.h"
#include "settingscache.h"
HandZone::HandZone(Player *_p, int _zoneHeight, QGraphicsItem *parent)
: CardZone(_p, "hand", false, false, _p->getLocal(), parent), zoneHeight(_zoneHeight)
HandZone::HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent)
: CardZone(_p, "hand", false, false, _contentsKnown, parent), zoneHeight(_zoneHeight)
{
connect(settingsCache, SIGNAL(handBgPathChanged()), this, SLOT(updateBgPixmap()));
updateBgPixmap();

View file

@ -11,7 +11,7 @@ private:
private slots:
void updateBgPixmap();
public:
HandZone(Player *_p, int _zoneHeight, QGraphicsItem *parent = 0);
HandZone(Player *_p, bool _contentsKnown, int _zoneHeight, QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();

View file

@ -104,7 +104,12 @@ void MessageLogWidget::logGameStart()
void MessageLogWidget::logSay(Player *player, QString message)
{
append(QString("<font color=\"red\">%1:</font> %2").arg(sanitizeHtml(player->getName())).arg(sanitizeHtml(message)));
append(QString("<b><font color=\"red\">%1:</font></b> %2").arg(sanitizeHtml(player->getName())).arg(sanitizeHtml(message)));
}
void MessageLogWidget::logSpectatorSay(QString spectatorName, QString message)
{
append(QString("<font color=\"red\">%1:</font> %2").arg(sanitizeHtml(spectatorName)).arg(sanitizeHtml(message)));
}
void MessageLogWidget::logShuffle(Player *player)

View file

@ -33,6 +33,7 @@ public slots:
void logConcede(Player *player);
void logGameStart();
void logSay(Player *player, QString message);
void logSpectatorSay(QString spectatorName, QString message);
void logShuffle(Player *player);
void logRollDie(Player *player, int sides, int roll);
void logDrawCards(Player *player, int number);

View file

@ -43,7 +43,7 @@ Player::Player(const QString &_name, int _id, bool _local, Client *_client, TabG
table = new TableZone(this, this);
connect(table, SIGNAL(sizeChanged()), this, SLOT(updateBoundingRect()));
hand = new HandZone(this, (int) table->boundingRect().height(), this);
hand = new HandZone(this, _local || (_parent->getSpectator() && _parent->getSpectatorsSeeEverything()), (int) table->boundingRect().height(), this);
base = QPointF(deck->boundingRect().width() + counterAreaWidth + 5, 0);
hand->setPos(base);

View file

@ -19,8 +19,8 @@
#include "arrowitem.h"
#include "main.h"
TabGame::TabGame(Client *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _resuming)
: Tab(), client(_client), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), started(false), resuming(_resuming), currentPhase(-1)
TabGame::TabGame(Client *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
: Tab(), client(_client), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), started(false), resuming(_resuming), currentPhase(-1)
{
scene = new GameScene(this);
gameView = new GameView(scene);
@ -74,8 +74,10 @@ TabGame::TabGame(Client *_client, int _gameId, const QString &_gameDescription,
mainLayout->addLayout(verticalLayout);
if (spectator) {
sayLabel->hide();
sayEdit->hide();
if (!spectatorsCanTalk) {
sayLabel->hide();
sayEdit->hide();
}
loadLocalButton->hide();
loadRemoteButton->hide();
readyStartButton->hide();
@ -226,7 +228,15 @@ void TabGame::processGameEventContainer(GameEventContainer *cont)
for (int i = 0; i < eventList.size(); ++i) {
GameEvent *event = eventList[i];
switch (event->getItemId()) {
if (spectators.contains(event->getPlayerId())) {
switch (event->getItemId()) {
case ItemId_Event_Say: eventSpectatorSay(qobject_cast<Event_Say *>(event), context); break;
default: {
qDebug() << "unhandled spectator game event";
break;
}
}
} else switch (event->getItemId()) {
case ItemId_Event_GameStateChanged: eventGameStateChanged(qobject_cast<Event_GameStateChanged *>(event), context); break;
case ItemId_Event_PlayerPropertiesChanged: eventPlayerPropertiesChanged(qobject_cast<Event_PlayerPropertiesChanged *>(event), context); break;
case ItemId_Event_Join: eventJoin(qobject_cast<Event_Join *>(event), context); break;
@ -289,6 +299,11 @@ void TabGame::stopGame()
deckViewContainer->show();
}
void TabGame::eventSpectatorSay(Event_Say *event, GameEventContext * /*context*/)
{
messageLog->logSpectatorSay(spectators.value(event->getPlayerId()), event->getMessage());
}
void TabGame::eventGameStateChanged(Event_GameStateChanged *event, GameEventContext * /*context*/)
{
const QList<ServerInfo_Player *> &plList = event->getPlayerList();

View file

@ -33,6 +33,7 @@ class Event_GameStart;
class Event_SetActivePlayer;
class Event_SetActivePhase;
class Event_Ping;
class Event_Say;
class Player;
class CardZone;
class AbstractCardItem;
@ -46,6 +47,7 @@ private:
QString gameDescription;
int localPlayerId;
bool spectator;
bool spectatorsCanTalk, spectatorsSeeEverything;
QMap<int, Player *> players;
QMap<int, QString> spectators;
bool started;
@ -73,6 +75,7 @@ private:
void startGame();
void stopGame();
void eventSpectatorSay(Event_Say *event, GameEventContext *context);
void eventGameStateChanged(Event_GameStateChanged *event, GameEventContext *context);
void eventPlayerPropertiesChanged(Event_PlayerPropertiesChanged *event, GameEventContext *context);
void eventJoin(Event_Join *event, GameEventContext *context);
@ -100,12 +103,15 @@ private slots:
void actNextPhase();
void actNextTurn();
public:
TabGame(Client *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _resuming);
TabGame(Client *_client, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming);
~TabGame();
void retranslateUi();
const QMap<int, Player *> &getPlayers() const { return players; }
int getGameId() const { return gameId; }
QString getTabText() const { return tr("Game %1: %2").arg(gameId).arg(gameDescription); }
bool getSpectator() const { return spectator; }
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
void processGameEventContainer(GameEventContainer *cont);
public slots:

View file

@ -81,7 +81,7 @@ void GameSelector::actJoin()
return;
ServerInfo_Game *game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
QString password;
if (game->getHasPassword()) {
if (game->getHasPassword() && !(spectator && !game->getSpectatorsNeedPassword())) {
bool ok;
password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
if (!ok)

View file

@ -103,7 +103,7 @@ void TabSupervisor::updatePingTime(int value, int max)
void TabSupervisor::gameJoined(Event_GameJoined *event)
{
TabGame *tab = new TabGame(client, event->getGameId(), event->getGameDescription(), event->getPlayerId(), event->getSpectator(), event->getResuming());
TabGame *tab = new TabGame(client, event->getGameId(), event->getGameDescription(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
myAddTab(tab);
gameTabs.insert(event->getGameId(), tab);