mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 08:52:15 -07:00
Add BannerCard to .cod format, use it in the visual deck storage widget.
This commit is contained in:
parent
48bcd0a6ec
commit
0d24e5d081
5 changed files with 106 additions and 61 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
|
#include <QComboBox>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
|
|
@ -94,6 +95,15 @@ void TabDeckEditor::createDeckDock()
|
||||||
commentsEdit->setObjectName("commentsEdit");
|
commentsEdit->setObjectName("commentsEdit");
|
||||||
commentsLabel->setBuddy(commentsEdit);
|
commentsLabel->setBuddy(commentsEdit);
|
||||||
connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments()));
|
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 = new QAction(QString(), this);
|
||||||
aIncrement->setIcon(QPixmap("theme:icons/increment"));
|
aIncrement->setIcon(QPixmap("theme:icons/increment"));
|
||||||
|
|
@ -121,6 +131,9 @@ void TabDeckEditor::createDeckDock()
|
||||||
upperLayout->addWidget(commentsLabel, 1, 0);
|
upperLayout->addWidget(commentsLabel, 1, 0);
|
||||||
upperLayout->addWidget(commentsEdit, 1, 1);
|
upperLayout->addWidget(commentsEdit, 1, 1);
|
||||||
|
|
||||||
|
upperLayout->addWidget(bannerCardLabel, 2, 0);
|
||||||
|
upperLayout->addWidget(bannerCardComboBox, 2, 1);
|
||||||
|
|
||||||
hashLabel1 = new QLabel();
|
hashLabel1 = new QLabel();
|
||||||
hashLabel1->setObjectName("hashLabel1");
|
hashLabel1->setObjectName("hashLabel1");
|
||||||
auto *hashSizePolicy = new QSizePolicy();
|
auto *hashSizePolicy = new QSizePolicy();
|
||||||
|
|
@ -794,6 +807,68 @@ void TabDeckEditor::updateComments()
|
||||||
setSaveStatus(true);
|
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)
|
void TabDeckEditor::updateCardInfo(CardInfoPtr _card)
|
||||||
{
|
{
|
||||||
cardInfo->setCard(_card);
|
cardInfo->setCard(_card);
|
||||||
|
|
@ -968,6 +1043,11 @@ void TabDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLocation d
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
delete l;
|
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));
|
QMessageBox::critical(this, tr("Error"), tr("Could not open deck at %1").arg(fileName));
|
||||||
}
|
}
|
||||||
setSaveStatus(true);
|
setSaveStatus(true);
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ class DeckLoader;
|
||||||
class Response;
|
class Response;
|
||||||
class FilterTreeModel;
|
class FilterTreeModel;
|
||||||
class FilterBuilder;
|
class FilterBuilder;
|
||||||
|
class QComboBox;
|
||||||
class QGroupBox;
|
class QGroupBox;
|
||||||
class QMessageBox;
|
class QMessageBox;
|
||||||
class QHBoxLayout;
|
class QHBoxLayout;
|
||||||
|
|
@ -35,6 +36,8 @@ class TabDeckEditor : public Tab
|
||||||
private slots:
|
private slots:
|
||||||
void updateName(const QString &name);
|
void updateName(const QString &name);
|
||||||
void updateComments();
|
void updateComments();
|
||||||
|
void updateBannerCardComboBox();
|
||||||
|
void setBannerCard();
|
||||||
void updateHash();
|
void updateHash();
|
||||||
void updateCardInfoLeft(const QModelIndex ¤t, const QModelIndex &previous);
|
void updateCardInfoLeft(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void updateCardInfoRight(const QModelIndex ¤t, const QModelIndex &previous);
|
void updateCardInfoRight(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
|
|
@ -129,6 +132,8 @@ private:
|
||||||
LineEditUnfocusable *nameEdit;
|
LineEditUnfocusable *nameEdit;
|
||||||
QLabel *commentsLabel;
|
QLabel *commentsLabel;
|
||||||
QTextEdit *commentsEdit;
|
QTextEdit *commentsEdit;
|
||||||
|
QLabel *bannerCardLabel;
|
||||||
|
QComboBox *bannerCardComboBox;
|
||||||
QLabel *hashLabel1;
|
QLabel *hashLabel1;
|
||||||
LineEditUnfocusable *hashLabel;
|
LineEditUnfocusable *hashLabel;
|
||||||
FilterTreeModel *filterModel;
|
FilterTreeModel *filterModel;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDirIterator>
|
||||||
#include <QFileSystemModel>
|
#include <QFileSystemModel>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
|
@ -83,68 +84,18 @@ QStringList TabDeckStorageVisual::getBannerCardsForDecks()
|
||||||
allFiles << it.next(); // Add each file path to the list
|
allFiles << it.next(); // Add each file path to the list
|
||||||
}
|
}
|
||||||
|
|
||||||
auto deck_loader = new DeckLoader();
|
|
||||||
foreach (const QString &file, allFiles) {
|
foreach (const QString &file, allFiles) {
|
||||||
qDebug() << file;
|
qDebug() << file;
|
||||||
|
auto deck_loader = new DeckLoader();
|
||||||
deck_loader->loadFromFile(file, DeckLoader::CockatriceFormat);
|
deck_loader->loadFromFile(file, DeckLoader::CockatriceFormat);
|
||||||
deck_list_model->setDeckList(new DeckLoader(*deck_loader));
|
deck_list_model->setDeckList(new DeckLoader(*deck_loader));
|
||||||
|
|
||||||
InnerDecklistNode *listRoot = deck_list_model->getDeckList()->getRoot();
|
CardInfoPictureWithTextOverlayWidget *display = new CardInfoPictureWithTextOverlayWidget(flow_widget, true);
|
||||||
|
qDebug() << "Banner card is: " << deck_loader->getBannerCard();
|
||||||
bool shouldExitOuterLoop = false; // Flag to indicate if we should exit the outer loop
|
display->setCard(CardDatabaseManager::getInstance()->getCard(deck_loader->getBannerCard()));
|
||||||
for (int i = 0; i < listRoot->size(); i++) {
|
display->setOverlayText(deck_loader->getName());
|
||||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
display->setFontSize(24);
|
||||||
|
flow_widget->addWidget(display);
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QStringList("lol");
|
return QStringList("lol");
|
||||||
|
|
@ -181,6 +132,4 @@ void TabDeckStorageVisual::actDeleteLocalDeck()
|
||||||
void TabDeckStorageVisual::cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
void TabDeckStorageVisual::cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||||
{
|
{
|
||||||
qDebug() << "Card update process finished with exit code:" << exitCode << "and exit status:" << exitStatus;
|
qDebug() << "Card update process finished with exit code:" << exitCode << "and exit status:" << exitStatus;
|
||||||
|
|
||||||
// You can add any additional logic you need here.
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -423,7 +423,9 @@ bool DeckList::readElement(QXmlStreamReader *xml)
|
||||||
name = xml->readElementText();
|
name = xml->readElementText();
|
||||||
else if (childName == "comments")
|
else if (childName == "comments")
|
||||||
comments = xml->readElementText();
|
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());
|
InnerDecklistNode *newZone = getZoneObjFromName(xml->attributes().value("name").toString());
|
||||||
newZone->readElement(xml);
|
newZone->readElement(xml);
|
||||||
} else if (childName == "sideboard_plan") {
|
} else if (childName == "sideboard_plan") {
|
||||||
|
|
@ -444,6 +446,7 @@ void DeckList::write(QXmlStreamWriter *xml)
|
||||||
xml->writeAttribute("version", "1");
|
xml->writeAttribute("version", "1");
|
||||||
xml->writeTextElement("deckname", name);
|
xml->writeTextElement("deckname", name);
|
||||||
xml->writeTextElement("comments", comments);
|
xml->writeTextElement("comments", comments);
|
||||||
|
xml->writeTextElement("bannerCard", bannerCard);
|
||||||
|
|
||||||
for (int i = 0; i < root->size(); i++)
|
for (int i = 0; i < root->size(); i++)
|
||||||
root->at(i)->writeElement(xml);
|
root->at(i)->writeElement(xml);
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,7 @@ class DeckList : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString name, comments;
|
QString name, comments, bannerCard;
|
||||||
QString deckHash;
|
QString deckHash;
|
||||||
QMap<QString, SideboardPlan *> sideboardPlans;
|
QMap<QString, SideboardPlan *> sideboardPlans;
|
||||||
InnerDecklistNode *root;
|
InnerDecklistNode *root;
|
||||||
|
|
@ -279,6 +279,10 @@ public slots:
|
||||||
{
|
{
|
||||||
comments = _comments;
|
comments = _comments;
|
||||||
}
|
}
|
||||||
|
void setBannerCard(const QString &_bannerCard = QString())
|
||||||
|
{
|
||||||
|
bannerCard = _bannerCard;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeckList();
|
explicit DeckList();
|
||||||
|
|
@ -293,6 +297,10 @@ public:
|
||||||
{
|
{
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
QString getBannerCard() const
|
||||||
|
{
|
||||||
|
return bannerCard;
|
||||||
|
}
|
||||||
QList<MoveCard_ToZone> getCurrentSideboardPlan();
|
QList<MoveCard_ToZone> getCurrentSideboardPlan();
|
||||||
void setCurrentSideboardPlan(const QList<MoveCard_ToZone> &plan);
|
void setCurrentSideboardPlan(const QList<MoveCard_ToZone> &plan);
|
||||||
const QMap<QString, SideboardPlan *> &getSideboardPlans() const
|
const QMap<QString, SideboardPlan *> &getSideboardPlans() const
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue