added menu item: game->game information, issue #1 fixed

This commit is contained in:
Max-Wilhelm Bruker 2012-03-24 22:09:06 +01:00
parent 5ff1fd8ec6
commit 542fd2c5c8
12 changed files with 182 additions and 88 deletions

View file

@ -8,14 +8,15 @@
#include <QSpinBox>
#include <QGroupBox>
#include <QMessageBox>
#include <QSet>
#include "dlg_creategame.h"
#include "tab_room.h"
#include "pending_command.h"
#include "pb/room_commands.pb.h"
#include "pb/serverinfo_game.pb.h"
DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent)
: QDialog(parent), room(_room), gameTypes(_gameTypes)
void DlgCreateGame::sharedCtor()
{
descriptionLabel = new QLabel(tr("&Description:"));
descriptionEdit = new QLineEdit;
@ -98,13 +99,63 @@ DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameType
setLayout(mainLayout);
setWindowTitle(tr("Create game"));
setFixedHeight(sizeHint().height());
}
DlgCreateGame::DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent)
: QDialog(parent), room(_room), gameTypes(_gameTypes)
{
sharedCtor();
setWindowTitle(tr("Create game"));
connect(okButton, SIGNAL(clicked()), this, SLOT(actOK()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}
DlgCreateGame::DlgCreateGame(const ServerInfo_Game &gameInfo, const QMap<int, QString> &_gameTypes, QWidget *parent)
: QDialog(parent), room(0), gameTypes(_gameTypes)
{
sharedCtor();
descriptionEdit->setEnabled(false);
maxPlayersEdit->setEnabled(false);
passwordEdit->setEnabled(false);
onlyBuddiesCheckBox->setEnabled(false);
onlyRegisteredCheckBox->setEnabled(false);
spectatorsAllowedCheckBox->setEnabled(false);
spectatorsNeedPasswordCheckBox->setEnabled(false);
spectatorsCanTalkCheckBox->setEnabled(false);
spectatorsSeeEverythingCheckBox->setEnabled(false);
descriptionEdit->setText(QString::fromStdString(gameInfo.description()));
maxPlayersEdit->setValue(gameInfo.max_players());
onlyBuddiesCheckBox->setChecked(gameInfo.only_buddies());
onlyRegisteredCheckBox->setChecked(gameInfo.only_registered());
spectatorsAllowedCheckBox->setChecked(gameInfo.spectators_allowed());
spectatorsNeedPasswordCheckBox->setChecked(gameInfo.spectators_need_password());
spectatorsCanTalkCheckBox->setChecked(gameInfo.spectators_can_chat());
spectatorsSeeEverythingCheckBox->setChecked(gameInfo.spectators_omniscient());
QSet<int> types;
for (int i = 0; i < gameInfo.game_types_size(); ++i)
types.insert(gameInfo.game_types(i));
QMapIterator<int, QString> gameTypeIterator(gameTypes);
while (gameTypeIterator.hasNext()) {
gameTypeIterator.next();
QCheckBox *gameTypeCheckBox = gameTypeCheckBoxes.value(gameTypeIterator.key());
gameTypeCheckBox->setEnabled(false);
gameTypeCheckBox->setChecked(types.contains(gameTypeIterator.key()));
}
setWindowTitle(tr("Game information"));
okButton->setAutoDefault(true);
cancelButton->hide();
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
}
void DlgCreateGame::actOK()
{
Command_CreateGame cmd;

View file

@ -13,10 +13,13 @@ class QGroupBox;
class QSpinBox;
class TabRoom;
class ServerInfo_Game;
class DlgCreateGame : public QDialog {
Q_OBJECT
public:
DlgCreateGame(TabRoom *_room, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
DlgCreateGame(const ServerInfo_Game &game, const QMap<int, QString> &_gameTypes, QWidget *parent = 0);
private slots:
void actOK();
void checkResponse(Response::ResponseCode response);
@ -33,6 +36,8 @@ private:
QCheckBox *onlyBuddiesCheckBox, *onlyRegisteredCheckBox;
QCheckBox *spectatorsAllowedCheckBox, *spectatorsNeedPasswordCheckBox, *spectatorsCanTalkCheckBox, *spectatorsSeeEverythingCheckBox;
QPushButton *okButton, *cancelButton;
void sharedCtor();
};
#endif

View file

@ -8,6 +8,7 @@
#include <QTimer>
#include <QToolButton>
#include "dlg_creategame.h"
#include "tab_game.h"
#include "tab_supervisor.h"
#include "cardinfowidget.h"
@ -204,10 +205,7 @@ TabGame::TabGame(GameReplay *_replay)
hostId(-1),
localPlayerId(-1),
spectator(true),
spectatorsCanTalk(false),
spectatorsSeeEverything(true),
gameStateKnown(false),
started(false),
resuming(false),
currentPhase(-1),
activeCard(0),
@ -216,8 +214,8 @@ TabGame::TabGame(GameReplay *_replay)
{
setAttribute(Qt::WA_DeleteOnClose);
gameId = replay->game_info().game_id();
gameDescription = QString::fromStdString(replay->game_info().description());
gameInfo.CopyFrom(replay->game_info());
gameInfo.set_spectators_omniscient(true);
// Create list: event number -> time [ms]
// Distribute simultaneous events evenly across 1 second.
@ -325,6 +323,7 @@ TabGame::TabGame(GameReplay *_replay)
aNextPhase = 0;
aNextTurn = 0;
aRemoveLocalArrows = 0;
aGameInfo = 0;
aConcede = 0;
aLeaveGame = 0;
aCloseReplay = new QAction(this);
@ -339,26 +338,25 @@ TabGame::TabGame(GameReplay *_replay)
splitter->restoreState(settingsCache->getTabGameSplitterSizes());
messageLog->logReplayStarted(gameId);
messageLog->logReplayStarted(gameInfo.game_id());
}
TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event)
TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes)
: Tab(_tabSupervisor),
clients(_clients),
gameId(event.game_id()),
gameDescription(QString::fromStdString(event.game_description())),
gameInfo(event.game_info()),
roomGameTypes(_roomGameTypes),
hostId(event.host_id()),
localPlayerId(event.player_id()),
spectator(event.spectator()),
spectatorsCanTalk(event.spectators_can_talk()),
spectatorsSeeEverything(event.spectators_see_everything()),
gameStateKnown(true),
started(false),
resuming(event.resuming()),
currentPhase(-1),
activeCard(0),
replay(0)
{
gameInfo.set_started(false);
gameTimer = new QTimer(this);
gameTimer->setInterval(1000);
connect(gameTimer, SIGNAL(timeout()), this, SLOT(incrementGameTime()));
@ -411,7 +409,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
mainLayout->addLayout(deckViewContainerLayout, 10);
mainLayout->addWidget(splitter);
if (spectator && !spectatorsCanTalk && tabSupervisor->getAdminLocked()) {
if (spectator && !gameInfo.spectators_can_chat() && tabSupervisor->getAdminLocked()) {
sayLabel->hide();
sayEdit->hide();
}
@ -425,6 +423,8 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn()));
aRemoveLocalArrows = new QAction(this);
connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows()));
aGameInfo = new QAction(this);
connect(aGameInfo, SIGNAL(triggered()), this, SLOT(actGameInfo()));
aConcede = new QAction(this);
connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede()));
aLeaveGame = new QAction(this);
@ -457,6 +457,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
tabMenu->addSeparator();
tabMenu->addAction(aRemoveLocalArrows);
tabMenu->addSeparator();
tabMenu->addAction(aGameInfo);
tabMenu->addAction(aConcede);
tabMenu->addAction(aLeaveGame);
@ -465,7 +466,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
splitter->restoreState(settingsCache->getTabGameSplitterSizes());
messageLog->logGameJoined(gameId);
messageLog->logGameJoined(gameInfo.game_id());
}
TabGame::~TabGame()
@ -504,6 +505,8 @@ void TabGame::retranslateUi()
aRemoveLocalArrows->setText(tr("&Remove all local arrows"));
aRemoveLocalArrows->setShortcut(tr("Ctrl+R"));
}
if (aGameInfo)
aGameInfo->setText(tr("Game &information"));
if (aConcede) {
aConcede->setText(tr("&Concede"));
aConcede->setShortcut(tr("F2"));
@ -607,11 +610,17 @@ void TabGame::incrementGameTime()
void TabGame::adminLockChanged(bool lock)
{
bool v = !(spectator && !spectatorsCanTalk && lock);
bool v = !(spectator && !gameInfo.spectators_can_chat() && lock);
sayLabel->setVisible(v);
sayEdit->setVisible(v);
}
void TabGame::actGameInfo()
{
DlgCreateGame dlg(gameInfo, roomGameTypes);
dlg.exec();
}
void TabGame::actConcede()
{
if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
@ -782,7 +791,7 @@ void TabGame::sendGameCommand(const google::protobuf::Message &command, int play
PendingCommand *TabGame::prepareGameCommand(const ::google::protobuf::Message &cmd)
{
CommandContainer cont;
cont.set_game_id(gameId);
cont.set_game_id(gameInfo.game_id());
GameCommand *c = cont.add_game_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont);
@ -791,7 +800,7 @@ PendingCommand *TabGame::prepareGameCommand(const ::google::protobuf::Message &c
PendingCommand *TabGame::prepareGameCommand(const QList< const ::google::protobuf::Message * > &cmdList)
{
CommandContainer cont;
cont.set_game_id(gameId);
cont.set_game_id(gameInfo.game_id());
for (int i = 0; i < cmdList.size(); ++i) {
GameCommand *c = cont.add_game_command();
c->GetReflection()->MutableMessage(c, cmdList[i]->GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(*cmdList[i]);
@ -819,7 +828,7 @@ void TabGame::startGame(bool resuming)
}
playerListWidget->setGameStarted(true, resuming);
started = true;
gameInfo.set_started(true);
static_cast<GameScene *>(gameView->scene())->rearrange();
gameView->show();
phasesToolbar->show();
@ -839,7 +848,7 @@ void TabGame::stopGame()
playerListWidget->setActivePlayer(-1);
playerListWidget->setGameStarted(false, false);
started = false;
gameInfo.set_started(false);
gameView->hide();
phasesToolbar->hide();
}
@ -897,13 +906,13 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event, int /*e
secondsElapsed = event.seconds_elapsed();
if (event.game_started() && !started) {
if (event.game_started() && !gameInfo.started()) {
startGame(!gameStateKnown);
if (gameStateKnown)
messageLog->logGameStart();
setActivePlayer(event.active_player_id());
setActivePhase(event.active_phase());
} else if (!event.game_started() && started) {
} else if (!event.game_started() && gameInfo.started()) {
stopGame();
scene->clearViews();
}
@ -1004,7 +1013,7 @@ void TabGame::eventGameHostChanged(const Event_GameHostChanged & /*event*/, int
void TabGame::eventGameClosed(const Event_GameClosed & /*event*/, int /*eventPlayerId*/, const GameEventContext & /*context*/)
{
started = false;
gameInfo.set_started(false);
messageLog->logGameClosed();
emit userEvent();
}
@ -1084,9 +1093,9 @@ CardItem *TabGame::getCard(int playerId, const QString &zoneName, int cardId) co
QString TabGame::getTabText() const
{
if (replay)
return tr("Replay %1: %2").arg(gameId).arg(gameDescription);
return tr("Replay %1: %2").arg(gameInfo.game_id()).arg(QString::fromStdString(gameInfo.description()));
else
return tr("Game %1: %2").arg(gameId).arg(gameDescription);
return tr("Game %1: %2").arg(gameInfo.game_id()).arg(QString::fromStdString(gameInfo.description()));
}
Player *TabGame::getActiveLocalPlayer() const

View file

@ -4,8 +4,8 @@
#include <QMap>
#include <QPushButton>
#include "tab.h"
#include "pb/serverinfo_game.pb.h"
namespace google { namespace protobuf { class Message; } }
class AbstractClient;
class CardDatabase;
class GameView;
@ -96,16 +96,14 @@ private:
QTimer *gameTimer;
int secondsElapsed;
QList<AbstractClient *> clients;
int gameId;
QString gameDescription;
ServerInfo_Game gameInfo;
QMap<int, QString> roomGameTypes;
int hostId;
int localPlayerId;
bool spectator;
bool spectatorsCanTalk, spectatorsSeeEverything;
QMap<int, Player *> players;
QMap<int, QString> spectators;
bool gameStateKnown;
bool started;
bool resuming;
QStringList phasesList;
int currentPhase;
@ -135,7 +133,7 @@ private:
ZoneViewLayout *zoneLayout;
QAction *playersSeparator;
QMenu *phasesMenu;
QAction *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
QList<QAction *> phaseActions;
Player *addPlayer(int playerId, const ServerInfo_User &info);
@ -180,6 +178,7 @@ private slots:
void newCardAdded(AbstractCardItem *card);
void updateCardMenu(AbstractCardItem *card);
void actGameInfo();
void actConcede();
void actLeaveGame();
void actRemoveLocalArrows();
@ -188,7 +187,7 @@ private slots:
void actNextPhase();
void actNextTurn();
public:
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event);
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes);
TabGame(GameReplay *replay);
~TabGame();
void retranslateUi();
@ -196,11 +195,10 @@ public:
const QMap<int, Player *> &getPlayers() const { return players; }
CardItem *getCard(int playerId, const QString &zoneName, int cardId) const;
bool isHost() const { return hostId == localPlayerId; }
int getGameId() const { return gameId; }
int getGameId() const { return gameInfo.game_id(); }
QString getTabText() const;
bool getSpectator() const { return spectator; }
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
bool getSpectatorsSeeEverything() const { return gameInfo.spectators_omniscient(); }
Player *getActiveLocalPlayer() const;
AbstractClient *getClientForPlayer(int playerId) const;

View file

@ -250,27 +250,35 @@ void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex)
void TabSupervisor::gameJoined(const Event_GameJoined &event)
{
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event);
QMap<int, QString> roomGameTypes;
TabRoom *room = roomTabs.value(event.game_info().room_id());
if (room)
roomGameTypes = room->getGameTypes();
else
for (int i = 0; i < event.game_types_size(); ++i)
roomGameTypes.insert(event.game_types(i).game_type_id(), QString::fromStdString(event.game_types(i).description()));
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event, roomGameTypes);
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
gameTabs.insert(event.game_id(), tab);
gameTabs.insert(event.game_info().game_id(), tab);
setCurrentWidget(tab);
}
void TabSupervisor::localGameJoined(const Event_GameJoined &event)
{
TabGame *tab = new TabGame(this, localClients, event);
TabGame *tab = new TabGame(this, localClients, event, QMap<int, QString>());
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex);
gameTabs.insert(event.game_id(), tab);
gameTabs.insert(event.game_info().game_id(), tab);
setCurrentWidget(tab);
for (int i = 1; i < localClients.size(); ++i) {
Command_JoinGame cmd;
cmd.set_game_id(event.game_id());
cmd.set_game_id(event.game_info().game_id());
localClients[i]->sendCommand(localClients[i]->prepareRoomCommand(cmd, 0));
}
}