phases toolbar improvement

This commit is contained in:
Max-Wilhelm Bruker 2009-08-28 15:28:25 +02:00
parent a5280946c2
commit 0dbc580b8a
6 changed files with 33 additions and 18 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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);

View file

@ -4,17 +4,12 @@
#include <QPainter>
#include <QPen>
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<PhaseButton *>(sender());
if (button->getActive())
return;
emit signalSetPhase(buttonList.indexOf(button));
}

View file

@ -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

View file

@ -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();