Add BannerCard to .cod format, use it in the visual deck storage widget.

This commit is contained in:
Lukas Brübach 2024-12-17 20:55:47 +01:00
parent 48bcd0a6ec
commit 0d24e5d081
5 changed files with 106 additions and 61 deletions

View file

@ -25,6 +25,7 @@
#include <QApplication>
#include <QClipboard>
#include <QCloseEvent>
#include <QComboBox>
#include <QDesktopServices>
#include <QDir>
#include <QDockWidget>
@ -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<QString> bannerCardSet;
InnerDecklistNode *listRoot = deckModel->getDeckList()->getRoot();
for (int i = 0; i < listRoot->size(); i++) {
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
for (int j = 0; j < currentZone->size(); j++) {
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(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);

View file

@ -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 &current, const QModelIndex &previous);
void updateCardInfoRight(const QModelIndex &current, const QModelIndex &previous);
@ -129,6 +132,8 @@ private:
LineEditUnfocusable *nameEdit;
QLabel *commentsLabel;
QTextEdit *commentsEdit;
QLabel *bannerCardLabel;
QComboBox *bannerCardComboBox;
QLabel *hashLabel1;
LineEditUnfocusable *hashLabel;
FilterTreeModel *filterModel;

View file

@ -17,6 +17,7 @@
#include <QAction>
#include <QDebug>
#include <QDirIterator>
#include <QFileSystemModel>
#include <QHBoxLayout>
#include <QInputDialog>
@ -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<InnerDecklistNode *>(listRoot->at(i));
for (int j = 0; j < currentZone->size(); j++) {
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(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.
}

View file

@ -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);

View file

@ -250,7 +250,7 @@ class DeckList : public QObject
{
Q_OBJECT
private:
QString name, comments;
QString name, comments, bannerCard;
QString deckHash;
QMap<QString, SideboardPlan *> 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<MoveCard_ToZone> getCurrentSideboardPlan();
void setCurrentSideboardPlan(const QList<MoveCard_ToZone> &plan);
const QMap<QString, SideboardPlan *> &getSideboardPlans() const