fix issues with #4648 (#4864)

This commit is contained in:
ebbit1q 2023-08-18 18:34:17 +02:00 committed by GitHub
parent ac5dc2578a
commit 90679d5669
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View file

@ -71,7 +71,9 @@
#include <QPainter> #include <QPainter>
#include <QRegularExpression> #include <QRegularExpression>
#include <QRegularExpressionMatch> #include <QRegularExpressionMatch>
#include <QTimer>
// 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) 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) 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), : QObject(_parent), game(_parent), movingCardsUntil(false), shortcutsActive(false), lastTokenDestroy(true),
active(false), local(_local), judge(_judge), mirrored(false), handVisible(false), conceded(false), zoneId(0), lastTokenTableRow(0), id(_id), active(false), local(_local), judge(_judge), mirrored(false), handVisible(false),
dialogSemaphore(false), deck(nullptr) conceded(false), zoneId(0), dialogSemaphore(false), deck(nullptr)
{ {
userInfo = new ServerInfo_User; userInfo = new ServerInfo_User;
userInfo->CopyFrom(info); userInfo->CopyFrom(info);
@ -533,6 +535,11 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T
addPlayer(player); addPlayer(player);
} }
moveTopCardTimer = new QTimer(this);
moveTopCardTimer->setInterval(MOVE_TOP_CARD_UNTIL_INTERVAL);
moveTopCardTimer->setSingleShot(true);
connect(moveTopCardTimer, &QTimer::timeout, [this]() { actMoveTopCardToPlay(); });
rearrangeZones(); rearrangeZones();
retranslateUi(); retranslateUi();
connect(&SettingsCache::instance().shortcuts(), SIGNAL(shortCutChanged()), this, SLOT(refreshShortcuts())); connect(&SettingsCache::instance().shortcuts(), SIGNAL(shortCutChanged()), this, SLOT(refreshShortcuts()));
@ -1301,6 +1308,8 @@ void Player::actMoveTopCardsToExile()
void Player::actMoveTopCardsUntil() void Player::actMoveTopCardsUntil()
{ {
moveTopCardTimer->stop();
movingCardsUntil = false;
QString expr = previousMovingCardsUntilExpr; QString expr = previousMovingCardsUntilExpr;
for (;;) { for (;;) {
bool ok; 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)) { if (zones.value("deck")->getCards().empty() || card.isNull() || movingCardsUntilFilter.check(card)) {
movingCardsUntil = false; movingCardsUntil = false;
} else { } else {
QTimer::singleShot(100, [this]() { actMoveTopCardToPlay(); }); moveTopCardTimer->start();
} }
} }
@ -2183,7 +2192,7 @@ void Player::eventMoveCard(const Event_MoveCard &event, const GameEventContext &
updateCardMenu(card); updateCardMenu(card);
if (movingCardsUntil && startZoneString == "deck" && targetZone->getName() == "stack") { if (movingCardsUntil && startZoneString == "deck" && targetZone->getName() == "stack") {
moveOneCardUntil(card->getName()); moveOneCardUntil(card->getInfo());
} }
} }

View file

@ -11,6 +11,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QMap> #include <QMap>
#include <QPoint> #include <QPoint>
#include <QTimer>
namespace google namespace google
{ {
@ -249,6 +250,7 @@ private:
*aMoveToXfromTopOfLibrary; *aMoveToXfromTopOfLibrary;
bool movingCardsUntil; bool movingCardsUntil;
QTimer *moveTopCardTimer;
QString previousMovingCardsUntilExpr = {}; QString previousMovingCardsUntilExpr = {};
FilterString movingCardsUntilFilter; FilterString movingCardsUntilFilter;
@ -298,7 +300,7 @@ private:
CardRelation::AttachType attach = CardRelation::DoesNotAttach, CardRelation::AttachType attach = CardRelation::DoesNotAttach,
bool persistent = false); bool persistent = false);
bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation); bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation);
void moveOneCardUntil(const QString &cardName); void moveOneCardUntil(const CardInfoPtr card);
QRectF bRect; QRectF bRect;

View file

@ -500,7 +500,7 @@ private:
{"Player/aMoveTopCardsToExile", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Exile (Multiple)"), {"Player/aMoveTopCardsToExile", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Exile (Multiple)"),
parseSequenceString(""), parseSequenceString(""),
ShortcutGroup::Move_top)}, 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"), parseSequenceString("Ctrl+Shift+Y"),
ShortcutGroup::Move_top)}, ShortcutGroup::Move_top)},
{"Player/aMoveTopCardToBottom", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Bottom of Library"), {"Player/aMoveTopCardToBottom", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Bottom of Library"),