From 3b3f5a639c1216cae8178347f095f751cdcf853d Mon Sep 17 00:00:00 2001 From: Bers Date: Tue, 15 May 2018 07:53:53 +0200 Subject: [PATCH] Hide non-existent card values in infowidget and cardframe (#3239) --- cockatrice/src/cardinfotext.cpp | 74 ++++++++++++++++++++++++++----- cockatrice/src/cardinfotext.h | 3 ++ cockatrice/src/cardinfowidget.cpp | 2 + 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/cockatrice/src/cardinfotext.cpp b/cockatrice/src/cardinfotext.cpp index 8ee3d727..9f315751 100644 --- a/cockatrice/src/cardinfotext.cpp +++ b/cockatrice/src/cardinfotext.cpp @@ -54,28 +54,78 @@ CardInfoText::CardInfoText(QWidget *parent) : QFrame(parent), info(nullptr) 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()); - manacostLabel2->setText(card->getManaCost()); - colorLabel2->setText(card->getColors().join("")); + 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()); - powtoughLabel2->setText(card->getPowTough()); - loyaltyLabel2->setText(card->getLoyalty()); + 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 { - nameLabel2->setText(""); - manacostLabel2->setText(""); - colorLabel2->setText(""); - cardtypeLabel2->setText(""); - powtoughLabel2->setText(""); - loyaltyLabel2->setText(""); - textLabel->setText(""); + 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(); } } +void CardInfoText::setInvalidCardName(const QString &cardName) +{ + nameLabel1->setText(tr("Unknown card:")); + nameLabel1->show(); + nameLabel2->setText(cardName); + nameLabel2->show(); +} + void CardInfoText::retranslateUi() { nameLabel1->setText(tr("Name:")); diff --git a/cockatrice/src/cardinfotext.h b/cockatrice/src/cardinfotext.h index 140d48b2..49445c09 100644 --- a/cockatrice/src/cardinfotext.h +++ b/cockatrice/src/cardinfotext.h @@ -22,9 +22,12 @@ private: CardInfoPtr info; + void resetLabels(); + public: CardInfoText(QWidget *parent = 0); void retranslateUi(); + void setInvalidCardName(const QString &cardName); public slots: void setCard(CardInfoPtr card); diff --git a/cockatrice/src/cardinfowidget.cpp b/cockatrice/src/cardinfowidget.cpp index 86377990..170540df 100644 --- a/cockatrice/src/cardinfowidget.cpp +++ b/cockatrice/src/cardinfowidget.cpp @@ -52,6 +52,8 @@ void CardInfoWidget::setCard(CardInfoPtr card) void CardInfoWidget::setCard(const QString &cardName) { setCard(db->getCardBySimpleName(cardName)); + if (!info) + text->setInvalidCardName(cardName); } void CardInfoWidget::setCard(AbstractCardItem *card)