mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-20 17:32:15 -07:00
refactor card_item
This commit is contained in:
parent
4360288990
commit
7e0214c31f
2 changed files with 39 additions and 30 deletions
|
|
@ -385,17 +385,46 @@ void CardItem::playCard(bool faceDown)
|
||||||
tz->toggleTapped();
|
tz->toggleTapped();
|
||||||
else {
|
else {
|
||||||
if (SettingsCache::instance().getClickPlaysAllSelected()) {
|
if (SettingsCache::instance().getClickPlaysAllSelected()) {
|
||||||
if (faceDown) {
|
faceDown ? zone->getPlayer()->actPlayFacedown() : zone->getPlayer()->actPlay();
|
||||||
zone->getPlayer()->actPlayFacedown();
|
|
||||||
} else {
|
|
||||||
zone->getPlayer()->actPlay();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
zone->getPlayer()->playCard(this, faceDown, info ? info->getCipt() : false);
|
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)
|
void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::RightButton) {
|
if (event->button() == Qt::RightButton) {
|
||||||
|
|
@ -405,21 +434,7 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
}
|
}
|
||||||
} else if ((event->modifiers() != Qt::AltModifier) && (event->button() == Qt::LeftButton) &&
|
} else if ((event->modifiers() != Qt::AltModifier) && (event->button() == Qt::LeftButton) &&
|
||||||
(!SettingsCache::instance().getDoubleClickToPlay())) {
|
(!SettingsCache::instance().getDoubleClickToPlay())) {
|
||||||
bool hideCard = false;
|
handleClickedToPlay(event->modifiers().testFlag(Qt::ShiftModifier));
|
||||||
if (zone && zone->getIsView()) {
|
|
||||||
auto *view = static_cast<ZoneViewZone *>(zone);
|
|
||||||
if (view->getRevealZone() && !view->getWriteableRevealZone())
|
|
||||||
hideCard = true;
|
|
||||||
}
|
|
||||||
if (zone && hideCard) {
|
|
||||||
if (SettingsCache::instance().getClickPlaysAllSelected()) {
|
|
||||||
zone->getPlayer()->actHide();
|
|
||||||
} else {
|
|
||||||
zone->removeCard(this);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (owner != nullptr) { // cards without owner will be deleted
|
if (owner != nullptr) { // cards without owner will be deleted
|
||||||
|
|
@ -430,16 +445,9 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
|
||||||
void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if ((event->modifiers() != Qt::AltModifier) && (SettingsCache::instance().getDoubleClickToPlay()) &&
|
if ((event->modifiers() != Qt::AltModifier) && (event->buttons() == Qt::LeftButton) &&
|
||||||
(event->buttons() == Qt::LeftButton)) {
|
(SettingsCache::instance().getDoubleClickToPlay())) {
|
||||||
if (revealedCard) {
|
handleClickedToPlay(event->modifiers().testFlag(Qt::ShiftModifier));
|
||||||
if (SettingsCache::instance().getClickPlaysAllSelected()) {
|
|
||||||
zone->getPlayer()->actHide();
|
|
||||||
} else {
|
|
||||||
zone->removeCard(this);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
playCard(event->modifiers().testFlag(Qt::ShiftModifier));
|
|
||||||
}
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ private:
|
||||||
QMenu *cardMenu, *ptMenu, *moveMenu;
|
QMenu *cardMenu, *ptMenu, *moveMenu;
|
||||||
|
|
||||||
void prepareDelete();
|
void prepareDelete();
|
||||||
|
void handleClickedToPlay(bool shiftHeld);
|
||||||
public slots:
|
public slots:
|
||||||
void deleteLater();
|
void deleteLater();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue