mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
phases
This commit is contained in:
parent
cb90463530
commit
1d400e195d
15 changed files with 507 additions and 204 deletions
|
|
@ -340,9 +340,9 @@ PendingCommand *Client::delCounter(const QString &counter)
|
|||
return cmd(QString("del_counter|%1").arg(counter));
|
||||
}
|
||||
|
||||
PendingCommand *Client::setActivePlayer(int player)
|
||||
PendingCommand *Client::nextTurn()
|
||||
{
|
||||
return cmd(QString("set_active_player|%1").arg(player));
|
||||
return cmd(QString("next_turn"));
|
||||
}
|
||||
|
||||
PendingCommand *Client::setActivePhase(int phase)
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ public:
|
|||
|
||||
void connectToServer(const QString &hostname, unsigned int port, const QString &_playerName, const QString &_password);
|
||||
void disconnectFromServer();
|
||||
public slots:
|
||||
PendingCommand *listGames();
|
||||
PendingCommand *listPlayers();
|
||||
PendingCommand *createGame(const QString &description, const QString &password, unsigned int maxPlayers);
|
||||
|
|
@ -107,11 +108,10 @@ public:
|
|||
PendingCommand *addCounter(const QString &counter, QColor color, int value);
|
||||
PendingCommand *setCounter(const QString &counter, int value);
|
||||
PendingCommand *delCounter(const QString &counter);
|
||||
PendingCommand *setActivePlayer(int player);
|
||||
PendingCommand *nextTurn();
|
||||
PendingCommand *setActivePhase(int phase);
|
||||
PendingCommand *dumpZone(int player, const QString &zone, int numberCards);
|
||||
PendingCommand *stopDumpZone(int player, const QString &zone);
|
||||
public slots:
|
||||
void submitDeck(const QStringList &deck);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ void Game::gameEvent(const ServerEventData &msg)
|
|||
case eventSetActivePhase: {
|
||||
QStringList data = msg.getEventData();
|
||||
int phase = data[0].toInt();
|
||||
emit setActivePhase(p, phase);
|
||||
emit setActivePhase(phase);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ signals:
|
|||
void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards);
|
||||
void logStopDumpZone(Player *player, QString zoneName, QString zoneOwner);
|
||||
void logSetActivePlayer(Player *player);
|
||||
void setActivePhase(Player *player, int phase);
|
||||
void setActivePhase(int phase);
|
||||
public:
|
||||
Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent = 0);
|
||||
~Game();
|
||||
|
|
|
|||
|
|
@ -207,9 +207,23 @@ void MessageLogWidget::logSetActivePlayer(Player *player)
|
|||
append("---");
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetActivePhase(Player *player, int phase)
|
||||
void MessageLogWidget::logSetActivePhase(int phase)
|
||||
{
|
||||
append("<font color=\"green\">" + tr("It is now the %1 phase.").arg(phase) + "</font>");
|
||||
QString phaseName;
|
||||
switch (phase) {
|
||||
case 0: phaseName = tr("untap step"); break;
|
||||
case 1: phaseName = tr("upkeep step"); break;
|
||||
case 2: phaseName = tr("draw step"); break;
|
||||
case 3: phaseName = tr("first main phase"); break;
|
||||
case 4: phaseName = tr("beginning of combat step"); break;
|
||||
case 5: phaseName = tr("declare attackers step"); break;
|
||||
case 6: phaseName = tr("declare blockers step"); break;
|
||||
case 7: phaseName = tr("combat damage step"); break;
|
||||
case 8: phaseName = tr("end of combat step"); break;
|
||||
case 9: phaseName = tr("second main phase"); break;
|
||||
case 10: phaseName = tr("end of turn step"); break;
|
||||
}
|
||||
append("<font color=\"green\">" + tr("It is now the %1.").arg(phaseName) + "</font>");
|
||||
}
|
||||
|
||||
void MessageLogWidget::connectToGame(Game *game)
|
||||
|
|
@ -232,7 +246,7 @@ void MessageLogWidget::connectToGame(Game *game)
|
|||
connect(game, SIGNAL(logDumpZone(Player *, QString, QString, int)), this, SLOT(logDumpZone(Player *, QString, QString, int)));
|
||||
connect(game, SIGNAL(logStopDumpZone(Player *, QString, QString)), this, SLOT(logStopDumpZone(Player *, QString, QString)));
|
||||
connect(game, SIGNAL(logSetActivePlayer(Player *)), this, SLOT(logSetActivePlayer(Player *)));
|
||||
connect(game, SIGNAL(setActivePhase(Player *, int)), this, SLOT(logSetActivePhase(Player *, int)));
|
||||
connect(game, SIGNAL(setActivePhase(int)), this, SLOT(logSetActivePhase(int)));
|
||||
}
|
||||
|
||||
MessageLogWidget::MessageLogWidget(QWidget *parent)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ private slots:
|
|||
void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards);
|
||||
void logStopDumpZone(Player *player, QString zoneName, QString zoneOwner);
|
||||
void logSetActivePlayer(Player *player);
|
||||
void logSetActivePhase(Player *player, int phase);
|
||||
void logSetActivePhase(int phase);
|
||||
public:
|
||||
void connectToGame(Game *game);
|
||||
MessageLogWidget(QWidget *parent = 0);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
#include "phasestoolbar.h"
|
||||
#include <QAction>
|
||||
#include <QVBoxLayout>
|
||||
#include <QButtonGroup>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
|
||||
PhaseButton::PhaseButton(QIcon icon)
|
||||
: QPushButton(icon, QString())
|
||||
: QPushButton(icon, QString()), active(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -19,27 +18,23 @@ void PhaseButton::update()
|
|||
void PhaseButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPushButton::paintEvent(event);
|
||||
if (isChecked()) {
|
||||
if (active) {
|
||||
QPainter painter(this);
|
||||
int height = size().height();
|
||||
int width = size().width();
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(3);
|
||||
pen.setColor(QColor::fromRgb(180, 0, 0));
|
||||
pen.setColor(QColor::fromRgb(180, 0, 0, 200));
|
||||
painter.setPen(pen);
|
||||
|
||||
// painter.setPen(QColor(0, 0, 0, 0));
|
||||
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));
|
||||
grad.setColorAt(1, QColor(180, 0, 0, 200));
|
||||
painter.setBrush(QBrush(grad));
|
||||
// painter.drawEllipse(QRect(0, 0, width, height));
|
||||
|
||||
painter.drawRect(3, 3, width - 7, height - 7);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,38 +64,34 @@ PhasesToolbar::PhasesToolbar(QWidget *parent)
|
|||
<< main2Button << cleanupButton;
|
||||
|
||||
for (int i = 0; i < buttonList.size(); ++i) {
|
||||
buttonList[i]->setCheckable(true);
|
||||
buttonList[i]->setIconSize(QSize(40, 40));
|
||||
buttonList[i]->setIconSize(QSize(36, 36));
|
||||
connect(buttonList[i], SIGNAL(clicked()), this, SLOT(phaseButtonClicked()));
|
||||
}
|
||||
|
||||
QPushButton *nextTurnButton = new QPushButton(QIcon(":/resources/icon_nextturn.svg"), QString());
|
||||
nextTurnButton->setIconSize(QSize(40, 40));
|
||||
nextTurnButton->setIconSize(QSize(36, 36));
|
||||
connect(nextTurnButton, SIGNAL(clicked()), this, SIGNAL(signalNextTurn()));
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->setSpacing(0);
|
||||
|
||||
QButtonGroup *bg = new QButtonGroup;
|
||||
for (int i = 0; i < buttonList.size(); ++i) {
|
||||
bg->addButton(buttonList[i]);
|
||||
}
|
||||
|
||||
layout->addStretch(1);
|
||||
layout->addWidget(untapButton);
|
||||
layout->addWidget(upkeepButton);
|
||||
layout->addWidget(drawButton);
|
||||
layout->addSpacing(15);
|
||||
layout->addSpacing(10);
|
||||
layout->addWidget(main1Button);
|
||||
layout->addSpacing(15);
|
||||
layout->addSpacing(10);
|
||||
layout->addWidget(combatStartButton);
|
||||
layout->addWidget(combatAttackersButton);
|
||||
layout->addWidget(combatBlockersButton);
|
||||
layout->addWidget(combatDamageButton);
|
||||
layout->addWidget(combatEndButton);
|
||||
layout->addSpacing(15);
|
||||
layout->addSpacing(10);
|
||||
layout->addWidget(main2Button);
|
||||
layout->addSpacing(15);
|
||||
layout->addSpacing(10);
|
||||
layout->addWidget(cleanupButton);
|
||||
layout->addSpacing(25);
|
||||
layout->addSpacing(20);
|
||||
layout->addWidget(nextTurnButton);
|
||||
layout->addStretch(1);
|
||||
|
||||
|
|
@ -122,3 +113,18 @@ void PhasesToolbar::retranslateUi()
|
|||
buttonList[9]->setPhaseText(tr("Second main phase"));
|
||||
buttonList[10]->setPhaseText(tr("End of turn step"));
|
||||
}
|
||||
|
||||
void PhasesToolbar::setActivePhase(int phase)
|
||||
{
|
||||
if (phase >= buttonList.size())
|
||||
return;
|
||||
|
||||
for (int i = 0; i < buttonList.size(); ++i)
|
||||
buttonList[i]->setActive(i == phase);
|
||||
}
|
||||
|
||||
void PhasesToolbar::phaseButtonClicked()
|
||||
{
|
||||
PhaseButton *button = qobject_cast<PhaseButton *>(sender());
|
||||
emit signalSetPhase(buttonList.indexOf(button));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,15 +5,19 @@
|
|||
#include <QList>
|
||||
#include <QPushButton>
|
||||
|
||||
class Player;
|
||||
|
||||
class PhaseButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString phaseText;
|
||||
bool active;
|
||||
public:
|
||||
PhaseButton();
|
||||
PhaseButton(QIcon);
|
||||
void setPhaseText(const QString &_phaseText);
|
||||
QString getPhaseText() const { return phaseText; }
|
||||
void setActive(bool _active) { active = _active; update(); }
|
||||
public slots:
|
||||
void update();
|
||||
protected:
|
||||
|
|
@ -22,11 +26,18 @@ protected:
|
|||
|
||||
class PhasesToolbar : public QFrame {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QList<PhaseButton *> buttonList;
|
||||
public:
|
||||
PhasesToolbar(QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
private:
|
||||
QList<PhaseButton *> buttonList;
|
||||
public slots:
|
||||
void setActivePhase(int phase);
|
||||
private slots:
|
||||
void phaseButtonClicked();
|
||||
signals:
|
||||
void signalSetPhase(int phase);
|
||||
void signalNextTurn();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ void MainWindow::statusChanged(ProtocolStatus _status)
|
|||
aDisconnect->setEnabled(false);
|
||||
aRestartGame->setEnabled(false);
|
||||
aLeaveGame->setEnabled(false);
|
||||
phasesToolbar->setEnabled(false);
|
||||
emit logDisconnected();
|
||||
break;
|
||||
case StatusLoggingIn:
|
||||
|
|
@ -81,11 +82,13 @@ void MainWindow::statusChanged(ProtocolStatus _status)
|
|||
}
|
||||
aRestartGame->setEnabled(false);
|
||||
aLeaveGame->setEnabled(false);
|
||||
phasesToolbar->setEnabled(false);
|
||||
|
||||
GameSelector *gameSelector = new GameSelector(client);
|
||||
viewLayout->insertWidget(0, gameSelector);
|
||||
}
|
||||
case StatusPlaying:
|
||||
phasesToolbar->setEnabled(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -166,6 +169,7 @@ 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(game, SIGNAL(setActivePhase(int)), phasesToolbar, SLOT(setActivePhase(int)));
|
||||
playerAdded(game->getLocalPlayer());
|
||||
|
||||
messageLog->connectToGame(game);
|
||||
|
|
@ -289,7 +293,8 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
|
|||
viewLayout = new QVBoxLayout;
|
||||
viewLayout->addWidget(view);
|
||||
|
||||
PhasesToolbar *phasesToolbar = new PhasesToolbar;
|
||||
phasesToolbar = new PhasesToolbar;
|
||||
phasesToolbar->setEnabled(false);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(phasesToolbar);
|
||||
|
|
@ -312,6 +317,8 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
|
|||
connect(this, SIGNAL(logDisconnected()), messageLog, SLOT(logDisconnected()));
|
||||
connect(client, SIGNAL(logSocketError(const QString &)), messageLog, SLOT(logSocketError(const QString &)));
|
||||
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()));
|
||||
|
||||
createActions();
|
||||
createMenus();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class QPushButton;
|
|||
class ServerZoneCard;
|
||||
class ZoneViewLayout;
|
||||
class ZoneViewWidget;
|
||||
class PhasesToolbar;
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
|
@ -78,6 +79,7 @@ private:
|
|||
MessageLogWidget *messageLog;
|
||||
QLabel *sayLabel;
|
||||
QLineEdit *sayEdit;
|
||||
PhasesToolbar *phasesToolbar;
|
||||
|
||||
Client *client;
|
||||
QGraphicsScene *scene;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue