diff --git a/cockatrice/src/client/settings/shortcuts_settings.h b/cockatrice/src/client/settings/shortcuts_settings.h index b6820798d..f3b7a53e6 100644 --- a/cockatrice/src/client/settings/shortcuts_settings.h +++ b/cockatrice/src/client/settings/shortcuts_settings.h @@ -562,9 +562,15 @@ private: ShortcutGroup::Move_selected)}, {"Player/aViewHand", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Hand"), parseSequenceString(""), ShortcutGroup::View)}, - {"Player/aSortHand", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Sort Hand"), - parseSequenceString("Ctrl+Shift+H"), - ShortcutGroup::View)}, + {"Player/aSortHandByName", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Sort Hand by Name"), + parseSequenceString(""), + ShortcutGroup::View)}, + {"Player/aSortHandByType", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Sort Hand by Type"), + parseSequenceString("Ctrl+Shift+H"), + ShortcutGroup::View)}, + {"Player/aSortHandByManaValue", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Sort Hand by Mana Value"), + parseSequenceString(""), + ShortcutGroup::View)}, {"Player/aViewGraveyard", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Graveyard"), parseSequenceString("F4"), ShortcutGroup::View)}, {"Player/aViewLibrary", diff --git a/cockatrice/src/game/player/menu/hand_menu.cpp b/cockatrice/src/game/player/menu/hand_menu.cpp index dc5fd0e2a..e8554499a 100644 --- a/cockatrice/src/game/player/menu/hand_menu.cpp +++ b/cockatrice/src/game/player/menu/hand_menu.cpp @@ -17,9 +17,22 @@ HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : T connect(aViewHand, &QAction::triggered, actions, &PlayerActions::actViewHand); addAction(aViewHand); - aSortHand = new QAction(this); - connect(aSortHand, &QAction::triggered, actions, &PlayerActions::actSortHand); - addAction(aSortHand); + mSortHand = addMenu(QString()); + + aSortHandByName = new QAction(this); + aSortHandByName->setData(CardList::SortByName); + aSortHandByType = new QAction(this); + aSortHandByType->setData(CardList::SortByMainType); + aSortHandByManaValue = new QAction(this); + aSortHandByManaValue->setData(CardList::SortByManaValue); + + connect(aSortHandByType, &QAction::triggered, actions, &PlayerActions::actSortHand); + connect(aSortHandByName, &QAction::triggered, actions, &PlayerActions::actSortHand); + connect(aSortHandByManaValue, &QAction::triggered, actions, &PlayerActions::actSortHand); + + mSortHand->addAction(aSortHandByName); + mSortHand->addAction(aSortHandByType); + mSortHand->addAction(aSortHandByManaValue); } mRevealHand = addMenu(QString()); @@ -73,7 +86,12 @@ void HandMenu::retranslateUi() if (player->getPlayerInfo()->getLocalOrJudge()) { aViewHand->setText(tr("&View hand")); - aSortHand->setText(tr("&Sort hand")); + + mSortHand->setTitle(tr("Sort hand by...")); + aSortHandByName->setText(tr("Name")); + aSortHandByType->setText(tr("Type")); + aSortHandByManaValue->setText(tr("Mana Value")); + aMulligan->setText(tr("Take &mulligan")); mMoveHandMenu->setTitle(tr("&Move hand to...")); @@ -91,14 +109,18 @@ void HandMenu::setShortcutsActive() { ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts(); aViewHand->setShortcuts(shortcuts.getShortcut("Player/aViewHand")); - aSortHand->setShortcuts(shortcuts.getShortcut("Player/aSortHand")); + aSortHandByName->setShortcuts(shortcuts.getShortcut("Player/aSortHandByName")); + aSortHandByType->setShortcuts(shortcuts.getShortcut("Player/aSortHandByType")); + aSortHandByManaValue->setShortcuts(shortcuts.getShortcut("Player/aSortHandByManaValue")); aMulligan->setShortcuts(shortcuts.getShortcut("Player/aMulligan")); } void HandMenu::setShortcutsInactive() { aViewHand->setShortcut(QKeySequence()); - aSortHand->setShortcut(QKeySequence()); + aSortHandByName->setShortcut(QKeySequence()); + aSortHandByType->setShortcut(QKeySequence()); + aSortHandByManaValue->setShortcut(QKeySequence()); aMulligan->setShortcut(QKeySequence()); } diff --git a/cockatrice/src/game/player/menu/hand_menu.h b/cockatrice/src/game/player/menu/hand_menu.h index f66cf25bb..d20fc7cd4 100644 --- a/cockatrice/src/game/player/menu/hand_menu.h +++ b/cockatrice/src/game/player/menu/hand_menu.h @@ -45,9 +45,13 @@ private: Player *player; QAction *aViewHand = nullptr; - QAction *aSortHand = nullptr; QAction *aMulligan = nullptr; + QMenu *mSortHand = nullptr; + QAction *aSortHandByName = nullptr; + QAction *aSortHandByType = nullptr; + QAction *aSortHandByManaValue = nullptr; + QMenu *mRevealHand = nullptr; QMenu *mRevealRandomHandCard = nullptr; diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index e37b34604..1fc91c492 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -139,9 +139,36 @@ void PlayerActions::actViewHand() player->getGameScene()->toggleZoneView(player, "hand", -1); } +/** + * @brief The sortHand actions only pass along a single SortOption in its data. + * This method fills out the rest of the sort priority list given that option. + * @param option The single sort option + * @return The sort priority list + */ +static QList expandSortOption(CardList::SortOption option) +{ + switch (option) { + case CardList::SortByName: + return {}; + case CardList::SortByMainType: + return {CardList::SortByMainType, CardList::SortByManaValue}; + case CardList::SortByManaValue: + return {CardList::SortByManaValue, CardList::SortByColors}; + default: + return {option}; + } +} + void PlayerActions::actSortHand() { - player->getGraphicsItem()->getHandZoneGraphicsItem()->sortHand(); + auto *action = qobject_cast(sender()); + CardList::SortOption option = static_cast(action->data().toInt()); + + QList sortOptions = expandSortOption(option); + + static QList defaultOptions = {CardList::SortByName, CardList::SortByPrinting}; + + player->getGraphicsItem()->getHandZoneGraphicsItem()->sortHand(sortOptions + defaultOptions); } void PlayerActions::actViewTopCards() diff --git a/cockatrice/src/game/zones/hand_zone.cpp b/cockatrice/src/game/zones/hand_zone.cpp index eb52f8f3b..860881f38 100644 --- a/cockatrice/src/game/zones/hand_zone.cpp +++ b/cockatrice/src/game/zones/hand_zone.cpp @@ -111,12 +111,13 @@ void HandZone::reorganizeCards() update(); } -void HandZone::sortHand() +void HandZone::sortHand(const QList &options) { if (getLogic()->getCards().isEmpty()) { return; } - getLogic()->sortCards({CardList::SortByMainType, CardList::SortByManaValue, CardList::SortByColorGrouping}); + + getLogic()->sortCards(options); reorganizeCards(); } diff --git a/cockatrice/src/game/zones/hand_zone.h b/cockatrice/src/game/zones/hand_zone.h index 1cee40372..25f4148bd 100644 --- a/cockatrice/src/game/zones/hand_zone.h +++ b/cockatrice/src/game/zones/hand_zone.h @@ -27,7 +27,7 @@ public: QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void reorganizeCards() override; - void sortHand(); + void sortHand(const QList &options); void setWidth(qreal _width); };