mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-07 05:53:59 -07:00
[Game] Refactor CardDragItem faceDown logic
This commit is contained in:
parent
c4d8c58a7b
commit
5a7b861827
3 changed files with 29 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "card_zone.h"
|
||||
|
||||
#include "../board/card_drag_item.h"
|
||||
#include "../board/card_item.h"
|
||||
#include "view_zone.h"
|
||||
|
||||
|
|
@ -28,6 +29,22 @@ void CardZone::retranslateUi()
|
|||
getLogic()->getCards()[i]->retranslateUi();
|
||||
}
|
||||
|
||||
bool CardZone::shouldDropFaceDown(const CardDragItem *item, const CardZoneLogic *startZone) const
|
||||
{
|
||||
// forceFaceDown takes precedence over everything
|
||||
if (item->isForceFaceDown()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Maintain face-down state if same zone.
|
||||
// Compare using zone names so card remains face-down when you hand it over to your opponent
|
||||
if (startZone->getName() == getLogic()->getName()) {
|
||||
return item->getItem()->getFaceDown();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CardZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * /*event*/)
|
||||
{
|
||||
if (doubleClickAction)
|
||||
|
|
|
|||
|
|
@ -67,6 +67,15 @@ public:
|
|||
doubleClickAction = _doubleClickAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the dropEvent caused by the given CardDragItem should result in the face_down field of the resulting
|
||||
* MoveCard command to be true.
|
||||
* @param item The CardDragItem that is being dropped into this zone
|
||||
* @param startZone The zone that the item came from
|
||||
* @return Whether to set face_down to true
|
||||
*/
|
||||
bool shouldDropFaceDown(const CardDragItem *item, const CardZoneLogic *startZone) const;
|
||||
|
||||
private:
|
||||
CardZoneLogic *logic;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -134,8 +134,9 @@ void TableZone::handleDropEventByGrid(const QList<CardDragItem *> &dragItems,
|
|||
for (const auto &item : dragItems) {
|
||||
CardToMove *ctm = cmd.mutable_cards_to_move()->add_card();
|
||||
ctm->set_card_id(item->getId());
|
||||
ctm->set_face_down(item->isForceFaceDown());
|
||||
if (startZone->getName() != getLogic()->getName() && !item->isForceFaceDown()) {
|
||||
bool faceDown = shouldDropFaceDown(item, startZone);
|
||||
ctm->set_face_down(faceDown);
|
||||
if (startZone->getName() != getLogic()->getName() && !faceDown) {
|
||||
const auto &card = item->getItem()->getCard();
|
||||
if (card) {
|
||||
ctm->set_pt(card.getInfo().getPowTough().toStdString());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue