[DeckEditor] Show card counts in Visual Deck Editor banners

This commit is contained in:
Lukas Brübach 2026-09-21 14:21:20 +02:00
parent 7a2492ac67
commit 709650c85a
10 changed files with 108 additions and 13 deletions

View file

@ -1,11 +1,13 @@
#include "card_group_display_widget.h"
#include "../../../../client/settings/cache_settings.h"
#include "../card_info_picture_with_text_overlay_widget.h"
#include <QResizeEvent>
#include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/models/deck_list/deck_list_model.h>
#include <libcockatrice/models/deck_list/deck_list_sort_filter_proxy_model.h>
#include <libcockatrice/settings/cards_display_settings.h>
CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
DeckListModel *_deckListModel,
@ -30,6 +32,7 @@ CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
layout->addWidget(banner);
CardGroupDisplayWidget::updateCardDisplays();
updateCardCount();
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &CardGroupDisplayWidget::onCardAddition);
if (selectionModel) {
@ -38,6 +41,11 @@ CardGroupDisplayWidget::CardGroupDisplayWidget(QWidget *parent,
}
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::onCardRemoval);
connect(deckListModel, &QAbstractItemModel::dataChanged, this, &CardGroupDisplayWidget::onDataChanged);
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &CardGroupDisplayWidget::updateCardCount);
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &CardGroupDisplayWidget::updateCardCount);
connect(deckListModel, &QAbstractItemModel::dataChanged, this, &CardGroupDisplayWidget::updateCardCount);
connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::visualDeckEditorShowCardCountsChanged,
this, &CardGroupDisplayWidget::updateCardCount);
}
// Just here so it can get overwritten in subclasses.
@ -348,4 +356,22 @@ void CardGroupDisplayWidget::onActiveSortCriteriaChanged(QStringList _activeSort
clearAllDisplayWidgets();
updateCardDisplays();
}
}
void CardGroupDisplayWidget::updateCardCount()
{
if (!banner || !deckListModel || !trackedIndex.isValid()) {
return;
}
QString text = cardGroupCategory;
if (SettingsCache::instance().cardsDisplay().getVisualDeckEditorShowCardCounts()) {
int total = 0;
for (int i = 0; i < deckListModel->rowCount(trackedIndex); ++i) {
total +=
deckListModel->index(i, DeckListModelColumns::CARD_AMOUNT, trackedIndex).data(Qt::EditRole).toInt();
}
text += QStringLiteral(" (%1)").arg(total);
}
banner->setText(text);
}

View file

@ -55,6 +55,7 @@ public slots:
virtual void onCardRemoval(const QModelIndex &parent, int first, int last);
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void onActiveSortCriteriaChanged(QStringList activeSortCriteria);
void updateCardCount();
void resizeEvent(QResizeEvent *event) override;
signals:

View file

@ -1,8 +1,10 @@
#include "deck_card_zone_display_widget.h"
#include "../../../client/settings/cache_settings.h"
#include "card_group_display_widgets/flat_card_group_display_widget.h"
#include "card_group_display_widgets/overlapped_card_group_display_widget.h"
#include "libcockatrice/card/database/card_database_manager.h"
#include "libcockatrice/settings/cards_display_settings.h"
#include <QResizeEvent>
#include <algorithm>
@ -39,6 +41,7 @@ DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
banner->setBuddy(cardGroupContainer);
displayCards();
updateZoneCardCount();
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &DeckCardZoneDisplayWidget::onCategoryAddition);
if (selectionModel) {
@ -46,6 +49,11 @@ DeckCardZoneDisplayWidget::DeckCardZoneDisplayWidget(QWidget *parent,
&DeckCardZoneDisplayWidget::onSelectionChanged);
}
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &DeckCardZoneDisplayWidget::onCategoryRemoval);
connect(deckListModel, &QAbstractItemModel::rowsInserted, this, &DeckCardZoneDisplayWidget::updateZoneCardCount);
connect(deckListModel, &QAbstractItemModel::rowsRemoved, this, &DeckCardZoneDisplayWidget::updateZoneCardCount);
connect(deckListModel, &QAbstractItemModel::dataChanged, this, &DeckCardZoneDisplayWidget::updateZoneCardCount);
connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::visualDeckEditorShowCardCountsChanged,
this, &DeckCardZoneDisplayWidget::updateZoneCardCount);
}
// =====================================================================================================================
@ -245,3 +253,21 @@ QList<QString> DeckCardZoneDisplayWidget::getGroupCriteriaValueList()
return groupCriteriaValues;
}
void DeckCardZoneDisplayWidget::updateZoneCardCount()
{
if (!banner || !deckListModel) {
return;
}
QString text = zoneName;
if (SettingsCache::instance().cardsDisplay().getVisualDeckEditorShowCardCounts()) {
int total = 0;
const auto cardNodes = deckListModel->getCardNodesForZone(zoneName);
for (const auto *node : cardNodes) {
total += node->getNumber();
}
text += QStringLiteral(" (%1)").arg(total);
}
banner->setText(text);
}

View file

@ -52,6 +52,7 @@ public slots:
QList<QString> getGroupCriteriaValueList();
void onCategoryAddition(const QModelIndex &parent, int first, int last);
void onCategoryRemoval(const QModelIndex &parent, int first, int last);
void updateZoneCardCount();
signals:
void cardClicked(QMouseEvent *event, const ExactCard &card, const QString &zoneName);

View file

@ -149,6 +149,11 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
connect(&openDeckInNewTabCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance().deckEditor(),
&DeckEditorSettings::setOpenDeckInNewTab);
visualDeckEditorShowCardCountsCheckBox.setChecked(
SettingsCache::instance().cardsDisplay().getVisualDeckEditorShowCardCounts());
connect(&visualDeckEditorShowCardCountsCheckBox, &QCheckBox::QT_STATE_CHANGED,
&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::setVisualDeckEditorShowCardCounts);
visualDeckStorageInGameCheckBox.setChecked(
SettingsCache::instance().visualDeckStorage().getVisualDeckStorageInGame());
connect(&visualDeckStorageInGameCheckBox, &QCheckBox::QT_STATE_CHANGED,
@ -244,18 +249,19 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
auto *deckEditorGrid = new QGridLayout;
deckEditorGrid->addWidget(&openDeckInNewTabCheckBox, 0, 0);
deckEditorGrid->addWidget(&visualDeckStorageInGameCheckBox, 1, 0);
deckEditorGrid->addWidget(&visualDeckStorageSelectionAnimationCheckBox, 2, 0);
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionLabel, 3, 0);
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionSelector, 3, 1);
deckEditorGrid->addWidget(&defaultDeckEditorTypeLabel, 4, 0);
deckEditorGrid->addWidget(&defaultDeckEditorTypeSelector, 4, 1);
deckEditorGrid->addWidget(&vdeStartupTabLabel, 5, 0);
deckEditorGrid->addWidget(&vdeStartupTabSelector, 5, 1);
deckEditorGrid->addWidget(&commanderSpellbookIntegrationEnabledLabel, 6, 0);
deckEditorGrid->addWidget(&commanderSpellbookIntegrationEnabledSelector, 6, 1);
deckEditorGrid->addWidget(labelWidget, 7, 0);
deckEditorGrid->addWidget(&commanderSpellbookIntegrationBracketNamingSelector, 7, 1);
deckEditorGrid->addWidget(&visualDeckEditorShowCardCountsCheckBox, 1, 0);
deckEditorGrid->addWidget(&visualDeckStorageInGameCheckBox, 2, 0);
deckEditorGrid->addWidget(&visualDeckStorageSelectionAnimationCheckBox, 3, 0);
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionLabel, 4, 0);
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionSelector, 4, 1);
deckEditorGrid->addWidget(&defaultDeckEditorTypeLabel, 5, 0);
deckEditorGrid->addWidget(&defaultDeckEditorTypeSelector, 5, 1);
deckEditorGrid->addWidget(&vdeStartupTabLabel, 6, 0);
deckEditorGrid->addWidget(&vdeStartupTabSelector, 6, 1);
deckEditorGrid->addWidget(&commanderSpellbookIntegrationEnabledLabel, 7, 0);
deckEditorGrid->addWidget(&commanderSpellbookIntegrationEnabledSelector, 7, 1);
deckEditorGrid->addWidget(labelWidget, 8, 0);
deckEditorGrid->addWidget(&commanderSpellbookIntegrationBracketNamingSelector, 8, 1);
deckEditorGroupBox = new QGroupBox;
deckEditorGroupBox->setLayout(deckEditorGrid);
@ -367,6 +373,7 @@ void UserInterfaceSettingsPage::retranslateUi()
deckEditorGroupBox->setTitle(tr("Deck editor/storage settings"));
openDeckInNewTabCheckBox.setText(tr("Open deck in new tab by default"));
visualDeckEditorShowCardCountsCheckBox.setText(tr("Show card counts in Visual Deck Editor"));
visualDeckStorageInGameCheckBox.setText(tr("Use visual deck storage in game lobby"));
visualDeckStorageSelectionAnimationCheckBox.setText(tr("Use selection animation for Visual Deck Storage"));
visualDeckStoragePromptForConversionLabel.setText(

View file

@ -51,6 +51,7 @@ private:
QComboBox visualDeckStoragePromptForConversionSelector;
QCheckBox visualDeckStorageInGameCheckBox;
QCheckBox visualDeckStorageSelectionAnimationCheckBox;
QCheckBox visualDeckEditorShowCardCountsCheckBox;
QLabel defaultDeckEditorTypeLabel;
QComboBox defaultDeckEditorTypeSelector;
QLabel vdeStartupTabLabel;

View file

@ -25,6 +25,7 @@ public:
[[nodiscard]] virtual int getVisualDeckStorageCardSize() const = 0;
[[nodiscard]] virtual int getVisualDatabaseDisplayCardSize() const = 0;
[[nodiscard]] virtual int getVisualDeckEditorCardSize() const = 0;
[[nodiscard]] virtual bool getVisualDeckEditorShowCardCounts() const = 0;
[[nodiscard]] virtual int getEDHRecCardSize() const = 0;
[[nodiscard]] virtual int getArchidektPreviewSize() const = 0;
[[nodiscard]] virtual int getSampleHandSize() const = 0;

View file

@ -90,6 +90,11 @@ int CardsDisplaySettings::getVisualDeckEditorCardSize() const
return getValue("visualDeckEditor", "cards", "cardSize", 100).toInt();
}
bool CardsDisplaySettings::getVisualDeckEditorShowCardCounts() const
{
return getValue("visualDeckEditorShowCardCounts", QString(), QString(), true).toBool();
}
int CardsDisplaySettings::getEDHRecCardSize() const
{
return getValue("edhrec", "cards", "cardSize", 100).toInt();
@ -217,6 +222,15 @@ void CardsDisplaySettings::setVisualDeckEditorCardSize(int _cardSize)
emit visualDeckEditorCardSizeChanged();
}
void CardsDisplaySettings::setVisualDeckEditorShowCardCounts(bool _showCardCounts)
{
if (_showCardCounts == getVisualDeckEditorShowCardCounts()) {
return;
}
setValue(_showCardCounts, "visualDeckEditorShowCardCounts");
emit visualDeckEditorShowCardCountsChanged(_showCardCounts);
}
void CardsDisplaySettings::setEDHRecCardSize(int _edhrecCardSize)
{
setValue(_edhrecCardSize, "edhrec", "cards", "cardSize");

View file

@ -29,6 +29,7 @@ public:
[[nodiscard]] int getVisualDeckStorageCardSize() const override;
[[nodiscard]] int getVisualDatabaseDisplayCardSize() const override;
[[nodiscard]] int getVisualDeckEditorCardSize() const override;
[[nodiscard]] bool getVisualDeckEditorShowCardCounts() const override;
[[nodiscard]] int getEDHRecCardSize() const override;
[[nodiscard]] int getArchidektPreviewSize() const override;
[[nodiscard]] int getSampleHandSize() const override;
@ -52,6 +53,7 @@ public:
void setVisualDeckStorageCardSize(int _cardSize);
void setVisualDatabaseDisplayCardSize(int _cardSize);
void setVisualDeckEditorCardSize(int _cardSize);
void setVisualDeckEditorShowCardCounts(bool _showCardCounts);
void setEDHRecCardSize(int _edhrecCardSize);
void setArchidektPreviewCardSize(int _archidektPreviewCardSize);
void setSampleHandSize(int _sampleHandSize);
@ -70,6 +72,7 @@ signals:
void visualDeckStorageCardSizeChanged();
void visualDatabaseDisplayCardSizeChanged();
void visualDeckEditorCardSizeChanged();
void visualDeckEditorShowCardCountsChanged(bool showCardCounts);
void edhRecCardSizeChanged();
void archidektPreviewSizeChanged();
void sampleHandSizeChanged(int amount);

View file

@ -538,6 +538,21 @@ TEST_F(SettingsDefaultsTest, CardsDisplay_VisualDeckEditorCardSize_Default)
ASSERT_EQ(s.getVisualDeckEditorCardSize(), 100);
}
TEST_F(SettingsDefaultsTest, CardsDisplay_VisualDeckEditorShowCardCounts_Default)
{
CardsDisplaySettings s(settingsPath, nullptr);
ASSERT_EQ(s.getVisualDeckEditorShowCardCounts(), true);
}
TEST_F(SettingsDefaultsTest, CardsDisplay_VisualDeckEditorShowCardCounts_SetAndGet)
{
CardsDisplaySettings s(settingsPath, nullptr);
s.setVisualDeckEditorShowCardCounts(false);
ASSERT_EQ(s.getVisualDeckEditorShowCardCounts(), false);
s.setVisualDeckEditorShowCardCounts(true);
ASSERT_EQ(s.getVisualDeckEditorShowCardCounts(), true);
}
TEST_F(SettingsDefaultsTest, CardsDisplay_EDHRecCardSize_Default)
{
CardsDisplaySettings s(settingsPath, nullptr);