mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 02:53:56 -07:00
style: Add braces to all control flow statements (#6887)
* style: Add braces to all control flow statements Standardize code style by adding explicit braces to all single-statement control flow blocks (if, else, for, while) across the entire codebase. Also documents the InsertBraces clang-format option (requires v15+) for future automated enforcement. * InsertBraces-check-enabled
This commit is contained in:
parent
7153f7d4c1
commit
aadee34238
173 changed files with 2725 additions and 1461 deletions
|
|
@ -24,10 +24,11 @@ AbstractClient *AbstractGame::getClientForPlayer(int playerId) const
|
|||
}
|
||||
|
||||
return gameState->getClients().at(playerId);
|
||||
} else if (gameState->getClients().isEmpty())
|
||||
} else if (gameState->getClients().isEmpty()) {
|
||||
return nullptr;
|
||||
else
|
||||
} else {
|
||||
return gameState->getClients().first();
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractGame::loadReplay(GameReplay *replay)
|
||||
|
|
@ -44,12 +45,14 @@ void AbstractGame::setActiveCard(CardItem *card)
|
|||
CardItem *AbstractGame::getCard(int playerId, const QString &zoneName, int cardId) const
|
||||
{
|
||||
Player *player = playerManager->getPlayer(playerId);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CardZoneLogic *zone = player->getZones().value(zoneName, 0);
|
||||
if (!zone)
|
||||
if (!zone) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return zone->getCard(cardId);
|
||||
}
|
||||
|
|
@ -25,11 +25,12 @@ AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item,
|
|||
setCursor(Qt::ClosedHandCursor);
|
||||
setZValue(ZValues::DRAG_ITEM);
|
||||
}
|
||||
if (item->getTapped())
|
||||
if (item->getTapped()) {
|
||||
setTransform(QTransform()
|
||||
.translate(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F)
|
||||
.rotate(90)
|
||||
.translate(-CardDimensions::WIDTH_HALF_F, -CardDimensions::HEIGHT_HALF_F));
|
||||
}
|
||||
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
|
||||
|
|
|
|||
|
|
@ -88,8 +88,9 @@ void AbstractCardItem::setRealZValue(qreal _zValue)
|
|||
// During hover, zValue is overridden to HOVERED_CARD. Layout operations
|
||||
// like reorganizeCards() call setRealZValue() on all cards including the
|
||||
// hovered one — skip setZValue() here to avoid clobbering the override.
|
||||
if (!isHovered)
|
||||
if (!isHovered) {
|
||||
setZValue(_zValue);
|
||||
}
|
||||
}
|
||||
|
||||
QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
|
||||
|
|
@ -130,8 +131,9 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
|
|||
// don't even spend time trying to load the picture if our size is too small
|
||||
if (translatedSize.width() > 10) {
|
||||
CardPictureLoader::getPixmap(translatedPixmap, exactCard, translatedSize.toSize());
|
||||
if (translatedPixmap.isNull())
|
||||
if (translatedPixmap.isNull()) {
|
||||
paintImage = false;
|
||||
}
|
||||
} else {
|
||||
paintImage = false;
|
||||
}
|
||||
|
|
@ -156,9 +158,9 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
|
|||
painter->setBackground(Qt::black);
|
||||
painter->setBackgroundMode(Qt::OpaqueMode);
|
||||
QString nameStr;
|
||||
if (facedown)
|
||||
if (facedown) {
|
||||
nameStr = "# " + QString::number(id);
|
||||
else {
|
||||
} else {
|
||||
QString prefix = "";
|
||||
if (SettingsCache::instance().debug().getShowCardId()) {
|
||||
prefix = "#" + QString::number(id) + " ";
|
||||
|
|
@ -185,10 +187,12 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
|
|||
|
||||
if (isSelected() || isHovered) {
|
||||
QPen pen;
|
||||
if (isHovered)
|
||||
if (isHovered) {
|
||||
pen.setColor(Qt::yellow);
|
||||
if (isSelected())
|
||||
}
|
||||
if (isSelected()) {
|
||||
pen.setColor(Qt::red);
|
||||
}
|
||||
pen.setWidth(0); // Cosmetic pen
|
||||
painter->setPen(pen);
|
||||
painter->drawPath(shape());
|
||||
|
|
@ -214,8 +218,9 @@ void AbstractCardItem::setCardRef(const CardRef &_cardRef)
|
|||
|
||||
void AbstractCardItem::setHovered(bool _hovered)
|
||||
{
|
||||
if (isHovered == _hovered)
|
||||
if (isHovered == _hovered) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_hovered) {
|
||||
processHoverEvent();
|
||||
|
|
@ -277,13 +282,14 @@ void AbstractCardItem::cacheBgColor()
|
|||
|
||||
void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
|
||||
{
|
||||
if (tapped == _tapped)
|
||||
if (tapped == _tapped) {
|
||||
return;
|
||||
}
|
||||
|
||||
tapped = _tapped;
|
||||
if (SettingsCache::instance().getTapAnimation() && canAnimate)
|
||||
if (SettingsCache::instance().getTapAnimation() && canAnimate) {
|
||||
static_cast<GameScene *>(scene())->registerAnimationItem(this);
|
||||
else {
|
||||
} else {
|
||||
tapAngle = tapped ? 90 : 0;
|
||||
setTransform(QTransform()
|
||||
.translate(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F)
|
||||
|
|
@ -309,17 +315,19 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
scene()->clearSelection();
|
||||
setSelected(true);
|
||||
}
|
||||
if (event->button() == Qt::LeftButton)
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
else if (event->button() == Qt::MiddleButton)
|
||||
} else if (event->button() == Qt::MiddleButton) {
|
||||
emit showCardInfoPopup(event->screenPos(), cardRef);
|
||||
}
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::MiddleButton)
|
||||
if (event->button() == Qt::MiddleButton) {
|
||||
emit deleteCardInfoPopup(cardRef.name);
|
||||
}
|
||||
|
||||
// This function ensures the parent function doesn't mess around with our selection.
|
||||
event->accept();
|
||||
|
|
@ -335,6 +343,7 @@ QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change,
|
|||
if (change == ItemSelectedHasChanged) {
|
||||
update();
|
||||
return value;
|
||||
} else
|
||||
} else {
|
||||
return ArrowTarget::itemChange(change, value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,10 +43,11 @@ AbstractCounter::AbstractCounter(Player *_player,
|
|||
menu->addSeparator();
|
||||
} else {
|
||||
QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
|
||||
if (i == -1)
|
||||
if (i == -1) {
|
||||
aDec = aIncrement;
|
||||
else if (i == 1)
|
||||
} else if (i == 1) {
|
||||
aInc = aIncrement;
|
||||
}
|
||||
aIncrement->setData(i);
|
||||
connect(aIncrement, &QAction::triggered, this, &AbstractCounter::incrementCounter);
|
||||
menu->addAction(aIncrement);
|
||||
|
|
@ -69,10 +70,11 @@ AbstractCounter::~AbstractCounter()
|
|||
|
||||
void AbstractCounter::delCounter()
|
||||
{
|
||||
if (dialogSemaphore)
|
||||
if (dialogSemaphore) {
|
||||
deleteAfterDialog = true;
|
||||
else
|
||||
} else {
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractCounter::retranslateUi()
|
||||
|
|
@ -136,8 +138,9 @@ void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
{
|
||||
if (isUnderMouse() && player->getPlayerInfo()->getLocalOrJudge()) {
|
||||
if (event->button() == Qt::MiddleButton || (QApplication::keyboardModifiers() & Qt::ShiftModifier)) {
|
||||
if (menu)
|
||||
if (menu) {
|
||||
menu->exec(event->screenPos());
|
||||
}
|
||||
event->accept();
|
||||
} else if (event->button() == Qt::LeftButton) {
|
||||
Command_IncCounter cmd;
|
||||
|
|
@ -152,8 +155,9 @@ void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
player->getPlayerActions()->sendGameCommand(cmd);
|
||||
event->accept();
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
|
||||
|
|
@ -189,8 +193,9 @@ void AbstractCounter::setCounter()
|
|||
}
|
||||
dialogSemaphore = false;
|
||||
|
||||
if (!ok)
|
||||
if (!ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
Expression exp(value);
|
||||
int newValue = static_cast<int>(exp.parse(dialog.textValue()));
|
||||
|
|
@ -231,8 +236,9 @@ void AbstractCounterDialog::changeValue(int diff)
|
|||
{
|
||||
bool ok;
|
||||
int curValue = textValue().toInt(&ok);
|
||||
if (!ok)
|
||||
if (!ok) {
|
||||
return;
|
||||
}
|
||||
curValue += diff;
|
||||
setTextValue(QString::number(curValue));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,16 @@ ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTar
|
|||
{
|
||||
setZValue(ZValues::ARROWS);
|
||||
|
||||
if (startItem)
|
||||
if (startItem) {
|
||||
startItem->addArrowFrom(this);
|
||||
if (targetItem)
|
||||
}
|
||||
if (targetItem) {
|
||||
targetItem->addArrowTo(this);
|
||||
}
|
||||
|
||||
if (startItem && targetItem)
|
||||
if (startItem && targetItem) {
|
||||
updatePath();
|
||||
}
|
||||
}
|
||||
|
||||
ArrowItem::~ArrowItem()
|
||||
|
|
@ -59,8 +62,9 @@ void ArrowItem::delArrow()
|
|||
|
||||
void ArrowItem::updatePath()
|
||||
{
|
||||
if (!targetItem)
|
||||
if (!targetItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF endPoint = targetItem->mapToScene(
|
||||
QPointF(targetItem->boundingRect().width() / 2, targetItem->boundingRect().height() / 2));
|
||||
|
|
@ -75,8 +79,9 @@ void ArrowItem::updatePath(const QPointF &endPoint)
|
|||
headWidth / qPow(2, 0.5); // aka headWidth / sqrt (2) but this produces a compile error with MSVC++
|
||||
const double phi = 15;
|
||||
|
||||
if (!startItem)
|
||||
if (!startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF startPoint =
|
||||
startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
|
||||
|
|
@ -84,9 +89,9 @@ void ArrowItem::updatePath(const QPointF &endPoint)
|
|||
qreal lineLength = line.length();
|
||||
|
||||
prepareGeometryChange();
|
||||
if (lineLength < 30)
|
||||
if (lineLength < 30) {
|
||||
path = QPainterPath();
|
||||
else {
|
||||
} else {
|
||||
QPointF c(lineLength / 2, qTan(phi * M_PI / 180) * lineLength);
|
||||
|
||||
QPainterPath centerLine;
|
||||
|
|
@ -123,10 +128,11 @@ void ArrowItem::updatePath(const QPointF &endPoint)
|
|||
void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
QColor paintColor(color);
|
||||
if (fullColor)
|
||||
if (fullColor) {
|
||||
paintColor.setAlpha(200);
|
||||
else
|
||||
} else {
|
||||
paintColor.setAlpha(150);
|
||||
}
|
||||
painter->setBrush(paintColor);
|
||||
painter->drawPath(path);
|
||||
}
|
||||
|
|
@ -168,8 +174,9 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
{
|
||||
// This ensures that if a mouse move event happens after a call to delArrow(),
|
||||
// the event will be discarded as it would create some stray pointers.
|
||||
if (targetLocked || !startItem)
|
||||
if (targetLocked || !startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF endPos = event->scenePos();
|
||||
|
||||
|
|
@ -213,8 +220,9 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
|
||||
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (!startItem)
|
||||
if (!startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetItem && (targetItem != startItem)) {
|
||||
CardZoneLogic *startZone = static_cast<CardItem *>(startItem)->getZone();
|
||||
|
|
@ -246,10 +254,11 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
bool playToStack = SettingsCache::instance().getPlayToStack();
|
||||
if (ci && ((!playToStack && ci->getUiAttributes().tableRow == 3) ||
|
||||
(playToStack && ci->getUiAttributes().tableRow != 0 &&
|
||||
startCard->getZone()->getName() != ZoneNames::STACK)))
|
||||
startCard->getZone()->getName() != ZoneNames::STACK))) {
|
||||
cmd.set_start_zone(ZoneNames::STACK);
|
||||
else
|
||||
} else {
|
||||
cmd.set_start_zone(playToStack ? ZoneNames::STACK : ZoneNames::TABLE);
|
||||
}
|
||||
}
|
||||
|
||||
if (deleteInPhase != 0) {
|
||||
|
|
@ -277,8 +286,9 @@ void ArrowAttachItem::addChildArrow(ArrowAttachItem *childArrow)
|
|||
|
||||
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (targetLocked || !startItem)
|
||||
if (targetLocked || !startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF endPos = event->scenePos();
|
||||
|
||||
|
|
@ -343,8 +353,9 @@ void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCar
|
|||
|
||||
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (!startItem)
|
||||
if (!startItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Attaching could move startItem under the current cursor position, causing all children to retarget to it right
|
||||
// before they are processed. Prevent that.
|
||||
|
|
|
|||
|
|
@ -30,11 +30,13 @@ void ArrowTarget::setBeingPointedAt(bool _beingPointedAt)
|
|||
QVariant ArrowTarget::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemScenePositionHasChanged && scene()) {
|
||||
for (auto *arrow : arrowsFrom)
|
||||
for (auto *arrow : arrowsFrom) {
|
||||
arrow->updatePath();
|
||||
}
|
||||
|
||||
for (auto *arrow : arrowsTo)
|
||||
for (auto *arrow : arrowsTo) {
|
||||
arrow->updatePath();
|
||||
}
|
||||
}
|
||||
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ void CardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
|||
{
|
||||
AbstractCardDragItem::paint(painter, option, widget);
|
||||
|
||||
if (occupied)
|
||||
if (occupied) {
|
||||
painter->fillPath(shape(), QColor(200, 0, 0, 100));
|
||||
}
|
||||
}
|
||||
|
||||
void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
||||
|
|
@ -38,16 +39,19 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
|||
ZoneViewZone *zoneViewZone = 0;
|
||||
for (int i = colliding.size() - 1; i >= 0; i--) {
|
||||
CardZone *temp = qgraphicsitem_cast<CardZone *>(colliding.at(i));
|
||||
if (!cardZone)
|
||||
if (!cardZone) {
|
||||
cardZone = temp;
|
||||
if (!zoneViewZone)
|
||||
}
|
||||
if (!zoneViewZone) {
|
||||
zoneViewZone = qobject_cast<ZoneViewZone *>(temp);
|
||||
}
|
||||
}
|
||||
CardZone *cursorZone = 0;
|
||||
if (zoneViewZone)
|
||||
if (zoneViewZone) {
|
||||
cursorZone = zoneViewZone;
|
||||
else if (cardZone)
|
||||
} 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.
|
||||
|
|
@ -59,8 +63,9 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
|||
QPointF newPos = cursorScenePos - hotSpot;
|
||||
|
||||
if (newPos != pos()) {
|
||||
for (int i = 0; i < childDrags.size(); i++)
|
||||
for (int i = 0; i < childDrags.size(); i++) {
|
||||
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
||||
}
|
||||
setPos(newPos);
|
||||
}
|
||||
|
||||
|
|
@ -78,23 +83,27 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
|||
// position.
|
||||
TableZone *tableZone = qobject_cast<TableZone *>(cursorZone);
|
||||
QPointF closestGridPoint;
|
||||
if (tableZone)
|
||||
if (tableZone) {
|
||||
closestGridPoint = tableZone->closestGridPoint(cursorPosInZone);
|
||||
else
|
||||
} else {
|
||||
closestGridPoint = cursorPosInZone - hotSpot;
|
||||
}
|
||||
|
||||
QPointF newPos = zonePos + closestGridPoint;
|
||||
|
||||
if (newPos != pos()) {
|
||||
for (int i = 0; i < childDrags.size(); i++)
|
||||
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))
|
||||
if (table) {
|
||||
if (table->getCardFromCoords(closestGridPoint)) {
|
||||
newOccupied = true;
|
||||
}
|
||||
}
|
||||
if (newOccupied != occupied) {
|
||||
occupied = newOccupied;
|
||||
update();
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@ CardItem::CardItem(Player *_owner, QGraphicsItem *parent, const CardRef &cardRef
|
|||
owner->addCard(this);
|
||||
|
||||
connect(&SettingsCache::instance().cardCounters(), &CardCounterSettings::colorChanged, this, [this](int counterId) {
|
||||
if (counters.contains(counterId))
|
||||
if (counters.contains(counterId)) {
|
||||
update();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -56,8 +57,9 @@ void CardItem::prepareDelete()
|
|||
void CardItem::deleteLater()
|
||||
{
|
||||
prepareDelete();
|
||||
if (scene())
|
||||
if (scene()) {
|
||||
static_cast<GameScene *>(scene())->unregisterAnimationItem(this);
|
||||
}
|
||||
AbstractCardItem::deleteLater();
|
||||
}
|
||||
|
||||
|
|
@ -152,10 +154,11 @@ void CardItem::setAttacking(bool _attacking)
|
|||
|
||||
void CardItem::setCounter(int _id, int _value)
|
||||
{
|
||||
if (_value)
|
||||
if (_value) {
|
||||
counters.insert(_id, _value);
|
||||
else
|
||||
} else {
|
||||
counters.remove(_id);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -227,8 +230,9 @@ void CardItem::resetState(bool keepAnnotations)
|
|||
attachedCards.clear();
|
||||
setTapped(false, false);
|
||||
setDoesntUntap(false);
|
||||
if (scene())
|
||||
if (scene()) {
|
||||
static_cast<GameScene *>(scene())->unregisterAnimationItem(this);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
@ -275,8 +279,9 @@ void CardItem::deleteDragItem()
|
|||
|
||||
void CardItem::drawArrow(const QColor &arrowColor)
|
||||
{
|
||||
if (owner->getGame()->getPlayerManager()->isSpectator())
|
||||
if (owner->getGame()->getPlayerManager()->isSpectator()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto *game = owner->getGame();
|
||||
Player *arrowOwner = game->getPlayerManager()->getActiveLocalPlayer(game->getGameState()->getActivePlayer());
|
||||
|
|
@ -291,10 +296,12 @@ void CardItem::drawArrow(const QColor &arrowColor)
|
|||
|
||||
for (const auto &item : scene()->selectedItems()) {
|
||||
CardItem *card = qgraphicsitem_cast<CardItem *>(item);
|
||||
if (card == nullptr || card == this)
|
||||
if (card == nullptr || card == this) {
|
||||
continue;
|
||||
if (card->getZone() != zone)
|
||||
}
|
||||
if (card->getZone() != zone) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ArrowDragItem *childArrow = new ArrowDragItem(arrowOwner, card, arrowColor, phase);
|
||||
scene()->addItem(childArrow);
|
||||
|
|
@ -304,8 +311,9 @@ void CardItem::drawArrow(const QColor &arrowColor)
|
|||
|
||||
void CardItem::drawAttachArrow()
|
||||
{
|
||||
if (owner->getGame()->getPlayerManager()->isSpectator())
|
||||
if (owner->getGame()->getPlayerManager()->isSpectator()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto *arrow = new ArrowAttachItem(this);
|
||||
scene()->addItem(arrow);
|
||||
|
|
@ -313,10 +321,12 @@ void CardItem::drawAttachArrow()
|
|||
|
||||
for (const auto &item : scene()->selectedItems()) {
|
||||
CardItem *card = qgraphicsitem_cast<CardItem *>(item);
|
||||
if (card == nullptr)
|
||||
if (card == nullptr) {
|
||||
continue;
|
||||
if (card->getZone() != zone)
|
||||
}
|
||||
if (card->getZone() != zone) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ArrowAttachItem *childArrow = new ArrowAttachItem(card);
|
||||
scene()->addItem(childArrow);
|
||||
|
|
@ -328,27 +338,32 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
{
|
||||
if (event->buttons().testFlag(Qt::RightButton)) {
|
||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::RightButton)).manhattanLength() <
|
||||
2 * QApplication::startDragDistance())
|
||||
2 * QApplication::startDragDistance()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QColor arrowColor = Qt::red;
|
||||
if (event->modifiers().testFlag(Qt::ControlModifier))
|
||||
if (event->modifiers().testFlag(Qt::ControlModifier)) {
|
||||
arrowColor = Qt::yellow;
|
||||
else if (event->modifiers().testFlag(Qt::AltModifier))
|
||||
} else if (event->modifiers().testFlag(Qt::AltModifier)) {
|
||||
arrowColor = Qt::blue;
|
||||
else if (event->modifiers().testFlag(Qt::ShiftModifier))
|
||||
} else if (event->modifiers().testFlag(Qt::ShiftModifier)) {
|
||||
arrowColor = Qt::green;
|
||||
}
|
||||
|
||||
drawArrow(arrowColor);
|
||||
} else if (event->buttons().testFlag(Qt::LeftButton)) {
|
||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() <
|
||||
2 * QApplication::startDragDistance())
|
||||
2 * QApplication::startDragDistance()) {
|
||||
return;
|
||||
}
|
||||
if (const ZoneViewZoneLogic *view = qobject_cast<const ZoneViewZoneLogic *>(zone)) {
|
||||
if (view->getRevealZone() && !view->getWriteableRevealZone())
|
||||
if (view->getRevealZone() && !view->getWriteableRevealZone()) {
|
||||
return;
|
||||
} else if (!owner->getPlayerInfo()->getLocalOrJudge())
|
||||
}
|
||||
} else if (!owner->getPlayerInfo()->getLocalOrJudge()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
||||
|
||||
|
|
@ -360,14 +375,16 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
int childIndex = 0;
|
||||
for (const auto &item : scene()->selectedItems()) {
|
||||
CardItem *card = static_cast<CardItem *>(item);
|
||||
if ((card == this) || (card->getZone() != zone))
|
||||
if ((card == this) || (card->getZone() != zone)) {
|
||||
continue;
|
||||
}
|
||||
++childIndex;
|
||||
QPointF childPos;
|
||||
if (zone->getHasCardAttr())
|
||||
if (zone->getHasCardAttr()) {
|
||||
childPos = card->pos() - pos();
|
||||
else
|
||||
} else {
|
||||
childPos = QPointF(childIndex * CardDimensions::WIDTH_HALF_F, 0);
|
||||
}
|
||||
CardDragItem *drag =
|
||||
new CardDragItem(card, card->getId(), childPos, card->getFaceDown() || forceFaceDown, dragItem);
|
||||
drag->setPos(dragItem->pos() + childPos);
|
||||
|
|
@ -380,13 +397,14 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
void CardItem::playCard(bool faceDown)
|
||||
{
|
||||
// Do nothing if the card belongs to another player
|
||||
if (!owner->getPlayerInfo()->getLocalOrJudge())
|
||||
if (!owner->getPlayerInfo()->getLocalOrJudge()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TableZoneLogic *tz = qobject_cast<TableZoneLogic *>(zone);
|
||||
if (tz)
|
||||
if (tz) {
|
||||
emit tz->toggleTapped();
|
||||
else {
|
||||
} else {
|
||||
if (SettingsCache::instance().getClickPlaysAllSelected()) {
|
||||
faceDown ? zone->getPlayer()->getPlayerActions()->actPlayFacedown()
|
||||
: zone->getPlayer()->getPlayerActions()->actPlay();
|
||||
|
|
@ -493,8 +511,9 @@ bool CardItem::animationEvent()
|
|||
{
|
||||
int rotation = ROTATION_DEGREES_PER_FRAME;
|
||||
bool animationIncomplete = true;
|
||||
if (!tapped)
|
||||
if (!tapped) {
|
||||
rotation *= -1;
|
||||
}
|
||||
|
||||
tapAngle += rotation;
|
||||
if (tapped && (tapAngle > 90)) {
|
||||
|
|
|
|||
|
|
@ -24,17 +24,21 @@ void DeckViewCardDragItem::updatePosition(const QPointF &cursorScenePos)
|
|||
QList<QGraphicsItem *> colliding = scene()->items(cursorScenePos);
|
||||
|
||||
DeckViewCardContainer *cursorZone = 0;
|
||||
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||
if ((cursorZone = qgraphicsitem_cast<DeckViewCardContainer *>(colliding.at(i))))
|
||||
for (int i = colliding.size() - 1; i >= 0; i--) {
|
||||
if ((cursorZone = qgraphicsitem_cast<DeckViewCardContainer *>(colliding.at(i)))) {
|
||||
break;
|
||||
if (!cursorZone)
|
||||
}
|
||||
}
|
||||
if (!cursorZone) {
|
||||
return;
|
||||
}
|
||||
currentZone = cursorZone;
|
||||
|
||||
QPointF newPos = cursorScenePos;
|
||||
if (newPos != pos()) {
|
||||
for (int i = 0; i < childDrags.size(); i++)
|
||||
for (int i = 0; i < childDrags.size(); i++) {
|
||||
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
||||
}
|
||||
setPos(newPos);
|
||||
}
|
||||
}
|
||||
|
|
@ -104,11 +108,13 @@ void DeckViewCard::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
|||
void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() <
|
||||
2 * QApplication::startDragDistance())
|
||||
2 * QApplication::startDragDistance()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (static_cast<DeckViewScene *>(scene())->getLocked())
|
||||
if (static_cast<DeckViewScene *>(scene())->getLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete dragItem;
|
||||
dragItem = new DeckViewCardDragItem(this, event->pos());
|
||||
|
|
@ -120,8 +126,9 @@ void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
int j = 0;
|
||||
for (int i = 0; i < sel.size(); i++) {
|
||||
auto *c = static_cast<DeckViewCard *>(sel.at(i));
|
||||
if (c == this)
|
||||
if (c == this) {
|
||||
continue;
|
||||
}
|
||||
++j;
|
||||
auto childPos = QPointF(j * CardDimensions::WIDTH_HALF_F, 0);
|
||||
auto *drag = new DeckViewCardDragItem(c, childPos, dragItem);
|
||||
|
|
@ -133,8 +140,9 @@ void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
|
||||
void DeckView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
if (static_cast<DeckViewScene *>(scene())->getLocked())
|
||||
if (static_cast<DeckViewScene *>(scene())->getLocked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
QList<MoveCard_ToZone> result;
|
||||
|
|
@ -147,12 +155,13 @@ void DeckView::mouseDoubleClickEvent(QMouseEvent *event)
|
|||
m.set_card_name(c->getName().toStdString());
|
||||
m.set_start_zone(zone->getName().toStdString());
|
||||
|
||||
if (zone->getName() == DECK_ZONE_MAIN)
|
||||
if (zone->getName() == DECK_ZONE_MAIN) {
|
||||
m.set_target_zone(DECK_ZONE_SIDE);
|
||||
else if (zone->getName() == DECK_ZONE_SIDE)
|
||||
} else if (zone->getName() == DECK_ZONE_SIDE) {
|
||||
m.set_target_zone(DECK_ZONE_MAIN);
|
||||
else // Trying to move from another zone
|
||||
} else { // Trying to move from another zone
|
||||
m.set_target_zone(zone->getName().toStdString());
|
||||
}
|
||||
|
||||
result.append(m);
|
||||
}
|
||||
|
|
@ -232,8 +241,9 @@ QList<QPair<int, int>> DeckViewCardContainer::getRowsAndCols() const
|
|||
{
|
||||
QList<QPair<int, int>> result;
|
||||
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
||||
for (int i = 0; i < cardTypeList.size(); ++i)
|
||||
for (int i = 0; i < cardTypeList.size(); ++i) {
|
||||
result.append(QPair<int, int>(1, cardsByType.count(cardTypeList[i])));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -262,8 +272,9 @@ QSizeF DeckViewCardContainer::calculateBoundingRect(const QList<QPair<int, int>>
|
|||
// Calculate space needed for cards
|
||||
for (int i = 0; i < rowsAndCols.size(); ++i) {
|
||||
totalHeight += CardDimensions::HEIGHT_F * rowsAndCols[i].first + paddingY;
|
||||
if (CardDimensions::WIDTH_F * rowsAndCols[i].second > totalWidth)
|
||||
if (CardDimensions::WIDTH_F * rowsAndCols[i].second > totalWidth) {
|
||||
totalWidth = CardDimensions::WIDTH_F * rowsAndCols[i].second;
|
||||
}
|
||||
}
|
||||
|
||||
return QSizeF(getCardTypeTextWidth() + totalWidth, totalHeight + separatorY + paddingY);
|
||||
|
|
@ -271,8 +282,9 @@ QSizeF DeckViewCardContainer::calculateBoundingRect(const QList<QPair<int, int>>
|
|||
|
||||
bool DeckViewCardContainer::sortCardsByName(DeckViewCard *c1, DeckViewCard *c2)
|
||||
{
|
||||
if (c1 && c2)
|
||||
if (c1 && c2) {
|
||||
return c1->getName() < c2->getName();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -322,15 +334,17 @@ DeckViewScene::~DeckViewScene()
|
|||
void DeckViewScene::clearContents()
|
||||
{
|
||||
QMapIterator<QString, DeckViewCardContainer *> i(cardContainers);
|
||||
while (i.hasNext())
|
||||
while (i.hasNext()) {
|
||||
delete i.next().value();
|
||||
}
|
||||
cardContainers.clear();
|
||||
}
|
||||
|
||||
void DeckViewScene::setDeck(const DeckList &_deck)
|
||||
{
|
||||
if (deck)
|
||||
if (deck) {
|
||||
delete deck;
|
||||
}
|
||||
|
||||
deck = new DeckList(_deck.writeToString_Native());
|
||||
rebuildTree();
|
||||
|
|
@ -342,8 +356,9 @@ void DeckViewScene::rebuildTree()
|
|||
{
|
||||
clearContents();
|
||||
|
||||
if (!deck)
|
||||
if (!deck) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto *currentZone : deck->getZoneNodes()) {
|
||||
DeckViewCardContainer *container = cardContainers.value(currentZone->getName(), 0);
|
||||
|
|
@ -355,8 +370,9 @@ void DeckViewScene::rebuildTree()
|
|||
|
||||
for (int j = 0; j < currentZone->size(); j++) {
|
||||
auto *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||
if (!currentCard)
|
||||
if (!currentCard) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||
auto *newCard = new DeckViewCard(container, currentCard->toCardRef(), currentZone->getName());
|
||||
|
|
@ -373,18 +389,21 @@ void DeckViewScene::applySideboardPlan(const QList<MoveCard_ToZone> &plan)
|
|||
const MoveCard_ToZone &m = plan[i];
|
||||
DeckViewCardContainer *start = cardContainers.value(QString::fromStdString(m.start_zone()));
|
||||
DeckViewCardContainer *target = cardContainers.value(QString::fromStdString(m.target_zone()));
|
||||
if (!start || !target)
|
||||
if (!start || !target) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DeckViewCard *card = 0;
|
||||
const QList<DeckViewCard *> &cardList = start->getCards();
|
||||
for (int j = 0; j < cardList.size(); ++j)
|
||||
for (int j = 0; j < cardList.size(); ++j) {
|
||||
if (cardList[j]->getName() == QString::fromStdString(m.card_name())) {
|
||||
card = cardList[j];
|
||||
break;
|
||||
}
|
||||
if (!card)
|
||||
}
|
||||
if (!card) {
|
||||
continue;
|
||||
}
|
||||
|
||||
start->removeCard(card);
|
||||
target->addCard(card);
|
||||
|
|
@ -405,8 +424,9 @@ void DeckViewScene::rearrangeItems()
|
|||
rowsAndColsList.append(rowsAndCols);
|
||||
|
||||
cardCountList.append(QList<int>());
|
||||
for (int j = 0; j < rowsAndCols.size(); ++j)
|
||||
for (int j = 0; j < rowsAndCols.size(); ++j) {
|
||||
cardCountList[i].append(rowsAndCols[j].second);
|
||||
}
|
||||
}
|
||||
|
||||
qreal totalHeight, totalWidth;
|
||||
|
|
@ -417,23 +437,27 @@ void DeckViewScene::rearrangeItems()
|
|||
for (int i = 0; i < contList.size(); ++i) {
|
||||
QSizeF contSize = contList[i]->calculateBoundingRect(rowsAndColsList[i]);
|
||||
totalHeight += contSize.height() + spacing;
|
||||
if (contSize.width() > totalWidth)
|
||||
if (contSize.width() > totalWidth) {
|
||||
totalWidth = contSize.width();
|
||||
}
|
||||
}
|
||||
|
||||
// We're done when the aspect ratio shifts from too high to too low.
|
||||
if (totalWidth / totalHeight <= optimalAspectRatio)
|
||||
if (totalWidth / totalHeight <= optimalAspectRatio) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Find category with highest column count
|
||||
int maxIndex1 = -1, maxIndex2 = -1, maxCols = 0;
|
||||
for (int i = 0; i < rowsAndColsList.size(); ++i)
|
||||
for (int j = 0; j < rowsAndColsList[i].size(); ++j)
|
||||
for (int i = 0; i < rowsAndColsList.size(); ++i) {
|
||||
for (int j = 0; j < rowsAndColsList[i].size(); ++j) {
|
||||
if (rowsAndColsList[i][j].second > maxCols) {
|
||||
maxIndex1 = i;
|
||||
maxIndex2 = j;
|
||||
maxCols = rowsAndColsList[i][j].second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add row to category
|
||||
const int maxRows = rowsAndColsList[maxIndex1][maxIndex2].first;
|
||||
|
|
@ -451,8 +475,9 @@ void DeckViewScene::rearrangeItems()
|
|||
}
|
||||
|
||||
totalWidth = totalHeight * optimalAspectRatio;
|
||||
for (int i = 0; i < contList.size(); ++i)
|
||||
for (int i = 0; i < contList.size(); ++i) {
|
||||
contList[i]->setWidth(totalWidth);
|
||||
}
|
||||
|
||||
setSceneRect(QRectF(0, 0, totalWidth, totalHeight));
|
||||
}
|
||||
|
|
@ -470,7 +495,7 @@ QList<MoveCard_ToZone> DeckViewScene::getSideboardPlan() const
|
|||
while (containerIterator.hasNext()) {
|
||||
DeckViewCardContainer *cont = containerIterator.next().value();
|
||||
const QList<DeckViewCard *> cardList = cont->getCards();
|
||||
for (int i = 0; i < cardList.size(); ++i)
|
||||
for (int i = 0; i < cardList.size(); ++i) {
|
||||
if (cardList[i]->getOriginZone() != cont->getName()) {
|
||||
MoveCard_ToZone m;
|
||||
m.set_card_name(cardList[i]->getName().toStdString());
|
||||
|
|
@ -478,6 +503,7 @@ QList<MoveCard_ToZone> DeckViewScene::getSideboardPlan() const
|
|||
m.set_target_zone(cont->getName().toStdString());
|
||||
result.append(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,8 +251,9 @@ void DeckViewContainer::unloadDeck()
|
|||
void DeckViewContainer::loadLocalDeck()
|
||||
{
|
||||
DlgLoadDeck dialog(this);
|
||||
if (!dialog.exec())
|
||||
if (!dialog.exec()) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadDeckFromFile(dialog.selectedFiles().at(0));
|
||||
}
|
||||
|
|
@ -364,8 +365,9 @@ void DeckViewContainer::sideboardPlanChanged()
|
|||
{
|
||||
Command_SetSideboardPlan cmd;
|
||||
const QList<MoveCard_ToZone> &newPlan = deckView->getSideboardPlan();
|
||||
for (const auto &i : newPlan)
|
||||
for (const auto &i : newPlan) {
|
||||
cmd.add_move_list()->CopyFrom(i);
|
||||
}
|
||||
parentGame->getGame()->getGameEventHandler()->sendGameCommand(cmd, playerId);
|
||||
}
|
||||
|
||||
|
|
@ -404,8 +406,9 @@ void DeckViewContainer::setSideboardLocked(bool locked)
|
|||
{
|
||||
sideboardLockButton->setState(!locked);
|
||||
deckView->setLocked(readyStartButton->getState() || !sideboardLockButton->getState());
|
||||
if (locked)
|
||||
if (locked) {
|
||||
deckView->resetSideboardPlan();
|
||||
}
|
||||
}
|
||||
|
||||
void DeckViewContainer::setDeck(const DeckList &deck)
|
||||
|
|
|
|||
|
|
@ -101,8 +101,9 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa
|
|||
chooseTokenView->resizeColumnToContents(0);
|
||||
chooseTokenView->setWordWrap(true);
|
||||
|
||||
if (!deckHeaderState.isNull())
|
||||
if (!deckHeaderState.isNull()) {
|
||||
chooseTokenView->header()->restoreState(deckHeaderState);
|
||||
}
|
||||
|
||||
chooseTokenView->header()->setStretchLastSection(false);
|
||||
chooseTokenView->header()->hideSection(1); // Sets
|
||||
|
|
@ -185,8 +186,9 @@ void DlgCreateToken::tokenSelectionChanged(const QModelIndex ¤t, const QMo
|
|||
const QChar cardColor = cardInfo->getColorChar();
|
||||
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
||||
ptEdit->setText(cardInfo->getPowTough());
|
||||
if (SettingsCache::instance().getAnnotateTokens())
|
||||
if (SettingsCache::instance().getAnnotateTokens()) {
|
||||
annotationEdit->setText(cardInfo->getText());
|
||||
}
|
||||
} else {
|
||||
nameEdit->setText("");
|
||||
colorEdit->setCurrentIndex(colorEdit->findData(QString(), Qt::UserRole, Qt::MatchFixedString));
|
||||
|
|
|
|||
|
|
@ -36,8 +36,9 @@ GameEventHandler::GameEventHandler(AbstractGame *_game) : QObject(_game), game(_
|
|||
void GameEventHandler::sendGameCommand(PendingCommand *pend, int playerId)
|
||||
{
|
||||
AbstractClient *client = game->getClientForPlayer(playerId);
|
||||
if (!client)
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
connect(pend, &PendingCommand::finished, this, &GameEventHandler::commandFinished);
|
||||
client->sendCommand(pend);
|
||||
|
|
@ -46,8 +47,9 @@ void GameEventHandler::sendGameCommand(PendingCommand *pend, int playerId)
|
|||
void GameEventHandler::sendGameCommand(const google::protobuf::Message &command, int playerId)
|
||||
{
|
||||
AbstractClient *client = game->getClientForPlayer(playerId);
|
||||
if (!client)
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
PendingCommand *pend = prepareGameCommand(command);
|
||||
connect(pend, &PendingCommand::finished, this, &GameEventHandler::commandFinished);
|
||||
|
|
@ -56,8 +58,9 @@ void GameEventHandler::sendGameCommand(const google::protobuf::Message &command,
|
|||
|
||||
void GameEventHandler::commandFinished(const Response &response)
|
||||
{
|
||||
if (response.response_code() == Response::RespChatFlood)
|
||||
if (response.response_code() == Response::RespChatFlood) {
|
||||
emit gameFlooded();
|
||||
}
|
||||
}
|
||||
|
||||
PendingCommand *GameEventHandler::prepareGameCommand(const ::google::protobuf::Message &cmd)
|
||||
|
|
@ -117,9 +120,11 @@ void GameEventHandler::processGameEventContainer(const GameEventContainer &cont,
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
if ((game->getGameState()->getClients().size() > 1) && (playerId != -1))
|
||||
if (game->getGameState()->getClients().at(playerId) != client)
|
||||
if ((game->getGameState()->getClients().size() > 1) && (playerId != -1)) {
|
||||
if (game->getGameState()->getClients().at(playerId) != client) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch (eventType) {
|
||||
case GameEvent::GAME_STATE_CHANGED:
|
||||
|
|
@ -284,8 +289,9 @@ void GameEventHandler::eventGameStateChanged(const Event_GameStateChanged &event
|
|||
if (event.game_started() && !game->getGameMetaInfo()->started()) {
|
||||
game->getGameState()->setResuming(!game->getGameState()->isGameStateKnown());
|
||||
game->getGameMetaInfo()->setStarted(event.game_started());
|
||||
if (game->getGameState()->isGameStateKnown())
|
||||
if (game->getGameState()->isGameStateKnown()) {
|
||||
emit logGameStart();
|
||||
}
|
||||
game->getGameState()->setActivePlayer(event.active_player_id());
|
||||
game->getGameState()->setCurrentPhase(event.active_phase());
|
||||
} else if (!event.game_started() && game->getGameMetaInfo()->started()) {
|
||||
|
|
@ -305,8 +311,9 @@ void GameEventHandler::processCardAttachmentsForPlayers(const Event_GameStateCha
|
|||
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
|
||||
if (!prop.spectator()) {
|
||||
Player *player = game->getPlayerManager()->getPlayers().value(prop.player_id(), 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
continue;
|
||||
}
|
||||
player->processCardAttachment(playerInfo);
|
||||
}
|
||||
}
|
||||
|
|
@ -317,8 +324,9 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
|||
const GameEventContext &context)
|
||||
{
|
||||
Player *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
const ServerInfo_PlayerProperties &prop = event.player_properties();
|
||||
emit playerPropertiesChanged(prop, eventPlayerId);
|
||||
|
||||
|
|
@ -326,8 +334,9 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
|||
switch (contextType) {
|
||||
case GameEventContext::READY_START: {
|
||||
bool ready = prop.ready_start();
|
||||
if (player->getPlayerInfo()->getLocal())
|
||||
if (player->getPlayerInfo()->getLocal()) {
|
||||
emit localPlayerReadyStateChanged(player->getPlayerInfo()->getId(), ready);
|
||||
}
|
||||
if (ready) {
|
||||
emit logReadyStart(player);
|
||||
} else {
|
||||
|
|
@ -339,8 +348,9 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
|||
player->setConceded(true);
|
||||
|
||||
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||
while (playerIterator.hasNext())
|
||||
while (playerIterator.hasNext()) {
|
||||
playerIterator.next().value()->updateZones();
|
||||
}
|
||||
|
||||
emit logConcede(eventPlayerId);
|
||||
|
||||
|
|
@ -350,8 +360,9 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
|||
player->setConceded(false);
|
||||
|
||||
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||
while (playerIterator.hasNext())
|
||||
while (playerIterator.hasNext()) {
|
||||
playerIterator.next().value()->updateZones();
|
||||
}
|
||||
|
||||
emit logUnconcede(eventPlayerId);
|
||||
|
||||
|
|
@ -389,8 +400,9 @@ void GameEventHandler::eventJoin(const Event_Join &event, int /*eventPlayerId*/,
|
|||
QString playerName = QString::fromStdString(playerInfo.user_info().name());
|
||||
emit addPlayerToAutoCompleteList(playerName);
|
||||
|
||||
if (game->getPlayerManager()->getPlayers().contains(playerId))
|
||||
if (game->getPlayerManager()->getPlayers().contains(playerId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (playerInfo.spectator()) {
|
||||
game->getPlayerManager()->addSpectator(playerId, playerInfo);
|
||||
|
|
@ -426,8 +438,9 @@ QString GameEventHandler::getLeaveReason(Event_Leave::LeaveReason reason)
|
|||
void GameEventHandler::eventLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext & /*context*/)
|
||||
{
|
||||
Player *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
|
||||
player->clear();
|
||||
emit playerLeft(eventPlayerId);
|
||||
|
|
@ -440,8 +453,9 @@ void GameEventHandler::eventLeave(const Event_Leave &event, int eventPlayerId, c
|
|||
|
||||
// Rearrange all remaining zones so that attachment relationship updates take place
|
||||
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||
while (playerIterator.hasNext())
|
||||
while (playerIterator.hasNext()) {
|
||||
playerIterator.next().value()->updateZones();
|
||||
}
|
||||
|
||||
emitUserEvent();
|
||||
}
|
||||
|
|
@ -461,8 +475,9 @@ void GameEventHandler::eventReverseTurn(const Event_ReverseTurn &event,
|
|||
const GameEventContext & /*context*/)
|
||||
{
|
||||
Player *player = game->getPlayerManager()->getPlayers().value(eventPlayerId, 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit logTurnReversed(player, event.reversed());
|
||||
}
|
||||
|
|
@ -491,8 +506,9 @@ void GameEventHandler::eventSetActivePlayer(const Event_SetActivePlayer &event,
|
|||
{
|
||||
game->getGameState()->setActivePlayer(event.active_player_id());
|
||||
Player *player = game->getPlayerManager()->getPlayer(event.active_player_id());
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
emit logActivePlayer(player);
|
||||
emitUserEvent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,15 +87,17 @@ public:
|
|||
public slots:
|
||||
void setStarted(bool s)
|
||||
{
|
||||
if (gameInfo_.started() == s)
|
||||
if (gameInfo_.started() == s) {
|
||||
return;
|
||||
}
|
||||
gameInfo_.set_started(s);
|
||||
emit startedChanged(s);
|
||||
}
|
||||
void setSpectatorsOmniscient(bool v)
|
||||
{
|
||||
if (gameInfo_.spectators_omniscient() == v)
|
||||
if (gameInfo_.spectators_omniscient() == v) {
|
||||
return;
|
||||
}
|
||||
gameInfo_.set_spectators_omniscient(v);
|
||||
emit spectatorsOmniscienceChanged(v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,8 +55,9 @@ GameScene::~GameScene()
|
|||
*/
|
||||
void GameScene::retranslateUi()
|
||||
{
|
||||
for (ZoneViewWidget *view : zoneViews)
|
||||
for (ZoneViewWidget *view : zoneViews) {
|
||||
view->retranslateUi();
|
||||
}
|
||||
}
|
||||
|
||||
QList<CardItem *> GameScene::selectedCards() const
|
||||
|
|
@ -209,10 +210,12 @@ QList<Player *> GameScene::rotatePlayers(const QList<Player *> &activePlayers, i
|
|||
QList<Player *> rotated = activePlayers;
|
||||
if (!rotated.isEmpty()) {
|
||||
int totalRotation = firstPlayerIndex + playerRotation;
|
||||
while (totalRotation < 0)
|
||||
while (totalRotation < 0) {
|
||||
totalRotation += rotated.size();
|
||||
for (int i = 0; i < totalRotation; ++i)
|
||||
}
|
||||
for (int i = 0; i < totalRotation; ++i) {
|
||||
rotated.append(rotated.takeFirst());
|
||||
}
|
||||
}
|
||||
return rotated;
|
||||
}
|
||||
|
|
@ -252,10 +255,11 @@ QSizeF GameScene::computeSceneSizeAndPlayerLayout(const QList<Player *> &players
|
|||
|
||||
for (int j = 0; j < rowsInColumn; ++j) {
|
||||
Player *player = playersIter.next();
|
||||
if (col == 0)
|
||||
if (col == 0) {
|
||||
playersByColumn[col].prepend(player->getGraphicsItem());
|
||||
else
|
||||
} else {
|
||||
playersByColumn[col].append(player->getGraphicsItem());
|
||||
}
|
||||
|
||||
auto *pgItem = player->getGraphicsItem();
|
||||
thisColumnHeight += pgItem->boundingRect().height() + playerAreaSpacing;
|
||||
|
|
@ -294,8 +298,9 @@ QList<qreal> GameScene::calculateMinWidthByColumn() const
|
|||
QList<qreal> minWidthByColumn;
|
||||
for (const auto &col : playersByColumn) {
|
||||
qreal maxWidth = 0;
|
||||
for (PlayerGraphicsItem *player : col)
|
||||
for (PlayerGraphicsItem *player : col) {
|
||||
maxWidth = std::max(maxWidth, player->getMinimumWidth());
|
||||
}
|
||||
minWidthByColumn.append(maxWidth);
|
||||
}
|
||||
return minWidthByColumn;
|
||||
|
|
@ -356,32 +361,38 @@ void GameScene::updateHover(const QPointF &scenePos)
|
|||
|
||||
void GameScene::updateHoveredCard(CardItem *newCard)
|
||||
{
|
||||
if (hoveredCard && (newCard != hoveredCard))
|
||||
if (hoveredCard && (newCard != hoveredCard)) {
|
||||
endCardHover(hoveredCard);
|
||||
if (newCard && (newCard != hoveredCard))
|
||||
}
|
||||
if (newCard && (newCard != hoveredCard)) {
|
||||
beginCardHover(newCard);
|
||||
}
|
||||
hoveredCard = newCard;
|
||||
}
|
||||
|
||||
void GameScene::beginCardHover(CardItem *card)
|
||||
{
|
||||
card->setHovered(true);
|
||||
if (auto *zone = SelectZone::findOwningSelectZone(card))
|
||||
if (auto *zone = SelectZone::findOwningSelectZone(card)) {
|
||||
zone->escapeClipForHover(card);
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::endCardHover(CardItem *card)
|
||||
{
|
||||
if (auto *zone = SelectZone::findOwningSelectZone(card))
|
||||
if (auto *zone = SelectZone::findOwningSelectZone(card)) {
|
||||
zone->restoreClipAfterHover(card);
|
||||
}
|
||||
card->setHovered(false);
|
||||
}
|
||||
|
||||
CardZone *GameScene::findTopmostZone(const QList<QGraphicsItem *> &items)
|
||||
{
|
||||
for (QGraphicsItem *item : items)
|
||||
if (auto *zone = qgraphicsitem_cast<CardZone *>(item))
|
||||
for (QGraphicsItem *item : items) {
|
||||
if (auto *zone = qgraphicsitem_cast<CardZone *>(item)) {
|
||||
return zone;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -392,14 +403,17 @@ CardItem *GameScene::findTopmostCardInZone(const QList<QGraphicsItem *> &items,
|
|||
|
||||
for (QGraphicsItem *item : items) {
|
||||
CardItem *card = qgraphicsitem_cast<CardItem *>(item);
|
||||
if (!card)
|
||||
if (!card) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (card->getAttachedTo()) {
|
||||
if (card->getAttachedTo()->getZone() != zone->getLogic())
|
||||
if (card->getAttachedTo()->getZone() != zone->getLogic()) {
|
||||
continue;
|
||||
} else if (card->getZone() != zone->getLogic())
|
||||
}
|
||||
} else if (card->getZone() != zone->getLogic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (card->getRealZValue() > maxZ) {
|
||||
maxZ = card->getRealZValue();
|
||||
|
|
@ -438,12 +452,13 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
|
|||
connect(item, &ZoneViewWidget::closePressed, this, &GameScene::removeZoneView);
|
||||
addItem(item);
|
||||
|
||||
if (zoneName == ZoneNames::GRAVE)
|
||||
if (zoneName == ZoneNames::GRAVE) {
|
||||
item->setPos(360, 100);
|
||||
else if (zoneName == ZoneNames::EXILE)
|
||||
} else if (zoneName == ZoneNames::EXILE) {
|
||||
item->setPos(380, 120);
|
||||
else
|
||||
} else {
|
||||
item->setPos(340, 80);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -480,8 +495,9 @@ void GameScene::removeZoneView(ZoneViewWidget *item)
|
|||
*/
|
||||
void GameScene::clearViews()
|
||||
{
|
||||
while (!zoneViews.isEmpty())
|
||||
while (!zoneViews.isEmpty()) {
|
||||
zoneViews.first()->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -489,8 +505,9 @@ void GameScene::clearViews()
|
|||
*/
|
||||
void GameScene::closeMostRecentZoneView()
|
||||
{
|
||||
if (!zoneViews.isEmpty())
|
||||
if (!zoneViews.isEmpty()) {
|
||||
zoneViews.last()->close();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- View Transforms ----------
|
||||
|
|
@ -509,10 +526,11 @@ QTransform GameScene::getViewportTransform() const
|
|||
|
||||
bool GameScene::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::GraphicsSceneMouseMove)
|
||||
if (event->type() == QEvent::GraphicsSceneMouseMove) {
|
||||
updateHover(static_cast<QGraphicsSceneMouseEvent *>(event)->scenePos());
|
||||
else if (event->type() == QEvent::Leave)
|
||||
} else if (event->type() == QEvent::Leave) {
|
||||
updateHoveredCard(nullptr);
|
||||
}
|
||||
|
||||
return QGraphicsScene::event(event);
|
||||
}
|
||||
|
|
@ -522,25 +540,29 @@ void GameScene::timerEvent(QTimerEvent * /*event*/)
|
|||
QMutableSetIterator<CardItem *> i(cardsToAnimate);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!i.value()->animationEvent())
|
||||
if (!i.value()->animationEvent()) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
if (cardsToAnimate.isEmpty())
|
||||
if (cardsToAnimate.isEmpty()) {
|
||||
animationTimer->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::registerAnimationItem(AbstractCardItem *card)
|
||||
{
|
||||
cardsToAnimate.insert(static_cast<CardItem *>(card));
|
||||
if (!animationTimer->isActive())
|
||||
if (!animationTimer->isActive()) {
|
||||
animationTimer->start(10, this);
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::unregisterAnimationItem(AbstractCardItem *card)
|
||||
{
|
||||
cardsToAnimate.remove(static_cast<CardItem *>(card));
|
||||
if (cardsToAnimate.isEmpty())
|
||||
if (cardsToAnimate.isEmpty()) {
|
||||
animationTimer->stop();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Rubber Band ----------
|
||||
|
|
|
|||
|
|
@ -75,8 +75,9 @@ void GameView::resizeEvent(QResizeEvent *event)
|
|||
QGraphicsView::resizeEvent(event);
|
||||
|
||||
GameScene *s = dynamic_cast<GameScene *>(scene());
|
||||
if (s)
|
||||
if (s) {
|
||||
s->processViewSizeChange(event->size());
|
||||
}
|
||||
|
||||
updateSceneRect(scene()->sceneRect());
|
||||
updateTotalSelectionCount(event->size());
|
||||
|
|
@ -89,8 +90,9 @@ void GameView::updateSceneRect(const QRectF &rect)
|
|||
|
||||
void GameView::startRubberBand(const QPointF &_selectionOrigin)
|
||||
{
|
||||
if (!rubberBand)
|
||||
if (!rubberBand) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectionOrigin = _selectionOrigin;
|
||||
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), QSize(0, 0)));
|
||||
|
|
@ -99,8 +101,9 @@ void GameView::startRubberBand(const QPointF &_selectionOrigin)
|
|||
|
||||
void GameView::resizeRubberBand(const QPointF &cursorPoint, int selectedCount)
|
||||
{
|
||||
if (!rubberBand)
|
||||
if (!rubberBand) {
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr int kLabelPaddingInPixels = 4;
|
||||
|
||||
|
|
@ -145,8 +148,9 @@ void GameView::resizeRubberBand(const QPointF &cursorPoint, int selectedCount)
|
|||
|
||||
void GameView::stopRubberBand()
|
||||
{
|
||||
if (!rubberBand)
|
||||
if (!rubberBand) {
|
||||
return;
|
||||
}
|
||||
|
||||
rubberBand->hide();
|
||||
dragCountLabel->hide();
|
||||
|
|
|
|||
|
|
@ -21,8 +21,9 @@ PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_
|
|||
activeAnimationTimer = new QTimer(this);
|
||||
connect(activeAnimationTimer, &QTimer::timeout, this, &PhaseButton::updateAnimation);
|
||||
activeAnimationTimer->setSingleShot(false);
|
||||
} else
|
||||
} else {
|
||||
activeAnimationCounter = 9;
|
||||
}
|
||||
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
}
|
||||
|
|
@ -63,8 +64,9 @@ void PhaseButton::setWidth(double _width)
|
|||
|
||||
void PhaseButton::setActive(bool _active)
|
||||
{
|
||||
if ((active == _active) || !highlightable)
|
||||
if ((active == _active) || !highlightable) {
|
||||
return;
|
||||
}
|
||||
|
||||
active = _active;
|
||||
activeAnimationTimer->start(25);
|
||||
|
|
@ -72,8 +74,9 @@ void PhaseButton::setActive(bool _active)
|
|||
|
||||
void PhaseButton::updateAnimation()
|
||||
{
|
||||
if (!highlightable)
|
||||
if (!highlightable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// the counter ticks up to 10 when active and down to 0 when inactive
|
||||
if (active && activeAnimationCounter < 10) {
|
||||
|
|
@ -99,8 +102,9 @@ void PhaseButton::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * /*event*/)
|
|||
|
||||
void PhaseButton::triggerDoubleClickAction()
|
||||
{
|
||||
if (doubleClickAction)
|
||||
if (doubleClickAction) {
|
||||
doubleClickAction->trigger();
|
||||
}
|
||||
}
|
||||
|
||||
PhasesToolbar::PhasesToolbar(QGraphicsItem *parent)
|
||||
|
|
@ -126,8 +130,9 @@ PhasesToolbar::PhasesToolbar(QGraphicsItem *parent)
|
|||
buttonList << untapButton << upkeepButton << drawButton << main1Button << combatStartButton << combatAttackersButton
|
||||
<< combatBlockersButton << combatDamageButton << combatEndButton << main2Button << cleanupButton;
|
||||
|
||||
for (auto &i : buttonList)
|
||||
for (auto &i : buttonList) {
|
||||
connect(i, &PhaseButton::clicked, this, &PhasesToolbar::phaseButtonClicked);
|
||||
}
|
||||
|
||||
nextTurnButton = new PhaseButton("nextturn", this, nullptr, false);
|
||||
connect(nextTurnButton, &PhaseButton::clicked, this, &PhasesToolbar::actNextTurn);
|
||||
|
|
@ -144,8 +149,9 @@ QRectF PhasesToolbar::boundingRect() const
|
|||
|
||||
void PhasesToolbar::retranslateUi()
|
||||
{
|
||||
for (int i = 0; i < buttonList.size(); ++i)
|
||||
for (int i = 0; i < buttonList.size(); ++i) {
|
||||
buttonList[i]->setToolTip(getLongPhaseName(i));
|
||||
}
|
||||
}
|
||||
|
||||
QString PhasesToolbar::getLongPhaseName(int phase) const
|
||||
|
|
@ -187,8 +193,9 @@ const double PhasesToolbar::marginSize = 3;
|
|||
|
||||
void PhasesToolbar::rearrangeButtons()
|
||||
{
|
||||
for (auto &i : buttonList)
|
||||
for (auto &i : buttonList) {
|
||||
i->setWidth(symbolSize);
|
||||
}
|
||||
nextTurnButton->setWidth(symbolSize);
|
||||
|
||||
double y = marginSize;
|
||||
|
|
@ -226,11 +233,13 @@ void PhasesToolbar::setHeight(double _height)
|
|||
|
||||
void PhasesToolbar::setActivePhase(int phase)
|
||||
{
|
||||
if (phase >= buttonList.size())
|
||||
if (phase >= buttonList.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < buttonList.size(); ++i)
|
||||
for (int i = 0; i < buttonList.size(); ++i) {
|
||||
buttonList[i]->setActive(i == phase);
|
||||
}
|
||||
}
|
||||
|
||||
void PhasesToolbar::triggerPhaseAction(int phase)
|
||||
|
|
@ -243,8 +252,9 @@ void PhasesToolbar::triggerPhaseAction(int phase)
|
|||
void PhasesToolbar::phaseButtonClicked()
|
||||
{
|
||||
auto *button = qobject_cast<PhaseButton *>(sender());
|
||||
if (button->getActive())
|
||||
if (button->getActive()) {
|
||||
button->triggerDoubleClickAction();
|
||||
}
|
||||
|
||||
Command_SetActivePhase cmd;
|
||||
cmd.set_phase(static_cast<google::protobuf::uint32>(buttonList.indexOf(button)));
|
||||
|
|
|
|||
|
|
@ -78,8 +78,9 @@ void GraveyardMenu::populateRevealRandomMenuWithActivePlayers()
|
|||
|
||||
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player)
|
||||
if (other == player) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealRandomGraveyardCard->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &GraveyardMenu::onRevealRandomTriggered);
|
||||
|
|
|
|||
|
|
@ -168,8 +168,9 @@ void HandMenu::populateRevealHandMenuWithActivePlayers()
|
|||
|
||||
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player)
|
||||
if (other == player) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealHand->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &HandMenu::onRevealHandTriggered);
|
||||
|
|
@ -186,8 +187,9 @@ void HandMenu::populateRevealRandomHandCardMenuWithActivePlayers()
|
|||
|
||||
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player)
|
||||
if (other == player) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealRandomHandCard->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardTriggered);
|
||||
|
|
@ -197,8 +199,9 @@ void HandMenu::populateRevealRandomHandCardMenuWithActivePlayers()
|
|||
void HandMenu::onRevealHandTriggered()
|
||||
{
|
||||
auto *action = qobject_cast<QAction *>(sender());
|
||||
if (!action)
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int targetId = action->data().toInt();
|
||||
player->getPlayerActions()->actRevealHand(targetId);
|
||||
|
|
@ -207,8 +210,9 @@ void HandMenu::onRevealHandTriggered()
|
|||
void HandMenu::onRevealRandomHandCardTriggered()
|
||||
{
|
||||
auto *action = qobject_cast<QAction *>(sender());
|
||||
if (!action)
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int targetId = action->data().toInt();
|
||||
player->getPlayerActions()->actRevealRandomHandCard(targetId);
|
||||
|
|
|
|||
|
|
@ -265,8 +265,9 @@ void LibraryMenu::populateRevealLibraryMenuWithActivePlayers()
|
|||
|
||||
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player)
|
||||
if (other == player) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealLibrary->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &LibraryMenu::onRevealLibraryTriggered);
|
||||
|
|
@ -279,8 +280,9 @@ void LibraryMenu::populateLendLibraryMenuWithActivePlayers()
|
|||
|
||||
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player)
|
||||
if (other == player) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mLendLibrary->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &LibraryMenu::onLendLibraryTriggered);
|
||||
|
|
@ -299,8 +301,9 @@ void LibraryMenu::populateRevealTopCardMenuWithActivePlayers()
|
|||
|
||||
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||
for (auto *other : players) {
|
||||
if (other == player)
|
||||
if (other == player) {
|
||||
continue;
|
||||
}
|
||||
QAction *a = mRevealTopCard->addAction(other->getPlayerInfo()->getName());
|
||||
a->setData(other->getPlayerInfo()->getId());
|
||||
connect(a, &QAction::triggered, this, &LibraryMenu::onRevealTopCardTriggered);
|
||||
|
|
|
|||
|
|
@ -63,8 +63,9 @@ Player::~Player()
|
|||
qCInfo(PlayerLog) << "Player destructor:" << getPlayerInfo()->getName();
|
||||
|
||||
QMapIterator<QString, CardZoneLogic *> i(zones);
|
||||
while (i.hasNext())
|
||||
while (i.hasNext()) {
|
||||
delete i.next().value();
|
||||
}
|
||||
zones.clear();
|
||||
|
||||
delete playerMenu;
|
||||
|
|
|
|||
|
|
@ -85,8 +85,9 @@ void PlayerActions::playCard(CardItem *card, bool faceDown)
|
|||
cardToMove->set_pt(info.getPowTough().toStdString());
|
||||
}
|
||||
cardToMove->set_tapped(!faceDown && info.getUiAttributes().cipt);
|
||||
if (tableRow != 3)
|
||||
if (tableRow != 3) {
|
||||
cmd.set_target_zone(ZoneNames::TABLE);
|
||||
}
|
||||
cmd.set_x(gridPoint.x());
|
||||
cmd.set_y(gridPoint.y());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,8 +43,9 @@ PlayerListTWI::PlayerListTWI() : QTreeWidgetItem(Type)
|
|||
bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const
|
||||
{
|
||||
// Sort by spectator/player
|
||||
if (data(1, Qt::UserRole) != other.data(1, Qt::UserRole))
|
||||
if (data(1, Qt::UserRole) != other.data(1, Qt::UserRole)) {
|
||||
return data(1, Qt::UserRole).toBool();
|
||||
}
|
||||
|
||||
// Sort by player ID
|
||||
return data(4, Qt::UserRole + 1).toInt() < other.data(4, Qt::UserRole + 1).toInt();
|
||||
|
|
@ -106,12 +107,14 @@ void PlayerListWidget::addPlayer(const ServerInfo_PlayerProperties &player)
|
|||
|
||||
void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties &prop, int playerId)
|
||||
{
|
||||
if (playerId == -1)
|
||||
if (playerId == -1) {
|
||||
playerId = prop.player_id();
|
||||
}
|
||||
|
||||
QTreeWidgetItem *player = players.value(playerId, 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool isSpectator = prop.has_spectator() && prop.spectator();
|
||||
if (prop.has_judge() || prop.has_spectator()) {
|
||||
|
|
@ -126,13 +129,16 @@ void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties
|
|||
}
|
||||
|
||||
if (!isSpectator) {
|
||||
if (prop.has_conceded())
|
||||
if (prop.has_conceded()) {
|
||||
player->setData(2, Qt::UserRole, prop.conceded());
|
||||
if (prop.has_ready_start())
|
||||
}
|
||||
if (prop.has_ready_start()) {
|
||||
player->setData(2, Qt::UserRole + 1, prop.ready_start());
|
||||
if (prop.has_conceded() || prop.has_ready_start())
|
||||
}
|
||||
if (prop.has_conceded() || prop.has_ready_start()) {
|
||||
player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon())
|
||||
: (prop.ready_start() ? readyIcon : notReadyIcon));
|
||||
}
|
||||
}
|
||||
if (prop.has_user_info()) {
|
||||
player->setData(3, Qt::UserRole, prop.user_info().user_level());
|
||||
|
|
@ -141,30 +147,35 @@ void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties
|
|||
QString::fromStdString(prop.user_info().privlevel())));
|
||||
player->setText(4, QString::fromStdString(prop.user_info().name()));
|
||||
const QString country = QString::fromStdString(prop.user_info().country());
|
||||
if (!country.isEmpty())
|
||||
if (!country.isEmpty()) {
|
||||
player->setIcon(4, QIcon(CountryPixmapGenerator::generatePixmap(12, country)));
|
||||
}
|
||||
player->setData(4, Qt::UserRole, QString::fromStdString(prop.user_info().name()));
|
||||
}
|
||||
|
||||
if (prop.has_player_id())
|
||||
if (prop.has_player_id()) {
|
||||
player->setData(4, Qt::UserRole + 1, prop.player_id());
|
||||
}
|
||||
|
||||
if (!isSpectator) {
|
||||
if (prop.has_deck_hash()) {
|
||||
player->setText(5, QString::fromStdString(prop.deck_hash()));
|
||||
}
|
||||
if (prop.has_sideboard_locked())
|
||||
if (prop.has_sideboard_locked()) {
|
||||
player->setIcon(5, prop.sideboard_locked() ? lockIcon : QIcon());
|
||||
}
|
||||
}
|
||||
if (prop.has_ping_seconds())
|
||||
if (prop.has_ping_seconds()) {
|
||||
player->setIcon(0, QIcon(PingPixmapGenerator::generatePixmap(12, prop.ping_seconds(), 10)));
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerListWidget::removePlayer(int playerId)
|
||||
{
|
||||
QTreeWidgetItem *player = players.value(playerId, 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
players.remove(playerId);
|
||||
delete takeTopLevelItem(indexOfTopLevelItem(player));
|
||||
}
|
||||
|
|
@ -193,13 +204,14 @@ void PlayerListWidget::setGameStarted(bool _gameStarted, bool resuming)
|
|||
QTreeWidgetItem *twi = i.next().value();
|
||||
|
||||
bool isPlayer = twi->data(1, Qt::UserRole).toBool();
|
||||
if (!isPlayer)
|
||||
if (!isPlayer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gameStarted) {
|
||||
if (resuming)
|
||||
if (resuming) {
|
||||
twi->setIcon(2, twi->data(2, Qt::UserRole).toBool() ? concededIcon : QIcon());
|
||||
else {
|
||||
} else {
|
||||
twi->setData(2, Qt::UserRole, false);
|
||||
twi->setIcon(2, QIcon());
|
||||
}
|
||||
|
|
@ -211,8 +223,9 @@ void PlayerListWidget::setGameStarted(bool _gameStarted, bool resuming)
|
|||
|
||||
void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
||||
{
|
||||
if (!userContextMenu)
|
||||
if (!userContextMenu) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString &userName = index.sibling(index.row(), 4).data(Qt::UserRole).toString();
|
||||
int playerId = index.sibling(index.row(), 4).data(Qt::UserRole + 1).toInt();
|
||||
|
|
|
|||
|
|
@ -21,15 +21,18 @@ bool PlayerManager::isMainPlayerConceded() const
|
|||
Player *PlayerManager::getActiveLocalPlayer(int activePlayer) const
|
||||
{
|
||||
Player *active = players.value(activePlayer, 0);
|
||||
if (active)
|
||||
if (active->getPlayerInfo()->getLocal())
|
||||
if (active) {
|
||||
if (active->getPlayerInfo()->getLocal()) {
|
||||
return active;
|
||||
}
|
||||
}
|
||||
|
||||
QMapIterator<int, Player *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
Player *temp = playerIterator.next().value();
|
||||
if (temp->getPlayerInfo()->getLocal())
|
||||
if (temp->getPlayerInfo()->getLocal()) {
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
@ -66,8 +69,9 @@ void PlayerManager::removePlayer(int playerId)
|
|||
Player *PlayerManager::getPlayer(int playerId) const
|
||||
{
|
||||
Player *player = players.value(playerId, 0);
|
||||
if (!player)
|
||||
if (!player) {
|
||||
return nullptr;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,8 +128,9 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
|
|||
resetPainterTransform(painter);
|
||||
|
||||
QString name = QString::fromStdString(info->name());
|
||||
if (name.size() > 13)
|
||||
if (name.size() > 13) {
|
||||
name = name.mid(0, 10) + "...";
|
||||
}
|
||||
|
||||
QFont font;
|
||||
font.setPixelSize(qMax(qRound(translatedNameRect.height() / 1.5), 9));
|
||||
|
|
@ -144,8 +145,9 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
|
|||
painter->setPen(pen);
|
||||
painter->drawRect(boundingRect().adjusted(border / 2, border / 2, -border / 2, -border / 2));
|
||||
|
||||
if (getBeingPointedAt())
|
||||
if (getBeingPointedAt()) {
|
||||
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
|
||||
}
|
||||
}
|
||||
|
||||
AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name, int _value)
|
||||
|
|
|
|||
|
|
@ -25,14 +25,16 @@ void CardZone::onCardAdded(CardItem *addedCard)
|
|||
|
||||
void CardZone::retranslateUi()
|
||||
{
|
||||
for (int i = 0; i < getLogic()->getCards().size(); ++i)
|
||||
for (int i = 0; i < getLogic()->getCards().size(); ++i) {
|
||||
getLogic()->getCards()[i]->retranslateUi();
|
||||
}
|
||||
}
|
||||
|
||||
void CardZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent * /*event*/)
|
||||
{
|
||||
if (doubleClickAction)
|
||||
if (doubleClickAction) {
|
||||
doubleClickAction->trigger();
|
||||
}
|
||||
}
|
||||
|
||||
bool CardZone::showContextMenu(const QPoint &screenPos)
|
||||
|
|
@ -47,12 +49,14 @@ bool CardZone::showContextMenu(const QPoint &screenPos)
|
|||
void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::RightButton) {
|
||||
if (showContextMenu(event->screenPos()))
|
||||
if (showContextMenu(event->screenPos())) {
|
||||
event->accept();
|
||||
else
|
||||
} else {
|
||||
event->ignore();
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
QPointF CardZone::closestGridPoint(const QPointF &point)
|
||||
|
|
|
|||
|
|
@ -34,9 +34,11 @@ void HandZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
|||
QPoint point = dropPoint + scenePos().toPoint();
|
||||
int x = -1;
|
||||
if (SettingsCache::instance().getHorizontalHand()) {
|
||||
for (x = 0; x < getLogic()->getCards().size(); x++)
|
||||
if (point.x() < static_cast<CardItem *>(getLogic()->getCards().at(x))->scenePos().x())
|
||||
for (x = 0; x < getLogic()->getCards().size(); x++) {
|
||||
if (point.x() < static_cast<CardItem *>(getLogic()->getCards().at(x))->scenePos().x()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
x = calcDropIndexFromY(dropPoint.y());
|
||||
}
|
||||
|
|
@ -49,18 +51,20 @@ void HandZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
|||
cmd.set_x(x);
|
||||
cmd.set_y(-1);
|
||||
|
||||
for (int i = 0; i < dragItems.size(); ++i)
|
||||
for (int i = 0; i < dragItems.size(); ++i) {
|
||||
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
|
||||
}
|
||||
|
||||
getLogic()->getPlayer()->getPlayerActions()->sendGameCommand(cmd);
|
||||
}
|
||||
|
||||
QRectF HandZone::boundingRect() const
|
||||
{
|
||||
if (SettingsCache::instance().getHorizontalHand())
|
||||
if (SettingsCache::instance().getHorizontalHand()) {
|
||||
return QRectF(0, 0, width, CardDimensions::HEIGHT_F + 10);
|
||||
else
|
||||
} else {
|
||||
return QRectF(0, 0, CardDimensions::WIDTH_F * 1.5, zoneHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
|
|
@ -90,9 +94,9 @@ void HandZone::reorganizeCards()
|
|||
CardItem *c = getLogic()->getCards().at(i);
|
||||
// If the total width of the cards is smaller than the available width,
|
||||
// the cards do not need to overlap and are displayed in the center of the area.
|
||||
if (cardWidth * cardCount > totalWidth)
|
||||
if (cardWidth * cardCount > totalWidth) {
|
||||
c->setPos(xPadding + ((qreal)i) * (totalWidth - cardWidth) / (cardCount - 1), 5);
|
||||
else {
|
||||
} else {
|
||||
qreal xPosition = leftJustified ? xPadding + ((qreal)i) * cardWidth
|
||||
: xPadding + ((qreal)i) * cardWidth +
|
||||
(totalWidth - cardCount * cardWidth) / 2;
|
||||
|
|
|
|||
|
|
@ -55,8 +55,9 @@ void CardZoneLogic::addCard(CardItem *card, const bool reorganize, const int x,
|
|||
emit cardAdded(card);
|
||||
addCardImpl(card, x, y);
|
||||
|
||||
if (reorganize)
|
||||
if (reorganize) {
|
||||
emit reorganizeCards();
|
||||
}
|
||||
|
||||
emit cardCountChanged();
|
||||
}
|
||||
|
|
@ -66,16 +67,19 @@ CardItem *CardZoneLogic::takeCard(int position, int cardId, bool toNewZone)
|
|||
if (position == -1) {
|
||||
// position == -1 means either that the zone is indexed by card id
|
||||
// or that it doesn't matter which card you take.
|
||||
for (int i = 0; i < cards.size(); ++i)
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
if (cards[i]->getId() == cardId) {
|
||||
position = i;
|
||||
break;
|
||||
}
|
||||
if (position == -1)
|
||||
}
|
||||
if (position == -1) {
|
||||
position = 0;
|
||||
}
|
||||
}
|
||||
if (position >= cards.size())
|
||||
if (position >= cards.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (auto *view : views) {
|
||||
qobject_cast<ZoneViewZoneLogic *>(view->getLogic())->removeCard(position, toNewZone);
|
||||
|
|
@ -142,8 +146,9 @@ void CardZoneLogic::moveAllToZone()
|
|||
cmd.set_target_zone(targetZone.toStdString());
|
||||
cmd.set_x(targetX);
|
||||
|
||||
for (int i = 0; i < cards.size(); ++i)
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
cmd.mutable_cards_to_move()->add_card()->set_card_id(cards[i]->getId());
|
||||
}
|
||||
|
||||
player->getPlayerActions()->sendGameCommand(cmd);
|
||||
}
|
||||
|
|
@ -175,9 +180,9 @@ void CardZoneLogic::clearContents()
|
|||
QString CardZoneLogic::getTranslatedName(bool theirOwn, GrammaticalCase gc) const
|
||||
{
|
||||
QString ownerName = player->getPlayerInfo()->getName();
|
||||
if (name == ZoneNames::HAND)
|
||||
if (name == ZoneNames::HAND) {
|
||||
return (theirOwn ? tr("their hand", "nominative") : tr("%1's hand", "nominative").arg(ownerName));
|
||||
else if (name == ZoneNames::DECK)
|
||||
} else if (name == ZoneNames::DECK) {
|
||||
switch (gc) {
|
||||
case CaseLookAtZone:
|
||||
return (theirOwn ? tr("their library", "look at zone")
|
||||
|
|
@ -193,11 +198,11 @@ QString CardZoneLogic::getTranslatedName(bool theirOwn, GrammaticalCase gc) cons
|
|||
default:
|
||||
return (theirOwn ? tr("their library", "nominative") : tr("%1's library", "nominative").arg(ownerName));
|
||||
}
|
||||
else if (name == ZoneNames::GRAVE)
|
||||
} else if (name == ZoneNames::GRAVE) {
|
||||
return (theirOwn ? tr("their graveyard", "nominative") : tr("%1's graveyard", "nominative").arg(ownerName));
|
||||
else if (name == ZoneNames::EXILE)
|
||||
} else if (name == ZoneNames::EXILE) {
|
||||
return (theirOwn ? tr("their exile", "nominative") : tr("%1's exile", "nominative").arg(ownerName));
|
||||
else if (name == ZoneNames::SIDEBOARD)
|
||||
} else if (name == ZoneNames::SIDEBOARD) {
|
||||
switch (gc) {
|
||||
case CaseLookAtZone:
|
||||
return (theirOwn ? tr("their sideboard", "look at zone")
|
||||
|
|
@ -208,7 +213,7 @@ QString CardZoneLogic::getTranslatedName(bool theirOwn, GrammaticalCase gc) cons
|
|||
default:
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return (theirOwn ? tr("their custom zone '%1'", "nominative").arg(name)
|
||||
: tr("%1's custom zone '%2'", "nominative").arg(ownerName).arg(name));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ void PileZoneLogic::addCardImpl(CardItem *card, int x, int /*y*/)
|
|||
card->setCardRef({});
|
||||
card->setId(-1);
|
||||
// If we obscure a previously revealed card, its name has to be forgotten
|
||||
if (cards.size() > x + 1)
|
||||
if (cards.size() > x + 1) {
|
||||
cards.at(x + 1)->setCardRef({});
|
||||
}
|
||||
}
|
||||
card->setVisible(false);
|
||||
card->resetState();
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ CardItem *TableZoneLogic::takeCard(int position, int cardId, bool toNewZone)
|
|||
{
|
||||
CardItem *result = CardZoneLogic::takeCard(position, cardId);
|
||||
|
||||
if (toNewZone)
|
||||
if (toNewZone) {
|
||||
emit contentSizeChanged();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -48,9 +48,10 @@ void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*optio
|
|||
{
|
||||
painter->drawPath(shape());
|
||||
|
||||
if (!getLogic()->getCards().isEmpty())
|
||||
if (!getLogic()->getCards().isEmpty()) {
|
||||
getLogic()->getCards().at(0)->paintPicture(painter, getLogic()->getCards().at(0)->getTranslatedSize(painter),
|
||||
90);
|
||||
}
|
||||
|
||||
painter->translate(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F);
|
||||
painter->rotate(-90);
|
||||
|
|
@ -87,24 +88,28 @@ void PileZone::reorganizeCards()
|
|||
void PileZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
CardZone::mousePressEvent(event);
|
||||
if (event->isAccepted())
|
||||
if (event->isAccepted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
event->accept();
|
||||
} else
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void PileZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() <
|
||||
QApplication::startDragDistance())
|
||||
QApplication::startDragDistance()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getLogic()->getCards().isEmpty())
|
||||
if (getLogic()->getCards().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
||||
bool bottomCard = event->modifiers().testFlag(Qt::ControlModifier);
|
||||
|
|
@ -123,7 +128,8 @@ void PileZone::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
|||
|
||||
void PileZone::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (!getLogic()->getCards().isEmpty())
|
||||
if (!getLogic()->getCards().isEmpty()) {
|
||||
getLogic()->getCards()[0]->processHoverEvent();
|
||||
}
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,9 @@ SelectZone *SelectZone::findOwningSelectZone(const QGraphicsItem *card)
|
|||
SelectZone::StackLayoutParams SelectZone::buildStackParams(qreal minOffset) const
|
||||
{
|
||||
const auto &cards = getLogic()->getCards();
|
||||
if (cards.isEmpty())
|
||||
if (cards.isEmpty()) {
|
||||
return {0, boundingRect().height(), 0.0, 0.0, minOffset};
|
||||
}
|
||||
const auto cardCount = static_cast<int>(cards.size());
|
||||
const qreal cardHeight = cards.at(0)->boundingRect().height();
|
||||
const qreal offset = stackingOffset(cardHeight);
|
||||
|
|
@ -93,8 +94,9 @@ int SelectZone::calcDropIndexFromY(qreal dropY, qreal minOffset) const
|
|||
|
||||
void SelectZone::restoreStaleEscapedCards()
|
||||
{
|
||||
if (!cardClipContainer)
|
||||
if (!cardClipContainer) {
|
||||
return;
|
||||
}
|
||||
for (auto *card : getLogic()->getCards()) {
|
||||
// A card parented to the zone (instead of the clip container) should
|
||||
// only occur while it is actively hovered. If hover cleanup was
|
||||
|
|
@ -108,10 +110,12 @@ void SelectZone::restoreStaleEscapedCards()
|
|||
void SelectZone::layoutCardsVertically(const StackLayoutParams ¶ms)
|
||||
{
|
||||
const auto &cards = getLogic()->getCards();
|
||||
if (cards.isEmpty() || params.cardCount <= 0)
|
||||
if (cards.isEmpty() || params.cardCount <= 0) {
|
||||
return;
|
||||
if (params.cardCount > cards.size())
|
||||
}
|
||||
if (params.cardCount > cards.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr qreal xspace = 5;
|
||||
const qreal cardWidth = cards.at(0)->boundingRect().width();
|
||||
|
|
@ -163,8 +167,9 @@ void SelectZone::onCardAdded(CardItem *addedCard)
|
|||
|
||||
void SelectZone::setupClipContainer(std::optional<qreal> zValue)
|
||||
{
|
||||
if (cardClipContainer)
|
||||
if (cardClipContainer) {
|
||||
return;
|
||||
}
|
||||
|
||||
setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
|
||||
|
||||
|
|
@ -209,15 +214,19 @@ void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
{
|
||||
if (event->buttons().testFlag(Qt::LeftButton)) {
|
||||
QPointF pos = event->pos();
|
||||
if (pos.x() < 0)
|
||||
if (pos.x() < 0) {
|
||||
pos.setX(0);
|
||||
}
|
||||
QRectF br = boundingRect();
|
||||
if (pos.x() > br.width())
|
||||
if (pos.x() > br.width()) {
|
||||
pos.setX(br.width());
|
||||
if (pos.y() < 0)
|
||||
}
|
||||
if (pos.y() < 0) {
|
||||
pos.setY(0);
|
||||
if (pos.y() > br.height())
|
||||
}
|
||||
if (pos.y() > br.height()) {
|
||||
pos.setY(br.height());
|
||||
}
|
||||
|
||||
QRectF selectionRect = QRectF(selectionOrigin, pos).normalized();
|
||||
for (auto card : getLogic()->getCards()) {
|
||||
|
|
@ -253,8 +262,9 @@ void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
selectionOrigin = event->pos();
|
||||
static_cast<GameScene *>(scene())->startRubberBand(event->scenePos());
|
||||
event->accept();
|
||||
} else
|
||||
} else {
|
||||
CardZone::mousePressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
|
|
|
|||
|
|
@ -108,8 +108,9 @@ void TableZone::paintLandDivider(QPainter *painter)
|
|||
// Place the line 2 grid heights down then back it off just enough to allow
|
||||
// some space between a 3-card stack and the land area.
|
||||
qreal separatorY = MARGIN_TOP + 2 * (CardDimensions::HEIGHT + PADDING_Y) - STACKED_CARD_OFFSET_Y / 2;
|
||||
if (isInverted())
|
||||
if (isInverted()) {
|
||||
separatorY = height - separatorY;
|
||||
}
|
||||
painter->setPen(QColor(255, 255, 255, 40));
|
||||
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
|
||||
}
|
||||
|
|
@ -157,8 +158,9 @@ void TableZone::reorganizeCards()
|
|||
|
||||
for (int i = 0; i < getLogic()->getCards().size(); ++i) {
|
||||
QPoint gridPoint = getLogic()->getCards()[i]->getGridPos();
|
||||
if (gridPoint.x() == -1)
|
||||
if (gridPoint.x() == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QPointF mapPoint = mapFromGrid(gridPoint);
|
||||
qreal x = mapPoint.x();
|
||||
|
|
@ -167,8 +169,9 @@ void TableZone::reorganizeCards()
|
|||
int numberAttachedCards = getLogic()->getCards()[i]->getAttachedCards().size();
|
||||
qreal actualX = x + numberAttachedCards * STACKED_CARD_OFFSET_X;
|
||||
qreal actualY = y;
|
||||
if (numberAttachedCards)
|
||||
if (numberAttachedCards) {
|
||||
actualY += 15;
|
||||
}
|
||||
|
||||
getLogic()->getCards()[i]->setPos(actualX, actualY);
|
||||
getLogic()->getCards()[i]->setRealZValue(ZValues::tableCardZValue(actualX, actualY));
|
||||
|
|
@ -227,16 +230,19 @@ void TableZone::resizeToContents()
|
|||
int xMax = 0;
|
||||
|
||||
// Find rightmost card position, which includes the left margin amount.
|
||||
for (int i = 0; i < getLogic()->getCards().size(); ++i)
|
||||
if (getLogic()->getCards()[i]->pos().x() > xMax)
|
||||
for (int i = 0; i < getLogic()->getCards().size(); ++i) {
|
||||
if (getLogic()->getCards()[i]->pos().x() > xMax) {
|
||||
xMax = (int)getLogic()->getCards()[i]->pos().x();
|
||||
}
|
||||
}
|
||||
|
||||
// Minimum width is the rightmost card position plus enough room for
|
||||
// another card with padding, then margin.
|
||||
currentMinimumWidth = xMax + (2 * CardDimensions::WIDTH) + PADDING_X + MARGIN_RIGHT;
|
||||
|
||||
if (currentMinimumWidth < MIN_WIDTH)
|
||||
if (currentMinimumWidth < MIN_WIDTH) {
|
||||
currentMinimumWidth = MIN_WIDTH;
|
||||
}
|
||||
|
||||
if (currentMinimumWidth != width) {
|
||||
prepareGeometryChange();
|
||||
|
|
@ -247,9 +253,11 @@ void TableZone::resizeToContents()
|
|||
|
||||
CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
|
||||
{
|
||||
for (int i = 0; i < getLogic()->getCards().size(); i++)
|
||||
if (getLogic()->getCards().at(i)->getGridPoint() == gridPoint)
|
||||
for (int i = 0; i < getLogic()->getCards().size(); i++) {
|
||||
if (getLogic()->getCards().at(i)->getGridPoint() == gridPoint) {
|
||||
return getLogic()->getCards().at(i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -266,8 +274,9 @@ void TableZone::computeCardStackWidths()
|
|||
QMap<int, int> cardStackCount;
|
||||
for (int i = 0; i < getLogic()->getCards().size(); ++i) {
|
||||
const QPoint &gridPoint = getLogic()->getCards()[i]->getGridPos();
|
||||
if (gridPoint.x() == -1)
|
||||
if (gridPoint.x() == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const int key = getCardStackMapKey(gridPoint.x() / 3, gridPoint.y());
|
||||
cardStackCount.insert(key, cardStackCount.value(key, 0) + 1);
|
||||
|
|
@ -277,16 +286,18 @@ void TableZone::computeCardStackWidths()
|
|||
cardStackWidth.clear();
|
||||
for (int i = 0; i < getLogic()->getCards().size(); ++i) {
|
||||
const QPoint &gridPoint = getLogic()->getCards()[i]->getGridPos();
|
||||
if (gridPoint.x() == -1)
|
||||
if (gridPoint.x() == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const int key = getCardStackMapKey(gridPoint.x() / 3, gridPoint.y());
|
||||
const int stackCount = cardStackCount.value(key, 0);
|
||||
if (stackCount == 1)
|
||||
if (stackCount == 1) {
|
||||
cardStackWidth.insert(key, CardDimensions::WIDTH + getLogic()->getCards()[i]->getAttachedCards().size() *
|
||||
STACKED_CARD_OFFSET_X);
|
||||
else
|
||||
} else {
|
||||
cardStackWidth.insert(key, CardDimensions::WIDTH + (stackCount - 1) * STACKED_CARD_OFFSET_X);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -303,15 +314,17 @@ QPointF TableZone::mapFromGrid(QPoint gridPoint) const
|
|||
x += cardStackWidth.value(key, CardDimensions::WIDTH) + PADDING_X;
|
||||
}
|
||||
|
||||
if (isInverted())
|
||||
if (isInverted()) {
|
||||
gridPoint.setY(TABLEROWS - 1 - gridPoint.y());
|
||||
}
|
||||
|
||||
// Start with margin plus stacked card offset
|
||||
y = MARGIN_TOP + (gridPoint.x() % 3) * STACKED_CARD_OFFSET_Y;
|
||||
|
||||
// Add in card size and padding for each row
|
||||
for (int i = 0; i < gridPoint.y(); ++i)
|
||||
for (int i = 0; i < gridPoint.y(); ++i) {
|
||||
y += CardDimensions::HEIGHT + PADDING_Y;
|
||||
}
|
||||
|
||||
return QPointF(x, y);
|
||||
}
|
||||
|
|
@ -330,8 +343,9 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
|
|||
|
||||
gridPointY = clampValidTableRow(gridPointY);
|
||||
|
||||
if (isInverted())
|
||||
if (isInverted()) {
|
||||
gridPointY = TABLEROWS - 1 - gridPointY;
|
||||
}
|
||||
|
||||
// Calculating the x-coordinate of the grid space requires adding up the
|
||||
// widths of each card stack along the row.
|
||||
|
|
@ -367,19 +381,23 @@ QPointF TableZone::closestGridPoint(const QPointF &point)
|
|||
{
|
||||
QPoint gridPoint = mapToGrid(point);
|
||||
gridPoint.setX((gridPoint.x() / 3) * 3);
|
||||
if (getCardFromGrid(gridPoint))
|
||||
if (getCardFromGrid(gridPoint)) {
|
||||
gridPoint.setX(gridPoint.x() + 1);
|
||||
if (getCardFromGrid(gridPoint))
|
||||
}
|
||||
if (getCardFromGrid(gridPoint)) {
|
||||
gridPoint.setX(gridPoint.x() + 1);
|
||||
}
|
||||
return mapFromGrid(gridPoint);
|
||||
}
|
||||
|
||||
int TableZone::clampValidTableRow(const int row)
|
||||
{
|
||||
if (row < 0)
|
||||
if (row < 0) {
|
||||
return 0;
|
||||
if (row >= TABLEROWS)
|
||||
}
|
||||
if (row >= TABLEROWS) {
|
||||
return TABLEROWS - 1;
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -203,9 +203,9 @@ ZoneViewZone::GridSize ZoneViewZone::positionCardsForDisplay(CardList &cards, Ca
|
|||
QString columnProp = extractor(c);
|
||||
|
||||
if (i) { // if not the first card
|
||||
if (columnProp == lastColumnProp)
|
||||
if (columnProp == lastColumnProp) {
|
||||
row++; // add below current card
|
||||
else { // if no match then move card to next column
|
||||
} else { // if no match then move card to next column
|
||||
col++;
|
||||
row = 0;
|
||||
}
|
||||
|
|
@ -233,8 +233,9 @@ ZoneViewZone::GridSize ZoneViewZone::positionCardsForDisplay(CardList &cards, Ca
|
|||
cols = qCeil((double)cardCount / minRows);
|
||||
}
|
||||
|
||||
if (cols < 2)
|
||||
if (cols < 2) {
|
||||
cols = 2;
|
||||
}
|
||||
|
||||
qCDebug(ViewZoneLog) << "reorganizeCards: rows=" << rows << "cols=" << cols;
|
||||
|
||||
|
|
|
|||
|
|
@ -252,8 +252,9 @@ void ZoneViewWidget::retranslateUi()
|
|||
|
||||
void ZoneViewWidget::stopWindowDrag()
|
||||
{
|
||||
if (!draggingWindow)
|
||||
if (!draggingWindow) {
|
||||
return;
|
||||
}
|
||||
|
||||
draggingWindow = false;
|
||||
ungrabMouse();
|
||||
|
|
@ -312,13 +313,15 @@ QGraphicsView *ZoneViewWidget::findDragView(QWidget *eventWidget) const
|
|||
{
|
||||
QWidget *current = eventWidget;
|
||||
while (current) {
|
||||
if (auto *view = qobject_cast<QGraphicsView *>(current))
|
||||
if (auto *view = qobject_cast<QGraphicsView *>(current)) {
|
||||
return view;
|
||||
}
|
||||
current = current->parentWidget();
|
||||
}
|
||||
|
||||
if (scene() && !scene()->views().isEmpty())
|
||||
if (scene() && !scene()->views().isEmpty()) {
|
||||
return scene()->views().constFirst();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -346,8 +349,9 @@ bool ZoneViewWidget::windowFrameEvent(QEvent *event)
|
|||
}
|
||||
|
||||
auto *me = dynamic_cast<QGraphicsSceneMouseEvent *>(event);
|
||||
if (!me)
|
||||
if (!me) {
|
||||
return QGraphicsWidget::windowFrameEvent(event);
|
||||
}
|
||||
|
||||
switch (event->type()) {
|
||||
case QEvent::GraphicsSceneMousePress:
|
||||
|
|
@ -506,8 +510,9 @@ void ZoneViewWidget::resizeToZoneContents(bool forceInitialHeight)
|
|||
|
||||
zone->setGeometry(QRectF(0, -scrollBar->value(), zoneContainer->size().width(), totalZoneHeight));
|
||||
|
||||
if (layout())
|
||||
if (layout()) {
|
||||
layout()->invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void ZoneViewWidget::handleScrollBarChange(int value)
|
||||
|
|
@ -521,8 +526,9 @@ void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
|||
disconnect(zone, &ZoneViewZone::closed, this, 0);
|
||||
// manually call zone->close in order to remove it from the origZones views
|
||||
zone->close();
|
||||
if (shuffleCheckBox.isChecked())
|
||||
if (shuffleCheckBox.isChecked()) {
|
||||
player->getPlayerActions()->sendGameCommand(Command_Shuffle());
|
||||
}
|
||||
zoneDeleted();
|
||||
event->accept();
|
||||
}
|
||||
|
|
@ -536,8 +542,9 @@ void ZoneViewWidget::zoneDeleted()
|
|||
void ZoneViewWidget::initStyleOption(QStyleOption *option) const
|
||||
{
|
||||
QStyleOptionTitleBar *titleBar = qstyleoption_cast<QStyleOptionTitleBar *>(option);
|
||||
if (titleBar)
|
||||
if (titleBar) {
|
||||
titleBar->icon = QPixmap("theme:cockatrice");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue