mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-24 18:33:03 -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
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue