[DeckEditor] Show card counts in Visual Deck Editor banners (#7339)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-09-23 19:19:30 +02:00 • committed by GitHub
parent 7a41dfe175
commit 71ef36374d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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;