diff --git a/cockatrice/src/client/tabs/tab_deck_editor.cpp b/cockatrice/src/client/tabs/tab_deck_editor.cpp index a10dc91f3..5cbab1eb2 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/tab_deck_editor.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -94,6 +95,15 @@ void TabDeckEditor::createDeckDock() commentsEdit->setObjectName("commentsEdit"); commentsLabel->setBuddy(commentsEdit); connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments())); + bannerCardLabel = new QLabel(); + bannerCardLabel->setObjectName("bannerCardLabel"); + bannerCardLabel->setText(tr("Banner Card")); + bannerCardComboBox = new QComboBox(this); + connect(deckModel, &DeckListModel::dataChanged, this, [this]() { + // Delay the update to avoid race conditions + QTimer::singleShot(100, this, &TabDeckEditor::updateBannerCardComboBox); + }); + connect(bannerCardComboBox, &QComboBox::currentIndexChanged, this, &TabDeckEditor::setBannerCard); aIncrement = new QAction(QString(), this); aIncrement->setIcon(QPixmap("theme:icons/increment")); @@ -121,6 +131,9 @@ void TabDeckEditor::createDeckDock() upperLayout->addWidget(commentsLabel, 1, 0); upperLayout->addWidget(commentsEdit, 1, 1); + upperLayout->addWidget(bannerCardLabel, 2, 0); + upperLayout->addWidget(bannerCardComboBox, 2, 1); + hashLabel1 = new QLabel(); hashLabel1->setObjectName("hashLabel1"); auto *hashSizePolicy = new QSizePolicy(); @@ -794,6 +807,68 @@ void TabDeckEditor::updateComments() setSaveStatus(true); } +void TabDeckEditor::updateBannerCardComboBox() +{ + // Store the current text of the combo box + QString currentText = bannerCardComboBox->currentText(); + + // Block signals temporarily + bool wasBlocked = bannerCardComboBox->blockSignals(true); + + // Clear the existing items in the combo box + bannerCardComboBox->clear(); + + // Prepare the new items with deduplication + QSet bannerCardSet; + InnerDecklistNode *listRoot = deckModel->getDeckList()->getRoot(); + for (int i = 0; i < listRoot->size(); i++) { + InnerDecklistNode *currentZone = dynamic_cast(listRoot->at(i)); + for (int j = 0; j < currentZone->size(); j++) { + DecklistCardNode *currentCard = dynamic_cast(currentZone->at(j)); + if (!currentCard) + continue; + + for (int k = 0; k < currentCard->getNumber(); ++k) { + CardInfoPtr info = CardDatabaseManager::getInstance()->getCard(currentCard->getName()); + if (info) { + bannerCardSet.insert(currentCard->getName()); + } + } + } + } + + // Convert the QSet to a sorted QStringList + QStringList bannerCardChoices = QStringList(bannerCardSet.begin(), bannerCardSet.end()); + bannerCardChoices.sort(Qt::CaseInsensitive); + + // Populate the combo box with new items + bannerCardComboBox->addItems(bannerCardChoices); + + // Try to restore the previous selection by finding the currentText + int restoredIndex = bannerCardComboBox->findText(currentText); + if (restoredIndex != -1) { + bannerCardComboBox->setCurrentIndex(restoredIndex); + } else { + // Add a placeholder "-" and set it as the current selection + int bannerIndex = bannerCardComboBox->findText(deckModel->getDeckList()->getBannerCard()); + if (bannerIndex != -1) { + bannerCardComboBox->setCurrentIndex(bannerIndex); + } else { + bannerCardComboBox->insertItem(0, "-"); + bannerCardComboBox->setCurrentIndex(0); + } + } + + // Restore the previous signal blocking state + bannerCardComboBox->blockSignals(wasBlocked); +} + +void TabDeckEditor::setBannerCard() +{ + qDebug() << "Banner card was set to: " << bannerCardComboBox->currentText(); + deckModel->getDeckList()->setBannerCard(bannerCardComboBox->currentText()); +} + void TabDeckEditor::updateCardInfo(CardInfoPtr _card) { cardInfo->setCard(_card); @@ -968,6 +1043,11 @@ void TabDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLocation d } } else { delete l; + updateBannerCardComboBox(); + if (!l->getBannerCard().isEmpty()) { + qDebug() << "Found banner card:" << l->getBannerCard(); + bannerCardComboBox->setCurrentIndex(bannerCardComboBox->findText(l->getBannerCard())); + } QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(fileName)); } setSaveStatus(true); diff --git a/cockatrice/src/client/tabs/tab_deck_editor.h b/cockatrice/src/client/tabs/tab_deck_editor.h index 14f96a73c..7352c57cc 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.h +++ b/cockatrice/src/client/tabs/tab_deck_editor.h @@ -22,6 +22,7 @@ class DeckLoader; class Response; class FilterTreeModel; class FilterBuilder; +class QComboBox; class QGroupBox; class QMessageBox; class QHBoxLayout; @@ -35,6 +36,8 @@ class TabDeckEditor : public Tab private slots: void updateName(const QString &name); void updateComments(); + void updateBannerCardComboBox(); + void setBannerCard(); void updateHash(); void updateCardInfoLeft(const QModelIndex ¤t, const QModelIndex &previous); void updateCardInfoRight(const QModelIndex ¤t, const QModelIndex &previous); @@ -129,6 +132,8 @@ private: LineEditUnfocusable *nameEdit; QLabel *commentsLabel; QTextEdit *commentsEdit; + QLabel *bannerCardLabel; + QComboBox *bannerCardComboBox; QLabel *hashLabel1; LineEditUnfocusable *hashLabel; FilterTreeModel *filterModel; diff --git a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp index d3b19233a..3226d00e4 100644 --- a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp +++ b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -83,68 +84,18 @@ QStringList TabDeckStorageVisual::getBannerCardsForDecks() allFiles << it.next(); // Add each file path to the list } - auto deck_loader = new DeckLoader(); foreach (const QString &file, allFiles) { qDebug() << file; + auto deck_loader = new DeckLoader(); deck_loader->loadFromFile(file, DeckLoader::CockatriceFormat); deck_list_model->setDeckList(new DeckLoader(*deck_loader)); - InnerDecklistNode *listRoot = deck_list_model->getDeckList()->getRoot(); - - bool shouldExitOuterLoop = false; // Flag to indicate if we should exit the outer loop - for (int i = 0; i < listRoot->size(); i++) { - InnerDecklistNode *currentZone = dynamic_cast(listRoot->at(i)); - - for (int j = 0; j < currentZone->size(); j++) { - DecklistCardNode *currentCard = dynamic_cast(currentZone->at(j)); - if (!currentCard) - continue; - - for (int k = 0; k < currentCard->getNumber(); ++k) { - CardInfoPtr info = CardDatabaseManager::getInstance()->getCard(currentCard->getName()); - if (info) { - if (info->getCardType().contains("Legendary Creature")) { - //qDebug() << currentCard->getName(); - //qDebug() << info->getCmc(); - //qDebug() << info->getProperties(); - //qDebug() << info->getCardType(); - - CardInfoPerSetMap setMap = info->getSets(); - OverlapWidget *printings_group_widget = - new OverlapWidget(this, 80, 0, 0, Qt::Orientation::Vertical); - for (auto set : setMap) { - // qDebug() << set.getPtr()->getLongName(); - CardInfoPtr set_info = CardDatabaseManager::getInstance()->getCardByNameAndProviderId( - currentCard->getName(), set.getProperty("uuid")); - CardInfoPictureWithTextOverlayWidget * display = new CardInfoPictureWithTextOverlayWidget(printings_group_widget, true); - display->setCard(set_info); - display->setOverlayText(deck_loader->getName()); - display->setFontSize(24); - printings_group_widget->addWidget(display); - } - flow_widget->addWidget(printings_group_widget); - - //db->getPreferredPrintingForCard(info->getName()); - - //PictureLoader::getCardBackPixmap(); - - shouldExitOuterLoop = true; // Set the flag to exit the outer loop - break; // Break the innermost loop - } - } else { - //qDebug() << "Card not found in database!"; - } - - // emit newCardAdded(newCard); - } - if (shouldExitOuterLoop) { - break; // Break the middle loop if flag is set - } - } - if (shouldExitOuterLoop) { - break; // Break the outer loop if flag is set - } - } + CardInfoPictureWithTextOverlayWidget *display = new CardInfoPictureWithTextOverlayWidget(flow_widget, true); + qDebug() << "Banner card is: " << deck_loader->getBannerCard(); + display->setCard(CardDatabaseManager::getInstance()->getCard(deck_loader->getBannerCard())); + display->setOverlayText(deck_loader->getName()); + display->setFontSize(24); + flow_widget->addWidget(display); } return QStringList("lol"); @@ -181,6 +132,4 @@ void TabDeckStorageVisual::actDeleteLocalDeck() void TabDeckStorageVisual::cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus) { qDebug() << "Card update process finished with exit code:" << exitCode << "and exit status:" << exitStatus; - - // You can add any additional logic you need here. } diff --git a/common/decklist.cpp b/common/decklist.cpp index 08b98a730..53b52b5e1 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -423,7 +423,9 @@ bool DeckList::readElement(QXmlStreamReader *xml) name = xml->readElementText(); else if (childName == "comments") comments = xml->readElementText(); - else if (childName == "zone") { + else if (childName == "bannerCard") { + bannerCard = xml->readElementText(); + } else if (childName == "zone") { InnerDecklistNode *newZone = getZoneObjFromName(xml->attributes().value("name").toString()); newZone->readElement(xml); } else if (childName == "sideboard_plan") { @@ -444,6 +446,7 @@ void DeckList::write(QXmlStreamWriter *xml) xml->writeAttribute("version", "1"); xml->writeTextElement("deckname", name); xml->writeTextElement("comments", comments); + xml->writeTextElement("bannerCard", bannerCard); for (int i = 0; i < root->size(); i++) root->at(i)->writeElement(xml); diff --git a/common/decklist.h b/common/decklist.h index 87596a884..e6e5dad15 100644 --- a/common/decklist.h +++ b/common/decklist.h @@ -250,7 +250,7 @@ class DeckList : public QObject { Q_OBJECT private: - QString name, comments; + QString name, comments, bannerCard; QString deckHash; QMap sideboardPlans; InnerDecklistNode *root; @@ -279,6 +279,10 @@ public slots: { comments = _comments; } + void setBannerCard(const QString &_bannerCard = QString()) + { + bannerCard = _bannerCard; + } public: explicit DeckList(); @@ -293,6 +297,10 @@ public: { return comments; } + QString getBannerCard() const + { + return bannerCard; + } QList getCurrentSideboardPlan(); void setCurrentSideboardPlan(const QList &plan); const QMap &getSideboardPlans() const