From b18bae5e05c7b5d4c61a32f7f8708154eebc14b4 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Fri, 15 May 2026 20:49:59 -0400 Subject: [PATCH 01/11] Add subtype breakdown counter for card selection Display a categorized count of creature subtypes (and other card type subtypes) when multiple cards are selected. The breakdown appears above the total selection counter in the bottom-right corner. Subtypes are grouped by main card type and sorted by frequency, with the most common subtypes positioned adjacent to the total count for quick reference. The feature can be toggled via a new checkbox in Settings > User Interface. --- .../src/client/settings/cache_settings.cpp | 7 + .../src/client/settings/cache_settings.h | 6 + cockatrice/src/game_graphics/game_view.cpp | 207 ++++++++++++++++-- cockatrice/src/game_graphics/game_view.h | 6 +- cockatrice/src/interface/theme_manager.cpp | 3 + .../user_interface_settings_page.cpp | 8 +- .../user_interface_settings_page.h | 1 + 7 files changed, 216 insertions(+), 22 deletions(-) diff --git a/cockatrice/src/client/settings/cache_settings.cpp b/cockatrice/src/client/settings/cache_settings.cpp index 64416e5ee..c4096ceeb 100644 --- a/cockatrice/src/client/settings/cache_settings.cpp +++ b/cockatrice/src/client/settings/cache_settings.cpp @@ -312,6 +312,7 @@ SettingsCache::SettingsCache() showDragSelectionCount = settings->value("interface/showlassoselectioncount", true).toBool(); showTotalSelectionCount = settings->value("interface/showpersistentselectioncount", true).toBool(); + showSubtypeSelectionCount = settings->value("interface/showsubtypeselectioncount", true).toBool(); showShortcuts = settings->value("menu/showshortcuts", true).toBool(); showGameSelectorFilterToolbar = settings->value("menu/showgameselectorfiltertoolbar", true).toBool(); @@ -1372,6 +1373,12 @@ void SettingsCache::setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSele settings->setValue("interface/showpersistentselectioncount", showTotalSelectionCount); } +void SettingsCache::setShowSubtypeSelectionCount(QT_STATE_CHANGED_T _showSubtypeSelectionCount) +{ + showSubtypeSelectionCount = static_cast(_showSubtypeSelectionCount); + settings->setValue("interface/showsubtypeselectioncount", showSubtypeSelectionCount); +} + void SettingsCache::loadPaths() { QString dataPath = getDataPath(); diff --git a/cockatrice/src/client/settings/cache_settings.h b/cockatrice/src/client/settings/cache_settings.h index b1197e267..72e1af32f 100644 --- a/cockatrice/src/client/settings/cache_settings.h +++ b/cockatrice/src/client/settings/cache_settings.h @@ -349,6 +349,7 @@ private: bool showStatusBar; bool showDragSelectionCount; bool showTotalSelectionCount; + bool showSubtypeSelectionCount; public: SettingsCache(); @@ -472,6 +473,10 @@ public: { return showTotalSelectionCount; } + [[nodiscard]] bool getShowSubtypeSelectionCount() const + { + return showSubtypeSelectionCount; + } [[nodiscard]] bool getNotificationsEnabled() const { return notificationsEnabled; @@ -1155,5 +1160,6 @@ public slots: void setRoundCardCorners(bool _roundCardCorners); void setShowDragSelectionCount(QT_STATE_CHANGED_T _showDragSelectionCount); void setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSelectionCount); + void setShowSubtypeSelectionCount(QT_STATE_CHANGED_T _showSubtypeSelectionCount); }; #endif diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index 4ba41cffb..d0dd1774b 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -1,12 +1,15 @@ #include "game_view.h" #include "../client/settings/cache_settings.h" +#include "board/card_item.h" #include "game_scene.h" #include #include +#include #include #include +#include // QRubberBand calls raise() in showEvent() and changeEvent() to stay on top of siblings. // This subclass disables that behavior so dragCountLabel can appear above it. @@ -42,7 +45,7 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par connect(scene, &GameScene::sigStartRubberBand, this, &GameView::startRubberBand); connect(scene, &GameScene::sigResizeRubberBand, this, &GameView::resizeRubberBand); connect(scene, &GameScene::sigStopRubberBand, this, &GameView::stopRubberBand); - connect(scene, &QGraphicsScene::selectionChanged, this, [this]() { updateTotalSelectionCount(); }); + connect(scene, &QGraphicsScene::selectionChanged, this, [this]() { updateSelectionCount(); }); aCloseMostRecentZoneView = new QAction(this); @@ -53,21 +56,30 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par refreshShortcuts(); rubberBand = new SelectionRubberBand(QRubberBand::Rectangle, this); - const QString countLabelStyle = "color: white; " - "font-size: 14px; " - "font-weight: bold; " - "background-color: rgba(0, 0, 0, 160); " - "border-radius: 3px; " - "padding: 1px 2px;"; + const QString baseProperties = "color: white; " + "font-family: monospace; " + "background-color: rgba(0, 0, 0, 160); " + "border-radius: 3px; " + "padding: 1px 2px; " + "white-space: pre;"; + + const QString dragCountLabelStyle = baseProperties + "font-size: 14px; font-weight: bold;"; + const QString totalCountLabelStyle = baseProperties + "font-size: 16px; font-weight: bold;"; + const QString subtypeCountLabelStyle = baseProperties + "font-size: 12px;"; dragCountLabel = new QLabel(this); - dragCountLabel->setStyleSheet(countLabelStyle); + dragCountLabel->setStyleSheet(dragCountLabelStyle); dragCountLabel->hide(); dragCountLabel->raise(); totalCountLabel = new QLabel(this); - totalCountLabel->setStyleSheet(countLabelStyle); + totalCountLabel->setStyleSheet(totalCountLabelStyle); totalCountLabel->hide(); + + subtypeCountLabel = new QLabel(this); + subtypeCountLabel->setStyleSheet(subtypeCountLabelStyle); + subtypeCountLabel->setTextFormat(Qt::RichText); + subtypeCountLabel->hide(); } void GameView::resizeEvent(QResizeEvent *event) @@ -80,7 +92,7 @@ void GameView::resizeEvent(QResizeEvent *event) } updateSceneRect(scene()->sceneRect()); - updateTotalSelectionCount(event->size()); + updateSelectionCount(event->size()); } void GameView::updateSceneRect(const QRectF &rect) @@ -162,27 +174,182 @@ void GameView::refreshShortcuts() SettingsCache::instance().shortcuts().getShortcut("Player/aCloseMostRecentZoneView")); } -void GameView::updateTotalSelectionCount(const QSize &viewSize) +/** @brief Extracts subtypes from a card face type string (e.g., "Creature — Human Wizard" -> ["Human", "Wizard"]) */ +static QStringList extractSubtypesFromFace(const QString &faceType) { - if (!SettingsCache::instance().getShowTotalSelectionCount()) { - totalCountLabel->hide(); - return; + QStringList parts = faceType.split(QStringLiteral(" — ")); + if (parts.size() > 1) { + return parts[1].split(QStringLiteral(" "), Qt::SkipEmptyParts); } + return {}; +} + +QString GameView::buildSubtypeCountText() const +{ + GameScene *gameScene = dynamic_cast(scene()); + if (!gameScene) { + return QString(); + } + + // Map: main card type -> (subtype -> count) + QMap> subtypesByMainType; + // Track cards contributing subtypes per main type (for group ordering) + QMap cardCountPerMainType; + + for (CardItem *card : gameScene->selectedCards()) { + if (card->getFaceDown() || card->getCard().isEmpty()) { + continue; + } + + QString mainType = card->getCardInfo().getMainCardType(); + if (mainType.isEmpty()) { + mainType = QStringLiteral("Other"); + } + + QString cardType = card->getCardInfo().getCardType(); + QStringList cardFaces = cardType.split(QStringLiteral(" // ")); + + bool contributedSubtypes = false; + for (const QString &face : cardFaces) { + QStringList subtypes = extractSubtypesFromFace(face); + for (const QString &subtype : subtypes) { + subtypesByMainType[mainType][subtype]++; + contributedSubtypes = true; + } + } + + if (contributedSubtypes) { + cardCountPerMainType[mainType]++; + } + } + + if (subtypesByMainType.isEmpty()) { + return QString(); + } + + // Build groups with sorted subtypes + struct MainTypeGroup + { + QString mainType; + int cardCount; + QList> subtypes; + }; + + QList groups; + for (auto it = subtypesByMainType.constBegin(); it != subtypesByMainType.constEnd(); ++it) { + MainTypeGroup group; + group.mainType = it.key(); + group.cardCount = cardCountPerMainType.value(it.key(), 0); + + for (auto subIt = it.value().constBegin(); subIt != it.value().constEnd(); ++subIt) { + group.subtypes.append({subIt.key(), subIt.value()}); + } + + /** + * Sort subtypes: by count ascending (lower counts at top of the list), then alphabetically. + * Since the subtype list displays above the total count label (bottom-right corner), + * ascending order places the most common subtypes visually adjacent to the total. + */ + std::sort(group.subtypes.begin(), group.subtypes.end(), + [](const QPair &a, const QPair &b) { + if (a.second != b.second) { + return a.second < b.second; + } + return a.first < b.first; + }); + + groups.append(group); + } + + // Sort groups: by card count ascending, then alphabetically by main type + std::sort(groups.begin(), groups.end(), [](const MainTypeGroup &a, const MainTypeGroup &b) { + if (a.cardCount != b.cardCount) { + return a.cardCount < b.cardCount; + } + return a.mainType < b.mainType; + }); + + // Flatten to final ordered list + QList> sortedEntries; + for (const MainTypeGroup &group : groups) { + for (const auto &entry : group.subtypes) { + sortedEntries.append(entry); + } + } + + // Calculate padding widths + int maxNameLen = 0; + int maxCountLen = 0; + for (const auto &entry : sortedEntries) { + maxNameLen = qMax(maxNameLen, entry.first.length()); + maxCountLen = qMax(maxCountLen, QString::number(entry.second).length()); + } + + // Format output + QStringList lines; + for (const auto &entry : sortedEntries) { + QString name = entry.first.toHtmlEscaped(); + QString count = QString::number(entry.second); + + QString namePadding = QString(QStringLiteral(" ")).repeated(maxNameLen - entry.first.length()); + QString countPadding = QString(QStringLiteral(" ")).repeated(maxCountLen - count.length()); + + lines << QStringLiteral( + "%1%2 %3%4") + .arg(namePadding, name, countPadding, count); + } + + return lines.join(QStringLiteral("
")); +} + +void GameView::updateSelectionCount(const QSize &viewSize) +{ + constexpr int kMarginInPixels = 10; + constexpr int kSpacingBetweenLabels = 4; + + int availableWidth = viewSize.isValid() ? viewSize.width() : viewport()->width(); + int availableHeight = viewSize.isValid() ? viewSize.height() : viewport()->height(); int count = scene()->selectedItems().count(); - if (count > 1) { + if (!SettingsCache::instance().getShowTotalSelectionCount() || count <= 1) { + totalCountLabel->hide(); + } else { totalCountLabel->setText(QString::number(count)); totalCountLabel->adjustSize(); - constexpr int kMarginInPixels = 10; - int availableWidth = viewSize.isValid() ? viewSize.width() : viewport()->width(); - int availableHeight = viewSize.isValid() ? viewSize.height() : viewport()->height(); int x = availableWidth - totalCountLabel->width() - kMarginInPixels; int y = availableHeight - totalCountLabel->height() - kMarginInPixels; totalCountLabel->move(x, y); totalCountLabel->show(); - } else { - totalCountLabel->hide(); } + + if (!SettingsCache::instance().getShowSubtypeSelectionCount() || count <= 1) { + subtypeCountLabel->hide(); + return; + } + + QString subtypeText = buildSubtypeCountText(); + + if (subtypeText.isEmpty()) { + subtypeCountLabel->hide(); + return; + } + + subtypeCountLabel->setText(subtypeText); + subtypeCountLabel->adjustSize(); + + int x = availableWidth - subtypeCountLabel->width() - kMarginInPixels; + int y; + + if (totalCountLabel->isVisible()) { + y = totalCountLabel->y() - subtypeCountLabel->height() - kSpacingBetweenLabels; + } else { + y = availableHeight - subtypeCountLabel->height() - kMarginInPixels; + } + + y = qMax(kMarginInPixels, y); + + subtypeCountLabel->move(x, y); + subtypeCountLabel->show(); } diff --git a/cockatrice/src/game_graphics/game_view.h b/cockatrice/src/game_graphics/game_view.h index 15abad9af..fb51ce230 100644 --- a/cockatrice/src/game_graphics/game_view.h +++ b/cockatrice/src/game_graphics/game_view.h @@ -21,8 +21,12 @@ private: QRubberBand *rubberBand; QLabel *dragCountLabel; QLabel *totalCountLabel; + QLabel *subtypeCountLabel; ///< Label displaying subtype breakdown for selected cards QPointF selectionOrigin; + /** @brief Builds formatted text showing subtype counts for all selected cards */ + QString buildSubtypeCountText() const; + protected: void resizeEvent(QResizeEvent *event) override; private slots: @@ -30,7 +34,7 @@ private slots: void resizeRubberBand(const QPointF &cursorPoint, int selectedCount); void stopRubberBand(); void refreshShortcuts(); - void updateTotalSelectionCount(const QSize &viewSize = QSize()); + void updateSelectionCount(const QSize &viewSize = QSize()); public slots: void updateSceneRect(const QRectF &rect); diff --git a/cockatrice/src/interface/theme_manager.cpp b/cockatrice/src/interface/theme_manager.cpp index 086845fe6..4ba35a00e 100644 --- a/cockatrice/src/interface/theme_manager.cpp +++ b/cockatrice/src/interface/theme_manager.cpp @@ -271,6 +271,9 @@ void ThemeManager::applyStyleAndPalette(const QString &themeName, const PaletteConfig &palCfg, const QString &activeScheme) { +#if (QT_VERSION < QT_VERSION_CHECK(6, 5, 0)) + Q_UNUSED(activeScheme) +#endif QString styleName = themeCfg.styleName; if (styleName.isEmpty() || styleName.compare("Default", Qt::CaseInsensitive) == 0) { if (themeName == FUSION_THEME_NAME) { diff --git a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp index dfa736a1a..6816fc48d 100644 --- a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp +++ b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp @@ -68,6 +68,10 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() connect(&showTotalSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), &SettingsCache::setShowTotalSelectionCount); + showSubtypeSelectionCountCheckBox.setChecked(SettingsCache::instance().getShowSubtypeSelectionCount()); + connect(&showSubtypeSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), + &SettingsCache::setShowSubtypeSelectionCount); + useTearOffMenusCheckBox.setChecked(SettingsCache::instance().getUseTearOffMenus()); connect(&useTearOffMenusCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), [](const QT_STATE_CHANGED_T state) { SettingsCache::instance().setUseTearOffMenus(state == Qt::Checked); }); @@ -82,7 +86,8 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() generalGrid->addWidget(&annotateTokensCheckBox, 6, 0); generalGrid->addWidget(&showDragSelectionCountCheckBox, 7, 0); generalGrid->addWidget(&showTotalSelectionCountCheckBox, 8, 0); - generalGrid->addWidget(&useTearOffMenusCheckBox, 9, 0); + generalGrid->addWidget(&showSubtypeSelectionCountCheckBox, 9, 0); + generalGrid->addWidget(&useTearOffMenusCheckBox, 10, 0); generalGroupBox = new QGroupBox; generalGroupBox->setLayout(generalGrid); @@ -206,6 +211,7 @@ void UserInterfaceSettingsPage::retranslateUi() annotateTokensCheckBox.setText(tr("Annotate card text on tokens")); showDragSelectionCountCheckBox.setText(tr("Show selection counter during drag selection")); showTotalSelectionCountCheckBox.setText(tr("Show total selection counter")); + showSubtypeSelectionCountCheckBox.setText(tr("Show subtype breakdown in selection counter")); useTearOffMenusCheckBox.setText(tr("Use tear-off menus, allowing right click menus to persist on screen")); notificationsGroupBox->setTitle(tr("Notifications settings")); notificationsEnabledCheckBox.setText(tr("Enable notifications in taskbar")); diff --git a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h index 6dd43ceae..fb8e9ff57 100644 --- a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h +++ b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h @@ -29,6 +29,7 @@ private: QCheckBox annotateTokensCheckBox; QCheckBox showDragSelectionCountCheckBox; QCheckBox showTotalSelectionCountCheckBox; + QCheckBox showSubtypeSelectionCountCheckBox; QCheckBox useTearOffMenusCheckBox; QCheckBox tapAnimationCheckBox; QCheckBox openDeckInNewTabCheckBox; From 20c8bc1c1eb98c76a41fe62f209446541df5c6b8 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Sat, 23 May 2026 23:18:38 -0400 Subject: [PATCH 02/11] Alignment fix --- cockatrice/src/game_graphics/game_view.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index d0dd1774b..e546e6863 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -299,7 +299,8 @@ QString GameView::buildSubtypeCountText() const .arg(namePadding, name, countPadding, count); } - return lines.join(QStringLiteral("
")); + return QStringLiteral("") + lines.join(QStringLiteral("
")) + + QStringLiteral("
"); } void GameView::updateSelectionCount(const QSize &viewSize) From c947808547fd54d0e479b4fc4702a18e61d45e23 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Sun, 24 May 2026 01:08:38 -0400 Subject: [PATCH 03/11] Computation logic moved to helper funtction in separate file --- cockatrice/CMakeLists.txt | 1 + .../src/game/selection_subtype_counter.cpp | 129 ++++++++++++++++++ .../src/game/selection_subtype_counter.h | 31 +++++ cockatrice/src/game_graphics/game_view.cpp | 126 +---------------- 4 files changed, 163 insertions(+), 124 deletions(-) create mode 100644 cockatrice/src/game/selection_subtype_counter.cpp create mode 100644 cockatrice/src/game/selection_subtype_counter.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index bd99d08bf..bc2833b58 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -82,6 +82,7 @@ set(cockatrice_SOURCES src/game_graphics/game_scene.cpp src/game/game_state.cpp src/game_graphics/game_view.cpp + src/game/selection_subtype_counter.cpp src/game_graphics/hand_counter.cpp src/game_graphics/log/message_log_widget.cpp src/game/phase.cpp diff --git a/cockatrice/src/game/selection_subtype_counter.cpp b/cockatrice/src/game/selection_subtype_counter.cpp new file mode 100644 index 000000000..b30f9438b --- /dev/null +++ b/cockatrice/src/game/selection_subtype_counter.cpp @@ -0,0 +1,129 @@ +#include "selection_subtype_counter.h" + +#include "board/card_item.h" + +#include +#include + +namespace SelectionSubtypeCounter +{ + +QStringList extractSubtypesFromFace(const QString &faceType) +{ + QStringList parts = faceType.split(QStringLiteral(" — ")); + if (parts.size() > 1) { + return parts[1].split(QStringLiteral(" "), Qt::SkipEmptyParts); + } + return {}; +} + +QList countSubtypes(const QList &cards) +{ + QMap> subtypesByMainType; + QMap cardCountPerMainType; + + for (CardItem *card : cards) { + if (card->getFaceDown() || card->getCard().isEmpty()) { + continue; + } + + QString mainType = card->getCardInfo().getMainCardType(); + if (mainType.isEmpty()) { + mainType = QStringLiteral("Other"); + } + + QString cardType = card->getCardInfo().getCardType(); + QStringList cardFaces = cardType.split(QStringLiteral(" // ")); + + bool contributedSubtypes = false; + for (const QString &face : cardFaces) { + QStringList subtypes = extractSubtypesFromFace(face); + for (const QString &subtype : subtypes) { + subtypesByMainType[mainType][subtype]++; + contributedSubtypes = true; + } + } + + if (contributedSubtypes) { + cardCountPerMainType[mainType]++; + } + } + + QList groups; + for (auto it = subtypesByMainType.constBegin(); it != subtypesByMainType.constEnd(); ++it) { + MainTypeGroup group; + group.mainType = it.key(); + group.cardCount = cardCountPerMainType.value(it.key(), 0); + + for (auto subIt = it.value().constBegin(); subIt != it.value().constEnd(); ++subIt) { + group.subtypes.append({subIt.key(), subIt.value()}); + } + + // Sort subtypes: by count ascending, then alphabetically + std::sort(group.subtypes.begin(), group.subtypes.end(), [](const SubtypeEntry &a, const SubtypeEntry &b) { + if (a.count != b.count) { + return a.count < b.count; + } + return a.name < b.name; + }); + + groups.append(group); + } + + // Sort groups: by card count ascending, then alphabetically by main type + std::sort(groups.begin(), groups.end(), [](const MainTypeGroup &a, const MainTypeGroup &b) { + if (a.cardCount != b.cardCount) { + return a.cardCount < b.cardCount; + } + return a.mainType < b.mainType; + }); + + return groups; +} + +QString formatAsHtml(const QList &groups) +{ + // Flatten to final ordered list + QList sortedEntries; + for (const MainTypeGroup &group : groups) { + for (const auto &entry : group.subtypes) { + sortedEntries.append(entry); + } + } + + // Calculate padding widths + int maxNameLen = 0; + int maxCountLen = 0; + for (const auto &entry : sortedEntries) { + maxNameLen = qMax(maxNameLen, entry.name.length()); + maxCountLen = qMax(maxCountLen, QString::number(entry.count).length()); + } + + // Format output + QStringList lines; + for (const auto &entry : sortedEntries) { + QString name = entry.name.toHtmlEscaped(); + QString count = QString::number(entry.count); + + QString namePadding = QString(QStringLiteral(" ")).repeated(maxNameLen - entry.name.length()); + QString countPadding = QString(QStringLiteral(" ")).repeated(maxCountLen - count.length()); + + lines << QStringLiteral( + "%1%2 %3%4") + .arg(namePadding, name, countPadding, count); + } + + return QStringLiteral("") + lines.join(QStringLiteral("
")) + + QStringLiteral("
"); +} + +QString buildSubtypeCountText(const QList &cards) +{ + QList groups = countSubtypes(cards); + if (groups.isEmpty()) { + return QString(); + } + return formatAsHtml(groups); +} + +} // namespace SelectionSubtypeCounter diff --git a/cockatrice/src/game/selection_subtype_counter.h b/cockatrice/src/game/selection_subtype_counter.h new file mode 100644 index 000000000..08dc389a7 --- /dev/null +++ b/cockatrice/src/game/selection_subtype_counter.h @@ -0,0 +1,31 @@ +#ifndef SELECTION_SUBTYPE_COUNTER_H +#define SELECTION_SUBTYPE_COUNTER_H + +#include +#include +#include + +class CardItem; + +struct SubtypeEntry +{ + QString name; + int count; +}; + +struct MainTypeGroup +{ + QString mainType; + int cardCount; + QList subtypes; +}; + +namespace SelectionSubtypeCounter +{ +QStringList extractSubtypesFromFace(const QString &faceType); +QList countSubtypes(const QList &cards); +QString formatAsHtml(const QList &groups); +QString buildSubtypeCountText(const QList &cards); +} // namespace SelectionSubtypeCounter + +#endif diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index e546e6863..83ee92099 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -1,15 +1,13 @@ #include "game_view.h" #include "../client/settings/cache_settings.h" -#include "board/card_item.h" #include "game_scene.h" +#include "selection_subtype_counter.h" #include #include -#include #include #include -#include // QRubberBand calls raise() in showEvent() and changeEvent() to stay on top of siblings. // This subclass disables that behavior so dragCountLabel can appear above it. @@ -174,133 +172,13 @@ void GameView::refreshShortcuts() SettingsCache::instance().shortcuts().getShortcut("Player/aCloseMostRecentZoneView")); } -/** @brief Extracts subtypes from a card face type string (e.g., "Creature — Human Wizard" -> ["Human", "Wizard"]) */ -static QStringList extractSubtypesFromFace(const QString &faceType) -{ - QStringList parts = faceType.split(QStringLiteral(" — ")); - if (parts.size() > 1) { - return parts[1].split(QStringLiteral(" "), Qt::SkipEmptyParts); - } - return {}; -} - QString GameView::buildSubtypeCountText() const { GameScene *gameScene = dynamic_cast(scene()); if (!gameScene) { return QString(); } - - // Map: main card type -> (subtype -> count) - QMap> subtypesByMainType; - // Track cards contributing subtypes per main type (for group ordering) - QMap cardCountPerMainType; - - for (CardItem *card : gameScene->selectedCards()) { - if (card->getFaceDown() || card->getCard().isEmpty()) { - continue; - } - - QString mainType = card->getCardInfo().getMainCardType(); - if (mainType.isEmpty()) { - mainType = QStringLiteral("Other"); - } - - QString cardType = card->getCardInfo().getCardType(); - QStringList cardFaces = cardType.split(QStringLiteral(" // ")); - - bool contributedSubtypes = false; - for (const QString &face : cardFaces) { - QStringList subtypes = extractSubtypesFromFace(face); - for (const QString &subtype : subtypes) { - subtypesByMainType[mainType][subtype]++; - contributedSubtypes = true; - } - } - - if (contributedSubtypes) { - cardCountPerMainType[mainType]++; - } - } - - if (subtypesByMainType.isEmpty()) { - return QString(); - } - - // Build groups with sorted subtypes - struct MainTypeGroup - { - QString mainType; - int cardCount; - QList> subtypes; - }; - - QList groups; - for (auto it = subtypesByMainType.constBegin(); it != subtypesByMainType.constEnd(); ++it) { - MainTypeGroup group; - group.mainType = it.key(); - group.cardCount = cardCountPerMainType.value(it.key(), 0); - - for (auto subIt = it.value().constBegin(); subIt != it.value().constEnd(); ++subIt) { - group.subtypes.append({subIt.key(), subIt.value()}); - } - - /** - * Sort subtypes: by count ascending (lower counts at top of the list), then alphabetically. - * Since the subtype list displays above the total count label (bottom-right corner), - * ascending order places the most common subtypes visually adjacent to the total. - */ - std::sort(group.subtypes.begin(), group.subtypes.end(), - [](const QPair &a, const QPair &b) { - if (a.second != b.second) { - return a.second < b.second; - } - return a.first < b.first; - }); - - groups.append(group); - } - - // Sort groups: by card count ascending, then alphabetically by main type - std::sort(groups.begin(), groups.end(), [](const MainTypeGroup &a, const MainTypeGroup &b) { - if (a.cardCount != b.cardCount) { - return a.cardCount < b.cardCount; - } - return a.mainType < b.mainType; - }); - - // Flatten to final ordered list - QList> sortedEntries; - for (const MainTypeGroup &group : groups) { - for (const auto &entry : group.subtypes) { - sortedEntries.append(entry); - } - } - - // Calculate padding widths - int maxNameLen = 0; - int maxCountLen = 0; - for (const auto &entry : sortedEntries) { - maxNameLen = qMax(maxNameLen, entry.first.length()); - maxCountLen = qMax(maxCountLen, QString::number(entry.second).length()); - } - - // Format output - QStringList lines; - for (const auto &entry : sortedEntries) { - QString name = entry.first.toHtmlEscaped(); - QString count = QString::number(entry.second); - - QString namePadding = QString(QStringLiteral(" ")).repeated(maxNameLen - entry.first.length()); - QString countPadding = QString(QStringLiteral(" ")).repeated(maxCountLen - count.length()); - - lines << QStringLiteral( - "%1%2 %3%4") - .arg(namePadding, name, countPadding, count); - } - - return QStringLiteral("") + lines.join(QStringLiteral("
")) + - QStringLiteral("
"); + return SelectionSubtypeCounter::buildSubtypeCountText(gameScene->selectedCards()); } void GameView::updateSelectionCount(const QSize &viewSize) From ca6cb8fb91cf9e978a3d124fced35532e4d84ea6 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Thu, 4 Jun 2026 19:35:05 -0400 Subject: [PATCH 04/11] Rename SubtypeCounter to SubtypeTally --- cockatrice/CMakeLists.txt | 2 +- ...subtype_counter.cpp => selection_subtype_tally.cpp} | 8 ++++---- ...ion_subtype_counter.h => selection_subtype_tally.h} | 10 +++++----- cockatrice/src/game_graphics/game_view.cpp | 8 ++++---- cockatrice/src/game_graphics/game_view.h | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) rename cockatrice/src/game/{selection_subtype_counter.cpp => selection_subtype_tally.cpp} (95%) rename cockatrice/src/game/{selection_subtype_counter.h => selection_subtype_tally.h} (67%) diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index bc2833b58..9dfb81f3c 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -82,7 +82,7 @@ set(cockatrice_SOURCES src/game_graphics/game_scene.cpp src/game/game_state.cpp src/game_graphics/game_view.cpp - src/game/selection_subtype_counter.cpp + src/game/selection_subtype_tally.cpp src/game_graphics/hand_counter.cpp src/game_graphics/log/message_log_widget.cpp src/game/phase.cpp diff --git a/cockatrice/src/game/selection_subtype_counter.cpp b/cockatrice/src/game/selection_subtype_tally.cpp similarity index 95% rename from cockatrice/src/game/selection_subtype_counter.cpp rename to cockatrice/src/game/selection_subtype_tally.cpp index b30f9438b..0d83a1670 100644 --- a/cockatrice/src/game/selection_subtype_counter.cpp +++ b/cockatrice/src/game/selection_subtype_tally.cpp @@ -1,11 +1,11 @@ -#include "selection_subtype_counter.h" +#include "selection_subtype_tally.h" #include "board/card_item.h" #include #include -namespace SelectionSubtypeCounter +namespace SelectionSubtypeTally { QStringList extractSubtypesFromFace(const QString &faceType) @@ -117,7 +117,7 @@ QString formatAsHtml(const QList &groups) QStringLiteral(""); } -QString buildSubtypeCountText(const QList &cards) +QString buildSubtypeTallyText(const QList &cards) { QList groups = countSubtypes(cards); if (groups.isEmpty()) { @@ -126,4 +126,4 @@ QString buildSubtypeCountText(const QList &cards) return formatAsHtml(groups); } -} // namespace SelectionSubtypeCounter +} // namespace SelectionSubtypeTally diff --git a/cockatrice/src/game/selection_subtype_counter.h b/cockatrice/src/game/selection_subtype_tally.h similarity index 67% rename from cockatrice/src/game/selection_subtype_counter.h rename to cockatrice/src/game/selection_subtype_tally.h index 08dc389a7..3c2f2092b 100644 --- a/cockatrice/src/game/selection_subtype_counter.h +++ b/cockatrice/src/game/selection_subtype_tally.h @@ -1,5 +1,5 @@ -#ifndef SELECTION_SUBTYPE_COUNTER_H -#define SELECTION_SUBTYPE_COUNTER_H +#ifndef SELECTION_SUBTYPE_TALLY_H +#define SELECTION_SUBTYPE_TALLY_H #include #include @@ -20,12 +20,12 @@ struct MainTypeGroup QList subtypes; }; -namespace SelectionSubtypeCounter +namespace SelectionSubtypeTally { QStringList extractSubtypesFromFace(const QString &faceType); QList countSubtypes(const QList &cards); QString formatAsHtml(const QList &groups); -QString buildSubtypeCountText(const QList &cards); -} // namespace SelectionSubtypeCounter +QString buildSubtypeTallyText(const QList &cards); +} // namespace SelectionSubtypeTally #endif diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index 83ee92099..3c268db37 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -2,7 +2,7 @@ #include "../client/settings/cache_settings.h" #include "game_scene.h" -#include "selection_subtype_counter.h" +#include "selection_subtype_tally.h" #include #include @@ -172,13 +172,13 @@ void GameView::refreshShortcuts() SettingsCache::instance().shortcuts().getShortcut("Player/aCloseMostRecentZoneView")); } -QString GameView::buildSubtypeCountText() const +QString GameView::buildSubtypeTallyText() const { GameScene *gameScene = dynamic_cast(scene()); if (!gameScene) { return QString(); } - return SelectionSubtypeCounter::buildSubtypeCountText(gameScene->selectedCards()); + return SelectionSubtypeTally::buildSubtypeTallyText(gameScene->selectedCards()); } void GameView::updateSelectionCount(const QSize &viewSize) @@ -208,7 +208,7 @@ void GameView::updateSelectionCount(const QSize &viewSize) return; } - QString subtypeText = buildSubtypeCountText(); + QString subtypeText = buildSubtypeTallyText(); if (subtypeText.isEmpty()) { subtypeCountLabel->hide(); diff --git a/cockatrice/src/game_graphics/game_view.h b/cockatrice/src/game_graphics/game_view.h index fb51ce230..1d8e586b9 100644 --- a/cockatrice/src/game_graphics/game_view.h +++ b/cockatrice/src/game_graphics/game_view.h @@ -24,8 +24,8 @@ private: QLabel *subtypeCountLabel; ///< Label displaying subtype breakdown for selected cards QPointF selectionOrigin; - /** @brief Builds formatted text showing subtype counts for all selected cards */ - QString buildSubtypeCountText() const; + /** @brief Builds formatted text showing subtype tally for all selected cards */ + QString buildSubtypeTallyText() const; protected: void resizeEvent(QResizeEvent *event) override; From 11bd4f5640303610f388c71593ea6df25366f262 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Thu, 4 Jun 2026 20:29:28 -0400 Subject: [PATCH 05/11] Fix subtype tally alignment by using grid layout instead of character padding --- .../src/game/selection_subtype_tally.cpp | 52 ++---------- cockatrice/src/game/selection_subtype_tally.h | 3 - cockatrice/src/game_graphics/game_view.cpp | 82 ++++++++++++++----- cockatrice/src/game_graphics/game_view.h | 9 +- .../libcockatrice/utility/qt_utils.h | 1 + 5 files changed, 74 insertions(+), 73 deletions(-) diff --git a/cockatrice/src/game/selection_subtype_tally.cpp b/cockatrice/src/game/selection_subtype_tally.cpp index 0d83a1670..c033d42c9 100644 --- a/cockatrice/src/game/selection_subtype_tally.cpp +++ b/cockatrice/src/game/selection_subtype_tally.cpp @@ -5,7 +5,7 @@ #include #include -namespace SelectionSubtypeTally +namespace { QStringList extractSubtypesFromFace(const QString &faceType) @@ -17,6 +17,11 @@ QStringList extractSubtypesFromFace(const QString &faceType) return {}; } +} // anonymous namespace + +namespace SelectionSubtypeTally +{ + QList countSubtypes(const QList &cards) { QMap> subtypesByMainType; @@ -81,49 +86,4 @@ QList countSubtypes(const QList &cards) return groups; } -QString formatAsHtml(const QList &groups) -{ - // Flatten to final ordered list - QList sortedEntries; - for (const MainTypeGroup &group : groups) { - for (const auto &entry : group.subtypes) { - sortedEntries.append(entry); - } - } - - // Calculate padding widths - int maxNameLen = 0; - int maxCountLen = 0; - for (const auto &entry : sortedEntries) { - maxNameLen = qMax(maxNameLen, entry.name.length()); - maxCountLen = qMax(maxCountLen, QString::number(entry.count).length()); - } - - // Format output - QStringList lines; - for (const auto &entry : sortedEntries) { - QString name = entry.name.toHtmlEscaped(); - QString count = QString::number(entry.count); - - QString namePadding = QString(QStringLiteral(" ")).repeated(maxNameLen - entry.name.length()); - QString countPadding = QString(QStringLiteral(" ")).repeated(maxCountLen - count.length()); - - lines << QStringLiteral( - "%1%2 %3%4") - .arg(namePadding, name, countPadding, count); - } - - return QStringLiteral("") + lines.join(QStringLiteral("
")) + - QStringLiteral("
"); -} - -QString buildSubtypeTallyText(const QList &cards) -{ - QList groups = countSubtypes(cards); - if (groups.isEmpty()) { - return QString(); - } - return formatAsHtml(groups); -} - } // namespace SelectionSubtypeTally diff --git a/cockatrice/src/game/selection_subtype_tally.h b/cockatrice/src/game/selection_subtype_tally.h index 3c2f2092b..a5014fafe 100644 --- a/cockatrice/src/game/selection_subtype_tally.h +++ b/cockatrice/src/game/selection_subtype_tally.h @@ -22,10 +22,7 @@ struct MainTypeGroup namespace SelectionSubtypeTally { -QStringList extractSubtypesFromFace(const QString &faceType); QList countSubtypes(const QList &cards); -QString formatAsHtml(const QList &groups); -QString buildSubtypeTallyText(const QList &cards); } // namespace SelectionSubtypeTally #endif diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index 3c268db37..3822bb4a5 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -2,10 +2,13 @@ #include "../client/settings/cache_settings.h" #include "game_scene.h" +#include "libcockatrice/utility/qt_utils.h" #include "selection_subtype_tally.h" #include +#include #include +#include #include #include @@ -74,10 +77,12 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par totalCountLabel->setStyleSheet(totalCountLabelStyle); totalCountLabel->hide(); - subtypeCountLabel = new QLabel(this); - subtypeCountLabel->setStyleSheet(subtypeCountLabelStyle); - subtypeCountLabel->setTextFormat(Qt::RichText); - subtypeCountLabel->hide(); + subtypeCountContainer = new QWidget(this); + subtypeCountContainer->setStyleSheet(subtypeCountLabelStyle); + subtypeCountLayout = new QGridLayout(subtypeCountContainer); + subtypeCountLayout->setContentsMargins(2, 2, 2, 2); + subtypeCountLayout->setSpacing(2); + subtypeCountContainer->hide(); } void GameView::resizeEvent(QResizeEvent *event) @@ -172,13 +177,33 @@ void GameView::refreshShortcuts() SettingsCache::instance().shortcuts().getShortcut("Player/aCloseMostRecentZoneView")); } -QString GameView::buildSubtypeTallyText() const +void GameView::clearSubtypeLabels() { - GameScene *gameScene = dynamic_cast(scene()); - if (!gameScene) { - return QString(); + QtUtils::clearLayoutRec(subtypeCountLayout); +} + +void GameView::rebuildSubtypeLabels(const QList &entries) +{ + clearSubtypeLabels(); + + const QString nameStyle = QStringLiteral("color: white; font-size: 12px; background: transparent;"); + const QString countStyle = + QStringLiteral("color: white; font-size: 14px; font-weight: bold; background: transparent;"); + + int row = 0; + for (const SubtypeEntry &entry : entries) { + auto *nameLabel = new QLabel(entry.name, subtypeCountContainer); + nameLabel->setStyleSheet(nameStyle); + nameLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + subtypeCountLayout->addWidget(nameLabel, row, 0); + + auto *countLabel = new QLabel(QString::number(entry.count), subtypeCountContainer); + countLabel->setStyleSheet(countStyle); + countLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + subtypeCountLayout->addWidget(countLabel, row, 1); + + ++row; } - return SelectionSubtypeTally::buildSubtypeTallyText(gameScene->selectedCards()); } void GameView::updateSelectionCount(const QSize &viewSize) @@ -204,31 +229,46 @@ void GameView::updateSelectionCount(const QSize &viewSize) } if (!SettingsCache::instance().getShowSubtypeSelectionCount() || count <= 1) { - subtypeCountLabel->hide(); + subtypeCountContainer->hide(); return; } - QString subtypeText = buildSubtypeTallyText(); - - if (subtypeText.isEmpty()) { - subtypeCountLabel->hide(); + GameScene *gameScene = dynamic_cast(scene()); + if (!gameScene) { + subtypeCountContainer->hide(); return; } - subtypeCountLabel->setText(subtypeText); - subtypeCountLabel->adjustSize(); + QList groups = SelectionSubtypeTally::countSubtypes(gameScene->selectedCards()); + if (groups.isEmpty()) { + subtypeCountContainer->hide(); + return; + } - int x = availableWidth - subtypeCountLabel->width() - kMarginInPixels; + QList entries; + for (const MainTypeGroup &group : groups) { + entries.append(group.subtypes); + } + + if (entries.isEmpty()) { + subtypeCountContainer->hide(); + return; + } + + rebuildSubtypeLabels(entries); + subtypeCountContainer->adjustSize(); + + int x = availableWidth - subtypeCountContainer->width() - kMarginInPixels; int y; if (totalCountLabel->isVisible()) { - y = totalCountLabel->y() - subtypeCountLabel->height() - kSpacingBetweenLabels; + y = totalCountLabel->y() - subtypeCountContainer->height() - kSpacingBetweenLabels; } else { - y = availableHeight - subtypeCountLabel->height() - kMarginInPixels; + y = availableHeight - subtypeCountContainer->height() - kMarginInPixels; } y = qMax(kMarginInPixels, y); - subtypeCountLabel->move(x, y); - subtypeCountLabel->show(); + subtypeCountContainer->move(x, y); + subtypeCountContainer->show(); } diff --git a/cockatrice/src/game_graphics/game_view.h b/cockatrice/src/game_graphics/game_view.h index 1d8e586b9..7e9e31e2f 100644 --- a/cockatrice/src/game_graphics/game_view.h +++ b/cockatrice/src/game_graphics/game_view.h @@ -10,8 +10,10 @@ #include class GameScene; +class QGridLayout; class QLabel; class QRubberBand; +struct SubtypeEntry; class GameView : public QGraphicsView { @@ -21,11 +23,12 @@ private: QRubberBand *rubberBand; QLabel *dragCountLabel; QLabel *totalCountLabel; - QLabel *subtypeCountLabel; ///< Label displaying subtype breakdown for selected cards + QWidget *subtypeCountContainer; ///< Container widget for subtype tally display + QGridLayout *subtypeCountLayout; ///< Grid layout for subtype name/count pairs QPointF selectionOrigin; - /** @brief Builds formatted text showing subtype tally for all selected cards */ - QString buildSubtypeTallyText() const; + void rebuildSubtypeLabels(const QList &entries); + void clearSubtypeLabels(); protected: void resizeEvent(QResizeEvent *event) override; diff --git a/libcockatrice_utility/libcockatrice/utility/qt_utils.h b/libcockatrice_utility/libcockatrice/utility/qt_utils.h index 334e56027..8e5212031 100644 --- a/libcockatrice_utility/libcockatrice/utility/qt_utils.h +++ b/libcockatrice_utility/libcockatrice/utility/qt_utils.h @@ -1,5 +1,6 @@ #ifndef COCKATRICE_QT_UTILS_H #define COCKATRICE_QT_UTILS_H +#include #include namespace QtUtils From 9c0180c183384d0a4b4bc2c766411fe01b0f87af Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Thu, 4 Jun 2026 23:34:20 -0400 Subject: [PATCH 06/11] Rename all count to tally in the feature --- .../src/client/settings/cache_settings.cpp | 24 +++++++-------- .../src/client/settings/cache_settings.h | 24 +++++++-------- cockatrice/src/game_graphics/game_view.cpp | 12 ++++---- cockatrice/src/game_graphics/game_view.h | 2 +- .../user_interface_settings_page.cpp | 30 +++++++++---------- .../user_interface_settings_page.h | 6 ++-- 6 files changed, 49 insertions(+), 49 deletions(-) diff --git a/cockatrice/src/client/settings/cache_settings.cpp b/cockatrice/src/client/settings/cache_settings.cpp index c4096ceeb..8b3f893a1 100644 --- a/cockatrice/src/client/settings/cache_settings.cpp +++ b/cockatrice/src/client/settings/cache_settings.cpp @@ -310,9 +310,9 @@ SettingsCache::SettingsCache() closeEmptyCardView = settings->value("interface/closeEmptyCardView", true).toBool(); focusCardViewSearchBar = settings->value("interface/focusCardViewSearchBar", true).toBool(); - showDragSelectionCount = settings->value("interface/showlassoselectioncount", true).toBool(); - showTotalSelectionCount = settings->value("interface/showpersistentselectioncount", true).toBool(); - showSubtypeSelectionCount = settings->value("interface/showsubtypeselectioncount", true).toBool(); + showDragSelectionTally = settings->value("interface/showlassoselectiontally", true).toBool(); + showTotalSelectionTally = settings->value("interface/showpersistentselectiontally", true).toBool(); + showSubtypeSelectionTally = settings->value("interface/showsubtypeselectiontally", true).toBool(); showShortcuts = settings->value("menu/showshortcuts", true).toBool(); showGameSelectorFilterToolbar = settings->value("menu/showgameselectorfiltertoolbar", true).toBool(); @@ -1361,22 +1361,22 @@ void SettingsCache::setRoundCardCorners(bool _roundCardCorners) emit roundCardCornersChanged(roundCardCorners); } -void SettingsCache::setShowDragSelectionCount(QT_STATE_CHANGED_T _showDragSelectionCount) +void SettingsCache::setShowDragSelectionTally(QT_STATE_CHANGED_T _showDragSelectionTally) { - showDragSelectionCount = static_cast(_showDragSelectionCount); - settings->setValue("interface/showlassoselectioncount", showDragSelectionCount); + showDragSelectionTally = static_cast(_showDragSelectionTally); + settings->setValue("interface/showlassoselectiontally", showDragSelectionTally); } -void SettingsCache::setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSelectionCount) +void SettingsCache::setShowTotalSelectionTally(QT_STATE_CHANGED_T _showTotalSelectionTally) { - showTotalSelectionCount = static_cast(_showTotalSelectionCount); - settings->setValue("interface/showpersistentselectioncount", showTotalSelectionCount); + showTotalSelectionTally = static_cast(_showTotalSelectionTally); + settings->setValue("interface/showpersistentselectiontally", showTotalSelectionTally); } -void SettingsCache::setShowSubtypeSelectionCount(QT_STATE_CHANGED_T _showSubtypeSelectionCount) +void SettingsCache::setShowSubtypeSelectionTally(QT_STATE_CHANGED_T _showSubtypeSelectionTally) { - showSubtypeSelectionCount = static_cast(_showSubtypeSelectionCount); - settings->setValue("interface/showsubtypeselectioncount", showSubtypeSelectionCount); + showSubtypeSelectionTally = static_cast(_showSubtypeSelectionTally); + settings->setValue("interface/showsubtypeselectiontally", showSubtypeSelectionTally); } void SettingsCache::loadPaths() diff --git a/cockatrice/src/client/settings/cache_settings.h b/cockatrice/src/client/settings/cache_settings.h index 72e1af32f..fc51bc1de 100644 --- a/cockatrice/src/client/settings/cache_settings.h +++ b/cockatrice/src/client/settings/cache_settings.h @@ -347,9 +347,9 @@ private: bool isPortableBuild; bool roundCardCorners; bool showStatusBar; - bool showDragSelectionCount; - bool showTotalSelectionCount; - bool showSubtypeSelectionCount; + bool showDragSelectionTally; + bool showTotalSelectionTally; + bool showSubtypeSelectionTally; public: SettingsCache(); @@ -465,17 +465,17 @@ public: { return showStatusBar; } - [[nodiscard]] bool getShowDragSelectionCount() const + [[nodiscard]] bool getShowDragSelectionTally() const { - return showDragSelectionCount; + return showDragSelectionTally; } - [[nodiscard]] bool getShowTotalSelectionCount() const + [[nodiscard]] bool getShowTotalSelectionTally() const { - return showTotalSelectionCount; + return showTotalSelectionTally; } - [[nodiscard]] bool getShowSubtypeSelectionCount() const + [[nodiscard]] bool getShowSubtypeSelectionTally() const { - return showSubtypeSelectionCount; + return showSubtypeSelectionTally; } [[nodiscard]] bool getNotificationsEnabled() const { @@ -1158,8 +1158,8 @@ public slots: void setUpdateReleaseChannelIndex(int value); void setMaxFontSize(int _max); void setRoundCardCorners(bool _roundCardCorners); - void setShowDragSelectionCount(QT_STATE_CHANGED_T _showDragSelectionCount); - void setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSelectionCount); - void setShowSubtypeSelectionCount(QT_STATE_CHANGED_T _showSubtypeSelectionCount); + void setShowDragSelectionTally(QT_STATE_CHANGED_T _showDragSelectionTally); + void setShowTotalSelectionTally(QT_STATE_CHANGED_T _showTotalSelectionTally); + void setShowSubtypeSelectionTally(QT_STATE_CHANGED_T _showSubtypeSelectionTally); }; #endif diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index 3822bb4a5..b6e637ec1 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -46,7 +46,7 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par connect(scene, &GameScene::sigStartRubberBand, this, &GameView::startRubberBand); connect(scene, &GameScene::sigResizeRubberBand, this, &GameView::resizeRubberBand); connect(scene, &GameScene::sigStopRubberBand, this, &GameView::stopRubberBand); - connect(scene, &QGraphicsScene::selectionChanged, this, [this]() { updateSelectionCount(); }); + connect(scene, &QGraphicsScene::selectionChanged, this, [this]() { updateSelectionTally(); }); aCloseMostRecentZoneView = new QAction(this); @@ -95,7 +95,7 @@ void GameView::resizeEvent(QResizeEvent *event) } updateSceneRect(scene()->sceneRect()); - updateSelectionCount(event->size()); + updateSelectionTally(event->size()); } void GameView::updateSceneRect(const QRectF &rect) @@ -126,7 +126,7 @@ void GameView::resizeRubberBand(const QPointF &cursorPoint, int selectedCount) QRect rect = QRect(mapFromScene(selectionOrigin), cursor).normalized(); rubberBand->setGeometry(rect); - if (!SettingsCache::instance().getShowDragSelectionCount()) { + if (!SettingsCache::instance().getShowDragSelectionTally()) { dragCountLabel->hide(); return; } @@ -206,7 +206,7 @@ void GameView::rebuildSubtypeLabels(const QList &entries) } } -void GameView::updateSelectionCount(const QSize &viewSize) +void GameView::updateSelectionTally(const QSize &viewSize) { constexpr int kMarginInPixels = 10; constexpr int kSpacingBetweenLabels = 4; @@ -216,7 +216,7 @@ void GameView::updateSelectionCount(const QSize &viewSize) int count = scene()->selectedItems().count(); - if (!SettingsCache::instance().getShowTotalSelectionCount() || count <= 1) { + if (!SettingsCache::instance().getShowTotalSelectionTally() || count <= 1) { totalCountLabel->hide(); } else { totalCountLabel->setText(QString::number(count)); @@ -228,7 +228,7 @@ void GameView::updateSelectionCount(const QSize &viewSize) totalCountLabel->show(); } - if (!SettingsCache::instance().getShowSubtypeSelectionCount() || count <= 1) { + if (!SettingsCache::instance().getShowSubtypeSelectionTally() || count <= 1) { subtypeCountContainer->hide(); return; } diff --git a/cockatrice/src/game_graphics/game_view.h b/cockatrice/src/game_graphics/game_view.h index 7e9e31e2f..aad5f96fc 100644 --- a/cockatrice/src/game_graphics/game_view.h +++ b/cockatrice/src/game_graphics/game_view.h @@ -37,7 +37,7 @@ private slots: void resizeRubberBand(const QPointF &cursorPoint, int selectedCount); void stopRubberBand(); void refreshShortcuts(); - void updateSelectionCount(const QSize &viewSize = QSize()); + void updateSelectionTally(const QSize &viewSize = QSize()); public slots: void updateSceneRect(const QRectF &rect); diff --git a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp index 6816fc48d..4d044a5d8 100644 --- a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp +++ b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp @@ -60,17 +60,17 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() connect(&annotateTokensCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), &SettingsCache::setAnnotateTokens); - showDragSelectionCountCheckBox.setChecked(SettingsCache::instance().getShowDragSelectionCount()); - connect(&showDragSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), - &SettingsCache::setShowDragSelectionCount); + showDragSelectionTallyCheckBox.setChecked(SettingsCache::instance().getShowDragSelectionTally()); + connect(&showDragSelectionTallyCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), + &SettingsCache::setShowDragSelectionTally); - showTotalSelectionCountCheckBox.setChecked(SettingsCache::instance().getShowTotalSelectionCount()); - connect(&showTotalSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), - &SettingsCache::setShowTotalSelectionCount); + showTotalSelectionTallyCheckBox.setChecked(SettingsCache::instance().getShowTotalSelectionTally()); + connect(&showTotalSelectionTallyCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), + &SettingsCache::setShowTotalSelectionTally); - showSubtypeSelectionCountCheckBox.setChecked(SettingsCache::instance().getShowSubtypeSelectionCount()); - connect(&showSubtypeSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), - &SettingsCache::setShowSubtypeSelectionCount); + showSubtypeSelectionTallyCheckBox.setChecked(SettingsCache::instance().getShowSubtypeSelectionTally()); + connect(&showSubtypeSelectionTallyCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), + &SettingsCache::setShowSubtypeSelectionTally); useTearOffMenusCheckBox.setChecked(SettingsCache::instance().getUseTearOffMenus()); connect(&useTearOffMenusCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), @@ -84,9 +84,9 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() generalGrid->addWidget(&closeEmptyCardViewCheckBox, 4, 0); generalGrid->addWidget(&focusCardViewSearchBarCheckBox, 5, 0); generalGrid->addWidget(&annotateTokensCheckBox, 6, 0); - generalGrid->addWidget(&showDragSelectionCountCheckBox, 7, 0); - generalGrid->addWidget(&showTotalSelectionCountCheckBox, 8, 0); - generalGrid->addWidget(&showSubtypeSelectionCountCheckBox, 9, 0); + generalGrid->addWidget(&showDragSelectionTallyCheckBox, 7, 0); + generalGrid->addWidget(&showTotalSelectionTallyCheckBox, 8, 0); + generalGrid->addWidget(&showSubtypeSelectionTallyCheckBox, 9, 0); generalGrid->addWidget(&useTearOffMenusCheckBox, 10, 0); generalGroupBox = new QGroupBox; @@ -209,9 +209,9 @@ void UserInterfaceSettingsPage::retranslateUi() closeEmptyCardViewCheckBox.setText(tr("Close card view window when last card is removed")); focusCardViewSearchBarCheckBox.setText(tr("Auto focus search bar when card view window is opened")); annotateTokensCheckBox.setText(tr("Annotate card text on tokens")); - showDragSelectionCountCheckBox.setText(tr("Show selection counter during drag selection")); - showTotalSelectionCountCheckBox.setText(tr("Show total selection counter")); - showSubtypeSelectionCountCheckBox.setText(tr("Show subtype breakdown in selection counter")); + showDragSelectionTallyCheckBox.setText(tr("Show selection tally during drag selection")); + showTotalSelectionTallyCheckBox.setText(tr("Show total selection tally")); + showSubtypeSelectionTallyCheckBox.setText(tr("Show subtype breakdown in selection tally")); useTearOffMenusCheckBox.setText(tr("Use tear-off menus, allowing right click menus to persist on screen")); notificationsGroupBox->setTitle(tr("Notifications settings")); notificationsEnabledCheckBox.setText(tr("Enable notifications in taskbar")); diff --git a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h index fb8e9ff57..f667a5a54 100644 --- a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h +++ b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h @@ -27,9 +27,9 @@ private: QCheckBox closeEmptyCardViewCheckBox; QCheckBox focusCardViewSearchBarCheckBox; QCheckBox annotateTokensCheckBox; - QCheckBox showDragSelectionCountCheckBox; - QCheckBox showTotalSelectionCountCheckBox; - QCheckBox showSubtypeSelectionCountCheckBox; + QCheckBox showDragSelectionTallyCheckBox; + QCheckBox showTotalSelectionTallyCheckBox; + QCheckBox showSubtypeSelectionTallyCheckBox; QCheckBox useTearOffMenusCheckBox; QCheckBox tapAnimationCheckBox; QCheckBox openDeckInNewTabCheckBox; From 7ca066389fc90f6a719cb6a06c944699bb9edbca Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Mon, 8 Jun 2026 16:36:10 -0400 Subject: [PATCH 07/11] partial rename --- .../src/client/settings/cache_settings.cpp | 16 +++++++-------- .../src/client/settings/cache_settings.h | 16 +++++++-------- cockatrice/src/game_graphics/game_view.cpp | 10 +++++----- cockatrice/src/game_graphics/game_view.h | 2 +- .../user_interface_settings_page.cpp | 20 +++++++++---------- .../user_interface_settings_page.h | 4 ++-- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/cockatrice/src/client/settings/cache_settings.cpp b/cockatrice/src/client/settings/cache_settings.cpp index 8b3f893a1..7c89c34ef 100644 --- a/cockatrice/src/client/settings/cache_settings.cpp +++ b/cockatrice/src/client/settings/cache_settings.cpp @@ -310,8 +310,8 @@ SettingsCache::SettingsCache() closeEmptyCardView = settings->value("interface/closeEmptyCardView", true).toBool(); focusCardViewSearchBar = settings->value("interface/focusCardViewSearchBar", true).toBool(); - showDragSelectionTally = settings->value("interface/showlassoselectiontally", true).toBool(); - showTotalSelectionTally = settings->value("interface/showpersistentselectiontally", true).toBool(); + showDragSelectionCount = settings->value("interface/showlassoselectioncount", true).toBool(); + showTotalSelectionCount = settings->value("interface/showpersistentselectioncount", true).toBool(); showSubtypeSelectionTally = settings->value("interface/showsubtypeselectiontally", true).toBool(); showShortcuts = settings->value("menu/showshortcuts", true).toBool(); @@ -1361,16 +1361,16 @@ void SettingsCache::setRoundCardCorners(bool _roundCardCorners) emit roundCardCornersChanged(roundCardCorners); } -void SettingsCache::setShowDragSelectionTally(QT_STATE_CHANGED_T _showDragSelectionTally) +void SettingsCache::setShowDragSelectionCount(QT_STATE_CHANGED_T _showDragSelectionCount) { - showDragSelectionTally = static_cast(_showDragSelectionTally); - settings->setValue("interface/showlassoselectiontally", showDragSelectionTally); + showDragSelectionCount = static_cast(_showDragSelectionCount); + settings->setValue("interface/showlassoselectioncount", showDragSelectionCount); } -void SettingsCache::setShowTotalSelectionTally(QT_STATE_CHANGED_T _showTotalSelectionTally) +void SettingsCache::setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSelectionCount) { - showTotalSelectionTally = static_cast(_showTotalSelectionTally); - settings->setValue("interface/showpersistentselectiontally", showTotalSelectionTally); + showTotalSelectionCount = static_cast(_showTotalSelectionCount); + settings->setValue("interface/showpersistentselectioncount", showTotalSelectionCount); } void SettingsCache::setShowSubtypeSelectionTally(QT_STATE_CHANGED_T _showSubtypeSelectionTally) diff --git a/cockatrice/src/client/settings/cache_settings.h b/cockatrice/src/client/settings/cache_settings.h index fc51bc1de..7fc0500dd 100644 --- a/cockatrice/src/client/settings/cache_settings.h +++ b/cockatrice/src/client/settings/cache_settings.h @@ -347,8 +347,8 @@ private: bool isPortableBuild; bool roundCardCorners; bool showStatusBar; - bool showDragSelectionTally; - bool showTotalSelectionTally; + bool showDragSelectionCount; + bool showTotalSelectionCount; bool showSubtypeSelectionTally; public: @@ -465,13 +465,13 @@ public: { return showStatusBar; } - [[nodiscard]] bool getShowDragSelectionTally() const + [[nodiscard]] bool getShowDragSelectionCount() const { - return showDragSelectionTally; + return showDragSelectionCount; } - [[nodiscard]] bool getShowTotalSelectionTally() const + [[nodiscard]] bool getShowTotalSelectionCount() const { - return showTotalSelectionTally; + return showTotalSelectionCount; } [[nodiscard]] bool getShowSubtypeSelectionTally() const { @@ -1158,8 +1158,8 @@ public slots: void setUpdateReleaseChannelIndex(int value); void setMaxFontSize(int _max); void setRoundCardCorners(bool _roundCardCorners); - void setShowDragSelectionTally(QT_STATE_CHANGED_T _showDragSelectionTally); - void setShowTotalSelectionTally(QT_STATE_CHANGED_T _showTotalSelectionTally); + void setShowDragSelectionCount(QT_STATE_CHANGED_T _showDragSelectionCount); + void setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSelectionCount); void setShowSubtypeSelectionTally(QT_STATE_CHANGED_T _showSubtypeSelectionTally); }; #endif diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index b6e637ec1..c1f7ba422 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -46,7 +46,7 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par connect(scene, &GameScene::sigStartRubberBand, this, &GameView::startRubberBand); connect(scene, &GameScene::sigResizeRubberBand, this, &GameView::resizeRubberBand); connect(scene, &GameScene::sigStopRubberBand, this, &GameView::stopRubberBand); - connect(scene, &QGraphicsScene::selectionChanged, this, [this]() { updateSelectionTally(); }); + connect(scene, &QGraphicsScene::selectionChanged, this, [this]() { updateSelectionCount(); }); aCloseMostRecentZoneView = new QAction(this); @@ -95,7 +95,7 @@ void GameView::resizeEvent(QResizeEvent *event) } updateSceneRect(scene()->sceneRect()); - updateSelectionTally(event->size()); + updateSelectionCount(event->size()); } void GameView::updateSceneRect(const QRectF &rect) @@ -126,7 +126,7 @@ void GameView::resizeRubberBand(const QPointF &cursorPoint, int selectedCount) QRect rect = QRect(mapFromScene(selectionOrigin), cursor).normalized(); rubberBand->setGeometry(rect); - if (!SettingsCache::instance().getShowDragSelectionTally()) { + if (!SettingsCache::instance().getShowDragSelectionCount()) { dragCountLabel->hide(); return; } @@ -206,7 +206,7 @@ void GameView::rebuildSubtypeLabels(const QList &entries) } } -void GameView::updateSelectionTally(const QSize &viewSize) +void GameView::updateSelectionCount(const QSize &viewSize) { constexpr int kMarginInPixels = 10; constexpr int kSpacingBetweenLabels = 4; @@ -216,7 +216,7 @@ void GameView::updateSelectionTally(const QSize &viewSize) int count = scene()->selectedItems().count(); - if (!SettingsCache::instance().getShowTotalSelectionTally() || count <= 1) { + if (!SettingsCache::instance().getShowTotalSelectionCount() || count <= 1) { totalCountLabel->hide(); } else { totalCountLabel->setText(QString::number(count)); diff --git a/cockatrice/src/game_graphics/game_view.h b/cockatrice/src/game_graphics/game_view.h index aad5f96fc..7e9e31e2f 100644 --- a/cockatrice/src/game_graphics/game_view.h +++ b/cockatrice/src/game_graphics/game_view.h @@ -37,7 +37,7 @@ private slots: void resizeRubberBand(const QPointF &cursorPoint, int selectedCount); void stopRubberBand(); void refreshShortcuts(); - void updateSelectionTally(const QSize &viewSize = QSize()); + void updateSelectionCount(const QSize &viewSize = QSize()); public slots: void updateSceneRect(const QRectF &rect); diff --git a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp index 4d044a5d8..13ec4753d 100644 --- a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp +++ b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.cpp @@ -60,13 +60,13 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() connect(&annotateTokensCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), &SettingsCache::setAnnotateTokens); - showDragSelectionTallyCheckBox.setChecked(SettingsCache::instance().getShowDragSelectionTally()); - connect(&showDragSelectionTallyCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), - &SettingsCache::setShowDragSelectionTally); + showDragSelectionCountCheckBox.setChecked(SettingsCache::instance().getShowDragSelectionCount()); + connect(&showDragSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), + &SettingsCache::setShowDragSelectionCount); - showTotalSelectionTallyCheckBox.setChecked(SettingsCache::instance().getShowTotalSelectionTally()); - connect(&showTotalSelectionTallyCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), - &SettingsCache::setShowTotalSelectionTally); + showTotalSelectionCountCheckBox.setChecked(SettingsCache::instance().getShowTotalSelectionCount()); + connect(&showTotalSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), + &SettingsCache::setShowTotalSelectionCount); showSubtypeSelectionTallyCheckBox.setChecked(SettingsCache::instance().getShowSubtypeSelectionTally()); connect(&showSubtypeSelectionTallyCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), @@ -84,8 +84,8 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() generalGrid->addWidget(&closeEmptyCardViewCheckBox, 4, 0); generalGrid->addWidget(&focusCardViewSearchBarCheckBox, 5, 0); generalGrid->addWidget(&annotateTokensCheckBox, 6, 0); - generalGrid->addWidget(&showDragSelectionTallyCheckBox, 7, 0); - generalGrid->addWidget(&showTotalSelectionTallyCheckBox, 8, 0); + generalGrid->addWidget(&showDragSelectionCountCheckBox, 7, 0); + generalGrid->addWidget(&showTotalSelectionCountCheckBox, 8, 0); generalGrid->addWidget(&showSubtypeSelectionTallyCheckBox, 9, 0); generalGrid->addWidget(&useTearOffMenusCheckBox, 10, 0); @@ -209,8 +209,8 @@ void UserInterfaceSettingsPage::retranslateUi() closeEmptyCardViewCheckBox.setText(tr("Close card view window when last card is removed")); focusCardViewSearchBarCheckBox.setText(tr("Auto focus search bar when card view window is opened")); annotateTokensCheckBox.setText(tr("Annotate card text on tokens")); - showDragSelectionTallyCheckBox.setText(tr("Show selection tally during drag selection")); - showTotalSelectionTallyCheckBox.setText(tr("Show total selection tally")); + showDragSelectionCountCheckBox.setText(tr("Show selection count during drag selection")); + showTotalSelectionCountCheckBox.setText(tr("Show total selection count")); showSubtypeSelectionTallyCheckBox.setText(tr("Show subtype breakdown in selection tally")); useTearOffMenusCheckBox.setText(tr("Use tear-off menus, allowing right click menus to persist on screen")); notificationsGroupBox->setTitle(tr("Notifications settings")); diff --git a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h index f667a5a54..38bb67e31 100644 --- a/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h +++ b/cockatrice/src/interface/widgets/settings_page/user_interface_settings_page.h @@ -27,8 +27,8 @@ private: QCheckBox closeEmptyCardViewCheckBox; QCheckBox focusCardViewSearchBarCheckBox; QCheckBox annotateTokensCheckBox; - QCheckBox showDragSelectionTallyCheckBox; - QCheckBox showTotalSelectionTallyCheckBox; + QCheckBox showDragSelectionCountCheckBox; + QCheckBox showTotalSelectionCountCheckBox; QCheckBox showSubtypeSelectionTallyCheckBox; QCheckBox useTearOffMenusCheckBox; QCheckBox tapAnimationCheckBox; From 6837cc52c1544522fc7c7306ee51d3a4c16db50a Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Mon, 8 Jun 2026 21:08:04 -0400 Subject: [PATCH 08/11] list position fixed --- cockatrice/src/game_graphics/game_view.cpp | 31 +++++++++++++++++----- cockatrice/src/game_graphics/game_view.h | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index c1f7ba422..52349e14c 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -182,7 +182,7 @@ void GameView::clearSubtypeLabels() QtUtils::clearLayoutRec(subtypeCountLayout); } -void GameView::rebuildSubtypeLabels(const QList &entries) +QSize GameView::rebuildSubtypeLabels(const QList &entries) { clearSubtypeLabels(); @@ -190,6 +190,10 @@ void GameView::rebuildSubtypeLabels(const QList &entries) const QString countStyle = QStringLiteral("color: white; font-size: 14px; font-weight: bold; background: transparent;"); + int totalHeight = 0; + int maxNameWidth = 0; + int maxCountWidth = 0; + int row = 0; for (const SubtypeEntry &entry : entries) { auto *nameLabel = new QLabel(entry.name, subtypeCountContainer); @@ -202,8 +206,23 @@ void GameView::rebuildSubtypeLabels(const QList &entries) countLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); subtypeCountLayout->addWidget(countLabel, row, 1); + QSize nameSize = nameLabel->sizeHint(); + QSize countSize = countLabel->sizeHint(); + maxNameWidth = qMax(maxNameWidth, nameSize.width()); + maxCountWidth = qMax(maxCountWidth, countSize.width()); + totalHeight += qMax(nameSize.height(), countSize.height()); + ++row; } + + int spacing = subtypeCountLayout->spacing(); + int margins = subtypeCountLayout->contentsMargins().left() + subtypeCountLayout->contentsMargins().right(); + int verticalMargins = subtypeCountLayout->contentsMargins().top() + subtypeCountLayout->contentsMargins().bottom(); + + int width = maxNameWidth + spacing + maxCountWidth + margins; + int height = totalHeight + (row - 1) * spacing + verticalMargins; + + return QSize(width, height); } void GameView::updateSelectionCount(const QSize &viewSize) @@ -255,16 +274,16 @@ void GameView::updateSelectionCount(const QSize &viewSize) return; } - rebuildSubtypeLabels(entries); - subtypeCountContainer->adjustSize(); + QSize containerSize = rebuildSubtypeLabels(entries); + subtypeCountContainer->resize(containerSize); - int x = availableWidth - subtypeCountContainer->width() - kMarginInPixels; + int x = availableWidth - containerSize.width() - kMarginInPixels; int y; if (totalCountLabel->isVisible()) { - y = totalCountLabel->y() - subtypeCountContainer->height() - kSpacingBetweenLabels; + y = totalCountLabel->y() - containerSize.height() - kSpacingBetweenLabels; } else { - y = availableHeight - subtypeCountContainer->height() - kMarginInPixels; + y = availableHeight - containerSize.height() - kMarginInPixels; } y = qMax(kMarginInPixels, y); diff --git a/cockatrice/src/game_graphics/game_view.h b/cockatrice/src/game_graphics/game_view.h index 7e9e31e2f..5fe0562cb 100644 --- a/cockatrice/src/game_graphics/game_view.h +++ b/cockatrice/src/game_graphics/game_view.h @@ -27,7 +27,7 @@ private: QGridLayout *subtypeCountLayout; ///< Grid layout for subtype name/count pairs QPointF selectionOrigin; - void rebuildSubtypeLabels(const QList &entries); + QSize rebuildSubtypeLabels(const QList &entries); void clearSubtypeLabels(); protected: From 5868db96c91126fbedb70c376a19d65e8c25b6f1 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Mon, 8 Jun 2026 22:20:48 -0400 Subject: [PATCH 09/11] Clean up code and documentation --- .../src/game/selection_subtype_tally.cpp | 55 +++++-------------- cockatrice/src/game/selection_subtype_tally.h | 30 ++++++---- cockatrice/src/game_graphics/game_view.cpp | 37 +++++-------- cockatrice/src/game_graphics/game_view.h | 8 ++- 4 files changed, 54 insertions(+), 76 deletions(-) diff --git a/cockatrice/src/game/selection_subtype_tally.cpp b/cockatrice/src/game/selection_subtype_tally.cpp index c033d42c9..afc5bc382 100644 --- a/cockatrice/src/game/selection_subtype_tally.cpp +++ b/cockatrice/src/game/selection_subtype_tally.cpp @@ -8,8 +8,10 @@ namespace { +/** @brief Extracts subtypes from a single card face's type line. */ QStringList extractSubtypesFromFace(const QString &faceType) { + // Card type format: "Creature — Goblin Warrior" or "Legendary Enchantment — Saga" QStringList parts = faceType.split(QStringLiteral(" — ")); if (parts.size() > 1) { return parts[1].split(QStringLiteral(" "), Qt::SkipEmptyParts); @@ -22,68 +24,41 @@ QStringList extractSubtypesFromFace(const QString &faceType) namespace SelectionSubtypeTally { -QList countSubtypes(const QList &cards) +QList countSubtypes(const QList &cards) { - QMap> subtypesByMainType; - QMap cardCountPerMainType; + QMap subtypeCounts; for (CardItem *card : cards) { if (card->getFaceDown() || card->getCard().isEmpty()) { continue; } - QString mainType = card->getCardInfo().getMainCardType(); - if (mainType.isEmpty()) { - mainType = QStringLiteral("Other"); - } - QString cardType = card->getCardInfo().getCardType(); + // Handle double-faced cards: "Creature — Human // Creature — Werewolf" QStringList cardFaces = cardType.split(QStringLiteral(" // ")); - bool contributedSubtypes = false; for (const QString &face : cardFaces) { QStringList subtypes = extractSubtypesFromFace(face); for (const QString &subtype : subtypes) { - subtypesByMainType[mainType][subtype]++; - contributedSubtypes = true; + subtypeCounts[subtype]++; } } - - if (contributedSubtypes) { - cardCountPerMainType[mainType]++; - } } - QList groups; - for (auto it = subtypesByMainType.constBegin(); it != subtypesByMainType.constEnd(); ++it) { - MainTypeGroup group; - group.mainType = it.key(); - group.cardCount = cardCountPerMainType.value(it.key(), 0); - - for (auto subIt = it.value().constBegin(); subIt != it.value().constEnd(); ++subIt) { - group.subtypes.append({subIt.key(), subIt.value()}); - } - - // Sort subtypes: by count ascending, then alphabetically - std::sort(group.subtypes.begin(), group.subtypes.end(), [](const SubtypeEntry &a, const SubtypeEntry &b) { - if (a.count != b.count) { - return a.count < b.count; - } - return a.name < b.name; - }); - - groups.append(group); + QList entries; + for (auto it = subtypeCounts.constBegin(); it != subtypeCounts.constEnd(); ++it) { + entries.append({it.key(), it.value()}); } - // Sort groups: by card count ascending, then alphabetically by main type - std::sort(groups.begin(), groups.end(), [](const MainTypeGroup &a, const MainTypeGroup &b) { - if (a.cardCount != b.cardCount) { - return a.cardCount < b.cardCount; + // Sort by count ascending, then alphabetically (lowest counts at bottom of display) + std::sort(entries.begin(), entries.end(), [](const SubtypeEntry &a, const SubtypeEntry &b) { + if (a.count != b.count) { + return a.count < b.count; } - return a.mainType < b.mainType; + return a.name < b.name; }); - return groups; + return entries; } } // namespace SelectionSubtypeTally diff --git a/cockatrice/src/game/selection_subtype_tally.h b/cockatrice/src/game/selection_subtype_tally.h index a5014fafe..9038653f6 100644 --- a/cockatrice/src/game/selection_subtype_tally.h +++ b/cockatrice/src/game/selection_subtype_tally.h @@ -3,26 +3,34 @@ #include #include -#include class CardItem; +/** @brief A single subtype (e.g., "Goblin", "Warrior") with its occurrence count. */ struct SubtypeEntry { - QString name; - int count; -}; - -struct MainTypeGroup -{ - QString mainType; - int cardCount; - QList subtypes; + QString name; ///< The subtype name + int count; ///< Number of selected cards with this subtype + + bool operator==(const SubtypeEntry &other) const + { + return name == other.name && count == other.count; + } }; +/** + * @brief Extracts and tallies subtypes from selected cards. + */ namespace SelectionSubtypeTally { -QList countSubtypes(const QList &cards); +/** + * @brief Parses card type lines and counts each subtype occurrence. + * + * Skips face-down cards and cards without type info. + * @param cards The list of selected card items to analyze. + * @return Entries sorted by count ascending, then alphabetically. + */ +QList countSubtypes(const QList &cards); } // namespace SelectionSubtypeTally #endif diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index 52349e14c..4a47b7aed 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -89,10 +89,8 @@ void GameView::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); - GameScene *s = dynamic_cast(scene()); - if (s) { - s->processViewSizeChange(event->size()); - } + GameScene *s = static_cast(scene()); + s->processViewSizeChange(event->size()); updateSceneRect(scene()->sceneRect()); updateSelectionCount(event->size()); @@ -249,33 +247,28 @@ void GameView::updateSelectionCount(const QSize &viewSize) if (!SettingsCache::instance().getShowSubtypeSelectionTally() || count <= 1) { subtypeCountContainer->hide(); + cachedSubtypeEntries.clear(); return; } - GameScene *gameScene = dynamic_cast(scene()); - if (!gameScene) { - subtypeCountContainer->hide(); - return; - } - - QList groups = SelectionSubtypeTally::countSubtypes(gameScene->selectedCards()); - if (groups.isEmpty()) { - subtypeCountContainer->hide(); - return; - } - - QList entries; - for (const MainTypeGroup &group : groups) { - entries.append(group.subtypes); - } + GameScene *gameScene = static_cast(scene()); + QList entries = SelectionSubtypeTally::countSubtypes(gameScene->selectedCards()); if (entries.isEmpty()) { subtypeCountContainer->hide(); + cachedSubtypeEntries.clear(); return; } - QSize containerSize = rebuildSubtypeLabels(entries); - subtypeCountContainer->resize(containerSize); + // Only rebuild labels if entries changed + QSize containerSize; + if (entries != cachedSubtypeEntries) { + cachedSubtypeEntries = entries; + containerSize = rebuildSubtypeLabels(entries); + subtypeCountContainer->resize(containerSize); + } else { + containerSize = subtypeCountContainer->size(); + } int x = availableWidth - containerSize.width() - kMarginInPixels; int y; diff --git a/cockatrice/src/game_graphics/game_view.h b/cockatrice/src/game_graphics/game_view.h index 5fe0562cb..a44f15808 100644 --- a/cockatrice/src/game_graphics/game_view.h +++ b/cockatrice/src/game_graphics/game_view.h @@ -7,13 +7,14 @@ #ifndef GAMEVIEW_H #define GAMEVIEW_H +#include "selection_subtype_tally.h" + #include class GameScene; class QGridLayout; class QLabel; class QRubberBand; -struct SubtypeEntry; class GameView : public QGraphicsView { @@ -23,9 +24,10 @@ private: QRubberBand *rubberBand; QLabel *dragCountLabel; QLabel *totalCountLabel; - QWidget *subtypeCountContainer; ///< Container widget for subtype tally display - QGridLayout *subtypeCountLayout; ///< Grid layout for subtype name/count pairs + QWidget *subtypeCountContainer; + QGridLayout *subtypeCountLayout; QPointF selectionOrigin; + QList cachedSubtypeEntries; ///< Cached entries to avoid redundant rebuilds QSize rebuildSubtypeLabels(const QList &entries); void clearSubtypeLabels(); From e2ebdc51addbef87c31441a8952620bbabe1406d Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Tue, 9 Jun 2026 11:58:49 -0400 Subject: [PATCH 10/11] Rename subtypeCountLabelStyle to subtypeTallyLabelStyle and fix include ordering --- cockatrice/CMakeLists.txt | 2 +- cockatrice/src/game_graphics/game_view.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 9dfb81f3c..086e189a1 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -82,8 +82,8 @@ set(cockatrice_SOURCES src/game_graphics/game_scene.cpp src/game/game_state.cpp src/game_graphics/game_view.cpp - src/game/selection_subtype_tally.cpp src/game_graphics/hand_counter.cpp + src/game/selection_subtype_tally.cpp src/game_graphics/log/message_log_widget.cpp src/game/phase.cpp src/game_graphics/phases_toolbar.cpp diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index 4a47b7aed..25392c174 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -2,7 +2,6 @@ #include "../client/settings/cache_settings.h" #include "game_scene.h" -#include "libcockatrice/utility/qt_utils.h" #include "selection_subtype_tally.h" #include @@ -11,6 +10,7 @@ #include #include #include +#include // QRubberBand calls raise() in showEvent() and changeEvent() to stay on top of siblings. // This subclass disables that behavior so dragCountLabel can appear above it. @@ -66,7 +66,7 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par const QString dragCountLabelStyle = baseProperties + "font-size: 14px; font-weight: bold;"; const QString totalCountLabelStyle = baseProperties + "font-size: 16px; font-weight: bold;"; - const QString subtypeCountLabelStyle = baseProperties + "font-size: 12px;"; + const QString subtypeTallyLabelStyle = baseProperties + "font-size: 12px;"; dragCountLabel = new QLabel(this); dragCountLabel->setStyleSheet(dragCountLabelStyle); @@ -78,7 +78,7 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par totalCountLabel->hide(); subtypeCountContainer = new QWidget(this); - subtypeCountContainer->setStyleSheet(subtypeCountLabelStyle); + subtypeCountContainer->setStyleSheet(subtypeTallyLabelStyle); subtypeCountLayout = new QGridLayout(subtypeCountContainer); subtypeCountLayout->setContentsMargins(2, 2, 2, 2); subtypeCountLayout->setSpacing(2); From 75beb5b2cbf9f052da07c144a8673f66ab60cc48 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Tue, 9 Jun 2026 12:21:53 -0400 Subject: [PATCH 11/11] Fix include path for selection_subtype_tally.h after file relocation --- cockatrice/src/game/selection_subtype_tally.cpp | 2 +- cockatrice/src/game_graphics/game_view.cpp | 2 +- cockatrice/src/game_graphics/game_view.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/game/selection_subtype_tally.cpp b/cockatrice/src/game/selection_subtype_tally.cpp index afc5bc382..e9f87fab9 100644 --- a/cockatrice/src/game/selection_subtype_tally.cpp +++ b/cockatrice/src/game/selection_subtype_tally.cpp @@ -1,6 +1,6 @@ #include "selection_subtype_tally.h" -#include "board/card_item.h" +#include "../game_graphics/board/card_item.h" #include #include diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index 25392c174..b7ce96fe3 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -1,8 +1,8 @@ #include "game_view.h" #include "../client/settings/cache_settings.h" +#include "../game/selection_subtype_tally.h" #include "game_scene.h" -#include "selection_subtype_tally.h" #include #include diff --git a/cockatrice/src/game_graphics/game_view.h b/cockatrice/src/game_graphics/game_view.h index a44f15808..37e3491cb 100644 --- a/cockatrice/src/game_graphics/game_view.h +++ b/cockatrice/src/game_graphics/game_view.h @@ -7,7 +7,7 @@ #ifndef GAMEVIEW_H #define GAMEVIEW_H -#include "selection_subtype_tally.h" +#include "../game/selection_subtype_tally.h" #include