diff --git a/cockatrice/src/game/player/menu/hand_menu.cpp b/cockatrice/src/game/player/menu/hand_menu.cpp index e8554499a..ddb5b6f2a 100644 --- a/cockatrice/src/game/player/menu/hand_menu.cpp +++ b/cockatrice/src/game/player/menu/hand_menu.cpp @@ -26,9 +26,11 @@ HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : T 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); + connect(aSortHandByType, &QAction::triggered, actions, [actions] { actions->actSortHand({}); }); + connect(aSortHandByName, &QAction::triggered, actions, + [actions] { actions->actSortHand({CardList::SortByMainType, CardList::SortByManaValue}); }); + connect(aSortHandByManaValue, &QAction::triggered, actions, + [actions] { actions->actSortHand({CardList::SortByManaValue, CardList::SortByColors}); }); mSortHand->addAction(aSortHandByName); mSortHand->addAction(aSortHandByType); diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index 388a88e01..1a14bff1a 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -140,32 +140,13 @@ void PlayerActions::actViewHand() } /** - * @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 + * @brief Sorts the cards in the hand using the given sort options. + * Appends SortByName and SortByPrinting to the end of the list, so that names and printings are grouped together. + * + * @param sortOptions The non-default options to sort the cards by. */ -static QList expandSortOption(CardList::SortOption option) +void PlayerActions::actSortHand(const QList &sortOptions) { - switch (option) { - case CardList::SortByName: - return {}; - case CardList::SortByMainType: - return {CardList::SortByMainType, CardList::SortByManaValue}; - case CardList::SortByManaValue: - return {CardList::SortByManaValue, CardList::SortByColors}; - default: - return {}; - } -} - -void PlayerActions::actSortHand() -{ - 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); diff --git a/cockatrice/src/game/player/player_actions.h b/cockatrice/src/game/player/player_actions.h index aba3726e8..34ddb7942 100644 --- a/cockatrice/src/game/player/player_actions.h +++ b/cockatrice/src/game/player/player_actions.h @@ -152,7 +152,7 @@ public slots: void actRevealRandomHandCard(int revealToPlayerId); void actRevealLibrary(int revealToPlayerId); - void actSortHand(); + void actSortHand(const QList &sortOptions); void cardMenuAction();