mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-29 04:10:23 -07:00
[Game] Use in-game menu for tally setting (#7036)
* [Game] Use in-game menu for tally setting * pluralize name * fix includes * clean up TallyMenu * update settings * fix guard
This commit is contained in:
parent
b70f770633
commit
3f9dbdb33b
12 changed files with 126 additions and 19 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
@ -1403,10 +1403,15 @@ void SettingsCache::setShowTotalSelectionCount(QT_STATE_CHANGED_T _showTotalSele
|
|||
settings->setValue("interface/showpersistentselectioncount", showTotalSelectionCount);
|
||||
}
|
||||
|
||||
void SettingsCache::setShowSubtypeSelectionTally(QT_STATE_CHANGED_T _showSubtypeSelectionTally)
|
||||
void SettingsCache::setTallyType(int value)
|
||||
{
|
||||
showSubtypeSelectionTally = static_cast<bool>(_showSubtypeSelectionTally);
|
||||
settings->setValue("interface/showsubtypeselectiontally", showSubtypeSelectionTally);
|
||||
if (tallyType == value) {
|
||||
return;
|
||||
}
|
||||
|
||||
tallyType = value;
|
||||
settings->setValue("interface/tallyType", value);
|
||||
emit tallyTypeChanged(value);
|
||||
}
|
||||
|
||||
void SettingsCache::loadPaths()
|
||||
|
|
|
|||
|
|
@ -197,6 +197,7 @@ signals:
|
|||
void useTearOffMenusChanged(bool state);
|
||||
void roundCardCornersChanged(bool roundCardCorners);
|
||||
void keepGameChatFocusChanged(bool value);
|
||||
void tallyTypeChanged(int type);
|
||||
|
||||
private:
|
||||
QSettings *settings;
|
||||
|
|
@ -356,7 +357,7 @@ private:
|
|||
bool showStatusBar;
|
||||
bool showDragSelectionCount;
|
||||
bool showTotalSelectionCount;
|
||||
bool showSubtypeSelectionTally;
|
||||
int tallyType;
|
||||
|
||||
public:
|
||||
SettingsCache();
|
||||
|
|
@ -480,9 +481,9 @@ public:
|
|||
{
|
||||
return showTotalSelectionCount;
|
||||
}
|
||||
[[nodiscard]] bool getShowSubtypeSelectionTally() const
|
||||
[[nodiscard]] int getTallyType() const
|
||||
{
|
||||
return showSubtypeSelectionTally;
|
||||
return tallyType;
|
||||
}
|
||||
[[nodiscard]] bool getNotificationsEnabled() const
|
||||
{
|
||||
|
|
@ -1187,6 +1188,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(int value);
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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 = Tally::intToType(SettingsCache::instance().getTallyType());
|
||||
|
||||
GameScene *gameScene = static_cast<GameScene *>(scene());
|
||||
QList<TallyRow> entries = Tally::compute(gameScene->selectedCards(), tallyType);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_
|
|||
utilityMenu = nullptr;
|
||||
}
|
||||
|
||||
tallyMenu = addManagedMenu<TallyMenu>();
|
||||
|
||||
if (player->getLogic()->getPlayerInfo()->getLocal()) {
|
||||
sayMenu = addManagedMenu<SayMenu>(player);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -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 <QList>
|
||||
|
|
@ -87,6 +88,7 @@ private:
|
|||
GraveyardMenu *graveMenu;
|
||||
RfgMenu *rfgMenu;
|
||||
UtilityMenu *utilityMenu;
|
||||
TallyMenu *tallyMenu;
|
||||
SayMenu *sayMenu;
|
||||
CustomZoneMenu *customZonesMenu;
|
||||
|
||||
|
|
|
|||
54
cockatrice/src/game_graphics/player/menu/tally_menu.cpp
Normal file
54
cockatrice/src/game_graphics/player/menu/tally_menu.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include "tally_menu.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
|
||||
#include <QActionGroup>
|
||||
|
||||
TallyMenu::TallyMenu()
|
||||
{
|
||||
actionGroup = new QActionGroup(this);
|
||||
actionGroup->setExclusive(true);
|
||||
|
||||
aTallyNone = createTallyAction(TallyType::None);
|
||||
aTallySubtypes = createTallyAction(TallyType::Subtypes);
|
||||
|
||||
addAction(aTallyNone);
|
||||
addSeparator();
|
||||
addAction(aTallySubtypes);
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
QAction *TallyMenu::createTallyAction(TallyType tallyType)
|
||||
{
|
||||
TallyType currentType = Tally::intToType(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(static_cast<int>(tallyType)); });
|
||||
|
||||
actionGroup->addAction(action);
|
||||
|
||||
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"));
|
||||
aTallySubtypes->setText(tr("Subtypes"));
|
||||
}
|
||||
30
cockatrice/src/game_graphics/player/menu/tally_menu.h
Normal file
30
cockatrice/src/game_graphics/player/menu/tally_menu.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#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 <QMenu>
|
||||
|
||||
class TallyMenu : public TearOffMenu, public AbstractPlayerComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TallyMenu();
|
||||
|
||||
void setShortcutsActive() override;
|
||||
void setShortcutsInactive() override;
|
||||
void retranslateUi() override;
|
||||
|
||||
private:
|
||||
QActionGroup *actionGroup = nullptr;
|
||||
|
||||
QAction *aTallyNone = nullptr;
|
||||
QAction *aTallySubtypes = nullptr;
|
||||
|
||||
QAction *createTallyAction(TallyType tallyType);
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_TALLY_MENU_H
|
||||
|
|
@ -2,6 +2,15 @@
|
|||
|
||||
#include "subtype_tally.h"
|
||||
|
||||
TallyType Tally::intToType(int value)
|
||||
{
|
||||
if (value < static_cast<int>(TallyType::None) || value > static_cast<int>(TallyType::MaxValue)) {
|
||||
return TallyType::None;
|
||||
}
|
||||
|
||||
return static_cast<TallyType>(value);
|
||||
}
|
||||
|
||||
QList<TallyRow> Tally::compute(const QList<CardItem *> &cards, const TallyType type)
|
||||
{
|
||||
switch (type) {
|
||||
|
|
|
|||
|
|
@ -20,11 +20,20 @@ enum class TallyType
|
|||
{
|
||||
None,
|
||||
Subtypes,
|
||||
MaxValue = Subtypes // sentinel value
|
||||
};
|
||||
|
||||
namespace Tally
|
||||
{
|
||||
|
||||
/**
|
||||
* Safely converts an int into the corresponding TallyType.
|
||||
*
|
||||
* @param value The int value
|
||||
* @return The TallyType. Returns TallyType::None if the value is not within range
|
||||
*/
|
||||
TallyType intToType(int value);
|
||||
|
||||
/**
|
||||
* @brief Analyzes the selected cards according to the tally type and builds the resulting tally rows.
|
||||
* This forwards the cards to the code for that tally type.
|
||||
|
|
|
|||
|
|
@ -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)"));
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ private:
|
|||
QCheckBox annotateTokensCheckBox;
|
||||
QCheckBox showDragSelectionCountCheckBox;
|
||||
QCheckBox showTotalSelectionCountCheckBox;
|
||||
QCheckBox showSubtypeSelectionTallyCheckBox;
|
||||
QCheckBox useTearOffMenusCheckBox;
|
||||
QCheckBox keepGameChatFocusCheckBox;
|
||||
QCheckBox tapAnimationCheckBox;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue