phase toolbar
This commit is contained in:
parent
0e4517bf63
commit
cb90463530
12 changed files with 146 additions and 81 deletions
|
@ -40,12 +40,11 @@ HEADERS += src/counter.h \
|
|||
src/carddatabasemodel.h \
|
||||
src/window_deckeditor.h \
|
||||
src/decklist.h \
|
||||
setsmodel.h \
|
||||
src/setsmodel.h \
|
||||
src/window_sets.h \
|
||||
src/abstractgraphicsitem.h \
|
||||
src/dlg_settings.h \
|
||||
src/phasestoolbar.h \
|
||||
src/phasebutton.h
|
||||
src/phasestoolbar.h
|
||||
SOURCES += src/counter.cpp \
|
||||
src/gameselector.cpp \
|
||||
src/dlg_creategame.cpp \
|
||||
|
@ -83,6 +82,5 @@ SOURCES += src/counter.cpp \
|
|||
src/window_sets.cpp \
|
||||
src/abstractgraphicsitem.cpp \
|
||||
src/dlg_settings.cpp \
|
||||
src/phasestoolbar.cpp \
|
||||
src/phasebutton.cpp
|
||||
src/phasestoolbar.cpp
|
||||
TRANSLATIONS += translations/cockatrice_de.ts translations/cockatrice_en.ts
|
||||
|
|
|
@ -224,10 +224,25 @@ void Game::gameEvent(const ServerEventData &msg)
|
|||
emit logRollDice(p, sides, roll);
|
||||
break;
|
||||
}
|
||||
case eventSetActivePlayer:
|
||||
case eventSetActivePlayer: {
|
||||
QStringList data = msg.getEventData();
|
||||
int playerId = data[0].toInt();
|
||||
Player *player = players.findPlayer(playerId);
|
||||
if (!player) {
|
||||
qDebug(QString("setActivePlayer: invalid player: %1").arg(playerId).toLatin1());
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < players.size(); ++i)
|
||||
players[i]->setActive(players[i] == player);
|
||||
emit logSetActivePlayer(player);
|
||||
break;
|
||||
case eventSetActivePhase:
|
||||
}
|
||||
case eventSetActivePhase: {
|
||||
QStringList data = msg.getEventData();
|
||||
int phase = data[0].toInt();
|
||||
emit setActivePhase(p, phase);
|
||||
break;
|
||||
}
|
||||
|
||||
case eventName:
|
||||
case eventCreateToken:
|
||||
|
|
|
@ -78,6 +78,8 @@ signals:
|
|||
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
||||
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);
|
||||
public:
|
||||
Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent = 0);
|
||||
~Game();
|
||||
|
|
|
@ -97,6 +97,9 @@ void MessageLogWidget::logDraw(Player *player, int number)
|
|||
|
||||
void MessageLogWidget::logMoveCard(Player *player, QString cardName, CardZone *startZone, int oldX, CardZone *targetZone, int newX)
|
||||
{
|
||||
if (cardName.isEmpty())
|
||||
cardName = tr("a card");
|
||||
|
||||
QString startName = startZone->getName();
|
||||
QString targetName = targetZone->getName();
|
||||
if (((startName == "table") && (targetName == "table")) || ((startName == "hand") && (targetName == "hand")))
|
||||
|
@ -197,6 +200,18 @@ void MessageLogWidget::logStopDumpZone(Player *player, QString zoneName, QString
|
|||
append(tr("%1 stops looking at %2's %3").arg(sanitizeHtml(player->getName())).arg(zoneOwner).arg(zoneName));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetActivePlayer(Player *player)
|
||||
{
|
||||
append("---");
|
||||
append("<font color=\"green\">" + tr("It is now %1's turn.").arg(player->getName()) + "</font>");
|
||||
append("---");
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetActivePhase(Player *player, int phase)
|
||||
{
|
||||
append("<font color=\"green\">" + tr("It is now the %1 phase.").arg(phase) + "</font>");
|
||||
}
|
||||
|
||||
void MessageLogWidget::connectToGame(Game *game)
|
||||
{
|
||||
connect(game, SIGNAL(logPlayerListReceived(QStringList)), this, SLOT(logPlayerListReceived(QStringList)));
|
||||
|
@ -216,6 +231,8 @@ void MessageLogWidget::connectToGame(Game *game)
|
|||
connect(game, SIGNAL(logSetDoesntUntap(Player *, QString, bool)), this, SLOT(logSetDoesntUntap(Player *, QString, bool)));
|
||||
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)));
|
||||
}
|
||||
|
||||
MessageLogWidget::MessageLogWidget(QWidget *parent)
|
||||
|
|
|
@ -37,6 +37,8 @@ private slots:
|
|||
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
||||
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);
|
||||
public:
|
||||
void connectToGame(Game *game);
|
||||
MessageLogWidget(QWidget *parent = 0);
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
#include "phasebutton.h"
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
//
|
||||
PhaseButton::PhaseButton(QIcon icon, QString name )
|
||||
: QPushButton(icon,name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//PhaseButton::PhaseButton( )
|
||||
//: QPushButton()
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
void PhaseButton::update()
|
||||
{
|
||||
QPushButton::update();
|
||||
}
|
||||
|
||||
void PhaseButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPushButton::paintEvent(event);
|
||||
if(isChecked())
|
||||
{
|
||||
QPainter painter(this);
|
||||
int height = size().height();
|
||||
int width = size().width();
|
||||
QPen pen;
|
||||
pen.setWidth(3);
|
||||
pen.setColor(QColor::fromRgb(180,0,0));
|
||||
painter.setPen(pen);
|
||||
painter.drawRect(3,3, width-7, height-7);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//
|
|
@ -1,16 +0,0 @@
|
|||
#ifndef PHASEBUTTON_H
|
||||
#define PHASEBUTTON_H
|
||||
//
|
||||
#include <QPushButton>
|
||||
//
|
||||
class PhaseButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PhaseButton();
|
||||
PhaseButton(QIcon, QString);
|
||||
void update();
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
};
|
||||
#endif
|
|
@ -1,35 +1,79 @@
|
|||
#include "phasestoolbar.h"
|
||||
#include <QAction>
|
||||
//#include <QPushButton>
|
||||
#include "phasebutton.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QButtonGroup>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
|
||||
PhaseButton::PhaseButton(QIcon icon)
|
||||
: QPushButton(icon, QString())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PhaseButton::update()
|
||||
{
|
||||
QPushButton::update();
|
||||
}
|
||||
|
||||
void PhaseButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPushButton::paintEvent(event);
|
||||
if (isChecked()) {
|
||||
QPainter painter(this);
|
||||
int height = size().height();
|
||||
int width = size().width();
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(3);
|
||||
pen.setColor(QColor::fromRgb(180, 0, 0));
|
||||
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));
|
||||
painter.setBrush(QBrush(grad));
|
||||
// painter.drawEllipse(QRect(0, 0, width, height));
|
||||
|
||||
painter.drawRect(3, 3, width - 7, height - 7);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void PhaseButton::setPhaseText(const QString &_phaseText)
|
||||
{
|
||||
phaseText = _phaseText;
|
||||
setToolTip(phaseText);
|
||||
}
|
||||
|
||||
PhasesToolbar::PhasesToolbar(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
PhaseButton *untapButton = new PhaseButton(QIcon(":/resources/icon_phase_untap.svg"), QString());
|
||||
PhaseButton *upkeepButton = new PhaseButton(QIcon(":/resources/icon_phase_upkeep.svg"), QString());
|
||||
PhaseButton *drawButton = new PhaseButton(QIcon(":/resources/icon_phase_draw.svg"), QString());
|
||||
PhaseButton *main1Button = new PhaseButton(QIcon(":/resources/icon_phase_main1.svg"), QString());
|
||||
PhaseButton *combatStartButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_start.svg"), QString());
|
||||
PhaseButton *combatAttackersButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_attackers.svg"), QString());
|
||||
PhaseButton *combatBlockersButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_blockers.svg"), QString());
|
||||
PhaseButton *combatDamageButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_damage.svg"), QString());
|
||||
PhaseButton *combatEndButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_end.svg"), QString());
|
||||
PhaseButton *main2Button = new PhaseButton(QIcon(":/resources/icon_phase_main2.svg"), QString());
|
||||
PhaseButton *cleanupButton = new PhaseButton(QIcon(":/resources/icon_phase_cleanup.svg"), QString());
|
||||
PhaseButton *untapButton = new PhaseButton(QIcon(":/resources/icon_phase_untap.svg"));
|
||||
PhaseButton *upkeepButton = new PhaseButton(QIcon(":/resources/icon_phase_upkeep.svg"));
|
||||
PhaseButton *drawButton = new PhaseButton(QIcon(":/resources/icon_phase_draw.svg"));
|
||||
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"));
|
||||
PhaseButton *combatBlockersButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_blockers.svg"));
|
||||
PhaseButton *combatDamageButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_damage.svg"));
|
||||
PhaseButton *combatEndButton = new PhaseButton(QIcon(":/resources/icon_phase_combat_end.svg"));
|
||||
PhaseButton *main2Button = new PhaseButton(QIcon(":/resources/icon_phase_main2.svg"));
|
||||
PhaseButton *cleanupButton = new PhaseButton(QIcon(":/resources/icon_phase_cleanup.svg"));
|
||||
|
||||
buttonList << untapButton << upkeepButton << drawButton << main1Button << combatStartButton
|
||||
<< combatAttackersButton << combatBlockersButton << combatDamageButton << combatEndButton
|
||||
<< main2Button << cleanupButton;
|
||||
|
||||
|
||||
for (int i = 0; i < buttonList.size(); ++i) {
|
||||
buttonList[i]->setCheckable(true);
|
||||
buttonList[i]->setIconSize(QSize(40, 40));
|
||||
}
|
||||
|
||||
PhaseButton *nextTurnButton = new PhaseButton(QIcon(":/resources/icon_nextturn.svg"), QString());
|
||||
QPushButton *nextTurnButton = new QPushButton(QIcon(":/resources/icon_nextturn.svg"), QString());
|
||||
nextTurnButton->setIconSize(QSize(40, 40));
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
|
@ -40,7 +84,6 @@ PhasesToolbar::PhasesToolbar(QWidget *parent)
|
|||
bg->addButton(buttonList[i]);
|
||||
}
|
||||
|
||||
|
||||
layout->addStretch(1);
|
||||
layout->addWidget(untapButton);
|
||||
layout->addWidget(upkeepButton);
|
||||
|
@ -61,5 +104,21 @@ PhasesToolbar::PhasesToolbar(QWidget *parent)
|
|||
layout->addWidget(nextTurnButton);
|
||||
layout->addStretch(1);
|
||||
|
||||
retranslateUi();
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void PhasesToolbar::retranslateUi()
|
||||
{
|
||||
buttonList[0]->setPhaseText(tr("Untap step"));
|
||||
buttonList[1]->setPhaseText(tr("Upkeep step"));
|
||||
buttonList[2]->setPhaseText(tr("Draw step"));
|
||||
buttonList[3]->setPhaseText(tr("First main phase"));
|
||||
buttonList[4]->setPhaseText(tr("Beginning of combat step"));
|
||||
buttonList[5]->setPhaseText(tr("Declare attackers step"));
|
||||
buttonList[6]->setPhaseText(tr("Declare blockers step"));
|
||||
buttonList[7]->setPhaseText(tr("Combat damage step"));
|
||||
buttonList[8]->setPhaseText(tr("End of combat step"));
|
||||
buttonList[9]->setPhaseText(tr("Second main phase"));
|
||||
buttonList[10]->setPhaseText(tr("End of turn step"));
|
||||
}
|
||||
|
|
|
@ -3,15 +3,30 @@
|
|||
|
||||
#include <QFrame>
|
||||
#include <QList>
|
||||
#include <QPushButton>
|
||||
|
||||
class QPushButton;
|
||||
class PhaseButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString phaseText;
|
||||
public:
|
||||
PhaseButton();
|
||||
PhaseButton(QIcon);
|
||||
void setPhaseText(const QString &_phaseText);
|
||||
QString getPhaseText() const { return phaseText; }
|
||||
public slots:
|
||||
void update();
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
};
|
||||
|
||||
class PhasesToolbar : public QFrame {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PhasesToolbar(QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
private:
|
||||
QList<QPushButton *> buttonList;
|
||||
QList<PhaseButton *> buttonList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <QMenu>
|
||||
|
||||
Player::Player(const QString &_name, int _id, QPointF _base, bool _local, CardDatabase *_db, Client *_client, QGraphicsScene *_scene, Game *_parent)
|
||||
: QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), base(_base), local(_local), db(_db), client(_client)
|
||||
: QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), active(false), base(_base), local(_local), db(_db), client(_client)
|
||||
{
|
||||
area = new PlayerArea(this);
|
||||
area->setPos(_base);
|
||||
|
@ -315,3 +315,8 @@ void Player::showCardMenu(const QPoint &p)
|
|||
{
|
||||
emit sigShowCardMenu(p);
|
||||
}
|
||||
|
||||
void Player::setActive(bool _active)
|
||||
{
|
||||
active = _active;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ private:
|
|||
int defaultNumberTopCards;
|
||||
QString name;
|
||||
int id;
|
||||
bool active;
|
||||
QPointF base;
|
||||
bool local;
|
||||
ZoneList zones;
|
||||
|
@ -68,6 +69,8 @@ public:
|
|||
void gameEvent(const ServerEventData &event);
|
||||
CardDatabase *getDb() const { return db; }
|
||||
void showCardMenu(const QPoint &p);
|
||||
bool getActive() const { return active; }
|
||||
void setActive(bool _active);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -609,6 +609,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdSetActivePlayer(const QList<QVariant>
|
|||
if (!game->getPlayer(active_player))
|
||||
return ReturnMessage::ReturnContextError;
|
||||
game->setActivePlayer(active_player);
|
||||
emit broadcastEvent(QString("set_active_player|%1").arg(active_player), this);
|
||||
return ReturnMessage::ReturnOk;
|
||||
}
|
||||
|
||||
|
@ -616,7 +617,10 @@ ReturnMessage::ReturnCode ServerSocket::cmdSetActivePhase(const QList<QVariant>
|
|||
{
|
||||
int active_phase = params[0].toInt();
|
||||
// XXX Überprüfung, ob die Phase existiert...
|
||||
if (game->getActivePlayer() != playerId)
|
||||
return ReturnMessage::ReturnContextError;
|
||||
game->setActivePhase(active_phase);
|
||||
emit broadcastEvent(QString("set_active_phase|%1").arg(active_phase), this);
|
||||
return ReturnMessage::ReturnOk;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue