p/t changes

This commit is contained in:
Max-Wilhelm Bruker 2011-02-16 18:34:46 +01:00
parent 713ebece78
commit d05603f83b
8 changed files with 157 additions and 24 deletions

View file

@ -34,6 +34,18 @@ CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, bool _reve
connect(aAttach, SIGNAL(triggered()), this, SLOT(actAttach())); connect(aAttach, SIGNAL(triggered()), this, SLOT(actAttach()));
aUnattach = new QAction(this); aUnattach = new QAction(this);
connect(aUnattach, SIGNAL(triggered()), this, SLOT(actUnattach())); connect(aUnattach, SIGNAL(triggered()), this, SLOT(actUnattach()));
aIncP = new QAction(this);
connect(aIncP, SIGNAL(triggered()), this, SLOT(actIncP()));
aDecP = new QAction(this);
connect(aDecP, SIGNAL(triggered()), this, SLOT(actDecP()));
aIncT = new QAction(this);
connect(aIncT, SIGNAL(triggered()), this, SLOT(actIncT()));
aDecT = new QAction(this);
connect(aDecT, SIGNAL(triggered()), this, SLOT(actDecT()));
aIncPT = new QAction(this);
connect(aIncPT, SIGNAL(triggered()), this, SLOT(actIncPT()));
aDecPT = new QAction(this);
connect(aDecPT, SIGNAL(triggered()), this, SLOT(actDecPT()));
aSetPT = new QAction(this); aSetPT = new QAction(this);
connect(aSetPT, SIGNAL(triggered()), this, SLOT(actSetPT())); connect(aSetPT, SIGNAL(triggered()), this, SLOT(actSetPT()));
aSetAnnotation = new QAction(this); aSetAnnotation = new QAction(this);
@ -77,6 +89,17 @@ CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, bool _reve
connect(tempSetCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger())); connect(tempSetCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
} }
cardMenu = new QMenu; cardMenu = new QMenu;
ptMenu = new QMenu;
ptMenu->addAction(aIncP);
ptMenu->addAction(aDecP);
ptMenu->addSeparator();
ptMenu->addAction(aIncT);
ptMenu->addAction(aDecT);
ptMenu->addSeparator();
ptMenu->addAction(aIncPT);
ptMenu->addAction(aDecPT);
ptMenu->addSeparator();
ptMenu->addAction(aSetPT);
moveMenu = new QMenu; moveMenu = new QMenu;
retranslateUi(); retranslateUi();
@ -144,7 +167,7 @@ void CardItem::updateCardMenu()
if (attachedTo) if (attachedTo)
cardMenu->addAction(aUnattach); cardMenu->addAction(aUnattach);
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addAction(aSetPT); cardMenu->addMenu(ptMenu);
cardMenu->addAction(aSetAnnotation); cardMenu->addAction(aSetAnnotation);
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addAction(aClone); cardMenu->addAction(aClone);
@ -180,10 +203,25 @@ void CardItem::retranslateUi()
aDoesntUntap->setText(tr("Toggle &normal untapping")); aDoesntUntap->setText(tr("Toggle &normal untapping"));
aFlip->setText(tr("&Flip")); aFlip->setText(tr("&Flip"));
aClone->setText(tr("&Clone")); aClone->setText(tr("&Clone"));
aClone->setShortcut(tr("Ctrl+H"));
aAttach->setText(tr("&Attach to card...")); aAttach->setText(tr("&Attach to card..."));
aAttach->setShortcut(tr("Ctrl+A")); aAttach->setShortcut(tr("Ctrl+A"));
aUnattach->setText(tr("Unattac&h")); aUnattach->setText(tr("Unattac&h"));
aSetPT->setText(tr("Set &P/T...")); ptMenu->setTitle(tr("&Power / toughness"));
aIncP->setText(tr("&Increase power"));
aIncP->setShortcut(tr("Ctrl++"));
aDecP->setText(tr("&Decrease power"));
aDecP->setShortcut(tr("Ctrl+-"));
aIncT->setText(tr("I&ncrease toughness"));
aIncT->setShortcut(tr("Alt++"));
aDecT->setText(tr("D&ecrease toughness"));
aDecT->setShortcut(tr("Alt+-"));
aIncPT->setText(tr("In&crease power and toughness"));
aIncPT->setShortcut(tr("Ctrl+Alt++"));
aDecPT->setText(tr("Dec&rease power and toughness"));
aDecPT->setShortcut(tr("Ctrl+Alt+-"));
aSetPT->setText(tr("Set &power and toughness..."));
aSetPT->setShortcut(tr("Ctrl+P"));
aSetAnnotation->setText(tr("&Set annotation...")); aSetAnnotation->setText(tr("&Set annotation..."));
QStringList counterColors; QStringList counterColors;
counterColors.append(tr("red")); counterColors.append(tr("red"));
@ -219,11 +257,13 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
paintNumberEllipse(counterIterator.value(), 14, color, i, counters.size(), painter); paintNumberEllipse(counterIterator.value(), 14, color, i, counters.size(), painter);
++i; ++i;
} }
QSizeF translatedSize = getTranslatedSize(painter);
qreal scaleFactor = translatedSize.width() / boundingRect().width();
if (!pt.isEmpty()) { if (!pt.isEmpty()) {
painter->save(); painter->save();
QSizeF translatedSize = getTranslatedSize(painter);
qreal scaleFactor = translatedSize.width() / boundingRect().width();
transformPainter(painter, translatedSize, tapAngle); transformPainter(painter, translatedSize, tapAngle);
painter->setBackground(Qt::black); painter->setBackground(Qt::black);
painter->setBackgroundMode(Qt::OpaqueMode); painter->setBackgroundMode(Qt::OpaqueMode);
@ -232,6 +272,17 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignRight | Qt::AlignBottom, pt); painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignRight | Qt::AlignBottom, pt);
painter->restore(); painter->restore();
} }
if (!annotation.isEmpty()) {
painter->save();
transformPainter(painter, translatedSize, tapAngle);
painter->setBackground(Qt::black);
painter->setBackgroundMode(Qt::OpaqueMode);
painter->setPen(Qt::white);
painter->drawText(QRectF(4 * scaleFactor, 4 * scaleFactor, translatedSize.width() - 8 * scaleFactor, translatedSize.height() - 8 * scaleFactor), Qt::AlignCenter | Qt::TextWrapAnywhere, annotation);
painter->restore();
}
if (getBeingPointedAt()) if (getBeingPointedAt())
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100))); painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
painter->restore(); painter->restore();
@ -263,7 +314,6 @@ void CardItem::setCounter(int _id, int _value)
void CardItem::setAnnotation(const QString &_annotation) void CardItem::setAnnotation(const QString &_annotation)
{ {
annotation = _annotation; annotation = _annotation;
setToolTip(annotation);
update(); update();
} }
@ -477,6 +527,36 @@ void CardItem::actUnattach()
owner->actUnattach(static_cast<QAction *>(sender())); owner->actUnattach(static_cast<QAction *>(sender()));
} }
void CardItem::actIncP()
{
owner->actIncPT(1, 0);
}
void CardItem::actDecP()
{
owner->actIncPT(-1, 0);
}
void CardItem::actIncT()
{
owner->actIncPT(0, 1);
}
void CardItem::actDecT()
{
owner->actIncPT(0, -1);
}
void CardItem::actIncPT()
{
owner->actIncPT(1, 1);
}
void CardItem::actDecPT()
{
owner->actIncPT(-1, -1);
}
void CardItem::actSetPT() void CardItem::actSetPT()
{ {
owner->actSetPT(static_cast<QAction *>(sender())); owner->actSetPT(static_cast<QAction *>(sender()));

View file

@ -33,9 +33,9 @@ private:
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter; QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;
QAction *aPlay, QAction *aPlay,
*aHide, *aHide,
*aTap, *aUntap, *aDoesntUntap, *aAttach, *aUnattach, *aSetPT, *aSetAnnotation, *aFlip, *aClone, *aTap, *aUntap, *aDoesntUntap, *aAttach, *aUnattach, *aSetPT, *aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aSetAnnotation, *aFlip, *aClone,
*aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToGraveyard, *aMoveToExile; *aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToGraveyard, *aMoveToExile;
QMenu *cardMenu, *moveMenu; QMenu *cardMenu, *ptMenu, *moveMenu;
void playCard(bool faceDown); void playCard(bool faceDown);
void prepareDelete(); void prepareDelete();
@ -45,6 +45,12 @@ private slots:
void actAttach(); void actAttach();
void actUnattach(); void actUnattach();
void actSetPT(); void actSetPT();
void actIncP();
void actDecP();
void actIncT();
void actDecT();
void actIncPT();
void actDecPT();
void actSetAnnotation(); void actSetAnnotation();
void actPlay(); void actPlay();
void actHide(); void actHide();

View file

@ -1365,6 +1365,16 @@ void Player::cardMenuAction(QAction *a)
sendCommandContainer(new CommandContainer(commandList)); sendCommandContainer(new CommandContainer(commandList));
} }
void Player::actIncPT(int deltaP, int deltaT)
{
QString ptString = "+" + QString::number(deltaP) + "/+" + QString::number(deltaT);
QListIterator<QGraphicsItem *> j(scene()->selectedItems());
while (j.hasNext()) {
CardItem *card = static_cast<CardItem *>(j.next());
sendGameCommand(new Command_SetCardAttr(-1, card->getZone()->getName(), card->getId(), "pt", ptString));
}
}
void Player::actSetPT(QAction * /*a*/) void Player::actSetPT(QAction * /*a*/)
{ {
QString oldPT; QString oldPT;

View file

@ -99,6 +99,7 @@ public slots:
void actAttach(QAction *action); void actAttach(QAction *action);
void actUnattach(QAction *action); void actUnattach(QAction *action);
void actIncPT(int deltaP, int deltaT);
void actSetPT(QAction *action); void actSetPT(QAction *action);
void actSetAnnotation(QAction *action); void actSetAnnotation(QAction *action);
void cardMenuAction(QAction *action); void cardMenuAction(QAction *action);

View file

@ -20,7 +20,7 @@
#include "server_card.h" #include "server_card.h"
Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y) Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y)
: id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), pt(QString()), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0) : id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), power(-1), toughness(-1), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0)
{ {
} }
@ -39,12 +39,13 @@ void Server_Card::resetState()
counters.clear(); counters.clear();
setTapped(false); setTapped(false);
setAttacking(false); setAttacking(false);
setPT(QString()); power = 0;
toughness = 0;
setAnnotation(QString()); setAnnotation(QString());
setDoesntUntap(false); setDoesntUntap(false);
} }
bool Server_Card::setAttribute(const QString &aname, const QString &avalue, bool allCards) QString Server_Card::setAttribute(const QString &aname, const QString &avalue, bool allCards)
{ {
if (aname == "tapped") { if (aname == "tapped") {
bool value = avalue == "1"; bool value = avalue == "1";
@ -58,14 +59,15 @@ bool Server_Card::setAttribute(const QString &aname, const QString &avalue, bool
setColor(avalue); setColor(avalue);
} else if (aname == "pt") { } else if (aname == "pt") {
setPT(avalue); setPT(avalue);
return getPT();
} else if (aname == "annotation") { } else if (aname == "annotation") {
setAnnotation(avalue); setAnnotation(avalue);
} else if (aname == "doesnt_untap") { } else if (aname == "doesnt_untap") {
setDoesntUntap(avalue == "1"); setDoesntUntap(avalue == "1");
} else } else
return false; return QString();
return true; return avalue;
} }
void Server_Card::setCounter(int id, int value) void Server_Card::setCounter(int id, int value)
@ -76,6 +78,36 @@ void Server_Card::setCounter(int id, int value)
counters.remove(id); counters.remove(id);
} }
void Server_Card::setPT(const QString &_pt)
{
int sep = _pt.indexOf('/');
QString p1 = _pt.left(sep);
QString p2 = _pt.mid(sep + 1);
if (p1.isEmpty() || p2.isEmpty())
return;
if ((p1[0] == '+') || (p2[0] == '+')) {
if (power < 0)
power = 0;
if (toughness < 0)
toughness = 0;
}
if (p1[0] == '+')
power += p1.mid(1).toInt();
else
power = p1.toInt();
if (p2[0] == '+')
toughness += p2.mid(1).toInt();
else
toughness = p2.toInt();
}
QString Server_Card::getPT() const
{
if (toughness < 0)
return QString("");
return QString::number(power) + "/" + QString::number(toughness);
}
void Server_Card::setParentCard(Server_Card *_parentCard) void Server_Card::setParentCard(Server_Card *_parentCard)
{ {
if (parentCard) if (parentCard)

View file

@ -38,7 +38,7 @@ private:
bool attacking; bool attacking;
bool facedown; bool facedown;
QString color; QString color;
QString pt; int power, toughness;
QString annotation; QString annotation;
bool destroyOnZoneChange; bool destroyOnZoneChange;
bool doesntUntap; bool doesntUntap;
@ -62,7 +62,7 @@ public:
bool getAttacking() const { return attacking; } bool getAttacking() const { return attacking; }
bool getFaceDown() const { return facedown; } bool getFaceDown() const { return facedown; }
QString getColor() const { return color; } QString getColor() const { return color; }
QString getPT() const { return pt; } QString getPT() const;
QString getAnnotation() const { return annotation; } QString getAnnotation() const { return annotation; }
bool getDoesntUntap() const { return doesntUntap; } bool getDoesntUntap() const { return doesntUntap; }
bool getDestroyOnZoneChange() const { return destroyOnZoneChange; } bool getDestroyOnZoneChange() const { return destroyOnZoneChange; }
@ -77,7 +77,7 @@ public:
void setAttacking(bool _attacking) { attacking = _attacking; } void setAttacking(bool _attacking) { attacking = _attacking; }
void setFaceDown(bool _facedown) { facedown = _facedown; } void setFaceDown(bool _facedown) { facedown = _facedown; }
void setColor(const QString &_color) { color = _color; } void setColor(const QString &_color) { color = _color; }
void setPT(const QString &_pt) { pt = _pt; } void setPT(const QString &_pt);
void setAnnotation(const QString &_annotation) { annotation = _annotation; } void setAnnotation(const QString &_annotation) { annotation = _annotation; }
void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; } void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; }
void setDoesntUntap(bool _doesntUntap) { doesntUntap = _doesntUntap; } void setDoesntUntap(bool _doesntUntap) { doesntUntap = _doesntUntap; }
@ -86,7 +86,7 @@ public:
void removeAttachedCard(Server_Card *card) { attachedCards.removeAt(attachedCards.indexOf(card)); } void removeAttachedCard(Server_Card *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
void resetState(); void resetState();
bool setAttribute(const QString &aname, const QString &avalue, bool allCards); QString setAttribute(const QString &aname, const QString &avalue, bool allCards);
}; };
#endif #endif

View file

@ -436,21 +436,25 @@ ResponseCode Server_Player::setCardAttrHelper(CommandContainer *cont, const QStr
if (!zone->hasCoords()) if (!zone->hasCoords())
return RespContextError; return RespContextError;
QString result;
if (cardId == -1) { if (cardId == -1) {
QListIterator<Server_Card *> CardIterator(zone->cards); QListIterator<Server_Card *> CardIterator(zone->cards);
while (CardIterator.hasNext()) while (CardIterator.hasNext()) {
if (!CardIterator.next()->setAttribute(attrName, attrValue, true)) result = CardIterator.next()->setAttribute(attrName, attrValue, true);
if (result.isNull())
return RespInvalidCommand; return RespInvalidCommand;
}
} else { } else {
Server_Card *card = zone->getCard(cardId, false); Server_Card *card = zone->getCard(cardId, false);
if (!card) if (!card)
return RespNameNotFound; return RespNameNotFound;
if (!card->setAttribute(attrName, attrValue, false)) result = card->setAttribute(attrName, attrValue, false);
if (result.isNull())
return RespInvalidCommand; return RespInvalidCommand;
} }
cont->enqueueGameEventPrivate(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, attrValue), game->getGameId()); cont->enqueueGameEventPrivate(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId());
cont->enqueueGameEventPublic(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, attrValue), game->getGameId()); cont->enqueueGameEventPublic(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId());
cont->enqueueGameEventOmniscient(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, attrValue), game->getGameId()); cont->enqueueGameEventOmniscient(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId());
return RespOk; return RespOk;
} }

View file

@ -191,7 +191,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data)
else if (v1 == "Type:") else if (v1 == "Type:")
cardType = v2.simplified(); cardType = v2.simplified();
else if (v1 == "Pow/Tgh:") else if (v1 == "Pow/Tgh:")
cardPT = v2.simplified(); cardPT = v2.simplified().remove('(').remove(')');
else if (v1 == "Rules Text:") else if (v1 == "Rules Text:")
cardText = v2.trimmed(); cardText = v2.trimmed();
} }