protocol changes, menu cleanups, phase button speed improvement

This commit is contained in:
Max-Wilhelm Bruker 2009-09-21 20:21:11 +02:00
parent ab3858239f
commit 890740bcc9
19 changed files with 514 additions and 442 deletions

View file

@ -158,7 +158,7 @@ void Client::readLine()
// XXX Parametergültigkeit überprüfen
if (prefix == "list_players")
playerlist << new ServerPlayer(val[0].toInt(), val[1]);
playerlist << new ServerPlayer(val[0].toInt(), val[1], val[2].toInt());
else if (prefix == "list_counters")
{ }
else if (prefix == "list_zones")
@ -185,10 +185,10 @@ void Client::readLine()
void Client::setStatus(const ProtocolStatus _status)
{
ProtocolStatus oldStatus = status;
status = _status;
if (oldStatus != _status)
if (_status != status) {
status = _status;
emit statusChanged(_status);
}
}
void Client::msg(const QString &s)

View file

@ -1,4 +1,5 @@
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
#include <QSettings>
#include <stdlib.h>
@ -13,51 +14,16 @@
#include "counter.h"
#include "gamescene.h"
Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent)
: QObject(parent), actionsMenu(_actionsMenu), cardMenu(_cardMenu), db(_db), client(_client), scene(_scene), started(false), currentPhase(-1)
Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menuBar, QObject *parent)
: QObject(parent), db(_db), client(_client), scene(_scene), started(false), currentPhase(-1)
{
localPlayer = addPlayer(playerId, playerName, true);
connect(client, SIGNAL(gameEvent(const ServerEventData &)), this, SLOT(gameEvent(const ServerEventData &)));
connect(client, SIGNAL(playerListReceived(QList<ServerPlayer *>)), this, SLOT(playerListReceived(QList<ServerPlayer *>)));
aUntapAll = new QAction(this);
connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll()));
aDecLife = new QAction(this);
connect(aDecLife, SIGNAL(triggered()), this, SLOT(actDecLife()));
aIncLife = new QAction(this);
connect(aIncLife, SIGNAL(triggered()), this, SLOT(actIncLife()));
aSetLife = new QAction(this);
connect(aSetLife, SIGNAL(triggered()), this, SLOT(actSetLife()));
aRollDie = new QAction(this);
connect(aRollDie, SIGNAL(triggered()), this, SLOT(actRollDie()));
aCreateToken = new QAction(this);
connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken()));
aNextPhase = new QAction(this);
connect(aNextPhase, SIGNAL(triggered()), this, SLOT(actNextPhase()));
aNextTurn = new QAction(this);
connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn()));
actionsMenu->addAction(aNextPhase);
actionsMenu->addAction(aNextTurn);
actionsMenu->addSeparator();
actionsMenu->addAction(aUntapAll);
actionsMenu->addSeparator();
actionsMenu->addAction(aDecLife);
actionsMenu->addAction(aIncLife);
actionsMenu->addAction(aSetLife);
actionsMenu->addSeparator();
actionsMenu->addAction(aRollDie);
actionsMenu->addSeparator();
actionsMenu->addAction(aCreateToken);
actionsMenu->addSeparator();
sayMenu = actionsMenu->addMenu(QString());
initSayMenu();
aTap = new QAction(this);
aUntap = new QAction(this);
aDoesntUntap = new QAction(this);
@ -71,6 +37,11 @@ Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenu *_action
aMoveToGraveyard = new QAction(this);
aMoveToExile = new QAction(this);
gameMenu = menuBar->addMenu(QString());
gameMenu->addAction(aNextPhase);
gameMenu->addAction(aNextTurn);
cardMenu = menuBar->addMenu(QString());
cardMenu->addAction(aTap);
cardMenu->addAction(aUntap);
cardMenu->addAction(aDoesntUntap);
@ -110,6 +81,8 @@ Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenu *_action
connect(dlgStartGame, SIGNAL(finished(int)), this, SLOT(readyStart()));
retranslateUi();
client->listPlayers();
}
Game::~Game()
@ -119,29 +92,19 @@ Game::~Game()
emit playerRemoved(players.at(i));
delete players.at(i);
}
delete gameMenu;
delete cardMenu;
}
void Game::retranslateUi()
{
aUntapAll->setText(tr("&Untap all permanents"));
aUntapAll->setShortcut(tr("Ctrl+U"));
aDecLife->setText(tr("&Decrement life"));
aDecLife->setShortcut(tr("F11"));
aIncLife->setText(tr("&Increment life"));
aIncLife->setShortcut(tr("F12"));
aSetLife->setText(tr("&Set life"));
aSetLife->setShortcut(tr("Ctrl+L"));
aRollDie->setText(tr("R&oll die..."));
aRollDie->setShortcut(tr("Ctrl+I"));
aCreateToken->setText(tr("&Create token..."));
aCreateToken->setShortcut(tr("Ctrl+T"));
gameMenu->setTitle(tr("&Game"));
aNextPhase->setText(tr("Next &phase"));
aNextPhase->setShortcut(tr("Ctrl+Space"));
aNextTurn->setText(tr("Next &turn"));
aNextTurn->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Return")) << QKeySequence(tr("Ctrl+Enter")));
sayMenu->setTitle(tr("S&ay"));
cardMenu->setTitle(tr("C&ard"));
aTap->setText(tr("&Tap"));
aUntap->setText(tr("&Untap"));
aDoesntUntap->setText(tr("Toggle &normal untapping"));
@ -161,30 +124,6 @@ void Game::retranslateUi()
players[i]->retranslateUi();
}
void Game::initSayMenu()
{
sayMenu->clear();
QSettings settings;
settings.beginGroup("messages");
int count = settings.value("count", 0).toInt();
for (int i = 0; i < count; i++) {
QAction *newAction = new QAction(settings.value(QString("msg%1").arg(i)).toString(), this);
QString shortcut;
switch (i) {
case 0: shortcut = tr("F5"); break;
case 1: shortcut = tr("F6"); break;
case 2: shortcut = tr("F7"); break;
case 3: shortcut = tr("F8"); break;
case 4: shortcut = tr("F9"); break;
case 5: shortcut = tr("F10"); break;
}
newAction->setShortcut(shortcut);
connect(newAction, SIGNAL(triggered()), this, SLOT(actSayMessage()));
sayMenu->addAction(newAction);
}
}
Player *Game::addPlayer(int playerId, const QString &playerName, bool local)
{
Player *newPlayer = new Player(playerName, playerId, local, db, client, this);
@ -213,8 +152,7 @@ void Game::playerListReceived(QList<ServerPlayer *> playerList)
nameList << temp->getName();
int id = temp->getPlayerId();
if (id != localPlayer->getId())
addPlayer(id, temp->getName(), false);
addPlayer(id, temp->getName(), temp->getLocal());
delete temp;
}
@ -235,10 +173,12 @@ void Game::restartGameDialog()
void Game::gameEvent(const ServerEventData &msg)
{
qDebug(QString("game::gameEvent: public=%1, player=%2, name=%3, type=%4, data=%5").arg(msg.getPublic()).arg(msg.getPlayerId()).arg(msg.getPlayerName()).arg(msg.getEventType()).arg(msg.getEventData().join("/")).toLatin1());
if (!msg.getPublic())
localPlayer->gameEvent(msg);
else {
Player *p = players.findPlayer(msg.getPlayerId());
Player *p = players.findPlayer(msg.getPlayerId());
if (!msg.getPublic()) {
if (!p)
return;
p->gameEvent(msg);
} else {
if ((!p) && (msg.getEventType() != eventJoin)) {
// XXX
}
@ -248,14 +188,32 @@ void Game::gameEvent(const ServerEventData &msg)
emit logSay(p, msg.getEventData()[0]);
break;
case eventJoin: {
Player *newPlayer = addPlayer(msg.getPlayerId(), msg.getPlayerName(), false);
emit logJoin(newPlayer);
const QStringList &data = msg.getEventData();
if (data.size() != 1)
return;
bool spectator = data[0].toInt();
if (spectator) {
spectatorList << msg.getPlayerName();
emit logJoinSpectator(msg.getPlayerName());
} else {
Player *newPlayer = addPlayer(msg.getPlayerId(), msg.getPlayerName(), false);
emit logJoin(newPlayer);
}
break;
}
case eventLeave:
emit logLeave(p);
// XXX Spieler natürlich noch rauswerfen
case eventLeave: {
if (p)
emit logLeave(p);
// XXX Spieler natürlich noch rauswerfen
else {
int spectatorIndex = spectatorList.indexOf(msg.getPlayerName());
if (spectatorIndex != -1) {
spectatorList.removeAt(spectatorIndex);
emit logLeaveSpectator(msg.getPlayerName());
}
}
break;
}
case eventReadyStart:
if (started) {
started = false;
@ -335,16 +293,14 @@ void Game::gameEvent(const ServerEventData &msg)
break;
}
case eventMoveCard: {
if (msg.getPlayerId() == localPlayer->getId())
break;
p->gameEvent(msg);
if (!p->getLocal())
p->gameEvent(msg);
break;
}
case eventDraw: {
emit logDraw(p, msg.getEventData()[0].toInt());
if (msg.getPlayerId() == localPlayer->getId())
break;
p->gameEvent(msg);
if (!p->getLocal())
p->gameEvent(msg);
break;
}
case eventInvalid: {
@ -369,44 +325,6 @@ void Game::actNextTurn()
client->nextTurn();
}
void Game::actUntapAll()
{
client->setCardAttr("table", -1, "tapped", "false");
}
void Game::actIncLife()
{
client->incCounter("life", 1);
}
void Game::actDecLife()
{
client->incCounter("life", -1);
}
void Game::actSetLife()
{
bool ok;
int life = QInputDialog::getInteger(0, tr("Set life"), tr("New life total:"), localPlayer->getCounter("life")->getValue(), 0, 2000000000, 1, &ok);
if (ok)
client->setCounter("life", life);
}
void Game::actRollDie()
{
bool ok;
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
if (ok)
client->rollDie(sides);
}
void Game::actCreateToken()
{
QString cardname = QInputDialog::getText(0, tr("Create token"), tr("Name:"));
if (!cardname.isEmpty())
client->createToken("table", cardname, QString(), 0, 0);
}
void Game::showCardMenu(QPoint p)
{
cardMenu->exec(p);
@ -501,12 +419,6 @@ void Game::actMoveToExile(CardItem *card)
client->moveCard(card->getId(), startZone->getName(), "rfg", 0, 0, false);
}
void Game::actSayMessage()
{
QAction *a = qobject_cast<QAction *>(sender());
client->say(a->text());
}
void Game::hoverCardEvent(CardItem *card)
{
emit hoverCard(card->getName());

View file

@ -2,6 +2,7 @@
#define GAME_H
#include <QHash>
#include <QStringList>
#include "playerlist.h"
class ServerPlayer;
@ -12,6 +13,7 @@ class ServerEventData;
class CardDatabase;
class DlgStartGame;
class CardItem;
class QMenuBar;
class Game : public QObject {
Q_OBJECT
@ -21,30 +23,22 @@ private:
typedef void (Game::*CardMenuHandler)(CardItem *card);
QHash<QAction *, CardMenuHandler> cardMenuHandlers;
QMenu *actionsMenu, *sayMenu, *cardMenu, *moveMenu;
QMenu *gameMenu, *cardMenu, *moveMenu;
QAction *aTap, *aUntap, *aDoesntUntap, *aFlip, *aAddCounter, *aRemoveCounter, *aSetCounters,
*aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToGraveyard, *aMoveToExile,
*aNextPhase, *aNextTurn, *aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aRollDie, *aCreateToken;
*aNextPhase, *aNextTurn;
DlgStartGame *dlgStartGame;
CardDatabase *db;
Client *client;
GameScene *scene;
QStringList spectatorList;
PlayerList players;
Player *localPlayer;
bool started;
int currentPhase;
Player *addPlayer(int playerId, const QString &playerName, bool local);
void initSayMenu();
public slots:
void actNextPhase();
void actNextTurn();
void actUntapAll();
void actIncLife();
void actDecLife();
void actSetLife();
void actRollDie();
void actCreateToken();
private slots:
void cardMenuAction();
@ -60,8 +54,6 @@ private slots:
void actMoveToBottomLibrary(CardItem *card);
void actMoveToGraveyard(CardItem *card);
void actMoveToExile(CardItem *card);
void actSayMessage();
void gameEvent(const ServerEventData &msg);
void playerListReceived(QList<ServerPlayer *> playerList);
@ -76,6 +68,8 @@ signals:
void logPlayerListReceived(QStringList players);
void logJoin(Player *player);
void logLeave(Player *player);
void logJoinSpectator(QString playerName);
void logLeaveSpectator(QString playerName);
void logReadyStart(Player *player);
void logGameStart();
void logSay(Player *player, QString text);
@ -93,12 +87,12 @@ signals:
void logSetActivePlayer(Player *player);
void setActivePhase(int phase);
public:
Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent = 0);
Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menuBar, QObject *parent = 0);
~Game();
Player *getLocalPlayer() const { return localPlayer; }
void retranslateUi();
void restartGameDialog();
void hoverCardEvent(CardItem *card);
Player *addPlayer(int playerId, const QString &playerName, bool local);
};
#endif

View file

@ -15,11 +15,11 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
ServerGame *g = gameList.at(index.row());
switch (index.column()) {
case 0: return g->getGameId();
case 0: return g->getDescription();
case 1: return g->getCreator();
case 2: return g->getDescription();
case 3: return QString(g->getHasPassword() ? tr("yes") : tr("no"));
case 4: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
case 2: return g->getHasPassword() ? tr("yes") : tr("no");
case 3: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
case 4: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorsCount()) : QVariant(tr("not allowed"));
default: return QVariant();
}
}
@ -29,11 +29,11 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
return QVariant();
switch (section) {
case 0: return tr("Game ID");
case 0: return tr("Description");
case 1: return tr("Creator");
case 2: return tr("Description");
case 3: return tr("Password");
case 4: return tr("Players");
case 2: return tr("Password");
case 3: return tr("Players");
case 4: return tr("Spectators");
default: return QVariant();
}
}

View file

@ -64,6 +64,16 @@ void MessageLogWidget::logLeave(Player *player)
append(tr("%1 has left the game").arg(sanitizeHtml(player->getName())));
}
void MessageLogWidget::logJoinSpectator(QString name)
{
append(tr("%1 is now watching the game.").arg(sanitizeHtml(name)));
}
void MessageLogWidget::logLeaveSpectator(QString name)
{
append(tr("%1 is not watching the game any more.").arg(sanitizeHtml(name)));
}
void MessageLogWidget::logReadyStart(Player *player)
{
append(tr("%1 is ready to start a new game.").arg(sanitizeHtml(player->getName())));
@ -249,6 +259,8 @@ void MessageLogWidget::connectToGame(Game *game)
connect(game, SIGNAL(logPlayerListReceived(QStringList)), this, SLOT(logPlayerListReceived(QStringList)));
connect(game, SIGNAL(logJoin(Player *)), this, SLOT(logJoin(Player *)));
connect(game, SIGNAL(logLeave(Player *)), this, SLOT(logLeave(Player *)));
connect(game, SIGNAL(logJoinSpectator(QString)), this, SLOT(logJoinSpectator(QString)));
connect(game, SIGNAL(logLeaveSpectator(QString)), this, SLOT(logLeaveSpectator(QString)));
connect(game, SIGNAL(logReadyStart(Player *)), this, SLOT(logReadyStart(Player *)));
connect(game, SIGNAL(logGameStart()), this, SLOT(logGameStart()));
connect(game, SIGNAL(logSay(Player *, QString)), this, SLOT(logSay(Player *, QString)));

View file

@ -26,6 +26,8 @@ private slots:
void logPlayerListReceived(QStringList players);
void logJoin(Player *player);
void logLeave(Player *player);
void logJoinSpectator(QString name);
void logLeaveSpectator(QString name);
void logReadyStart(Player *player);
void logGameStart();
void logSay(Player *player, QString message);

View file

@ -5,30 +5,37 @@
#include <QPen>
PhaseButton::PhaseButton(const QIcon &icon, QAction *_doubleClickAction)
: QPushButton(icon, QString()), active(false), doubleClickAction(_doubleClickAction)
: QPushButton(icon, QString()), active(false), doubleClickAction(_doubleClickAction), activePixmap(50, 50), inactivePixmap(50, 50)
{
setFixedSize(50, 50);
updatePixmap(activePixmap, true);
updatePixmap(inactivePixmap, false);
}
void PhaseButton::paintEvent(QPaintEvent *event)
void PhaseButton::updatePixmap(QPixmap &pixmap, bool active)
{
QPushButton::paintEvent(event);
if (active) {
QPainter painter(this);
int height = size().height();
int width = size().width();
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
int height = pixmap.height();
int width = pixmap.width();
painter.setPen(QPen(Qt::transparent));
if (active)
painter.setBrush(Qt::red);
painter.setPen(Qt::gray);
painter.drawRect(1, 1, width - 2, height - 2);
QRadialGradient grad(QPointF(0.5, 0.5), 0.5);
grad.setCoordinateMode(QGradient::ObjectBoundingMode);
grad.setColorAt(0, QColor(180, 0, 0, 0));
grad.setColorAt(0.8, QColor(180, 0, 0, 0));
grad.setColorAt(1, QColor(180, 0, 0, 255));
painter.setBrush(QBrush(grad));
icon().paint(&painter, 5, 5, width - 10, height - 10);
}
painter.drawRect(2, 2, width - 4, height - 4);
}
void PhaseButton::paintEvent(QPaintEvent */*event*/)
{
QPainter painter(this);
if (active)
painter.drawPixmap(0, 0, size().width(), size().height(), activePixmap);
else
painter.drawPixmap(0, 0, size().width(), size().height(), inactivePixmap);
}
void PhaseButton::setPhaseText(const QString &_phaseText)
@ -67,13 +74,11 @@ PhasesToolbar::PhasesToolbar(QWidget *parent)
<< combatAttackersButton << combatBlockersButton << combatDamageButton << combatEndButton
<< main2Button << cleanupButton;
for (int i = 0; i < buttonList.size(); ++i) {
buttonList[i]->setIconSize(QSize(36, 36));
for (int i = 0; i < buttonList.size(); ++i)
connect(buttonList[i], SIGNAL(clicked()), this, SLOT(phaseButtonClicked()));
}
QPushButton *nextTurnButton = new QPushButton(QIcon(":/resources/icon_nextturn.svg"), QString());
nextTurnButton->setIconSize(QSize(36, 36));
nextTurnButton->setIconSize(QSize(40, 40));
nextTurnButton->setFixedSize(50, 50);
connect(nextTurnButton, SIGNAL(clicked()), this, SIGNAL(signalNextTurn()));

View file

@ -13,6 +13,9 @@ private:
QString phaseText;
bool active;
QAction *doubleClickAction;
QPixmap activePixmap, inactivePixmap;
void updatePixmap(QPixmap &pixmap, bool active);
public:
PhaseButton(const QIcon &icon, QAction *_doubleClickAction = 0);
void setPhaseText(const QString &_phaseText);

View file

@ -112,6 +112,37 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
sbMenu = playerMenu->addMenu(QString());
sbMenu->addAction(aViewSideboard);
sb->setMenu(sbMenu, aViewSideboard);
aUntapAll = new QAction(this);
connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll()));
aDecLife = new QAction(this);
connect(aDecLife, SIGNAL(triggered()), this, SLOT(actDecLife()));
aIncLife = new QAction(this);
connect(aIncLife, SIGNAL(triggered()), this, SLOT(actIncLife()));
aSetLife = new QAction(this);
connect(aSetLife, SIGNAL(triggered()), this, SLOT(actSetLife()));
aRollDie = new QAction(this);
connect(aRollDie, SIGNAL(triggered()), this, SLOT(actRollDie()));
aCreateToken = new QAction(this);
connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken()));
playerMenu->addSeparator();
playerMenu->addAction(aUntapAll);
playerMenu->addSeparator();
playerMenu->addAction(aDecLife);
playerMenu->addAction(aIncLife);
playerMenu->addAction(aSetLife);
playerMenu->addSeparator();
playerMenu->addAction(aRollDie);
playerMenu->addSeparator();
playerMenu->addAction(aCreateToken);
playerMenu->addSeparator();
sayMenu = playerMenu->addMenu(QString());
initSayMenu();
} else
sbMenu = 0;
@ -126,6 +157,7 @@ Player::~Player()
delete zones.at(i);
clearCounters();
delete playerMenu;
}
void Player::updateBoundingRect()
@ -160,6 +192,44 @@ void Player::retranslateUi()
handMenu->setTitle(tr("&Hand"));
sbMenu->setTitle(tr("&Sideboard"));
libraryMenu->setTitle(tr("&Library"));
aUntapAll->setText(tr("&Untap all permanents"));
aUntapAll->setShortcut(tr("Ctrl+U"));
aDecLife->setText(tr("&Decrement life"));
aDecLife->setShortcut(tr("F11"));
aIncLife->setText(tr("&Increment life"));
aIncLife->setShortcut(tr("F12"));
aSetLife->setText(tr("&Set life"));
aSetLife->setShortcut(tr("Ctrl+L"));
aRollDie->setText(tr("R&oll die..."));
aRollDie->setShortcut(tr("Ctrl+I"));
aCreateToken->setText(tr("&Create token..."));
aCreateToken->setShortcut(tr("Ctrl+T"));
sayMenu->setTitle(tr("S&ay"));
}
}
void Player::initSayMenu()
{
sayMenu->clear();
QSettings settings;
settings.beginGroup("messages");
int count = settings.value("count", 0).toInt();
for (int i = 0; i < count; i++) {
QAction *newAction = new QAction(settings.value(QString("msg%1").arg(i)).toString(), this);
QString shortcut;
switch (i) {
case 0: shortcut = tr("F5"); break;
case 1: shortcut = tr("F6"); break;
case 2: shortcut = tr("F7"); break;
case 3: shortcut = tr("F8"); break;
case 4: shortcut = tr("F9"); break;
case 5: shortcut = tr("F10"); break;
}
newAction->setShortcut(shortcut);
connect(newAction, SIGNAL(triggered()), this, SLOT(actSayMessage()));
sayMenu->addAction(newAction);
}
}
@ -220,6 +290,50 @@ void Player::actDrawCards()
client->drawCards(number);
}
void Player::actUntapAll()
{
client->setCardAttr("table", -1, "tapped", "false");
}
void Player::actIncLife()
{
client->incCounter("life", 1);
}
void Player::actDecLife()
{
client->incCounter("life", -1);
}
void Player::actSetLife()
{
bool ok;
int life = QInputDialog::getInteger(0, tr("Set life"), tr("New life total:"), getCounter("life")->getValue(), 0, 2000000000, 1, &ok);
if (ok)
client->setCounter("life", life);
}
void Player::actRollDie()
{
bool ok;
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
if (ok)
client->rollDie(sides);
}
void Player::actCreateToken()
{
QString cardname = QInputDialog::getText(0, tr("Create token"), tr("Name:"));
if (!cardname.isEmpty())
client->createToken("table", cardname, QString(), 0, 0);
}
void Player::actSayMessage()
{
QAction *a = qobject_cast<QAction *>(sender());
client->say(a->text());
}
void Player::addZone(CardZone *z)
{
zones << z;

View file

@ -33,6 +33,15 @@ signals:
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
void sizeChanged();
public slots:
void actUntapAll();
void actIncLife();
void actDecLife();
void actSetLife();
void actRollDie();
void actCreateToken();
void actSayMessage();
private slots:
void updateBoundingRect();
@ -49,10 +58,11 @@ private slots:
void actViewRfg();
void actViewSideboard();
private:
QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu;
QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *sayMenu;
QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary,
*aViewLibrary, *aViewTopCards, *aViewGraveyard, *aViewRfg, *aViewSideboard,
*aDrawCard, *aDrawCards, *aShuffle;
*aDrawCard, *aDrawCards, *aShuffle,
*aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aRollDie, *aCreateToken;
int defaultNumberTopCards;
QString name;
@ -72,6 +82,7 @@ private:
QList<Counter *> counterList;
void rearrangeCounters();
void initSayMenu();
public:
enum { Type = typeOther };
int type() const { return Type; }

View file

@ -7,11 +7,13 @@ class ServerPlayer {
private:
int PlayerId;
QString name;
bool local;
public:
ServerPlayer(int _PlayerId, const QString &_name)
: PlayerId(_PlayerId), name(_name) { }
ServerPlayer(int _PlayerId, const QString &_name, bool _local)
: PlayerId(_PlayerId), name(_name), local(_local) { }
int getPlayerId() const { return PlayerId; }
QString getName() const { return name; }
bool getLocal() const { return local; }
};
#endif

View file

@ -38,11 +38,6 @@
#include "zoneviewlayout.h"
#include "chatwidget.h"
void MainWindow::hoverCard(QString name)
{
cardInfo->setCard(name);
}
void MainWindow::playerAdded(Player *player)
{
menuBar()->addMenu(player->getPlayerMenu());
@ -50,11 +45,6 @@ void MainWindow::playerAdded(Player *player)
connect(player, SIGNAL(closeZoneView(ZoneViewZone *)), zoneLayout, SLOT(removeItem(ZoneViewZone *)));
}
void MainWindow::playerRemoved(Player *player)
{
menuBar()->removeAction(player->getPlayerMenu()->menuAction());
}
void MainWindow::statusChanged(ProtocolStatus _status)
{
switch (_status) {
@ -95,11 +85,22 @@ void MainWindow::statusChanged(ProtocolStatus _status)
chatWidget->enableChat();
break;
}
case StatusPlaying:
case StatusPlaying: {
chatWidget->disableChat();
game = new Game(db, client, scene, menuBar(), this);
connect(game, SIGNAL(hoverCard(QString)), cardInfo, SLOT(setCard(const QString &)));
connect(game, SIGNAL(playerAdded(Player *)), this, SLOT(playerAdded(Player *)));
connect(game, SIGNAL(playerRemoved(Player *)), scene, SLOT(removePlayer(Player *)));
connect(game, SIGNAL(setActivePhase(int)), phasesToolbar, SLOT(setActivePhase(int)));
messageLog->connectToGame(game);
aRestartGame->setEnabled(true);
aLeaveGame->setEnabled(true);
phasesToolbar->show();
view->show();
break;
}
default:
break;
}
@ -164,24 +165,6 @@ void MainWindow::actSay()
sayEdit->clear();
}
void MainWindow::playerIdReceived(int id, QString name)
{
game = new Game(db, client, scene, actionsMenu, cardMenu, id, name, this);
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(game, SIGNAL(playerRemoved(Player *)), scene, SLOT(removePlayer(Player *)));
connect(game, SIGNAL(setActivePhase(int)), phasesToolbar, SLOT(setActivePhase(int)));
connect(phasesToolbar, SIGNAL(signalUntapAll()), game, SLOT(actUntapAll()));
playerAdded(game->getLocalPlayer());
messageLog->connectToGame(game);
aRestartGame->setEnabled(true);
aLeaveGame->setEnabled(true);
client->listPlayers();
}
void MainWindow::serverTimeout()
{
QMessageBox::critical(this, tr("Error"), tr("Server timeout"));
@ -204,9 +187,7 @@ void MainWindow::retranslateUi()
aCloseMostRecentZoneView->setText(tr("Close most recent zone view"));
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
gameMenu->setTitle(tr("&Game"));
actionsMenu->setTitle(tr("&Actions"));
cardMenu->setTitle(tr("&Card"));
cockatriceMenu->setTitle(tr("&Cockatrice"));
sayLabel->setText(tr("&Say:"));
@ -248,24 +229,20 @@ void MainWindow::createActions()
void MainWindow::createMenus()
{
gameMenu = menuBar()->addMenu(QString());
gameMenu->addAction(aConnect);
gameMenu->addAction(aDisconnect);
gameMenu->addSeparator();
gameMenu->addAction(aRestartGame);
gameMenu->addAction(aLeaveGame);
gameMenu->addSeparator();
gameMenu->addAction(aDeckEditor);
gameMenu->addSeparator();
gameMenu->addAction(aFullScreen);
gameMenu->addSeparator();
gameMenu->addAction(aSettings);
gameMenu->addSeparator();
gameMenu->addAction(aExit);
actionsMenu = menuBar()->addMenu(QString());
cardMenu = menuBar()->addMenu(QString());
cockatriceMenu = menuBar()->addMenu(QString());
cockatriceMenu->addAction(aConnect);
cockatriceMenu->addAction(aDisconnect);
cockatriceMenu->addSeparator();
cockatriceMenu->addAction(aRestartGame);
cockatriceMenu->addAction(aLeaveGame);
cockatriceMenu->addSeparator();
cockatriceMenu->addAction(aDeckEditor);
cockatriceMenu->addSeparator();
cockatriceMenu->addAction(aFullScreen);
cockatriceMenu->addSeparator();
cockatriceMenu->addAction(aSettings);
cockatriceMenu->addSeparator();
cockatriceMenu->addAction(aExit);
}
MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
@ -323,7 +300,6 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
connect(client, SIGNAL(statusChanged(ProtocolStatus)), this, SLOT(statusChanged(ProtocolStatus)));
connect(client, SIGNAL(playerIdReceived(int, QString)), this, SLOT(playerIdReceived(int, QString)));
connect(this, SIGNAL(logConnecting(QString)), messageLog, SLOT(logConnecting(QString)));
connect(client, SIGNAL(welcomeMsgReceived(QString)), messageLog, SLOT(logConnected(QString)));

View file

@ -46,11 +46,8 @@ class ChatWidget;
class MainWindow : public QMainWindow {
Q_OBJECT
private slots:
void hoverCard(QString name);
void playerAdded(Player *player);
void playerRemoved(Player *player);
void statusChanged(ProtocolStatus _status);
void playerIdReceived(int id, QString name);
void serverTimeout();
void actSay();
@ -70,7 +67,7 @@ private:
void retranslateUi();
void createActions();
void createMenus();
QMenu *gameMenu, *actionsMenu, *cardMenu;
QMenu *cockatriceMenu;
QAction *aConnect, *aDisconnect, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
QAction *aCloseMostRecentZoneView;
QVBoxLayout *viewLayout;