diff --git a/cockatrice/src/counter.cpp b/cockatrice/src/counter.cpp index a4bb456c..ea159f3c 100644 --- a/cockatrice/src/counter.cpp +++ b/cockatrice/src/counter.cpp @@ -4,10 +4,46 @@ #include Counter::Counter(Player *_player, int _id, const QString &_name, QColor _color, int _radius, int _value, QGraphicsItem *parent) - : QGraphicsItem(parent), id(_id), name(_name), color(_color), radius(_radius), value(_value), player(_player) + : QGraphicsItem(parent), player(_player), id(_id), name(_name), color(_color), radius(_radius), value(_value), aDec(0), aInc(0) { if (radius > Player::counterAreaWidth / 2) radius = Player::counterAreaWidth / 2; + + menu = new QMenu(name); + aSet = new QAction(this); + connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter())); + menu->addAction(aSet); + menu->addSeparator(); + for (int i = -10; i <= 10; ++i) + if (i == 0) + menu->addSeparator(); + else { + QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this); + if (i == -1) + aDec = aIncrement; + else if (i == 1) + aInc = aIncrement; + aIncrement->setData(i); + connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter())); + menu->addAction(aIncrement); + } + + retranslateUi(); +} + +Counter::~Counter() +{ + delete menu; +} + +void Counter::retranslateUi() +{ + aSet->setText(tr("&Set counter...")); + if (name == "life") { + aSet->setShortcut(tr("Ctrl+L")); + aDec->setShortcut(tr("F11")); + aInc->setShortcut(tr("F12")); + } } QRectF Counter::boundingRect() const @@ -36,8 +72,26 @@ void Counter::setValue(int _value) void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) - player->client->incCounter(id, 1); - else if (event->button() == Qt::RightButton) + if (event->button() == Qt::LeftButton) { player->client->incCounter(id, -1); + event->accept(); + } else if (event->button() == Qt::RightButton) { + menu->exec(event->screenPos()); + event->accept(); + } else + event->ignore(); +} + +void Counter::incrementCounter() +{ + int delta = static_cast(sender())->data().toInt(); + player->client->incCounter(id, delta); +} + +void Counter::setCounter() +{ + bool ok; + int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, 0, 2000000000, 1, &ok); + if (ok) + player->client->setCounter(id, newValue); } diff --git a/cockatrice/src/counter.h b/cockatrice/src/counter.h index aa20b620..0556250b 100644 --- a/cockatrice/src/counter.h +++ b/cockatrice/src/counter.h @@ -4,22 +4,35 @@ #include class Player; +class QMenu; +class QAction; -class Counter : public QGraphicsItem { +class Counter : public QObject, public QGraphicsItem { + Q_OBJECT private: + Player *player; int id; QString name; QColor color; int radius; int value; + + QAction *aSet, *aDec, *aInc; + QMenu *menu; +private slots: + void incrementCounter(); + void setCounter(); protected: - Player *player; void mousePressEvent(QGraphicsSceneMouseEvent *event); public: Counter(Player *_player, int _id, const QString &_name, QColor _color, int _radius, int _value, QGraphicsItem *parent = 0); + ~Counter(); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QMenu *getMenu() const { return menu; } + void retranslateUi(); + int getId() const { return id; } QString getName() const { return name; } int getValue() const { return value; } diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 0ef99013..8c1a6d64 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -151,13 +151,6 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl 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())); @@ -165,11 +158,9 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken())); playerMenu->addSeparator(); - playerMenu->addAction(aUntapAll); + countersMenu = playerMenu->addMenu(QString()); playerMenu->addSeparator(); - playerMenu->addAction(aDecLife); - playerMenu->addAction(aIncLife); - playerMenu->addAction(aSetLife); + playerMenu->addAction(aUntapAll); playerMenu->addSeparator(); playerMenu->addAction(aRollDie); playerMenu->addSeparator(); @@ -177,7 +168,6 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl playerMenu->addSeparator(); sayMenu = playerMenu->addMenu(QString()); initSayMenu(); - } else sbMenu = 0; @@ -231,20 +221,19 @@ void Player::retranslateUi() handMenu->setTitle(tr("&Hand")); sbMenu->setTitle(tr("&Sideboard")); libraryMenu->setTitle(tr("&Library")); + countersMenu->setTitle(tr("&Counters")); 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")); + + QMapIterator counterIterator(counters); + while (counterIterator.hasNext()) + counterIterator.next().value()->retranslateUi(); } } @@ -324,26 +313,6 @@ void Player::actUntapAll() client->setCardAttr("table", -1, "tapped", "false"); } -void Player::actIncLife() -{ - // XXX - client->incCounter(lifeCounter->getId(), 1); -} - -void Player::actDecLife() -{ - // XXX - client->incCounter(lifeCounter->getId(), -1); -} - -void Player::actSetLife() -{ - bool ok; - int life = QInputDialog::getInteger(0, tr("Set life"), tr("New life total:"), lifeCounter->getValue(), 0, 2000000000, 1, &ok); - if (ok) - client->setCounter(lifeCounter->getId(), life); -} - void Player::actRollDie() { bool ok; @@ -633,9 +602,7 @@ void Player::addCounter(int counterId, const QString &name, QColor color, int ra { Counter *c = new Counter(this, counterId, name, color, radius, value, this); counters.insert(counterId, c); - if (name == "life") - lifeCounter = c; - // XXX + countersMenu->addMenu(c->getMenu()); rearrangeCounters(); } diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index 16a16df8..784f5046 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -37,9 +37,6 @@ signals: void sizeChanged(); public slots: void actUntapAll(); - void actIncLife(); - void actDecLife(); - void actSetLife(); void actRollDie(); void actCreateToken(); @@ -57,11 +54,11 @@ private slots: void actViewRfg(); void actViewSideboard(); private: - QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *sayMenu; + QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *countersMenu, *sayMenu; QAction *aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToHand, *aMoveToGraveyard, *aMoveToRfg, *aViewLibrary, *aViewTopCards, *aViewGraveyard, *aViewRfg, *aViewSideboard, *aDrawCard, *aDrawCards, *aShuffle, - *aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aRollDie, *aCreateToken; + *aUntapAll, *aRollDie, *aCreateToken; int defaultNumberTopCards; QString name; @@ -80,9 +77,8 @@ private: QRectF bRect; QMap counters; - Counter *lifeCounter; - void rearrangeCounters(); + void initSayMenu(); public: static const int counterAreaWidth = 65; diff --git a/cockatrice/translations/cockatrice_de.ts b/cockatrice/translations/cockatrice_de.ts index d452c8d9..ca0839a1 100644 --- a/cockatrice/translations/cockatrice_de.ts +++ b/cockatrice/translations/cockatrice_de.ts @@ -281,6 +281,39 @@ Spielerzahl + + Counter + + + &Set counter... + Zähler &setzen... + + + + Ctrl+L + Ctrl+L + + + + F11 + F11 + + + + F12 + F12 + + + + Set counter + Zähler setzen + + + + New value for counter '%1': + Neuer Wert für den Zähler '%1': + + DeckList @@ -1623,37 +1656,37 @@ Player - + Move to &top of library Oben auf die Biblio&thek legen - + Move to &bottom of library Unter die &Bibliothek legen - + &View library &Zeige Bibliothek - + F3 F3 - + View &top cards of library... Zeige die oberen Kar&ten der Bibliothek... - + &View graveyard &Zeige Friedhof - + F4 F4 @@ -1662,27 +1695,27 @@ Zeige ent&fernte Karten - + &View sideboard Zeige &Sideboard - + Player "%1" Spieler "%1" - + &Hand &Hand - + &Library Bib&liothek - + &Graveyard &Friedhof @@ -1691,207 +1724,204 @@ Entfe&rnte Karten - + &Sideboard &Sideboard - + View top cards of library Zeige die obersten Karten der Bibliothek - + Number of cards: Anzahl der Karten: - + &Draw card Karte &ziehen - + &View exile &Zeige Exil - + &Exile &Exil - + Move to &hand auf die &Hand nehmen - + Move to g&raveyard auf den &Friedhof legen - + Move to &exile ins &Exil schicken - + Ctrl+D Ctrl+D - + D&raw cards... Ka&rten ziehen... - + Ctrl+E Ctrl+E - + &Shuffle Mi&schen - + Ctrl+S Ctrl+S - + + &Counters + &Zähler + + + &Untap all permanents &Enttappe alle bleibenden Karten - + Ctrl+U Ctrl+U - &Decrement life - Lebenspunkte &verringern + Lebenspunkte &verringern - F11 - F11 + F11 - &Increment life - Lebens&punkte erhöhen + Lebens&punkte erhöhen - F12 - F12 + F12 - &Set life - &Setze Lebenspunkte + &Setze Lebenspunkte - Ctrl+L - Ctrl+L + Ctrl+L - + R&oll die... &Würfeln... - + Ctrl+I Ctrl+I - + &Create token... &Token erstellen... - + Ctrl+T Ctrl+T - + S&ay &Sagen - + F5 F5 - + F6 F6 - + F7 F7 - + F8 F8 - + F9 F9 - + F10 F10 - + Draw cards Karten ziehen - + Number: Anzahl: - Set life - Lebenspunkte setzen + Lebenspunkte setzen - New life total: - Neue Lebenspunkte insgesamt: + Neue Lebenspunkte insgesamt: - + Roll die Würfeln - + Number of sides: Anzahl der Seiten: - + Create token Token erstellen - + Name: Name: diff --git a/cockatrice/translations/cockatrice_en.ts b/cockatrice/translations/cockatrice_en.ts index 61bc126e..bdcb980e 100644 --- a/cockatrice/translations/cockatrice_en.ts +++ b/cockatrice/translations/cockatrice_en.ts @@ -246,6 +246,39 @@ + + Counter + + + &Set counter... + + + + + Ctrl+L + + + + + F11 + + + + + F12 + + + + + Set counter + + + + + New value for counter '%1': + + + DeckList @@ -1161,267 +1194,232 @@ Player - + Move to &top of library - + Move to &bottom of library - + &View library - + F3 - + View &top cards of library... - + &View graveyard - + F4 - + &View sideboard - + Player "%1" - + &Hand - + &Library - + &Graveyard - + &Sideboard - + View top cards of library - + Number of cards: - + &Draw card - + &View exile - + &Exile - + Move to &hand - + Move to g&raveyard - + Move to &exile - + Ctrl+D - + D&raw cards... - + Ctrl+E - + &Shuffle - + Ctrl+S - + + &Counters + + + + &Untap all permanents - + Ctrl+U - - &Decrement life - - - - - F11 - - - - - &Increment life - - - - - F12 - - - - - &Set life - - - - - Ctrl+L - - - - + R&oll die... - + Ctrl+I - + &Create token... - + Ctrl+T - + S&ay - + F5 - + F6 - + F7 - + F8 - + F9 - + F10 - + Draw cards - + Number: - - Set life - - - - - New life total: - - - - + Roll die - + Number of sides: - + Create token - + Name: