mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
experimental card stacking
This commit is contained in:
parent
21cc0ed8d6
commit
f4962d021e
8 changed files with 291 additions and 212 deletions
|
|
@ -19,7 +19,7 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
|||
if (settingsCache->getEconomicalGrid())
|
||||
height = 2 * boxLineWidth + (int) (11.0 / 3 * CARD_HEIGHT + 2 * paddingY);
|
||||
else
|
||||
height = 2 * boxLineWidth + 3 * CARD_HEIGHT + 2 * paddingY;
|
||||
height = 2 * boxLineWidth + 3 * (CARD_HEIGHT + 20) + 2 * paddingY;
|
||||
width = minWidth + 2 * marginX + 2 * boxLineWidth;
|
||||
currentMinimumWidth = minWidth;
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*optio
|
|||
else
|
||||
painter->fillRect(boundingRect(), QBrush(bgPixmap));
|
||||
painter->setPen(QColor(255, 255, 255, 40));
|
||||
qreal separatorY = 2 * (CARD_HEIGHT + paddingY) + boxLineWidth - paddingY / 2;
|
||||
qreal separatorY = 2 * (CARD_HEIGHT + 20 + paddingY) + boxLineWidth - paddingY / 2;
|
||||
if (isInverted())
|
||||
separatorY = height - separatorY;
|
||||
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
|
||||
|
|
@ -103,13 +103,27 @@ void TableZone::reorganizeCards()
|
|||
QList<ArrowItem *> arrowsToUpdate;
|
||||
|
||||
// Calculate table grid distortion so that the mapping functions work properly
|
||||
gridPointWidth.clear();
|
||||
QMap<int, int> gridPointStackCount;
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
QPoint gridPoint = cards[i]->getGridPos();
|
||||
const 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));
|
||||
const int key = gridPoint.x() / 3 + gridPoint.y() * 1000;
|
||||
gridPointStackCount.insert(key, gridPointStackCount.value(key, 0) + 1);
|
||||
}
|
||||
gridPointWidth.clear();
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
const QPoint &gridPoint = cards[i]->getGridPos();
|
||||
if (gridPoint.x() == -1)
|
||||
continue;
|
||||
|
||||
const int key = gridPoint.x() / 3 + gridPoint.y() * 1000;
|
||||
const int stackCount = gridPointStackCount.value(key, 0);
|
||||
if (stackCount == 1)
|
||||
gridPointWidth.insert(key, CARD_WIDTH * (1 + cards[i]->getAttachedCards().size() / 3.0));
|
||||
else
|
||||
gridPointWidth.insert(key, CARD_WIDTH * (1 + (stackCount - 1) / 3.0));
|
||||
}
|
||||
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
|
|
@ -216,16 +230,12 @@ CardItem *TableZone::getCardFromCoords(const QPointF &point) const
|
|||
QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const
|
||||
{
|
||||
qreal x, y;
|
||||
if ((gridPoint.y() == 2) && (settingsCache->getEconomicalGrid())) {
|
||||
x = marginX + (CARD_WIDTH * gridPoint.x() + CARD_WIDTH * (gridPoint.x() / 3)) / 2;
|
||||
y = boxLineWidth + (CARD_HEIGHT + paddingY) * gridPoint.y() + (gridPoint.x() % 3 * CARD_HEIGHT) / 3;
|
||||
} else {
|
||||
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);
|
||||
|
||||
y = boxLineWidth + (CARD_HEIGHT + paddingY) * gridPoint.y();
|
||||
}
|
||||
x = marginX + (gridPoint.x() % 3) * CARD_WIDTH / 3.0;
|
||||
for (int i = 0; i < gridPoint.x() / 3; ++i)
|
||||
x += gridPointWidth.value(gridPoint.y() * 1000 + i, CARD_WIDTH) + paddingX;
|
||||
|
||||
y = boxLineWidth + gridPoint.y() * (CARD_HEIGHT + paddingY + 20) + (gridPoint.x() % 3) * 10;
|
||||
|
||||
if (isInverted())
|
||||
y = height - CARD_HEIGHT - y;
|
||||
|
||||
|
|
@ -238,7 +248,7 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
|||
qreal y = mapPoint.y();
|
||||
if (isInverted())
|
||||
y = height - y;
|
||||
y += paddingY / 2 - boxLineWidth;
|
||||
y -= boxLineWidth;
|
||||
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
|
|
@ -249,27 +259,24 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
|||
else if (y > height - CARD_HEIGHT)
|
||||
y = height - CARD_HEIGHT;
|
||||
|
||||
int resultY = (int) (y / (CARD_HEIGHT + paddingY));
|
||||
int resultY = round(y / (CARD_HEIGHT + paddingY + 20));
|
||||
|
||||
if ((resultY == 2) && (settingsCache->getEconomicalGrid()))
|
||||
return QPoint(
|
||||
(int) (x * 2 / CARD_WIDTH - floor(x / (2 * CARD_WIDTH))),
|
||||
2
|
||||
);
|
||||
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);
|
||||
}
|
||||
int baseX = -1;
|
||||
qreal oldTempX = 0, tempX = 0;
|
||||
do {
|
||||
++baseX;
|
||||
oldTempX = tempX;
|
||||
tempX += gridPointWidth.value(resultY * 1000 + baseX, CARD_WIDTH) + paddingX;
|
||||
} while (tempX < x + 1);
|
||||
|
||||
qreal xdiff = x - oldTempX;
|
||||
int resultX = baseX * 3 + qMin((int) floor(xdiff * 3 / CARD_WIDTH), 2);
|
||||
return QPoint(resultX, resultY);
|
||||
}
|
||||
|
||||
QPointF TableZone::closestGridPoint(const QPointF &point)
|
||||
{
|
||||
return mapFromGrid(mapToGrid(point + QPoint(CARD_WIDTH / 2, CARD_HEIGHT / 2)));
|
||||
return mapFromGrid(mapToGrid(point + QPoint(1, 1)));
|
||||
}
|
||||
|
||||
void TableZone::setWidth(qreal _width)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue