mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 16:24:45 -07:00
Rework of the card database, xml format and oracle parser (#3511)
* CardDB: merge all card properties in a new structure * Pre Json parser changes * Cockatrice: use qt's builtin json support * Move qt-json src dir from cockatrice to oracle * Add dummy cockatricexml4 parser (yet to be implemented) * Implement a new parser and xml format * cockatricexml4: new xml parser following the "generic properties hash" pattern; * oracleimporter: refactor the parsing code to better adapt to cockatricexml4; rewrote split cards parsing * carddb: change "colors" from a stringlist to a string * carddb: move the getMainCardType() method to the cockatricexml3 parser * * CardInfo: show all properties (stil missing: nice name + translation) * Rework the "add related card" feature so that it doesn't change the card name in the carddb Also, fix token count display * Picture loader: Added support for transform cards * Fix side information for flip cards Mtgjson uses side a/b for flip cards, while scryfall doesn't * Pictureloader: dynamic tag resolution from card properties Examples old => new * !cardid! => !set:muid! * !uuid! => !set:uuid! * !collectornumber! => !set:num! New examples: * !prop:type! * !prop:manacost! * Start moving mtg-related property names to a specific file * Clangify * Fix tests * Make gcc an happy puppy * Revert "Make gcc an happy puppy" This reverts commit 446ec5f27516c4d3b32dbfc79557f4827c5c5bdf. * Some gcc fixes * Share set list between different db parsers, so they won't overwrite one each other * All glory to the hypnoclangifier! * Fix test compilation * Cleanup edited files in the prior PR. (#3519) * Cleanup edited files in the prior PR. Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com> * Fix includes Signed-off-by: Zach Halpern <ZaHalpern+github@gmail.com> * Update carddatabase.h
This commit is contained in:
parent
19180243aa
commit
ed70099e36
44 changed files with 1814 additions and 1360 deletions
|
|
@ -1,137 +1,83 @@
|
|||
#include "cardinfotext.h"
|
||||
|
||||
#include "carditem.h"
|
||||
#include "game_specific_terms.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
|
||||
CardInfoText::CardInfoText(QWidget *parent) : QFrame(parent), info(nullptr)
|
||||
{
|
||||
nameLabel1 = new QLabel;
|
||||
nameLabel2 = new QLabel;
|
||||
nameLabel2->setWordWrap(true);
|
||||
nameLabel2->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
manacostLabel1 = new QLabel;
|
||||
manacostLabel2 = new QLabel;
|
||||
manacostLabel2->setWordWrap(true);
|
||||
manacostLabel2->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
colorLabel1 = new QLabel;
|
||||
colorLabel2 = new QLabel;
|
||||
colorLabel2->setWordWrap(true);
|
||||
colorLabel2->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
cardtypeLabel1 = new QLabel;
|
||||
cardtypeLabel2 = new QLabel;
|
||||
cardtypeLabel2->setWordWrap(true);
|
||||
cardtypeLabel2->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
powtoughLabel1 = new QLabel;
|
||||
powtoughLabel2 = new QLabel;
|
||||
powtoughLabel2->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
loyaltyLabel1 = new QLabel;
|
||||
loyaltyLabel2 = new QLabel;
|
||||
loyaltyLabel1->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
nameLabel = new QLabel;
|
||||
nameLabel->setOpenExternalLinks(false);
|
||||
connect(nameLabel, SIGNAL(linkActivated(const QString &)), this, SIGNAL(linkActivated(const QString &)));
|
||||
|
||||
textLabel = new QTextEdit();
|
||||
textLabel->setReadOnly(true);
|
||||
|
||||
QGridLayout *grid = new QGridLayout(this);
|
||||
int row = 0;
|
||||
grid->addWidget(nameLabel1, row, 0);
|
||||
grid->addWidget(nameLabel2, row++, 1);
|
||||
grid->addWidget(manacostLabel1, row, 0);
|
||||
grid->addWidget(manacostLabel2, row++, 1);
|
||||
grid->addWidget(colorLabel1, row, 0);
|
||||
grid->addWidget(colorLabel2, row++, 1);
|
||||
grid->addWidget(cardtypeLabel1, row, 0);
|
||||
grid->addWidget(cardtypeLabel2, row++, 1);
|
||||
grid->addWidget(powtoughLabel1, row, 0);
|
||||
grid->addWidget(powtoughLabel2, row++, 1);
|
||||
grid->addWidget(loyaltyLabel1, row, 0);
|
||||
grid->addWidget(loyaltyLabel2, row++, 1);
|
||||
grid->addWidget(textLabel, row, 0, -1, 2);
|
||||
grid->setRowStretch(row, 1);
|
||||
grid->addWidget(nameLabel, 0, 0);
|
||||
grid->addWidget(textLabel, 1, 0, -1, 2);
|
||||
grid->setRowStretch(1, 1);
|
||||
grid->setColumnStretch(1, 1);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
// Reset every label which is optionally hidden
|
||||
void CardInfoText::resetLabels()
|
||||
{
|
||||
nameLabel1->show();
|
||||
nameLabel2->show();
|
||||
manacostLabel1->show();
|
||||
manacostLabel2->show();
|
||||
colorLabel1->show();
|
||||
colorLabel2->show();
|
||||
cardtypeLabel1->show();
|
||||
cardtypeLabel2->show();
|
||||
powtoughLabel1->show();
|
||||
powtoughLabel2->show();
|
||||
loyaltyLabel1->show();
|
||||
loyaltyLabel2->show();
|
||||
textLabel->show();
|
||||
}
|
||||
|
||||
void CardInfoText::setCard(CardInfoPtr card)
|
||||
{
|
||||
if (card) {
|
||||
resetLabels();
|
||||
nameLabel2->setText(card->getName());
|
||||
if (!card->getManaCost().isEmpty()) {
|
||||
manacostLabel2->setText(card->getManaCost());
|
||||
} else {
|
||||
manacostLabel1->hide();
|
||||
manacostLabel2->hide();
|
||||
}
|
||||
if (!card->getColors().isEmpty()) {
|
||||
colorLabel2->setText(card->getColors().join(""));
|
||||
} else {
|
||||
colorLabel2->setText("Colorless");
|
||||
}
|
||||
cardtypeLabel2->setText(card->getCardType());
|
||||
if (!card->getPowTough().isEmpty()) {
|
||||
powtoughLabel2->setText(card->getPowTough());
|
||||
} else {
|
||||
powtoughLabel1->hide();
|
||||
powtoughLabel2->hide();
|
||||
}
|
||||
if (!card->getLoyalty().isEmpty()) {
|
||||
loyaltyLabel2->setText(card->getLoyalty());
|
||||
} else {
|
||||
loyaltyLabel1->hide();
|
||||
loyaltyLabel2->hide();
|
||||
}
|
||||
textLabel->setText(card->getText());
|
||||
} else {
|
||||
nameLabel1->hide();
|
||||
nameLabel2->hide();
|
||||
manacostLabel1->hide();
|
||||
manacostLabel2->hide();
|
||||
colorLabel1->hide();
|
||||
colorLabel2->hide();
|
||||
cardtypeLabel1->hide();
|
||||
cardtypeLabel2->hide();
|
||||
powtoughLabel1->hide();
|
||||
powtoughLabel2->hide();
|
||||
loyaltyLabel1->hide();
|
||||
loyaltyLabel2->hide();
|
||||
textLabel->hide();
|
||||
if (card == nullptr) {
|
||||
nameLabel->setText("");
|
||||
textLabel->setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
QString text = "<table width=\"100%\" border=0 cellspacing=0 cellpadding=0>";
|
||||
text += QString("<tr><td>%1</td><td width=\"5\"></td><td>%2</td></tr>")
|
||||
.arg(tr("Name:"), card->getName().toHtmlEscaped());
|
||||
|
||||
QStringList cardProps = card->getProperties();
|
||||
foreach (QString key, cardProps) {
|
||||
QString keyText = Mtg::getNicePropertyName(key).toHtmlEscaped() + ":";
|
||||
text +=
|
||||
QString("<tr><td>%1</td><td></td><td>%2</td></tr>").arg(keyText, card->getProperty(key).toHtmlEscaped());
|
||||
}
|
||||
|
||||
auto relatedCards = card->getRelatedCards();
|
||||
auto reverserelatedCards2Me = card->getReverseRelatedCards2Me();
|
||||
if (relatedCards.size() || reverserelatedCards2Me.size()) {
|
||||
text += QString("<tr><td>%1</td><td width=\"5\"></td><td>").arg(tr("Related cards:"));
|
||||
|
||||
for (int i = 0; i < relatedCards.size(); ++i) {
|
||||
QString tmp = relatedCards.at(i)->getName().toHtmlEscaped();
|
||||
text += "<a href=\"" + tmp + "\">" + tmp + "</a><br>";
|
||||
}
|
||||
|
||||
for (int i = 0; i < reverserelatedCards2Me.size(); ++i) {
|
||||
QString tmp = reverserelatedCards2Me.at(i)->getName().toHtmlEscaped();
|
||||
text += "<a href=\"" + tmp + "\">" + tmp + "</a><br>";
|
||||
}
|
||||
|
||||
text += "</td></tr>";
|
||||
}
|
||||
|
||||
text += "</table>";
|
||||
nameLabel->setText(text);
|
||||
textLabel->setText(card->getText());
|
||||
}
|
||||
|
||||
void CardInfoText::setInvalidCardName(const QString &cardName)
|
||||
{
|
||||
nameLabel1->setText(tr("Unknown card:"));
|
||||
nameLabel1->show();
|
||||
nameLabel2->setText(cardName);
|
||||
nameLabel2->show();
|
||||
nameLabel->setText(tr("Unknown card:") + " " + cardName);
|
||||
textLabel->setText("");
|
||||
}
|
||||
|
||||
void CardInfoText::retranslateUi()
|
||||
{
|
||||
nameLabel1->setText(tr("Name:"));
|
||||
manacostLabel1->setText(tr("Mana cost:"));
|
||||
colorLabel1->setText(tr("Color(s):"));
|
||||
cardtypeLabel1->setText(tr("Card type:"));
|
||||
powtoughLabel1->setText(tr("P / T:"));
|
||||
loyaltyLabel1->setText(tr("Loyalty:"));
|
||||
/*
|
||||
* There's no way we can really translate the text currently being rendered.
|
||||
* The best we can do is invalidate the current text.
|
||||
*/
|
||||
setInvalidCardName("");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue