mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 17:02:15 -07:00
Add the option to define the banner card in the VDS directly.
This commit is contained in:
parent
a15175eb3f
commit
309678caaf
2 changed files with 119 additions and 3 deletions
|
|
@ -38,6 +38,15 @@ DeckPreviewWidget::DeckPreviewWidget(QWidget *_parent,
|
||||||
layout->addWidget(bannerCardDisplayWidget);
|
layout->addWidget(bannerCardDisplayWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckPreviewWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
if (bannerCardDisplayWidget == nullptr || bannerCardComboBox == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bannerCardComboBox->setMaximumWidth(bannerCardDisplayWidget->width());
|
||||||
|
}
|
||||||
|
|
||||||
void DeckPreviewWidget::initializeUi(const bool deckLoadSuccess)
|
void DeckPreviewWidget::initializeUi(const bool deckLoadSuccess)
|
||||||
{
|
{
|
||||||
if (!deckLoadSuccess) {
|
if (!deckLoadSuccess) {
|
||||||
|
|
@ -56,10 +65,26 @@ void DeckPreviewWidget::initializeUi(const bool deckLoadSuccess)
|
||||||
|
|
||||||
colorIdentityWidget = new DeckPreviewColorIdentityWidget(this, getColorIdentity());
|
colorIdentityWidget = new DeckPreviewColorIdentityWidget(this, getColorIdentity());
|
||||||
deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckLoader);
|
deckTagsDisplayWidget = new DeckPreviewDeckTagsDisplayWidget(this, deckLoader);
|
||||||
|
|
||||||
|
bannerCardLabel = new QLabel();
|
||||||
|
bannerCardLabel->setObjectName("bannerCardLabel");
|
||||||
|
bannerCardLabel->setText(tr("Banner Card"));
|
||||||
|
bannerCardComboBox = new QComboBox(this);
|
||||||
|
bannerCardComboBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||||
|
bannerCardComboBox->setObjectName("bannerCardComboBox");
|
||||||
|
bannerCardComboBox->setCurrentText(deckLoader->getBannerCard().first);
|
||||||
|
bannerCardComboBox->installEventFilter(new NoScrollFilter());
|
||||||
|
connect(bannerCardComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||||
|
&DeckPreviewWidget::setBannerCard);
|
||||||
|
|
||||||
updateTagsVisibility(SettingsCache::instance().getVisualDeckStorageShowTagsOnDeckPreviews());
|
updateTagsVisibility(SettingsCache::instance().getVisualDeckStorageShowTagsOnDeckPreviews());
|
||||||
|
|
||||||
|
updateBannerCardComboBox();
|
||||||
|
|
||||||
layout->addWidget(colorIdentityWidget);
|
layout->addWidget(colorIdentityWidget);
|
||||||
layout->addWidget(deckTagsDisplayWidget);
|
layout->addWidget(deckTagsDisplayWidget);
|
||||||
|
layout->addWidget(bannerCardLabel);
|
||||||
|
layout->addWidget(bannerCardComboBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckPreviewWidget::updateVisibility()
|
void DeckPreviewWidget::updateVisibility()
|
||||||
|
|
@ -133,6 +158,79 @@ void DeckPreviewWidget::refreshBannerCardText()
|
||||||
deckLoader->getName().isEmpty() ? QFileInfo(deckLoader->getLastFileName()).fileName() : deckLoader->getName());
|
deckLoader->getName().isEmpty() ? QFileInfo(deckLoader->getLastFileName()).fileName() : deckLoader->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckPreviewWidget::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<QPair<QString, QString>> bannerCardSet;
|
||||||
|
InnerDecklistNode *listRoot = deckLoader->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()->getCardByNameAndProviderId(
|
||||||
|
currentCard->getName(), currentCard->getCardProviderId());
|
||||||
|
if (info) {
|
||||||
|
bannerCardSet.insert(
|
||||||
|
QPair<QString, QString>(currentCard->getName(), currentCard->getCardProviderId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QPair<QString, QString>> pairList = bannerCardSet.values();
|
||||||
|
|
||||||
|
// Sort QList by the first() element of the QPair
|
||||||
|
std::sort(pairList.begin(), pairList.end(), [](const QPair<QString, QString> &a, const QPair<QString, QString> &b) {
|
||||||
|
return a.first.toLower() < b.first.toLower();
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const auto &pair : pairList) {
|
||||||
|
QVariantMap dataMap;
|
||||||
|
dataMap["name"] = pair.first;
|
||||||
|
dataMap["uuid"] = pair.second;
|
||||||
|
|
||||||
|
bannerCardComboBox->addItem(pair.first, dataMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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(deckLoader->getBannerCard().first);
|
||||||
|
if (bannerIndex != -1) {
|
||||||
|
bannerCardComboBox->setCurrentIndex(bannerIndex);
|
||||||
|
} else {
|
||||||
|
bannerCardComboBox->insertItem(0, "-");
|
||||||
|
bannerCardComboBox->setCurrentIndex(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore the previous signal blocking state
|
||||||
|
bannerCardComboBox->blockSignals(wasBlocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckPreviewWidget::setBannerCard(int /* changedIndex */)
|
||||||
|
{
|
||||||
|
QVariantMap itemData = bannerCardComboBox->itemData(bannerCardComboBox->currentIndex()).toMap();
|
||||||
|
deckLoader->setBannerCard(QPair<QString, QString>(itemData["name"].toString(), itemData["uuid"].toString()));
|
||||||
|
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
void DeckPreviewWidget::imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
void DeckPreviewWidget::imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||||
{
|
{
|
||||||
Q_UNUSED(instance);
|
Q_UNUSED(instance);
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ public:
|
||||||
QVBoxLayout *layout;
|
QVBoxLayout *layout;
|
||||||
QString filePath;
|
QString filePath;
|
||||||
DeckLoader *deckLoader;
|
DeckLoader *deckLoader;
|
||||||
DeckPreviewCardPictureWidget *bannerCardDisplayWidget;
|
DeckPreviewCardPictureWidget *bannerCardDisplayWidget = nullptr;
|
||||||
DeckPreviewColorIdentityWidget *colorIdentityWidget;
|
DeckPreviewColorIdentityWidget *colorIdentityWidget = nullptr;
|
||||||
DeckPreviewDeckTagsDisplayWidget *deckTagsDisplayWidget;
|
DeckPreviewDeckTagsDisplayWidget *deckTagsDisplayWidget = nullptr;
|
||||||
|
QLabel *bannerCardLabel = nullptr;
|
||||||
|
QComboBox *bannerCardComboBox = nullptr;
|
||||||
bool filteredBySearch = false;
|
bool filteredBySearch = false;
|
||||||
bool filteredByColor = false;
|
bool filteredByColor = false;
|
||||||
bool filteredByTags = false;
|
bool filteredByTags = false;
|
||||||
|
|
@ -41,11 +43,27 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
void setFilePath(const QString &filePath);
|
void setFilePath(const QString &filePath);
|
||||||
void refreshBannerCardText();
|
void refreshBannerCardText();
|
||||||
|
void updateBannerCardComboBox();
|
||||||
|
void setBannerCard(int);
|
||||||
void imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
void imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||||
void imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
void imageDoubleClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance);
|
||||||
void initializeUi(bool deckLoadSuccess);
|
void initializeUi(bool deckLoadSuccess);
|
||||||
void updateVisibility();
|
void updateVisibility();
|
||||||
void updateTagsVisibility(bool visible);
|
void updateTagsVisibility(bool visible);
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class NoScrollFilter : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event) override
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::Wheel) {
|
||||||
|
return true; // Blocks the event
|
||||||
|
}
|
||||||
|
return QObject::eventFilter(obj, event);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DECK_PREVIEW_WIDGET_H
|
#endif // DECK_PREVIEW_WIDGET_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue