Reintroduce ability to display unused mana symbol widgets. (#5726)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-03-15 20:11:46 +01:00 committed by GitHub
parent 1851f71850
commit a407c8b956
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 9 deletions

View file

@ -1,5 +1,6 @@
#include "color_identity_widget.h" #include "color_identity_widget.h"
#include "../../../../../settings/cache_settings.h"
#include "mana_symbol_widget.h" #include "mana_symbol_widget.h"
#include <QHBoxLayout> #include <QHBoxLayout>
@ -17,18 +18,21 @@ ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, CardInfoPtr _card) : Q
layout->setAlignment(Qt::AlignCenter); // Ensure icons are centered layout->setAlignment(Qt::AlignCenter); // Ensure icons are centered
setLayout(layout); setLayout(layout);
// Define the full WUBRG set (White, Blue, Black, Red, Green)
QString fullColorIdentity = "WUBRG";
if (card) { if (card) {
QString manaCost = card->getColors(); // Get mana cost string manaCost = card->getColors(); // Get mana cost string
QStringList symbols = parseColorIdentity(manaCost); // Parse mana cost string QStringList symbols = parseColorIdentity(manaCost); // Parse mana cost string
for (const QString &symbol : symbols) { populateManaSymbolWidgets();
ManaSymbolWidget *manaSymbol = new ManaSymbolWidget(this, symbol, true);
layout->addWidget(manaSymbol);
}
} }
connect(&SettingsCache::instance(), &SettingsCache::visualDeckStorageDrawUnusedColorIdentitiesChanged, this,
&ColorIdentityWidget::toggleUnusedVisibility);
} }
ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, QString manaCost) : QWidget(parent), card(nullptr) ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, QString _manaCost)
: QWidget(parent), card(nullptr), manaCost(_manaCost)
{ {
layout = new QHBoxLayout(this); layout = new QHBoxLayout(this);
layout->setSpacing(5); // Small spacing between icons layout->setSpacing(5); // Small spacing between icons
@ -36,14 +40,43 @@ ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, QString manaCost) : QW
layout->setAlignment(Qt::AlignCenter); // Ensure icons are centered layout->setAlignment(Qt::AlignCenter); // Ensure icons are centered
setLayout(layout); setLayout(layout);
populateManaSymbolWidgets();
connect(&SettingsCache::instance(), &SettingsCache::visualDeckStorageDrawUnusedColorIdentitiesChanged, this,
&ColorIdentityWidget::toggleUnusedVisibility);
}
void ColorIdentityWidget::populateManaSymbolWidgets()
{
// Define the full WUBRG set (White, Blue, Black, Red, Green)
QString fullColorIdentity = "WUBRG";
QStringList symbols = parseColorIdentity(manaCost); // Parse mana cost string QStringList symbols = parseColorIdentity(manaCost); // Parse mana cost string
for (const QString &symbol : symbols) { if (SettingsCache::instance().getVisualDeckStorageDrawUnusedColorIdentities()) {
ManaSymbolWidget *manaSymbol = new ManaSymbolWidget(this, symbol); for (const QString symbol : fullColorIdentity) {
layout->addWidget(manaSymbol); auto *manaSymbol = new ManaSymbolWidget(this, symbol, symbols.contains(symbol));
layout->addWidget(manaSymbol);
}
} else {
for (const QString &symbol : symbols) {
auto *manaSymbol = new ManaSymbolWidget(this, symbol, symbols.contains(symbol));
layout->addWidget(manaSymbol);
}
} }
} }
void ColorIdentityWidget::toggleUnusedVisibility()
{
if (layout != nullptr) {
QLayoutItem *item;
while ((item = layout->takeAt(0)) != nullptr) {
item->widget()->deleteLater(); // Delete the widget
delete item; // Delete the layout item
}
}
populateManaSymbolWidgets();
}
void ColorIdentityWidget::resizeEvent(QResizeEvent *event) void ColorIdentityWidget::resizeEvent(QResizeEvent *event)
{ {
QWidget::resizeEvent(event); QWidget::resizeEvent(event);

View file

@ -12,13 +12,17 @@ class ColorIdentityWidget : public QWidget
public: public:
explicit ColorIdentityWidget(QWidget *parent, CardInfoPtr card); explicit ColorIdentityWidget(QWidget *parent, CardInfoPtr card);
explicit ColorIdentityWidget(QWidget *parent, QString manaCost); explicit ColorIdentityWidget(QWidget *parent, QString manaCost);
void populateManaSymbolWidgets();
QStringList parseColorIdentity(const QString &manaString); QStringList parseColorIdentity(const QString &manaString);
public slots: public slots:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void toggleUnusedVisibility();
private: private:
CardInfoPtr card; CardInfoPtr card;
QString manaCost;
QHBoxLayout *layout; QHBoxLayout *layout;
}; };