diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 05918c30..04390e60 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -71,7 +71,9 @@ #include #include #include -#include + +// milliseconds in between triggers of the move top cards until action +static constexpr int MOVE_TOP_CARD_UNTIL_INTERVAL = 100; PlayerArea::PlayerArea(QGraphicsItem *parentItem) : QObject(), QGraphicsItem(parentItem) { @@ -108,9 +110,9 @@ void PlayerArea::setPlayerZoneId(int _playerZoneId) } Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, TabGame *_parent) - : QObject(_parent), game(_parent), shortcutsActive(false), lastTokenDestroy(true), lastTokenTableRow(0), id(_id), - active(false), local(_local), judge(_judge), mirrored(false), handVisible(false), conceded(false), zoneId(0), - dialogSemaphore(false), deck(nullptr) + : QObject(_parent), game(_parent), movingCardsUntil(false), shortcutsActive(false), lastTokenDestroy(true), + lastTokenTableRow(0), id(_id), active(false), local(_local), judge(_judge), mirrored(false), handVisible(false), + conceded(false), zoneId(0), dialogSemaphore(false), deck(nullptr) { userInfo = new ServerInfo_User; userInfo->CopyFrom(info); @@ -533,6 +535,11 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T addPlayer(player); } + moveTopCardTimer = new QTimer(this); + moveTopCardTimer->setInterval(MOVE_TOP_CARD_UNTIL_INTERVAL); + moveTopCardTimer->setSingleShot(true); + connect(moveTopCardTimer, &QTimer::timeout, [this]() { actMoveTopCardToPlay(); }); + rearrangeZones(); retranslateUi(); connect(&SettingsCache::instance().shortcuts(), SIGNAL(shortCutChanged()), this, SLOT(refreshShortcuts())); @@ -1301,6 +1308,8 @@ void Player::actMoveTopCardsToExile() void Player::actMoveTopCardsUntil() { + moveTopCardTimer->stop(); + movingCardsUntil = false; QString expr = previousMovingCardsUntilExpr; for (;;) { bool ok; @@ -1328,13 +1337,13 @@ void Player::actMoveTopCardsUntil() } } -void Player::moveOneCardUntil(const QString &cardName) +void Player::moveOneCardUntil(const CardInfoPtr card) { - auto card = db->getCard(cardName); + moveTopCardTimer->stop(); if (zones.value("deck")->getCards().empty() || card.isNull() || movingCardsUntilFilter.check(card)) { movingCardsUntil = false; } else { - QTimer::singleShot(100, [this]() { actMoveTopCardToPlay(); }); + moveTopCardTimer->start(); } } @@ -2183,7 +2192,7 @@ void Player::eventMoveCard(const Event_MoveCard &event, const GameEventContext & updateCardMenu(card); if (movingCardsUntil && startZoneString == "deck" && targetZone->getName() == "stack") { - moveOneCardUntil(card->getName()); + moveOneCardUntil(card->getInfo()); } } diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index 96e2ba95..f19c6306 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace google { @@ -249,6 +250,7 @@ private: *aMoveToXfromTopOfLibrary; bool movingCardsUntil; + QTimer *moveTopCardTimer; QString previousMovingCardsUntilExpr = {}; FilterString movingCardsUntilFilter; @@ -298,7 +300,7 @@ private: CardRelation::AttachType attach = CardRelation::DoesNotAttach, bool persistent = false); bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation); - void moveOneCardUntil(const QString &cardName); + void moveOneCardUntil(const CardInfoPtr card); QRectF bRect; diff --git a/cockatrice/src/shortcutssettings.h b/cockatrice/src/shortcutssettings.h index 6ff06eb2..fb2613d2 100644 --- a/cockatrice/src/shortcutssettings.h +++ b/cockatrice/src/shortcutssettings.h @@ -500,7 +500,7 @@ private: {"Player/aMoveTopCardsToExile", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Exile (Multiple)"), parseSequenceString(""), ShortcutGroup::Move_top)}, - {"Player/aMoveTopCardsUntil", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Stack"), + {"Player/aMoveTopCardsUntil", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Stack Until Found"), parseSequenceString("Ctrl+Shift+Y"), ShortcutGroup::Move_top)}, {"Player/aMoveTopCardToBottom", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Bottom of Library"),