mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
* Player refactor. Took 1 hour 43 minutes Took 1 minute Took 23 seconds * Tiny lint. Took 3 minutes * Hook up tap logic again. Took 13 minutes * Fix an include. Took 3 minutes * Stuff. Took 6 minutes * Fix typo. Took 7 minutes * Include. Took 1 minute * Reorganize method/variable definitions, remove unused ones. Took 1 hour 8 minutes Took 24 seconds * Clean up some unused imports. Took 6 minutes * Player holds the deck, emits deckChanged(), other elements player->getDeck() to respond to changes. Took 37 minutes * Connect player->openDeckEditor signal directly in the player constructor Took 6 minutes * Emit openDeckEditor signal in player_actions again. Took 3 minutes * Do to-do's Took 3 hours 32 minutes * Lint. Took 3 minutes * Lint again. Took 2 minutes * Fix include. Took 32 minutes * The stack should ensure card visibility. Took 21 minutes * Fine, the game can remember the tab. Took 10 minutes Took 21 seconds Took 9 seconds * zoneId is a dynamic gameplay property and thus belongs in player.cpp Took 11 minutes Took 19 seconds * Signal view removal, addition. Took 5 minutes * Ensure all players are considered local in local game. Took 10 minutes * ENSURE they are. Took 8 minutes * Bounds check data sent by QAction() Took 54 minutes * Move comment. Took 20 seconds * Reimplement logging category for game_event_handler.cpp, remove linebreaks. Took 36 seconds * PlayerGraphicsItem is responsible for retranslateUi, not Player. Took 14 seconds * Set menu for sideboard again, translate some menu titles, reimplement actIncPT action Took 54 seconds * Comment spacing. Took 43 seconds * Change message_log_widget.cpp slots to take CardZoneLogic parameters as emitted by PlayerEventHandler. Took 7 minutes Took 14 seconds * Remove unused player_logger.cpp Took 2 minutes * Query local game state correctly from tab_supervisor again Took 3 minutes * Revert Deck legality checker. Took 3 minutes * Instantiate menu before graphics item. Took 1 hour 5 minutes Took 55 minutes * Differentiate games and replays. Took 9 seconds * Lint. Took 10 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
134 lines
4.4 KiB
C++
134 lines
4.4 KiB
C++
#include "card_drag_item.h"
|
|
|
|
#include "../game_scene.h"
|
|
#include "../zones/card_zone.h"
|
|
#include "../zones/table_zone.h"
|
|
#include "../zones/view_zone.h"
|
|
#include "card_item.h"
|
|
|
|
#include <QCursor>
|
|
#include <QGraphicsSceneMouseEvent>
|
|
#include <QPainter>
|
|
|
|
CardDragItem::CardDragItem(CardItem *_item,
|
|
int _id,
|
|
const QPointF &_hotSpot,
|
|
bool _faceDown,
|
|
AbstractCardDragItem *parentDrag)
|
|
: AbstractCardDragItem(_item, _hotSpot, parentDrag), id(_id), faceDown(_faceDown), occupied(false), currentZone(0)
|
|
{
|
|
}
|
|
|
|
void CardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
{
|
|
AbstractCardDragItem::paint(painter, option, widget);
|
|
|
|
if (occupied)
|
|
painter->fillPath(shape(), QColor(200, 0, 0, 100));
|
|
}
|
|
|
|
void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
|
{
|
|
QList<QGraphicsItem *> colliding =
|
|
scene()->items(cursorScenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder,
|
|
static_cast<GameScene *>(scene())->getViewTransform());
|
|
|
|
CardZone *cardZone = 0;
|
|
ZoneViewZone *zoneViewZone = 0;
|
|
for (int i = colliding.size() - 1; i >= 0; i--) {
|
|
CardZone *temp = qgraphicsitem_cast<CardZone *>(colliding.at(i));
|
|
if (!cardZone)
|
|
cardZone = temp;
|
|
if (!zoneViewZone)
|
|
zoneViewZone = qobject_cast<ZoneViewZone *>(temp);
|
|
}
|
|
CardZone *cursorZone = 0;
|
|
if (zoneViewZone)
|
|
cursorZone = zoneViewZone;
|
|
else if (cardZone)
|
|
cursorZone = cardZone;
|
|
|
|
// Always update the current zone, even if its null, to cancel the drag
|
|
// instead of dropping cards into an non-intuitive location.
|
|
currentZone = cursorZone;
|
|
|
|
if (!cursorZone) {
|
|
// Avoid the cards getting stuck visually when not over
|
|
// any zone.
|
|
QPointF newPos = cursorScenePos - hotSpot;
|
|
|
|
if (newPos != pos()) {
|
|
for (int i = 0; i < childDrags.size(); i++)
|
|
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
|
setPos(newPos);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
QPointF zonePos = currentZone->scenePos();
|
|
QPointF cursorPosInZone = cursorScenePos - zonePos;
|
|
|
|
// If we are on a Table, we center the card around the cursor, because we
|
|
// snap it into place and no longer see it being dragged.
|
|
//
|
|
// For other zones (where we do display the card under the cursor), we use
|
|
// the hotspot to feel like the card was dragged at the corresponding
|
|
// position.
|
|
TableZone *tableZone = qobject_cast<TableZone *>(cursorZone);
|
|
QPointF closestGridPoint;
|
|
if (tableZone)
|
|
closestGridPoint = tableZone->closestGridPoint(cursorPosInZone);
|
|
else
|
|
closestGridPoint = cursorPosInZone - hotSpot;
|
|
|
|
QPointF newPos = zonePos + closestGridPoint;
|
|
|
|
if (newPos != pos()) {
|
|
for (int i = 0; i < childDrags.size(); i++)
|
|
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
|
setPos(newPos);
|
|
|
|
bool newOccupied = false;
|
|
TableZone *table = qobject_cast<TableZone *>(cursorZone);
|
|
if (table)
|
|
if (table->getCardFromCoords(closestGridPoint))
|
|
newOccupied = true;
|
|
if (newOccupied != occupied) {
|
|
occupied = newOccupied;
|
|
update();
|
|
}
|
|
}
|
|
}
|
|
|
|
void CardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
setCursor(Qt::OpenHandCursor);
|
|
QGraphicsScene *sc = scene();
|
|
QPointF sp = pos();
|
|
sc->removeItem(this);
|
|
|
|
QList<CardDragItem *> dragItemList;
|
|
CardZoneLogic *startZone = static_cast<CardItem *>(item)->getZone();
|
|
if (currentZone && !(static_cast<CardItem *>(item)->getAttachedTo() && (startZone == currentZone->getLogic()))) {
|
|
if (!occupied) {
|
|
dragItemList.append(this);
|
|
}
|
|
|
|
for (int i = 0; i < childDrags.size(); i++) {
|
|
CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]);
|
|
if (!occupied &&
|
|
!(static_cast<CardItem *>(c->item)->getAttachedTo() && (startZone == currentZone->getLogic())) &&
|
|
!c->occupied) {
|
|
dragItemList.append(c);
|
|
}
|
|
sc->removeItem(c);
|
|
}
|
|
}
|
|
|
|
if (currentZone) {
|
|
currentZone->handleDropEvent(dragItemList, startZone, (sp - currentZone->scenePos()).toPoint());
|
|
}
|
|
|
|
event->accept();
|
|
}
|