mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 04:23:55 -07: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:
parent
6bc2293292
commit
757e9f3415
6 changed files with 74 additions and 14 deletions
|
|
@ -562,9 +562,15 @@ private:
|
||||||
ShortcutGroup::Move_selected)},
|
ShortcutGroup::Move_selected)},
|
||||||
{"Player/aViewHand",
|
{"Player/aViewHand",
|
||||||
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Hand"), parseSequenceString(""), ShortcutGroup::View)},
|
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Hand"), parseSequenceString(""), ShortcutGroup::View)},
|
||||||
{"Player/aSortHand", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Sort Hand"),
|
{"Player/aSortHandByName", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Sort Hand by Name"),
|
||||||
parseSequenceString("Ctrl+Shift+H"),
|
parseSequenceString(""),
|
||||||
ShortcutGroup::View)},
|
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",
|
{"Player/aViewGraveyard",
|
||||||
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Graveyard"), parseSequenceString("F4"), ShortcutGroup::View)},
|
ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Graveyard"), parseSequenceString("F4"), ShortcutGroup::View)},
|
||||||
{"Player/aViewLibrary",
|
{"Player/aViewLibrary",
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,22 @@ HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : T
|
||||||
connect(aViewHand, &QAction::triggered, actions, &PlayerActions::actViewHand);
|
connect(aViewHand, &QAction::triggered, actions, &PlayerActions::actViewHand);
|
||||||
addAction(aViewHand);
|
addAction(aViewHand);
|
||||||
|
|
||||||
aSortHand = new QAction(this);
|
mSortHand = addMenu(QString());
|
||||||
connect(aSortHand, &QAction::triggered, actions, &PlayerActions::actSortHand);
|
|
||||||
addAction(aSortHand);
|
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());
|
mRevealHand = addMenu(QString());
|
||||||
|
|
@ -73,7 +86,12 @@ void HandMenu::retranslateUi()
|
||||||
|
|
||||||
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||||
aViewHand->setText(tr("&View hand"));
|
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"));
|
aMulligan->setText(tr("Take &mulligan"));
|
||||||
|
|
||||||
mMoveHandMenu->setTitle(tr("&Move hand to..."));
|
mMoveHandMenu->setTitle(tr("&Move hand to..."));
|
||||||
|
|
@ -91,14 +109,18 @@ void HandMenu::setShortcutsActive()
|
||||||
{
|
{
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
aViewHand->setShortcuts(shortcuts.getShortcut("Player/aViewHand"));
|
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"));
|
aMulligan->setShortcuts(shortcuts.getShortcut("Player/aMulligan"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandMenu::setShortcutsInactive()
|
void HandMenu::setShortcutsInactive()
|
||||||
{
|
{
|
||||||
aViewHand->setShortcut(QKeySequence());
|
aViewHand->setShortcut(QKeySequence());
|
||||||
aSortHand->setShortcut(QKeySequence());
|
aSortHandByName->setShortcut(QKeySequence());
|
||||||
|
aSortHandByType->setShortcut(QKeySequence());
|
||||||
|
aSortHandByManaValue->setShortcut(QKeySequence());
|
||||||
aMulligan->setShortcut(QKeySequence());
|
aMulligan->setShortcut(QKeySequence());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,13 @@ private:
|
||||||
Player *player;
|
Player *player;
|
||||||
|
|
||||||
QAction *aViewHand = nullptr;
|
QAction *aViewHand = nullptr;
|
||||||
QAction *aSortHand = nullptr;
|
|
||||||
QAction *aMulligan = nullptr;
|
QAction *aMulligan = nullptr;
|
||||||
|
|
||||||
|
QMenu *mSortHand = nullptr;
|
||||||
|
QAction *aSortHandByName = nullptr;
|
||||||
|
QAction *aSortHandByType = nullptr;
|
||||||
|
QAction *aSortHandByManaValue = nullptr;
|
||||||
|
|
||||||
QMenu *mRevealHand = nullptr;
|
QMenu *mRevealHand = nullptr;
|
||||||
QMenu *mRevealRandomHandCard = nullptr;
|
QMenu *mRevealRandomHandCard = nullptr;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,9 +139,36 @@ void PlayerActions::actViewHand()
|
||||||
player->getGameScene()->toggleZoneView(player, "hand", -1);
|
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()
|
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()
|
void PlayerActions::actViewTopCards()
|
||||||
|
|
|
||||||
|
|
@ -111,12 +111,13 @@ void HandZone::reorganizeCards()
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::sortHand()
|
void HandZone::sortHand(const QList<CardList::SortOption> &options)
|
||||||
{
|
{
|
||||||
if (getLogic()->getCards().isEmpty()) {
|
if (getLogic()->getCards().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getLogic()->sortCards({CardList::SortByMainType, CardList::SortByManaValue, CardList::SortByColorGrouping});
|
|
||||||
|
getLogic()->sortCards(options);
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ public:
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
void reorganizeCards() override;
|
void reorganizeCards() override;
|
||||||
void sortHand();
|
void sortHand(const QList<CardList::SortOption> &options);
|
||||||
void setWidth(qreal _width);
|
void setWidth(qreal _width);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue