From 06738cae9300b3c3188d61c8ef354d34210a928d Mon Sep 17 00:00:00 2001 From: Paul Carroll <57120760+carrollpaul@users.noreply.github.com> Date: Sat, 2 Aug 2025 00:40:17 -0400 Subject: [PATCH] Add menu option and hotkey to sort hand (#6057) * Add sort hand shortcut * add function to sort hand by type and name * rig up the sort hand to the player * fix sorting param * use getShortcut instead of getSingleShortcut * use correct method * change default sorting --------- Co-authored-by: Zach H --- cockatrice/src/game/player/player.cpp | 11 +++++++++++ cockatrice/src/game/player/player.h | 4 ++-- cockatrice/src/game/zones/hand_zone.cpp | 9 +++++++++ cockatrice/src/game/zones/hand_zone.h | 1 + cockatrice/src/settings/shortcuts_settings.h | 3 +++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/game/player/player.cpp b/cockatrice/src/game/player/player.cpp index efb694090..1034b5651 100644 --- a/cockatrice/src/game/player/player.cpp +++ b/cockatrice/src/game/player/player.cpp @@ -210,6 +210,8 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T connect(aViewLibrary, &QAction::triggered, this, &Player::actViewLibrary); aViewHand = new QAction(this); connect(aViewHand, &QAction::triggered, this, &Player::actViewHand); + aSortHand = new QAction(this); + connect(aSortHand, &QAction::triggered, this, &Player::actSortHand); aViewTopCards = new QAction(this); connect(aViewTopCards, &QAction::triggered, this, &Player::actViewTopCards); @@ -298,6 +300,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T if (local || judge) { handMenu = playerMenu->addTearOffMenu(QString()); handMenu->addAction(aViewHand); + handMenu->addAction(aSortHand); playerLists.append(mRevealHand = handMenu->addMenu(QString())); playerLists.append(mRevealRandomHandCard = handMenu->addMenu(QString())); handMenu->addSeparator(); @@ -795,6 +798,7 @@ void Player::retranslateUi() aViewLibrary->setText(tr("&View library")); aViewHand->setText(tr("&View hand")); + aSortHand->setText(tr("&Sort hand")); aViewTopCards->setText(tr("View &top cards of library...")); aViewBottomCards->setText(tr("View bottom cards of library...")); mRevealLibrary->setTitle(tr("Reveal &library to...")); @@ -959,6 +963,7 @@ void Player::setShortcutsActive() aMoveToHand->setShortcuts(shortcuts.getShortcut("Player/aMoveToHand")); aMoveToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveToGraveyard")); aMoveToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveToExile")); + aSortHand->setShortcuts(shortcuts.getShortcut("Player/aSortHand")); aSelectAll->setShortcuts(shortcuts.getShortcut("Player/aSelectAll")); aSelectRow->setShortcuts(shortcuts.getShortcut("Player/aSelectRow")); @@ -1064,6 +1069,7 @@ void Player::setShortcutsInactive() aMoveBottomCardToExile->setShortcut(QKeySequence()); aMoveBottomCardsToExile->setShortcut(QKeySequence()); aIncrementAllCardCounters->setShortcut(QKeySequence()); + aSortHand->setShortcut(QKeySequence()); QMapIterator counterIterator(counters); while (counterIterator.hasNext()) { @@ -1134,6 +1140,11 @@ void Player::actViewHand() static_cast(scene())->toggleZoneView(this, "hand", -1); } +void Player::actSortHand() +{ + hand->sortHand(); +} + void Player::actViewTopCards() { int deckSize = zones.value("deck")->getCards().size(); diff --git a/cockatrice/src/game/player/player.h b/cockatrice/src/game/player/player.h index c2aa957a6..3efad6b77 100644 --- a/cockatrice/src/game/player/player.h +++ b/cockatrice/src/game/player/player.h @@ -239,7 +239,7 @@ private slots: void actSetAnnotation(); void actReveal(QAction *action); void refreshShortcuts(); - + void actSortHand(); void initSayMenu(); public: @@ -276,7 +276,7 @@ private: QAction *aPlay, *aPlayFacedown, *aHide, *aTap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetPT, *aResetPT, *aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aFlowP, *aFlowT, *aSetAnnotation, *aFlip, *aPeek, *aClone, *aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToHand, *aMoveToGraveyard, *aMoveToExile, - *aMoveToXfromTopOfLibrary, *aSelectAll, *aSelectRow, *aSelectColumn, *aIncrementAllCardCounters; + *aMoveToXfromTopOfLibrary, *aSelectAll, *aSelectRow, *aSelectColumn, *aSortHand, *aIncrementAllCardCounters; bool movingCardsUntil; QTimer *moveTopCardTimer; diff --git a/cockatrice/src/game/zones/hand_zone.cpp b/cockatrice/src/game/zones/hand_zone.cpp index d645a299e..2d6947c9d 100644 --- a/cockatrice/src/game/zones/hand_zone.cpp +++ b/cockatrice/src/game/zones/hand_zone.cpp @@ -127,6 +127,15 @@ void HandZone::reorganizeCards() update(); } +void HandZone::sortHand() +{ + if (cards.isEmpty()) { + return; + } + cards.sortBy({CardList::SortByMainType, CardList::SortByManaValue, CardList::SortByColorGrouping}); + reorganizeCards(); +} + void HandZone::setWidth(qreal _width) { if (SettingsCache::instance().getHorizontalHand()) { diff --git a/cockatrice/src/game/zones/hand_zone.h b/cockatrice/src/game/zones/hand_zone.h index 8189c7087..3fd55b20b 100644 --- a/cockatrice/src/game/zones/hand_zone.h +++ b/cockatrice/src/game/zones/hand_zone.h @@ -19,6 +19,7 @@ public: QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; void reorganizeCards() override; + void sortHand(); void setWidth(qreal _width); protected: diff --git a/cockatrice/src/settings/shortcuts_settings.h b/cockatrice/src/settings/shortcuts_settings.h index 838cfa22d..fdf422783 100644 --- a/cockatrice/src/settings/shortcuts_settings.h +++ b/cockatrice/src/settings/shortcuts_settings.h @@ -556,6 +556,9 @@ 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/aViewGraveyard", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Graveyard"), parseSequenceString("F4"), ShortcutGroup::View)}, {"Player/aViewLibrary",