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();
|
QPointF endPos = event->scenePos();
|
||||||
|
|
||||||
QList<QGraphicsItem *> colliding = scene()->items(endPos);
|
QList<QGraphicsItem *> colliding = scene()->items(endPos);
|
||||||
ArrowTarget *cursorItem = 0;
|
ArrowTarget *cursorItem = 0;
|
||||||
for (int i = colliding.size() - 1; i >= 0; i--)
|
int cursorItemZ = -1;
|
||||||
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i))) {
|
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||||
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
|
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i)))
|
||||||
break;
|
if (colliding.at(i)->zValue() > cursorItemZ) {
|
||||||
}
|
cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
|
||||||
|
cursorItemZ = cursorItem->zValue();
|
||||||
|
}
|
||||||
if ((cursorItem != targetItem) && targetItem) {
|
if ((cursorItem != targetItem) && targetItem) {
|
||||||
targetItem->setBeingPointedAt(false);
|
targetItem->setBeingPointedAt(false);
|
||||||
targetItem->removeArrowTo(this);
|
targetItem->removeArrowTo(this);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "tab_game.h"
|
#include "tab_game.h"
|
||||||
|
|
||||||
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, QGraphicsItem *parent)
|
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);
|
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)
|
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
|
@ -17,6 +17,7 @@ class CardItem : public AbstractCardItem {
|
||||||
private:
|
private:
|
||||||
CardZone *zone;
|
CardZone *zone;
|
||||||
int id;
|
int id;
|
||||||
|
qreal realZValue;
|
||||||
bool attacking;
|
bool attacking;
|
||||||
bool facedown;
|
bool facedown;
|
||||||
QMap<int, int> counters;
|
QMap<int, int> counters;
|
||||||
|
@ -47,6 +48,8 @@ public:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
QPoint getGridPoint() const { return gridPoint; }
|
QPoint getGridPoint() const { return gridPoint; }
|
||||||
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
|
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
|
||||||
|
qreal getRealZValue() const { return realZValue; }
|
||||||
|
void setRealZValue(qreal _zValue);
|
||||||
QPoint getGridPos() const { return gridPoint; }
|
QPoint getGridPos() const { return gridPoint; }
|
||||||
Player *getOwner() const { return owner; }
|
Player *getOwner() const { return owner; }
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "zoneviewwidget.h"
|
#include "zoneviewwidget.h"
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QDebug>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
|
||||||
GameScene::GameScene(QObject *parent)
|
GameScene::GameScene(QObject *parent)
|
||||||
: QGraphicsScene(parent)
|
: QGraphicsScene(parent)
|
||||||
|
@ -68,8 +68,6 @@ void GameScene::rearrange()
|
||||||
|
|
||||||
setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight);
|
setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight);
|
||||||
processViewSizeChange(viewSize);
|
processViewSizeChange(viewSize);
|
||||||
|
|
||||||
qDebug(QString("rearrange(): w=%1 h=%2").arg(sceneWidth).arg(sceneHeight).toLatin1());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numberCards)
|
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)
|
for (int i = 0; i < players.size(); ++i)
|
||||||
players[i]->processSceneSizeChange(sceneRect().size());
|
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();
|
void closeMostRecentZoneView();
|
||||||
private slots:
|
private slots:
|
||||||
void rearrange();
|
void rearrange();
|
||||||
|
protected:
|
||||||
|
bool event(QEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -75,7 +75,7 @@ void HandZone::reorganizeCards()
|
||||||
c->setPos(xPadding + ((qreal) i) * (totalWidth - cardWidth) / (cardCount - 1), 5);
|
c->setPos(xPadding + ((qreal) i) * (totalWidth - cardWidth) / (cardCount - 1), 5);
|
||||||
else
|
else
|
||||||
c->setPos(xPadding + ((qreal) i) * cardWidth + (totalWidth - cardCount * cardWidth) / 2, 5);
|
c->setPos(xPadding + ((qreal) i) * cardWidth + (totalWidth - cardCount * cardWidth) / 2, 5);
|
||||||
c->setZValue(i);
|
c->setRealZValue(i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qreal totalWidth = boundingRect().width();
|
qreal totalWidth = boundingRect().width();
|
||||||
|
@ -95,7 +95,7 @@ void HandZone::reorganizeCards()
|
||||||
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
|
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
|
||||||
else
|
else
|
||||||
c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2);
|
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);
|
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())
|
if (!cards.isEmpty())
|
||||||
cards.at(0)->paintPicture(painter, 90);
|
cards.at(0)->paintPicture(painter, 90);
|
||||||
|
|
|
@ -77,7 +77,7 @@ void StackZone::reorganizeCards()
|
||||||
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
|
c->setPos(x, ((qreal) i) * (totalHeight - cardHeight) / (cardCount - 1));
|
||||||
else
|
else
|
||||||
c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2);
|
c->setPos(x, ((qreal) i) * cardHeight + (totalHeight - cardCount * cardHeight) / 2);
|
||||||
c->setZValue(i);
|
c->setRealZValue(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
|
|
|
@ -128,7 +128,7 @@ void TableZone::reorganizeCards()
|
||||||
actualY += 5;
|
actualY += 5;
|
||||||
|
|
||||||
cards[i]->setPos(actualX, actualY);
|
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());
|
QListIterator<CardItem *> attachedCardIterator(cards[i]->getAttachedCards());
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
@ -138,7 +138,7 @@ void TableZone::reorganizeCards()
|
||||||
qreal childX = actualX - j * CARD_WIDTH / 3.0;
|
qreal childX = actualX - j * CARD_WIDTH / 3.0;
|
||||||
qreal childY = y - 5;
|
qreal childY = y - 5;
|
||||||
attachedCard->setPos(childX, childY);
|
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->getArrowsFrom());
|
||||||
arrowsToUpdate.append(attachedCard->getArrowsTo());
|
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)
|
: QGraphicsWidget(0, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
setZValue(100);
|
setZValue(2000000006);
|
||||||
|
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setPixelSize(10);
|
font.setPixelSize(10);
|
||||||
|
|
|
@ -95,7 +95,7 @@ void ZoneViewZone::reorganizeCards()
|
||||||
qreal x = (i / rows) * CARD_WIDTH;
|
qreal x = (i / rows) * CARD_WIDTH;
|
||||||
qreal y = (i % rows) * CARD_HEIGHT / 3;
|
qreal y = (i % rows) * CARD_HEIGHT / 3;
|
||||||
c->setPos(x, y);
|
c->setPos(x, y);
|
||||||
c->setZValue(i);
|
c->setRealZValue(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
optimumRect = QRectF(0, 0, cols * CARD_WIDTH, ((rows - 1) * CARD_HEIGHT) / 3 + CARD_HEIGHT);
|
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) {
|
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->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());
|
||||||
|
|
Loading…
Reference in a new issue