From ce53e03d42c1ec7df4a211e09e4891d2d6b414b8 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Fri, 19 Jun 2026 04:06:37 -0700 Subject: [PATCH] [Game] Use in-game menu for tally setting --- cockatrice/CMakeLists.txt | 1 + .../src/client/settings/cache_settings.cpp | 9 ++-- .../src/client/settings/cache_settings.h | 10 ++-- cockatrice/src/game_graphics/game_view.cpp | 5 +- .../game_graphics/player/menu/player_menu.cpp | 2 + .../game_graphics/player/menu/player_menu.h | 2 + .../game_graphics/player/menu/tally_menu.cpp | 49 +++++++++++++++++++ .../game_graphics/player/menu/tally_menu.h | 28 +++++++++++ .../user_interface_settings_page.cpp | 10 +--- .../user_interface_settings_page.h | 1 - 10 files changed, 98 insertions(+), 19 deletions(-) create mode 100644 cockatrice/src/game_graphics/player/menu/tally_menu.cpp create mode 100644 cockatrice/src/game_graphics/player/menu/tally_menu.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 60ba06593..728f898e4 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -97,6 +97,7 @@ set(cockatrice_SOURCES src/game_graphics/player/menu/rfg_menu.cpp src/game_graphics/player/menu/say_menu.cpp src/game_graphics/player/menu/sideboard_menu.cpp + src/game_graphics/player/menu/tally_menu.cpp src/game_graphics/player/menu/utility_menu.cpp src/game_graphics/tally/subtype_tally.cpp src/game_graphics/tally/tally.cpp diff --git a/cockatrice/src/client/settings/cache_settings.cpp b/cockatrice/src/client/settings/cache_settings.cpp index b6bc8a47d..cef9c53cb 100644 --- a/cockatrice/src/client/settings/cache_settings.cpp +++ b/cockatrice/src/client/settings/cache_settings.cpp @@ -313,7 +313,7 @@ SettingsCache::SettingsCache() showDragSelectionCount = settings->value("interface/showlassoselectioncount", true).toBool(); showTotalSelectionCount = settings->value("interface/showpersistentselectioncount", true).toBool(); - showSubtypeSelectionTally = settings->value("interface/showsubtypeselectiontally", true).toBool(); + tallyType = settings->value("interface/tallyType", 0).toInt(); showShortcuts = settings->value("menu/showshortcuts", true).toBool(); showGameSelectorFilterToolbar = settings->value("menu/showgameselectorfiltertoolbar", true).toBool(); @@ -1396,10 +1396,11 @@ void SettingsCache::setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSele settings->setValue("interface/showpersistentselectioncount", showTotalSelectionCount); } -void SettingsCache::setShowSubtypeSelectionTally(QT_STATE_CHANGED_T _showSubtypeSelectionTally) +void SettingsCache::setTallyType(TallyType value) { - showSubtypeSelectionTally = static_cast(_showSubtypeSelectionTally); - settings->setValue("interface/showsubtypeselectiontally", showSubtypeSelectionTally); + tallyType = static_cast(value); + settings->setValue("interface/tallyType", tallyType); + emit tallyTypeChanged(value); } void SettingsCache::loadPaths() diff --git a/cockatrice/src/client/settings/cache_settings.h b/cockatrice/src/client/settings/cache_settings.h index 29af89587..651aedc76 100644 --- a/cockatrice/src/client/settings/cache_settings.h +++ b/cockatrice/src/client/settings/cache_settings.h @@ -7,6 +7,7 @@ #ifndef SETTINGSCACHE_H #define SETTINGSCACHE_H +#include "../../game_graphics/tally/tally.h" #include "../../interface/card_picture_loader/card_picture_loader_cache_method.h" #include "../../interface/card_picture_loader/card_picture_loader_local_schemes.h" #include "shortcuts_settings.h" @@ -197,6 +198,7 @@ signals: void useTearOffMenusChanged(bool state); void roundCardCornersChanged(bool roundCardCorners); void keepGameChatFocusChanged(bool value); + void tallyTypeChanged(TallyType type); private: QSettings *settings; @@ -355,7 +357,7 @@ private: bool showStatusBar; bool showDragSelectionCount; bool showTotalSelectionCount; - bool showSubtypeSelectionTally; + int tallyType; public: SettingsCache(); @@ -479,9 +481,9 @@ public: { return showTotalSelectionCount; } - [[nodiscard]] bool getShowSubtypeSelectionTally() const + [[nodiscard]] TallyType getTallyType() const { - return showSubtypeSelectionTally; + return static_cast(tallyType); } [[nodiscard]] bool getNotificationsEnabled() const { @@ -1181,6 +1183,6 @@ public slots: void setRoundCardCorners(bool _roundCardCorners); void setShowDragSelectionCount(QT_STATE_CHANGED_T _showDragSelectionCount); void setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSelectionCount); - void setShowSubtypeSelectionTally(QT_STATE_CHANGED_T _showSubtypeSelectionTally); + void setTallyType(TallyType value); }; #endif diff --git a/cockatrice/src/game_graphics/game_view.cpp b/cockatrice/src/game_graphics/game_view.cpp index db17aaead..68e9197eb 100644 --- a/cockatrice/src/game_graphics/game_view.cpp +++ b/cockatrice/src/game_graphics/game_view.cpp @@ -45,6 +45,8 @@ GameView::GameView(GameScene *scene, QWidget *parent) : QGraphicsView(scene, par connect(scene, &GameScene::sigResizeRubberBand, this, &GameView::resizeRubberBand); connect(scene, &GameScene::sigStopRubberBand, this, &GameView::stopRubberBand); connect(scene, &QGraphicsScene::selectionChanged, this, [this]() { updateTotalSelectionCount(); }); + connect(&SettingsCache::instance(), &SettingsCache::tallyTypeChanged, this, + [this] { updateTotalSelectionCount(); }); setFocusDisabled(SettingsCache::instance().getKeepGameChatFocus()); connect(&SettingsCache::instance(), &SettingsCache::keepGameChatFocusChanged, this, &GameView::setFocusDisabled); @@ -246,8 +248,7 @@ void GameView::updateTotalSelectionCount(const QSize &viewSize) totalCountLabel->show(); } - TallyType tallyType = - SettingsCache::instance().getShowSubtypeSelectionTally() ? TallyType::Subtypes : TallyType::None; + TallyType tallyType = SettingsCache::instance().getTallyType(); GameScene *gameScene = static_cast(scene()); QList entries = Tally::compute(gameScene->selectedCards(), tallyType); diff --git a/cockatrice/src/game_graphics/player/menu/player_menu.cpp b/cockatrice/src/game_graphics/player/menu/player_menu.cpp index 17b791222..c7d321c81 100644 --- a/cockatrice/src/game_graphics/player/menu/player_menu.cpp +++ b/cockatrice/src/game_graphics/player/menu/player_menu.cpp @@ -44,6 +44,8 @@ PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_ utilityMenu = nullptr; } + tallyMenu = addManagedMenu(); + if (player->getLogic()->getPlayerInfo()->getLocal()) { sayMenu = addManagedMenu(player); } else { diff --git a/cockatrice/src/game_graphics/player/menu/player_menu.h b/cockatrice/src/game_graphics/player/menu/player_menu.h index 62ba66df7..ec43df374 100644 --- a/cockatrice/src/game_graphics/player/menu/player_menu.h +++ b/cockatrice/src/game_graphics/player/menu/player_menu.h @@ -15,6 +15,7 @@ #include "rfg_menu.h" #include "say_menu.h" #include "sideboard_menu.h" +#include "tally_menu.h" #include "utility_menu.h" #include @@ -87,6 +88,7 @@ private: GraveyardMenu *graveMenu; RfgMenu *rfgMenu; UtilityMenu *utilityMenu; + TallyMenu *tallyMenu; SayMenu *sayMenu; CustomZoneMenu *customZonesMenu; diff --git a/cockatrice/src/game_graphics/player/menu/tally_menu.cpp b/cockatrice/src/game_graphics/player/menu/tally_menu.cpp new file mode 100644 index 000000000..a507f4b2f --- /dev/null +++ b/cockatrice/src/game_graphics/player/menu/tally_menu.cpp @@ -0,0 +1,49 @@ +#include "tally_menu.h" + +#include "../../client/settings/cache_settings.h" + +TallyMenu::TallyMenu() +{ + aTallyNone = createTallyAction(TallyType::None); + aTallySubtype = createTallyAction(TallyType::Subtypes); + + addAction(aTallyNone); + addSeparator(); + addAction(aTallySubtype); + + retranslateUi(); +} + +QAction *TallyMenu::createTallyAction(TallyType tallyType) +{ + TallyType currentType = SettingsCache::instance().getTallyType(); + + QAction *action = new QAction(this); + action->setCheckable(true); + action->setChecked(tallyType == currentType); + + connect(action, &QAction::triggered, &SettingsCache::instance(), + [tallyType] { SettingsCache::instance().setTallyType(tallyType); }); + connect(&SettingsCache::instance(), &SettingsCache::tallyTypeChanged, action, + [action, tallyType](TallyType type) { action->setChecked(type == tallyType); }); + + return action; +} + +void TallyMenu::setShortcutsActive() +{ + // no-op because we haven't decided if we're adding shortcuts for tally types +} + +void TallyMenu::setShortcutsInactive() +{ + // no-op because we haven't decided if we're adding shortcuts for tally types +} + +void TallyMenu::retranslateUi() +{ + setTitle(tr("Tally")); + + aTallyNone->setText(tr("None")); + aTallySubtype->setText(tr("Subtype")); +} diff --git a/cockatrice/src/game_graphics/player/menu/tally_menu.h b/cockatrice/src/game_graphics/player/menu/tally_menu.h new file mode 100644 index 000000000..4bfd42fcc --- /dev/null +++ b/cockatrice/src/game_graphics/player/menu/tally_menu.h @@ -0,0 +1,28 @@ +#ifndef COCKATRICE_TALLY_MENU_H +#define COCKATRICE_TALLY_MENU_H + +#include "../../../interface/widgets/menus/tearoff_menu.h" +#include "../../tally/tally.h" +#include "abstract_player_component.h" + +#include + +class TallyMenu : public TearOffMenu, public AbstractPlayerComponent +{ + Q_OBJECT + +public: + explicit TallyMenu(); + + void setShortcutsActive() override; + void setShortcutsInactive() override; + void retranslateUi() override; + +private: + QAction *aTallyNone = nullptr; + QAction *aTallySubtype = nullptr; + + QAction *createTallyAction(TallyType tallyType); +}; + +#endif // COCKATRICE_TALLY_MENU_H 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 44b30d29c..8576934c1 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,10 +68,6 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() connect(&showTotalSelectionCountCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(), &SettingsCache::setShowTotalSelectionCount); - 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(), [](const QT_STATE_CHANGED_T state) { SettingsCache::instance().setUseTearOffMenus(state == Qt::Checked); }); @@ -90,9 +86,8 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() generalGrid->addWidget(&annotateTokensCheckBox, 6, 0); generalGrid->addWidget(&showDragSelectionCountCheckBox, 7, 0); generalGrid->addWidget(&showTotalSelectionCountCheckBox, 8, 0); - generalGrid->addWidget(&showSubtypeSelectionTallyCheckBox, 9, 0); - generalGrid->addWidget(&useTearOffMenusCheckBox, 10, 0); - generalGrid->addWidget(&keepGameChatFocusCheckBox, 11, 0); + generalGrid->addWidget(&useTearOffMenusCheckBox, 9, 0); + generalGrid->addWidget(&keepGameChatFocusCheckBox, 10, 0); generalGroupBox = new QGroupBox; generalGroupBox->setLayout(generalGrid); @@ -216,7 +211,6 @@ void UserInterfaceSettingsPage::retranslateUi() annotateTokensCheckBox.setText(tr("Annotate card text on tokens")); 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")); keepGameChatFocusCheckBox.setText( tr("Keep game chat focused when clicking in game (Note: disables card view search bar)")); 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 06f0e6b83..e10ed2a06 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,7 +29,6 @@ private: QCheckBox annotateTokensCheckBox; QCheckBox showDragSelectionCountCheckBox; QCheckBox showTotalSelectionCountCheckBox; - QCheckBox showSubtypeSelectionTallyCheckBox; QCheckBox useTearOffMenusCheckBox; QCheckBox keepGameChatFocusCheckBox; QCheckBox tapAnimationCheckBox;