mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-30 10:33: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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ private:
|
|||
QMenu *cardMenu, *ptMenu, *moveMenu;
|
||||
|
||||
void prepareDelete();
|
||||
void handleClickedToPlay(bool shiftHeld);
|
||||
public slots:
|
||||
void deleteLater();
|
||||
|
||||
|
|
|
|||
|
|
@ -3540,13 +3540,36 @@ static bool isUnwritableRevealZone(CardZone *zone)
|
|||
return false;
|
||||
}
|
||||
|
||||
void Player::playSelectedCards(const bool faceDown)
|
||||
{
|
||||
QList<CardItem *> selectedCards;
|
||||
for (const auto &item : scene()->selectedItems()) {
|
||||
auto *card = static_cast<CardItem *>(item);
|
||||
selectedCards.append(card);
|
||||
}
|
||||
|
||||
// CardIds will get shuffled downwards when cards leave the deck.
|
||||
// We need to iterate through the cards in reverse order so cardIds don't get changed out from under us as we play
|
||||
// out the cards one-by-one.
|
||||
std::sort(selectedCards.begin(), selectedCards.end(),
|
||||
[](const auto &card1, const auto &card2) { return card1->getId() > card2->getId(); });
|
||||
|
||||
for (auto &card : selectedCards) {
|
||||
if (card && !isUnwritableRevealZone(card->getZone()) && card->getZone()->getName() != "table") {
|
||||
const bool cipt = !faceDown && card->getInfo() ? card->getInfo()->getCipt() : false;
|
||||
playCard(card, faceDown, cipt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::actPlay()
|
||||
{
|
||||
auto *card = game->getActiveCard();
|
||||
if (card) {
|
||||
const bool cipt = card->getInfo() ? card->getInfo()->getCipt() : false;
|
||||
playCard(card, false, cipt);
|
||||
}
|
||||
playSelectedCards(false);
|
||||
}
|
||||
|
||||
void Player::actPlayFacedown()
|
||||
{
|
||||
playSelectedCards(true);
|
||||
}
|
||||
|
||||
void Player::actHide()
|
||||
|
|
@ -3559,14 +3582,6 @@ void Player::actHide()
|
|||
}
|
||||
}
|
||||
|
||||
void Player::actPlayFacedown()
|
||||
{
|
||||
auto *card = game->getActiveCard();
|
||||
if (card) {
|
||||
playCard(card, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::actReveal(QAction *action)
|
||||
{
|
||||
const int otherPlayerId = action->data().toInt();
|
||||
|
|
|
|||
|
|
@ -162,6 +162,11 @@ public slots:
|
|||
void actDrawCards();
|
||||
void actUndoDraw();
|
||||
void actMulligan();
|
||||
|
||||
void actPlay();
|
||||
void actPlayFacedown();
|
||||
void actHide();
|
||||
|
||||
void actMoveTopCardToPlay();
|
||||
void actMoveTopCardToPlayFaceDown();
|
||||
void actMoveTopCardToGrave();
|
||||
|
|
@ -223,9 +228,6 @@ private slots:
|
|||
void actFlowP();
|
||||
void actFlowT();
|
||||
void actSetAnnotation();
|
||||
void actPlay();
|
||||
void actHide();
|
||||
void actPlayFacedown();
|
||||
void actReveal(QAction *action);
|
||||
void refreshShortcuts();
|
||||
|
||||
|
|
@ -323,6 +325,8 @@ private:
|
|||
void addPlayerToList(QMenu *playerList, Player *player);
|
||||
static void removePlayerFromList(QMenu *playerList, Player *player);
|
||||
|
||||
void playSelectedCards(bool faceDown = false);
|
||||
|
||||
QRectF bRect;
|
||||
|
||||
QMap<int, AbstractCounter *> counters;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue