attach arrow bug fix, improved stacking

This commit is contained in:
Max-Wilhelm Bruker 2010-12-16 00:42:46 +01:00
parent f94fac80c1
commit feb1dac1e1
6 changed files with 58 additions and 21 deletions

View file

@ -154,7 +154,7 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QList<QGraphicsItem *> colliding = scene()->items(endPos); QList<QGraphicsItem *> colliding = scene()->items(endPos);
ArrowTarget *cursorItem = 0; ArrowTarget *cursorItem = 0;
int cursorItemZ = -1; qreal cursorItemZ = -1;
for (int i = colliding.size() - 1; i >= 0; i--) for (int i = colliding.size() - 1; i >= 0; i--)
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i))) if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i)))
if (colliding.at(i)->zValue() > cursorItemZ) { if (colliding.at(i)->zValue() > cursorItemZ) {
@ -243,11 +243,14 @@ void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QList<QGraphicsItem *> colliding = scene()->items(endPos); QList<QGraphicsItem *> colliding = scene()->items(endPos);
ArrowTarget *cursorItem = 0; ArrowTarget *cursorItem = 0;
qreal cursorItemZ = -1;
for (int i = colliding.size() - 1; i >= 0; i--) for (int i = colliding.size() - 1; i >= 0; i--)
if (qgraphicsitem_cast<CardItem *>(colliding.at(i))) { if (qgraphicsitem_cast<CardItem *>(colliding.at(i)))
cursorItem = static_cast<ArrowTarget *>(colliding.at(i)); if (colliding.at(i)->zValue() > cursorItemZ) {
break; cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
} cursorItemZ = cursorItem->zValue();
}
if ((cursorItem != targetItem) && targetItem) if ((cursorItem != targetItem) && targetItem)
targetItem->setBeingPointedAt(false); targetItem->setBeingPointedAt(false);
if (!cursorItem) { if (!cursorItem) {

View file

@ -33,6 +33,8 @@ void SelectZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event) void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
scene()->clearSelection();
selectionOrigin = event->pos(); selectionOrigin = event->pos();
static_cast<GameScene *>(scene())->startRubberBand(event->scenePos()); static_cast<GameScene *>(scene())->startRubberBand(event->scenePos());
event->accept(); event->accept();

View file

@ -82,11 +82,25 @@ int Server_CardZone::getFreeGridColumn(int x, int y, const QString &cardName) co
coordMap.insert(cards[i]->getX(), cards[i]); coordMap.insert(cards[i]->getX(), cards[i]);
int resultX = 0; int resultX = 0;
if (x != -1) { if (x == -1) {
for (int i = 0; i < cards.size(); ++i)
if ((cards[i]->getName() == cardName) && !(cards[i]->getX() % 3) && (cards[i]->getY() == y)) {
if (!cards[i]->getAttachedCards().isEmpty())
continue;
if (!coordMap.value(cards[i]->getX() + 1))
return cards[i]->getX() + 1;
if (!coordMap.value(cards[i]->getX() + 2))
return cards[i]->getX() + 2;
}
} else if (x == -2) {
} else {
x = (x / 3) * 3; x = (x / 3) * 3;
if (!coordMap.contains(x)) if (!coordMap.contains(x))
resultX = x; resultX = x;
else if (!coordMap.contains(x + 1)) else if (!coordMap.value(x)->getAttachedCards().isEmpty()) {
resultX = x;
x = -1;
} else if (!coordMap.contains(x + 1))
resultX = x + 1; resultX = x + 1;
else if (!coordMap.contains(x + 2)) else if (!coordMap.contains(x + 2))
resultX = x + 2; resultX = x + 2;
@ -94,22 +108,35 @@ int Server_CardZone::getFreeGridColumn(int x, int y, const QString &cardName) co
resultX = x; resultX = x;
x = -1; x = -1;
} }
} else }
for (int i = 0; i < cards.size(); ++i)
if ((cards[i]->getName() == cardName) && !(cards[i]->getX() % 3) && (cards[i]->getY() == y)) {
if (!coordMap.value(cards[i]->getX() + 1))
return cards[i]->getX() + 1;
if (!coordMap.value(cards[i]->getX() + 2))
return cards[i]->getX() + 2;
}
if (x == -1) if (x < 0)
while (coordMap.value(resultX)) while (coordMap.value(resultX))
resultX += 3; resultX += 3;
return resultX; return resultX;
} }
bool Server_CardZone::isColumnStacked(int x, int y) const
{
QMap<int, Server_Card *> coordMap;
for (int i = 0; i < cards.size(); ++i)
if (cards[i]->getY() == y)
coordMap.insert(cards[i]->getX(), cards[i]);
return coordMap.contains((x / 3) * 3 + 1);
}
bool Server_CardZone::isColumnEmpty(int x, int y) const
{
QMap<int, Server_Card *> coordMap;
for (int i = 0; i < cards.size(); ++i)
if (cards[i]->getY() == y)
coordMap.insert(cards[i]->getX(), cards[i]);
return !coordMap.contains((x / 3) * 3);
}
void Server_CardZone::moveCard(CommandContainer *cont, QMap<int, Server_Card *> &coordMap, Server_Card *card, int x, int y) void Server_CardZone::moveCard(CommandContainer *cont, QMap<int, Server_Card *> &coordMap, Server_Card *card, int x, int y)
{ {
coordMap.remove(card->getX()); coordMap.remove(card->getX());

View file

@ -50,6 +50,8 @@ public:
Server_Player *getPlayer() const { return player; } Server_Player *getPlayer() const { return player; }
int getFreeGridColumn(int x, int y, const QString &cardName) const; int getFreeGridColumn(int x, int y, const QString &cardName) const;
bool isColumnEmpty(int x, int y) const;
bool isColumnStacked(int x, int y) const;
void fixFreeSpaces(CommandContainer *cont, int x, int y); void fixFreeSpaces(CommandContainer *cont, int x, int y);
void moveCard(CommandContainer *cont, QMap<int, Server_Card *> &coordMap, Server_Card *card, int x, int y); void moveCard(CommandContainer *cont, QMap<int, Server_Card *> &coordMap, Server_Card *card, int x, int y);
QList<Server_Card *> cards; QList<Server_Card *> cards;

View file

@ -217,9 +217,13 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
return RespContextError; return RespContextError;
*/ */
int position = -1; int position = -1;
Server_Card *card = startzone->getCard(_cardId, true, &position); Server_Card *card = startzone->getCard(_cardId, false, &position);
if (!card) if (!card)
return RespNameNotFound; return RespNameNotFound;
if (!card->getAttachedCards().isEmpty() && !targetzone->isColumnEmpty(x, y))
return RespContextError;
startzone->getCard(_cardId, true);
int oldX = card->getX(), oldY = card->getY(); int oldX = card->getX(), oldY = card->getY();
if (startzone != targetzone) { if (startzone != targetzone) {
@ -246,10 +250,6 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
} }
} }
if (startzone->hasCoords()) {
}
if (card->getDestroyOnZoneChange() && (startzone != targetzone)) { if (card->getDestroyOnZoneChange() && (startzone != targetzone)) {
cont->enqueueGameEventPrivate(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId()); cont->enqueueGameEventPrivate(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId());
cont->enqueueGameEventPublic(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId()); cont->enqueueGameEventPublic(new Event_DestroyCard(getPlayerId(), startzone->getName(), card->getId()), game->getGameId());

View file

@ -673,6 +673,9 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm
for (int i = 0; i < attachedList.size(); ++i) for (int i = 0; i < attachedList.size(); ++i)
player->unattachCard(cont, attachedList[i]); player->unattachCard(cont, attachedList[i]);
if (targetzone->isColumnStacked(targetCard->getX(), targetCard->getY()))
targetPlayer->moveCard(cont, targetzone, targetCard->getId(), targetzone, targetzone->getFreeGridColumn(-2, targetCard->getY(), targetCard->getName()), targetCard->getY(), targetCard->getFaceDown(), false);
card->setParentCard(targetCard); card->setParentCard(targetCard);
card->setCoords(-1, card->getY()); card->setCoords(-1, card->getY());
cont->enqueueGameEventPrivate(new Event_AttachCard(player->getPlayerId(), startzone->getName(), card->getId(), targetPlayer->getPlayerId(), targetzone->getName(), targetCard->getId()), game->getGameId()); cont->enqueueGameEventPrivate(new Event_AttachCard(player->getPlayerId(), startzone->getName(), card->getId(), targetPlayer->getPlayerId(), targetzone->getName(), targetCard->getId()), game->getGameId());