mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-11 21:04:07 -07:00
Directly pass sort order as param
This commit is contained in:
parent
f5426b2236
commit
23fb74ca41
3 changed files with 11 additions and 28 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<CardList::SortOption> expandSortOption(CardList::SortOption option)
|
||||
void PlayerActions::actSortHand(const QList<CardList::SortOption> &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<QAction *>(sender());
|
||||
CardList::SortOption option = static_cast<CardList::SortOption>(action->data().toInt());
|
||||
|
||||
QList<CardList::SortOption> sortOptions = expandSortOption(option);
|
||||
|
||||
static QList defaultOptions = {CardList::SortByName, CardList::SortByPrinting};
|
||||
|
||||
player->getGraphicsItem()->getHandZoneGraphicsItem()->sortHand(sortOptions + defaultOptions);
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ public slots:
|
|||
void actRevealRandomHandCard(int revealToPlayerId);
|
||||
void actRevealLibrary(int revealToPlayerId);
|
||||
|
||||
void actSortHand();
|
||||
void actSortHand(const QList<CardList::SortOption> &sortOptions);
|
||||
|
||||
void cardMenuAction();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue