Merge pull request #1134 from ctrlaltca/related_cards

Related cards
This commit is contained in:
ctrlaltca 2015-06-22 17:22:47 +02:00
commit 2415ba2605
8 changed files with 110 additions and 14 deletions

View file

@ -492,13 +492,16 @@ CardInfo::CardInfo(CardDatabase *_db,
const QString &_powtough,
const QString &_text,
const QStringList &_colors,
const QStringList &_relatedCards,
bool _upsideDownArt,
int _loyalty,
bool _cipt,
int _tableRow,
const SetList &_sets,
const QStringMap &_customPicURLs,
const QStringMap &_customPicURLsHq,
MuidMap _muIds)
MuidMap _muIds
)
: db(_db),
name(_name),
isToken(_isToken),
@ -509,6 +512,8 @@ CardInfo::CardInfo(CardDatabase *_db,
powtough(_powtough),
text(_text),
colors(_colors),
relatedCards(_relatedCards),
upsideDownArt(_upsideDownArt),
loyalty(_loyalty),
customPicURLs(_customPicURLs),
customPicURLsHq(_customPicURLsHq),
@ -590,7 +595,13 @@ void CardInfo::loadPixmap(QPixmap &pixmap)
void CardInfo::imageLoaded(const QImage &image)
{
if (!image.isNull()) {
QPixmapCache::insert(pixmapCacheKey, QPixmap::fromImage(image));
if(upsideDownArt)
{
QImage mirrorImage = image.mirrored(true, true);
QPixmapCache::insert(pixmapCacheKey, QPixmap::fromImage(mirrorImage));
} else {
QPixmapCache::insert(pixmapCacheKey, QPixmap::fromImage(image));
}
emit pixmapUpdated();
}
}
@ -695,6 +706,10 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
for (int i = 0; i < colors.size(); i++)
xml.writeTextElement("color", colors[i]);
const QStringList &related = info->getRelatedCards();
for (int i = 0; i < related.size(); i++)
xml.writeTextElement("related", related[i]);
xml.writeTextElement("manacost", info->getManaCost());
xml.writeTextElement("cmc", info->getCmc());
xml.writeTextElement("type", info->getCardType());
@ -708,6 +723,8 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
xml.writeTextElement("cipt", "1");
if (info->getIsToken())
xml.writeTextElement("token", "1");
if (info->getUpsideDownArt())
xml.writeTextElement("upsidedown", "1");
xml.writeEndElement(); // card
return xml;
@ -862,7 +879,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens)
break;
if (xml.name() == "card") {
QString name, manacost, cmc, type, pt, text;
QStringList colors;
QStringList colors, relatedCards;
QStringMap customPicURLs, customPicURLsHq;
MuidMap muids;
SetList sets;
@ -870,6 +887,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens)
int loyalty = 0;
bool cipt = false;
bool isToken = false;
bool upsideDown = false;
while (!xml.atEnd()) {
if (xml.readNext() == QXmlStreamReader::EndElement)
break;
@ -900,10 +918,14 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens)
}
} else if (xml.name() == "color")
colors << xml.readElementText();
else if (xml.name() == "related")
relatedCards << xml.readElementText();
else if (xml.name() == "tablerow")
tableRow = xml.readElementText().toInt();
else if (xml.name() == "cipt")
cipt = (xml.readElementText() == "1");
else if (xml.name() == "upsidedown")
upsideDown = (xml.readElementText() == "1");
else if (xml.name() == "loyalty")
loyalty = xml.readElementText().toInt();
else if (xml.name() == "token")
@ -911,7 +933,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens)
}
if (isToken == tokens) {
addCard(new CardInfo(this, name, isToken, manacost, cmc, type, pt, text, colors, loyalty, cipt, tableRow, sets, customPicURLs, customPicURLsHq, muids));
addCard(new CardInfo(this, name, isToken, manacost, cmc, type, pt, text, colors, relatedCards, upsideDown, loyalty, cipt, tableRow, sets, customPicURLs, customPicURLsHq, muids));
}
}
}

View file

@ -132,6 +132,8 @@ private:
QString powtough;
QString text;
QStringList colors;
QStringList relatedCards;
bool upsideDownArt;
int loyalty;
QStringMap customPicURLs, customPicURLsHq;
MuidMap muIds;
@ -148,13 +150,16 @@ public:
const QString &_powtough = QString(),
const QString &_text = QString(),
const QStringList &_colors = QStringList(),
const QStringList &_relatedCards = QStringList(),
bool _upsideDownArt = false,
int _loyalty = 0,
bool _cipt = false,
int _tableRow = 0,
const SetList &_sets = SetList(),
const QStringMap &_customPicURLs = QStringMap(),
const QStringMap &_customPicURLsHq = QStringMap(),
MuidMap muids = MuidMap());
MuidMap muids = MuidMap()
);
~CardInfo();
const QString &getName() const { return name; }
const QString &getSimpleName() const { return simpleName; }
@ -174,6 +179,8 @@ public:
void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); }
void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); }
const QStringList &getColors() const { return colors; }
const QStringList &getRelatedCards() const { return relatedCards; }
bool getUpsideDownArt() const { return upsideDownArt; }
QString getCustomPicURL(const QString &set) const { return customPicURLs.value(set); }
QString getCustomPicURLHq(const QString &set) const { return customPicURLsHq.value(set); }
int getMuId(const QString &set) const { return muIds.value(set); }

View file

@ -676,7 +676,7 @@ void Player::retranslateUi()
for (int i = 0; i < allPlayersActions.size(); ++i)
allPlayersActions[i]->setText(tr("&All players"));
}
aPlay->setText(tr("&Play"));
aHide->setText(tr("&Hide"));
aPlayFacedown->setText(tr("Play &Face Down"));
@ -1076,6 +1076,30 @@ void Player::actCreatePredefinedToken()
actCreateAnotherToken();
}
void Player::actCreateRelatedCard()
{
// get the clicked card
CardItem * sourceCard = game->getActiveCard();
if(!sourceCard)
return;
// get the target card name
QAction *action = static_cast<QAction *>(sender());
CardInfo *cardInfo = db->getCard(action->text());
// create the token for the related card
Command_CreateToken cmd;
cmd.set_zone("table");
cmd.set_card_name(cardInfo->getName().toStdString());
cmd.set_color(cardInfo->getColors().isEmpty() ? QString().toStdString() : cardInfo->getColors().first().toLower().toStdString());
cmd.set_pt(cardInfo->getPowTough().toStdString());
cmd.set_destroy_on_zone_change(true);
cmd.set_target_zone(sourceCard->getZone()->getName().toStdString());
cmd.set_target_card_id(sourceCard->getId());
sendGameCommand(cmd);
}
void Player::actSayMessage()
{
QAction *a = qobject_cast<QAction *>(sender());
@ -2247,6 +2271,17 @@ void Player::updateCardMenu(CardItem *card)
cardMenu->addAction(aFlip);
if (card->getFaceDown())
cardMenu->addAction(aPeek);
QStringList relatedCards = card->getInfo()->getRelatedCards();
if(relatedCards.size())
{
QMenu * createRelatedCardMenu = cardMenu->addMenu(tr("Cr&eate related card"));
for (int i = 0; i < relatedCards.size(); ++i) {
QAction *a = createRelatedCardMenu->addAction(relatedCards.at(i));
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
}
}
cardMenu->addSeparator();
cardMenu->addAction(aAttach);
if (card->getAttachedTo())

View file

@ -141,6 +141,7 @@ private slots:
void actOpenDeckInDeckEditor();
void actCreatePredefinedToken();
void actCreateRelatedCard();
void cardMenuAction();
void actCardCounterTrigger();
void actAttach();