mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-12 15:49:28 -08:00
Add more sort options to hand sort (#6279)
* Add more sort options to hand sort Took 14 minutes * Move defaultOptions up a level * Directly pass sort order as param * fix include * revert * fallback expandSortOption
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<CardList::SortOption> 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<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);
|
||||
}
|
||||
|
||||
void PlayerActions::actViewTopCards()
|
||||
|
||||
@@ -111,12 +111,13 @@ void HandZone::reorganizeCards()
|
||||
update();
|
||||
}
|
||||
|
||||
void HandZone::sortHand()
|
||||
void HandZone::sortHand(const QList<CardList::SortOption> &options)
|
||||
{
|
||||
if (getLogic()->getCards().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
getLogic()->sortCards({CardList::SortByMainType, CardList::SortByManaValue, CardList::SortByColorGrouping});
|
||||
|
||||
getLogic()->sortCards(options);
|
||||
reorganizeCards();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<CardList::SortOption> &options);
|
||||
void setWidth(qreal _width);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user