diff --git a/cockatrice/src/client.h b/cockatrice/src/client.h index c799dadd..ab4b0121 100644 --- a/cockatrice/src/client.h +++ b/cockatrice/src/client.h @@ -107,6 +107,7 @@ public slots: PendingCommand *say(const QString &s); PendingCommand *shuffle(); PendingCommand *rollDie(unsigned int sides); + PendingCommand *drawCard() { return drawCards(1); } PendingCommand *drawCards(unsigned int number); PendingCommand *moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false); PendingCommand *createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y); diff --git a/cockatrice/src/game.cpp b/cockatrice/src/game.cpp index 1cf464a2..be69f79b 100644 --- a/cockatrice/src/game.cpp +++ b/cockatrice/src/game.cpp @@ -294,8 +294,10 @@ void Game::gameEvent(const ServerEventData &msg) case eventSetActivePhase: { QStringList data = msg.getEventData(); int phase = data[0].toInt(); - currentPhase = phase; - emit setActivePhase(phase); + if (currentPhase != phase) { + currentPhase = phase; + emit setActivePhase(phase); + } break; } diff --git a/cockatrice/src/game.h b/cockatrice/src/game.h index 7d3d0710..e2af69a5 100644 --- a/cockatrice/src/game.h +++ b/cockatrice/src/game.h @@ -36,9 +36,7 @@ private: int currentPhase; Player *addPlayer(int playerId, const QString &playerName, QPointF base, bool local); void initSayMenu(); -private slots: - void cardMenuAction(); - +public slots: void actNextPhase(); void actNextTurn(); void actUntapAll(); @@ -47,6 +45,8 @@ private slots: void actSetLife(); void actRollDie(); void actCreateToken(); +private slots: + void cardMenuAction(); void showCardMenu(QPoint p); void actTap(CardItem *card); diff --git a/cockatrice/src/phasestoolbar.cpp b/cockatrice/src/phasestoolbar.cpp index 233b6f26..894bd349 100644 --- a/cockatrice/src/phasestoolbar.cpp +++ b/cockatrice/src/phasestoolbar.cpp @@ -4,17 +4,12 @@ #include #include -PhaseButton::PhaseButton(QIcon icon) - : QPushButton(icon, QString()), active(false) +PhaseButton::PhaseButton(const QIcon &icon, QAction *_doubleClickAction) + : QPushButton(icon, QString()), active(false), doubleClickAction(_doubleClickAction) { setFixedSize(50, 50); } -void PhaseButton::update() -{ - QPushButton::update(); -} - void PhaseButton::paintEvent(QPaintEvent *event) { QPushButton::paintEvent(event); @@ -42,12 +37,23 @@ void PhaseButton::setPhaseText(const QString &_phaseText) setToolTip(phaseText); } +void PhaseButton::mouseDoubleClickEvent(QMouseEvent */*event*/) +{ + if (doubleClickAction) + doubleClickAction->trigger(); +} + PhasesToolbar::PhasesToolbar(QWidget *parent) : QFrame(parent) { - PhaseButton *untapButton = new PhaseButton(QIcon(":/resources/icon_phase_untap.svg")); + QAction *aUntapAll = new QAction(this); + connect(aUntapAll, SIGNAL(triggered()), this, SIGNAL(signalUntapAll())); + QAction *aDrawCard = new QAction(this); + connect(aDrawCard, SIGNAL(triggered()), this, SIGNAL(signalDrawCard())); + + PhaseButton *untapButton = new PhaseButton(QIcon(":/resources/icon_phase_untap.svg"), aUntapAll); PhaseButton *upkeepButton = new PhaseButton(QIcon(":/resources/icon_phase_upkeep.svg")); - PhaseButton *drawButton = new PhaseButton(QIcon(":/resources/icon_phase_draw.svg")); + PhaseButton *drawButton = new PhaseButton(QIcon(":/resources/icon_phase_draw.svg"), aDrawCard); PhaseButton *main1Button = new PhaseButton(QIcon(":/resources/icon_phase_main1.svg")); PhaseButton *combatStartButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_start.svg")); PhaseButton *combatAttackersButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_attackers.svg")); @@ -125,5 +131,7 @@ void PhasesToolbar::setActivePhase(int phase) void PhasesToolbar::phaseButtonClicked() { PhaseButton *button = qobject_cast(sender()); + if (button->getActive()) + return; emit signalSetPhase(buttonList.indexOf(button)); } diff --git a/cockatrice/src/phasestoolbar.h b/cockatrice/src/phasestoolbar.h index b4ea6ff2..1c247c02 100644 --- a/cockatrice/src/phasestoolbar.h +++ b/cockatrice/src/phasestoolbar.h @@ -12,16 +12,16 @@ class PhaseButton : public QPushButton { private: QString phaseText; bool active; + QAction *doubleClickAction; public: - PhaseButton(); - PhaseButton(QIcon); + PhaseButton(const QIcon &icon, QAction *_doubleClickAction = 0); void setPhaseText(const QString &_phaseText); QString getPhaseText() const { return phaseText; } void setActive(bool _active) { active = _active; update(); } -public slots: - void update(); + bool getActive() const { return active; } protected: void paintEvent(QPaintEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); }; class PhasesToolbar : public QFrame { @@ -38,6 +38,8 @@ private slots: signals: void signalSetPhase(int phase); void signalNextTurn(); + void signalUntapAll(); + void signalDrawCard(); }; #endif diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index fcff6589..c9410f3d 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -179,6 +179,7 @@ void MainWindow::playerIdReceived(int id, QString name) connect(game, SIGNAL(playerAdded(Player *)), this, SLOT(playerAdded(Player *))); connect(game, SIGNAL(playerRemoved(Player *)), this, SLOT(playerRemoved(Player *))); connect(game, SIGNAL(setActivePhase(int)), phasesToolbar, SLOT(setActivePhase(int))); + connect(phasesToolbar, SIGNAL(signalUntapAll()), game, SLOT(actUntapAll())); playerAdded(game->getLocalPlayer()); messageLog->connectToGame(game); @@ -342,6 +343,7 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent) connect(client, SIGNAL(serverError(ServerResponse)), messageLog, SLOT(logServerError(ServerResponse))); connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int))); connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn())); + connect(phasesToolbar, SIGNAL(signalDrawCard()), client, SLOT(drawCard())); createActions(); createMenus();