From 6d4bcc6664b5611de60674f4363d5da109cd6387 Mon Sep 17 00:00:00 2001 From: DawnFire42 Date: Sat, 14 Mar 2026 00:19:37 -0400 Subject: [PATCH] feat(game): add persistent selection counter overlay. Display total count of selected cards in bottom-right corner when multiple cards are selected. Updates on selection changes and window resize. The counter connects to QGraphicsScene::selectionChanged to stay up-to-date without requiring manual refresh. Adds user setting to enable/disable the total count overlay. --- .../src/client/settings/cache_settings.cpp | 7 +++++ .../src/client/settings/cache_settings.h | 6 ++++ cockatrice/src/game/game_view.cpp | 31 +++++++++++++++++++ cockatrice/src/game/game_view.h | 2 ++ .../widgets/dialogs/dlg_settings.cpp | 8 ++++- .../interface/widgets/dialogs/dlg_settings.h | 1 + 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/client/settings/cache_settings.cpp b/cockatrice/src/client/settings/cache_settings.cpp index bd1f1cd23..a66897b4a 100644 --- a/cockatrice/src/client/settings/cache_settings.cpp +++ b/cockatrice/src/client/settings/cache_settings.cpp @@ -285,6 +285,7 @@ SettingsCache::SettingsCache() focusCardViewSearchBar = settings->value("interface/focusCardViewSearchBar", true).toBool(); showDragSelectionCount = settings->value("interface/showlassoselectioncount", true).toBool(); + showTotalSelectionCount = settings->value("interface/showpersistentselectioncount", true).toBool(); showShortcuts = settings->value("menu/showshortcuts", true).toBool(); showGameSelectorFilterToolbar = settings->value("menu/showgameselectorfiltertoolbar", true).toBool(); @@ -1316,6 +1317,12 @@ void SettingsCache::setShowDragSelectionCount(QT_STATE_CHANGED_T _showDragSelect settings->setValue("interface/showlassoselectioncount", showDragSelectionCount); } +void SettingsCache::setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSelectionCount) +{ + showTotalSelectionCount = static_cast(_showTotalSelectionCount); + settings->setValue("interface/showpersistentselectioncount", showTotalSelectionCount); +} + 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 b8b68cda4..ece61487f 100644 --- a/cockatrice/src/client/settings/cache_settings.h +++ b/cockatrice/src/client/settings/cache_settings.h @@ -341,6 +341,7 @@ private: bool roundCardCorners; bool showStatusBar; bool showDragSelectionCount; + bool showTotalSelectionCount; public: SettingsCache(); @@ -460,6 +461,10 @@ public: { return showDragSelectionCount; } + [[nodiscard]] bool getShowTotalSelectionCount() const + { + return showTotalSelectionCount; + } [[nodiscard]] bool getNotificationsEnabled() const { return notificationsEnabled; @@ -1126,5 +1131,6 @@ public slots: void setMaxFontSize(int _max); void setRoundCardCorners(bool _roundCardCorners); void setShowDragSelectionCount(QT_STATE_CHANGED_T _showDragSelectionCount); + void setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSelectionCount); }; #endif diff --git a/cockatrice/src/game/game_view.cpp b/cockatrice/src/game/game_view.cpp index d9aee7d16..ce53828a7 100644 --- a/cockatrice/src/game/game_view.cpp +++ b/cockatrice/src/game/game_view.cpp @@ -42,6 +42,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(); }); aCloseMostRecentZoneView = new QAction(this); @@ -63,6 +64,10 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par dragCountLabel->setStyleSheet(countLabelStyle); dragCountLabel->hide(); dragCountLabel->raise(); + + totalCountLabel = new QLabel(this); + totalCountLabel->setStyleSheet(countLabelStyle); + totalCountLabel->hide(); } void GameView::resizeEvent(QResizeEvent *event) @@ -74,6 +79,7 @@ void GameView::resizeEvent(QResizeEvent *event) s->processViewSizeChange(event->size()); updateSceneRect(scene()->sceneRect()); + updateTotalSelectionCount(event->size()); } void GameView::updateSceneRect(const QRectF &rect) @@ -151,3 +157,28 @@ void GameView::refreshShortcuts() aCloseMostRecentZoneView->setShortcuts( SettingsCache::instance().shortcuts().getShortcut("Player/aCloseMostRecentZoneView")); } + +void GameView::updateTotalSelectionCount(const QSize &viewSize) +{ + if (!SettingsCache::instance().getShowTotalSelectionCount()) { + totalCountLabel->hide(); + return; + } + + int count = scene()->selectedItems().count(); + + if (count > 1) { + 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(); + } +} diff --git a/cockatrice/src/game/game_view.h b/cockatrice/src/game/game_view.h index 3c1b1467b..a77ab9257 100644 --- a/cockatrice/src/game/game_view.h +++ b/cockatrice/src/game/game_view.h @@ -20,6 +20,7 @@ private: QAction *aCloseMostRecentZoneView; QRubberBand *rubberBand; QLabel *dragCountLabel; + QLabel *totalCountLabel; QPointF selectionOrigin; protected: @@ -29,6 +30,7 @@ private slots: void resizeRubberBand(const QPointF &cursorPoint, int selectedCount); void stopRubberBand(); void refreshShortcuts(); + void updateTotalSelectionCount(const QSize &viewSize = QSize()); public slots: void updateSceneRect(const QRectF &rect); diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp index 851230881..e3bf209dc 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_settings.cpp @@ -825,6 +825,10 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() connect(&showDragSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), &SettingsCache::setShowDragSelectionCount); + showTotalSelectionCountCheckBox.setChecked(SettingsCache::instance().getShowTotalSelectionCount()); + connect(&showTotalSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), + &SettingsCache::setShowTotalSelectionCount); + 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); }); @@ -838,7 +842,8 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() generalGrid->addWidget(&focusCardViewSearchBarCheckBox, 5, 0); generalGrid->addWidget(&annotateTokensCheckBox, 6, 0); generalGrid->addWidget(&showDragSelectionCountCheckBox, 7, 0); - generalGrid->addWidget(&useTearOffMenusCheckBox, 8, 0); + generalGrid->addWidget(&showTotalSelectionCountCheckBox, 8, 0); + generalGrid->addWidget(&useTearOffMenusCheckBox, 9, 0); generalGroupBox = new QGroupBox; generalGroupBox->setLayout(generalGrid); @@ -961,6 +966,7 @@ void UserInterfaceSettingsPage::retranslateUi() 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")); 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/dialogs/dlg_settings.h b/cockatrice/src/interface/widgets/dialogs/dlg_settings.h index 1bcbbbdf2..b655a30bc 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_settings.h +++ b/cockatrice/src/interface/widgets/dialogs/dlg_settings.h @@ -172,6 +172,7 @@ private: QCheckBox focusCardViewSearchBarCheckBox; QCheckBox annotateTokensCheckBox; QCheckBox showDragSelectionCountCheckBox; + QCheckBox showTotalSelectionCountCheckBox; QCheckBox useTearOffMenusCheckBox; QCheckBox tapAnimationCheckBox; QCheckBox openDeckInNewTabCheckBox;