clicking to play can now play all selected (#5254)

* play action now applies to all selected cards

* check card zone before applying action

* fix bug with wonky play from deck

* refactor

* don't play card if it's already on table

* add new setting

* make actPlay and friends public

* implement thing

* refactor card_item
This commit is contained in:
RickyRister 2024-12-17 20:43:17 -08:00 committed by GitHub
parent fd5a649246
commit a6b5abf271
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 109 additions and 38 deletions

View file

@ -383,8 +383,46 @@ void CardItem::playCard(bool faceDown)
TableZone *tz = qobject_cast<TableZone *>(zone);
if (tz)
tz->toggleTapped();
else
zone->getPlayer()->playCard(this, faceDown, info ? info->getCipt() : false);
else {
if (SettingsCache::instance().getClickPlaysAllSelected()) {
faceDown ? zone->getPlayer()->actPlayFacedown() : zone->getPlayer()->actPlay();
} else {
zone->getPlayer()->playCard(this, faceDown, info ? info->getCipt() : false);
}
}
}
/**
* @brief returns true if the zone is a unwritable reveal zone view (eg a card reveal window). Will return false if zone
* is nullptr.
*/
static bool isUnwritableRevealZone(CardZone *zone)
{
if (zone && zone->getIsView()) {
if (auto *view = static_cast<ZoneViewZone *>(zone)) {
return view->getRevealZone() && !view->getWriteableRevealZone();
}
}
return false;
}
/**
* This method is called when a "click to play" is done on the card.
* This is either triggered by a single click or double click, depending on the settings.
*
* @param shiftHeld if the shift key was held during the click
*/
void CardItem::handleClickedToPlay(bool shiftHeld)
{
if (isUnwritableRevealZone(zone)) {
if (SettingsCache::instance().getClickPlaysAllSelected()) {
zone->getPlayer()->actHide();
} else {
zone->removeCard(this);
}
} else {
playCard(shiftHeld);
}
}
void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
@ -396,17 +434,7 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
}
} else if ((event->modifiers() != Qt::AltModifier) && (event->button() == Qt::LeftButton) &&
(!SettingsCache::instance().getDoubleClickToPlay())) {
bool hideCard = false;
if (zone && zone->getIsView()) {
auto *view = static_cast<ZoneViewZone *>(zone);
if (view->getRevealZone() && !view->getWriteableRevealZone())
hideCard = true;
}
if (zone && hideCard) {
zone->removeCard(this);
} else {
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
}
handleClickedToPlay(event->modifiers().testFlag(Qt::ShiftModifier));
}
if (owner != nullptr) { // cards without owner will be deleted
@ -417,12 +445,9 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if ((event->modifiers() != Qt::AltModifier) && (SettingsCache::instance().getDoubleClickToPlay()) &&
(event->buttons() == Qt::LeftButton)) {
if (revealedCard)
zone->removeCard(this);
else
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
if ((event->modifiers() != Qt::AltModifier) && (event->buttons() == Qt::LeftButton) &&
(SettingsCache::instance().getDoubleClickToPlay())) {
handleClickedToPlay(event->modifiers().testFlag(Qt::ShiftModifier));
}
event->accept();
}