mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
* make cards on the stack slightly overlap to stress order dragging cards to the stack now places the card at the location it is dropped * make default play action append to stack * add vertical overlap to settings and vertical hand * Update cockatrice/src/dlg_settings.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * Fix format --------- Co-authored-by: tooomm <tooomm@users.noreply.github.com> Co-authored-by: ZeldaZach <zahalpern+github@gmail.com>
90 lines
2.9 KiB
C++
90 lines
2.9 KiB
C++
#include "selectzone.h"
|
|
|
|
#include "carditem.h"
|
|
#include "gamescene.h"
|
|
#include "settingscache.h"
|
|
|
|
#include <QDebug>
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
qreal divideCardSpaceInZone(qreal index, int cardCount, qreal totalHeight, qreal cardHeight, bool reverse)
|
|
{
|
|
qreal cardMinOverlap = cardHeight * SettingsCache::instance().getStackCardOverlapPercent() / 100;
|
|
qreal desiredHeight = cardHeight * cardCount - cardMinOverlap * (cardCount - 1);
|
|
qreal y;
|
|
if (desiredHeight > totalHeight) {
|
|
if (reverse) {
|
|
y = index / ((totalHeight - cardHeight) / (cardCount - 1));
|
|
} else {
|
|
y = index * (totalHeight - cardHeight) / (cardCount - 1);
|
|
}
|
|
} else {
|
|
qreal start = (totalHeight - desiredHeight) / 2;
|
|
if (reverse) {
|
|
if (index <= start) {
|
|
return 0;
|
|
}
|
|
y = (index - start) / (cardHeight - cardMinOverlap);
|
|
} else {
|
|
y = index * (cardHeight - cardMinOverlap) + start;
|
|
}
|
|
}
|
|
return y;
|
|
}
|
|
|
|
SelectZone::SelectZone(Player *_player,
|
|
const QString &_name,
|
|
bool _hasCardAttr,
|
|
bool _isShufflable,
|
|
bool _contentsKnown,
|
|
QGraphicsItem *parent,
|
|
bool isView)
|
|
: CardZone(_player, _name, _hasCardAttr, _isShufflable, _contentsKnown, parent, isView)
|
|
{
|
|
}
|
|
|
|
void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
if (event->buttons().testFlag(Qt::LeftButton)) {
|
|
QPointF pos = event->pos();
|
|
if (pos.x() < 0)
|
|
pos.setX(0);
|
|
QRectF br = boundingRect();
|
|
if (pos.x() > br.width())
|
|
pos.setX(br.width());
|
|
if (pos.y() < 0)
|
|
pos.setY(0);
|
|
if (pos.y() > br.height())
|
|
pos.setY(br.height());
|
|
|
|
QRectF selectionRect = QRectF(selectionOrigin, pos).normalized();
|
|
for (int i = 0; i < cards.size(); ++i) {
|
|
if (cards[i]->getAttachedTo())
|
|
if (cards[i]->getAttachedTo()->getZone() != this)
|
|
continue;
|
|
cards[i]->setSelected(selectionRect.intersects(cards[i]->mapRectToParent(cards[i]->boundingRect())));
|
|
}
|
|
static_cast<GameScene *>(scene())->resizeRubberBand(
|
|
deviceTransform(static_cast<GameScene *>(scene())->getViewportTransform()).map(pos));
|
|
event->accept();
|
|
}
|
|
}
|
|
|
|
void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
if (event->button() == Qt::LeftButton) {
|
|
scene()->clearSelection();
|
|
|
|
selectionOrigin = event->pos();
|
|
static_cast<GameScene *>(scene())->startRubberBand(event->scenePos());
|
|
event->accept();
|
|
} else
|
|
CardZone::mousePressEvent(event);
|
|
}
|
|
|
|
void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
selectionOrigin = QPoint();
|
|
static_cast<GameScene *>(scene())->stopRubberBand();
|
|
event->accept();
|
|
}
|