changed card hover handling
This commit is contained in:
parent
5b7dd037c1
commit
92d40515f2
12 changed files with 66 additions and 18 deletions
|
@ -153,12 +153,14 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
QPointF endPos = event->scenePos();
|
||||
|
||||
QList<QGraphicsItem *> colliding = scene()->items(endPos);
|
||||
ArrowTarget *cursorItem = 0;
|
||||
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i))) {
|
||||
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
|
||||
break;
|
||||
}
|
||||
ArrowTarget *cursorItem = 0;
|
||||
int cursorItemZ = -1;
|
||||
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i)))
|
||||
if (colliding.at(i)->zValue() > cursorItemZ) {
|
||||
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
|
||||
cursorItemZ = cursorItem->zValue();
|
||||
}
|
||||
if ((cursorItem != targetItem) && targetItem) {
|
||||
targetItem->setBeingPointedAt(false);
|
||||
targetItem->removeArrowTo(this);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "tab_game.h"
|
||||
|
||||
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, QGraphicsItem *parent)
|
||||
: AbstractCardItem(_name, _owner, parent), id(_cardid), attacking(false), facedown(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
||||
: AbstractCardItem(_name, _owner, parent), id(_cardid), realZValue(0), attacking(false), facedown(false), destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
||||
{
|
||||
owner->addCard(this);
|
||||
|
||||
|
@ -154,6 +154,12 @@ void CardItem::retranslateUi()
|
|||
}
|
||||
}
|
||||
|
||||
void CardItem::setRealZValue(qreal _zValue)
|
||||
{
|
||||
realZValue = _zValue;
|
||||
setZValue(_zValue);
|
||||
}
|
||||
|
||||
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
painter->save();
|
||||
|
|
|
@ -17,6 +17,7 @@ class CardItem : public AbstractCardItem {
|
|||
private:
|
||||
CardZone *zone;
|
||||
int id;
|
||||
qreal realZValue;
|
||||
bool attacking;
|
||||
bool facedown;
|
||||
QMap<int, int> counters;
|
||||
|
@ -47,6 +48,8 @@ public:
|
|||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
QPoint getGridPoint() const { return gridPoint; }
|
||||
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
|
||||
qreal getRealZValue() const { return realZValue; }
|
||||
void setRealZValue(qreal _zValue);
|
||||
QPoint getGridPos() const { return gridPoint; }
|
||||
Player *getOwner() const { return owner; }
|
||||
int getId() const { return id; }
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "zoneviewwidget.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
GameScene::GameScene(QObject *parent)
|
||||
: QGraphicsScene(parent)
|
||||
|
@ -68,8 +68,6 @@ void GameScene::rearrange()
|
|||
|
||||
setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight);
|
||||
processViewSizeChange(viewSize);
|
||||
|
||||
qDebug(QString("rearrange(): w=%1 h=%2").arg(sceneWidth).arg(sceneHeight).toLatin1());
|
||||
}
|
||||
|
||||
void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numberCards)
|
||||
|
@ -141,3 +139,35 @@ void GameScene::processViewSizeChange(const QSize &newSize)
|
|||
for (int i = 0; i < players.size(); ++i)
|
||||
players[i]->processSceneSizeChange(sceneRect().size());
|
||||
}
|
||||
|
||||
bool GameScene::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::GraphicsSceneMouseMove) {
|
||||
QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
|
||||
|
||||
QList<QGraphicsItem *> oldItemList = items(mouseEvent->lastScenePos());
|
||||
for (int i = 0; i < oldItemList.size(); ++i) {
|
||||
CardItem *card = qgraphicsitem_cast<CardItem *>(oldItemList[i]);
|
||||
if (card)
|
||||
card->setZValue(card->getRealZValue());
|
||||
}
|
||||
|
||||
QList<QGraphicsItem *> itemList = items(mouseEvent->scenePos());
|
||||
qreal maxZ = 0;
|
||||
CardItem *maxZCard = 0;
|
||||
QList<CardItem *> cardList;
|
||||
for (int i = 0; i < itemList.size(); ++i) {
|
||||
CardItem *card = qgraphicsitem_cast<CardItem *>(itemList[i]);
|
||||
if (!card)
|
||||
continue;
|
||||
cardList.append(card);
|
||||
if (card->getRealZValue() > maxZ) {
|
||||
maxZ = card->getRealZValue();
|
||||
maxZCard = card;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < cardList.size(); ++i)
|
||||
cardList[i]->setZValue(cardList[i] == maxZCard ? 2000000004 : cardList[i]->getRealZValue());
|
||||
}
|
||||
return QGraphicsScene::event(event);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ public slots:
|
|||
void closeMostRecentZoneView();
|
||||
private slots:
|
||||
void rearrange();
|
||||
protected:
|
||||
bool event(QEvent *event);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -75,7 +75,7 @@ void HandZone::reorganizeCards()
|
|||
c->setPos(xPadding + ((qreal) i) * (totalWidth - cardWidth) / (cardCount - 1), 5);
|
||||
else
|
||||
c->setPos(xPadding + ((qreal) i) * cardWidth + (totalWidth - cardCount * cardWidth) / 2, 5);
|
||||
c->setZValue(i);
|
||||
c->setRealZValue(i);
|
||||
}
|
||||
} else {
|
||||
qreal totalWidth = boundingRect().width();
|
||||
|
@ -95,7 +95,7 @@ void HandZone::reorganizeCards()
|
|||
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
|
||||
else
|
||||
c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2);
|
||||
c->setZValue(i);
|
||||
c->setRealZValue(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ QRectF PileZone::boundingRect() const
|
|||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||
}
|
||||
|
||||
void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
if (!cards.isEmpty())
|
||||
cards.at(0)->paintPicture(painter, 90);
|
||||
|
|
|
@ -77,7 +77,7 @@ void StackZone::reorganizeCards()
|
|||
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
|
||||
else
|
||||
c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2);
|
||||
c->setZValue(i);
|
||||
c->setRealZValue(i);
|
||||
}
|
||||
}
|
||||
update();
|
||||
|
|
|
@ -128,7 +128,7 @@ void TableZone::reorganizeCards()
|
|||
actualY += 5;
|
||||
|
||||
cards[i]->setPos(actualX, actualY);
|
||||
cards[i]->setZValue((actualY + CARD_HEIGHT) * 10000000 + (actualX + 1) * 10000);
|
||||
cards[i]->setRealZValue((actualY + CARD_HEIGHT) * 100000 + (actualX + 1) * 100);
|
||||
|
||||
QListIterator<CardItem *> attachedCardIterator(cards[i]->getAttachedCards());
|
||||
int j = 0;
|
||||
|
@ -138,7 +138,7 @@ void TableZone::reorganizeCards()
|
|||
qreal childX = actualX - j * CARD_WIDTH / 3.0;
|
||||
qreal childY = y - 5;
|
||||
attachedCard->setPos(childX, childY);
|
||||
attachedCard->setZValue((childY + CARD_HEIGHT) * 10000000 + (childX + 1) * 10000);
|
||||
attachedCard->setRealZValue((childY + CARD_HEIGHT) * 100000 + (childX + 1) * 100);
|
||||
|
||||
arrowsToUpdate.append(attachedCard->getArrowsFrom());
|
||||
arrowsToUpdate.append(attachedCard->getArrowsTo());
|
||||
|
|
|
@ -13,7 +13,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC
|
|||
: QGraphicsWidget(0, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setZValue(100);
|
||||
setZValue(2000000006);
|
||||
|
||||
QFont font;
|
||||
font.setPixelSize(10);
|
||||
|
|
|
@ -95,7 +95,7 @@ void ZoneViewZone::reorganizeCards()
|
|||
qreal x = (i / rows) * CARD_WIDTH;
|
||||
qreal y = (i % rows) * CARD_HEIGHT / 3;
|
||||
c->setPos(x, y);
|
||||
c->setZValue(i);
|
||||
c->setRealZValue(i);
|
||||
}
|
||||
|
||||
optimumRect = QRectF(0, 0, cols * CARD_WIDTH, ((rows - 1) * CARD_HEIGHT) / 3 + CARD_HEIGHT);
|
||||
|
|
|
@ -791,6 +791,11 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(Command_AttachCard *cmd, Comm
|
|||
}
|
||||
|
||||
if (targetCard) {
|
||||
// Unattach all cards attached to the card being attached.
|
||||
const QList<Server_Card *> &attachedList = card->getAttachedCards();
|
||||
for (int i = 0; i < attachedList.size(); ++i)
|
||||
unattachCard(game, player, cont, attachedList[i]);
|
||||
|
||||
card->setParentCard(targetCard);
|
||||
card->setCoords(-1, card->getY());
|
||||
cont->enqueueGameEventPrivate(new Event_AttachCard(player->getPlayerId(), startzone->getName(), card->getId(), targetPlayer->getPlayerId(), targetzone->getName(), targetCard->getId()), game->getGameId());
|
||||
|
|
Loading…
Reference in a new issue