mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 16:24:45 -07:00
arrows can target players; card attachment works
This commit is contained in:
parent
61b82bd6f9
commit
614f106304
32 changed files with 885 additions and 402 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include "client.h"
|
||||
#include "protocol_items.h"
|
||||
#include "settingscache.h"
|
||||
#include "arrowitem.h"
|
||||
|
||||
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
||||
: CardZone(_p, "table", true, false, true, parent), active(false)
|
||||
|
|
@ -91,17 +92,61 @@ void TableZone::handleDropEventByGrid(int cardId, CardZone *startZone, const QPo
|
|||
|
||||
void TableZone::reorganizeCards()
|
||||
{
|
||||
QList<ArrowItem *> arrowsToUpdate;
|
||||
|
||||
// Calculate table grid distortion so that the mapping functions work properly
|
||||
gridPointWidth.clear();
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
QPointF mapPoint = mapFromGrid(cards[i]->getGridPos());
|
||||
QPoint gridPoint = cards[i]->getGridPos();
|
||||
if (gridPoint.x() == -1)
|
||||
continue;
|
||||
|
||||
gridPointWidth.insert(gridPoint.x() + gridPoint.y() * 1000, CARD_WIDTH * (1 + cards[i]->getAttachedCards().size() / 3.0));
|
||||
}
|
||||
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
QPoint gridPoint = cards[i]->getGridPos();
|
||||
if (gridPoint.x() == -1)
|
||||
continue;
|
||||
|
||||
QPointF mapPoint = mapFromGrid(gridPoint);
|
||||
qreal x = mapPoint.x();
|
||||
qreal y = mapPoint.y();
|
||||
|
||||
if (player->getMirrored())
|
||||
y = height - CARD_HEIGHT - y;
|
||||
cards[i]->setPos(x, y);
|
||||
cards[i]->setZValue((y + CARD_HEIGHT) * 10000000 + x + 1000);
|
||||
|
||||
int numberAttachedCards = cards[i]->getAttachedCards().size();
|
||||
qreal actualX = x + numberAttachedCards * CARD_WIDTH / 3.0;
|
||||
qreal actualY = y;
|
||||
if (numberAttachedCards)
|
||||
actualY += 5;
|
||||
|
||||
cards[i]->setPos(actualX, actualY);
|
||||
cards[i]->setZValue((actualY + CARD_HEIGHT) * 10000000 + (actualX + 1) * 10000);
|
||||
|
||||
QListIterator<CardItem *> attachedCardIterator(cards[i]->getAttachedCards());
|
||||
int j = 0;
|
||||
while (attachedCardIterator.hasNext()) {
|
||||
++j;
|
||||
CardItem *attachedCard = attachedCardIterator.next();
|
||||
qreal childX = actualX - j * CARD_WIDTH / 3.0;
|
||||
qreal childY = y - 5;
|
||||
attachedCard->setPos(childX, childY);
|
||||
attachedCard->setZValue((childY + CARD_HEIGHT) * 10000000 + (childX + 1) * 10000);
|
||||
|
||||
arrowsToUpdate.append(attachedCard->getArrowsFrom());
|
||||
arrowsToUpdate.append(attachedCard->getArrowsTo());
|
||||
}
|
||||
|
||||
arrowsToUpdate.append(cards[i]->getArrowsFrom());
|
||||
arrowsToUpdate.append(cards[i]->getArrowsTo());
|
||||
}
|
||||
|
||||
QSetIterator<ArrowItem *> arrowIterator(QSet<ArrowItem *>::fromList(arrowsToUpdate));
|
||||
while (arrowIterator.hasNext())
|
||||
arrowIterator.next()->updatePath();
|
||||
|
||||
resizeToContents();
|
||||
update();
|
||||
}
|
||||
|
|
@ -164,11 +209,16 @@ QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const
|
|||
marginX + (CARD_WIDTH * gridPoint.x() + CARD_WIDTH * (gridPoint.x() / 3)) / 2,
|
||||
boxLineWidth + (CARD_HEIGHT + paddingY) * gridPoint.y() + (gridPoint.x() % 3 * CARD_HEIGHT) / 3
|
||||
);
|
||||
else
|
||||
else {
|
||||
qreal x = marginX + 0.5 * CARD_WIDTH * gridPoint.x();
|
||||
for (int i = 0; i < gridPoint.x(); ++i)
|
||||
x += gridPointWidth.value(gridPoint.y() * 1000 + i, CARD_WIDTH);
|
||||
|
||||
return QPointF(
|
||||
marginX + 3 * CARD_WIDTH * gridPoint.x() / 2,
|
||||
x,
|
||||
boxLineWidth + (CARD_HEIGHT + paddingY) * gridPoint.y()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
||||
|
|
@ -184,18 +234,22 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
|||
else if (y > height - CARD_HEIGHT)
|
||||
y = height - CARD_HEIGHT;
|
||||
|
||||
QPoint result = QPoint(
|
||||
(int) (x / (1.5 * CARD_WIDTH)),
|
||||
(int) (y / (CARD_HEIGHT + paddingY))
|
||||
);
|
||||
int resultY = (int) (y / (CARD_HEIGHT + paddingY));
|
||||
|
||||
if ((result.y() == 3) && (settingsCache->getEconomicGrid()))
|
||||
if ((resultY == 3) && (settingsCache->getEconomicGrid()))
|
||||
return QPoint(
|
||||
(int) (x * 2 / CARD_WIDTH - floor(x / (2 * CARD_WIDTH))),
|
||||
3
|
||||
);
|
||||
else
|
||||
return result;
|
||||
else {
|
||||
int resultX = -1;
|
||||
qreal tempX = 0;
|
||||
do {
|
||||
++resultX;
|
||||
tempX += gridPointWidth.value(resultY * 1000 + resultX, CARD_WIDTH) + 0.5 * CARD_WIDTH;
|
||||
} while (tempX < x + 1);
|
||||
return QPoint(resultX, resultY);
|
||||
}
|
||||
}
|
||||
|
||||
QPointF TableZone::closestGridPoint(const QPointF &point)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue