mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-29 01:53:54 -07:00
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:
parent
fd5a649246
commit
a6b5abf271
10 changed files with 109 additions and 38 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue