arrows: clean all arrows when changing phase; arrow color dependent on modifier keys; remove a single arrow by rightclicking
This commit is contained in:
parent
c57e138a78
commit
897dca2386
8 changed files with 58 additions and 11 deletions
|
@ -7,8 +7,8 @@
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
ArrowItem::ArrowItem(int _id, CardItem *_startItem, CardItem *_targetItem, const QColor &_color)
|
ArrowItem::ArrowItem(Player *_player, int _id, CardItem *_startItem, CardItem *_targetItem, const QColor &_color)
|
||||||
: QGraphicsItem(), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color), fullColor(true)
|
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color), fullColor(true)
|
||||||
{
|
{
|
||||||
setZValue(2000000005);
|
setZValue(2000000005);
|
||||||
if (startItem && targetItem)
|
if (startItem && targetItem)
|
||||||
|
@ -60,14 +60,32 @@ void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*opti
|
||||||
painter->drawPath(path);
|
painter->drawPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrowDragItem::ArrowDragItem(CardItem *_startItem)
|
void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
: ArrowItem(-1, _startItem)
|
{
|
||||||
|
if (!player->getLocal()) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QGraphicsItem *> colliding = scene()->items(event->scenePos());
|
||||||
|
for (int i = 0; i < colliding.size(); ++i)
|
||||||
|
if (qgraphicsitem_cast<CardItem *>(colliding[i])) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event->accept();
|
||||||
|
if (event->button() == Qt::RightButton)
|
||||||
|
player->client->deleteArrow(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrowDragItem::ArrowDragItem(CardItem *_startItem, const QColor &_color)
|
||||||
|
: ArrowItem(static_cast<CardZone *>(_startItem->parentItem())->getPlayer(), -1, _startItem, 0, _color)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
event->accept();
|
|
||||||
QPointF endPos = event->scenePos();
|
QPointF endPos = event->scenePos();
|
||||||
|
|
||||||
QList<QGraphicsItem *> colliding = scene()->items(endPos);
|
QList<QGraphicsItem *> colliding = scene()->items(endPos);
|
||||||
|
@ -92,7 +110,7 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
||||||
if (targetItem && (targetItem != startItem)) {
|
if (targetItem && (targetItem != startItem)) {
|
||||||
CardZone *startZone = static_cast<CardZone *>(startItem->parentItem());
|
CardZone *startZone = static_cast<CardZone *>(startItem->parentItem());
|
||||||
CardZone *targetZone = static_cast<CardZone *>(targetItem->parentItem());
|
CardZone *targetZone = static_cast<CardZone *>(targetItem->parentItem());
|
||||||
startZone->getPlayer()->client->createArrow(
|
player->client->createArrow(
|
||||||
startZone->getPlayer()->getId(),
|
startZone->getPlayer()->getId(),
|
||||||
startZone->getName(),
|
startZone->getName(),
|
||||||
startItem->getId(),
|
startItem->getId(),
|
||||||
|
|
|
@ -5,18 +5,23 @@
|
||||||
|
|
||||||
class CardItem;
|
class CardItem;
|
||||||
class QGraphicsSceneMouseEvent;
|
class QGraphicsSceneMouseEvent;
|
||||||
|
class QMenu;
|
||||||
|
class Player;
|
||||||
|
|
||||||
class ArrowItem : public QObject, public QGraphicsItem {
|
class ArrowItem : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
|
QMenu *menu;
|
||||||
protected:
|
protected:
|
||||||
|
Player *player;
|
||||||
int id;
|
int id;
|
||||||
CardItem *startItem, *targetItem;
|
CardItem *startItem, *targetItem;
|
||||||
QColor color;
|
QColor color;
|
||||||
bool fullColor;
|
bool fullColor;
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
public:
|
public:
|
||||||
ArrowItem(int id, CardItem *_startItem = 0, CardItem *_targetItem = 0, const QColor &color = Qt::red);
|
ArrowItem(Player *_player, int _id, CardItem *_startItem, CardItem *_targetItem, const QColor &color);
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
QRectF boundingRect() const { return path.boundingRect(); }
|
QRectF boundingRect() const { return path.boundingRect(); }
|
||||||
void updatePath();
|
void updatePath();
|
||||||
|
@ -32,7 +37,7 @@ public:
|
||||||
class ArrowDragItem : public ArrowItem {
|
class ArrowDragItem : public ArrowItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ArrowDragItem(CardItem *_startItem);
|
ArrowDragItem(CardItem *_startItem, const QColor &_color);
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
|
@ -204,7 +204,16 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
if (event->buttons().testFlag(Qt::RightButton)) {
|
if (event->buttons().testFlag(Qt::RightButton)) {
|
||||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::RightButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
if ((event->screenPos() - event->buttonDownScreenPos(Qt::RightButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
||||||
return;
|
return;
|
||||||
ArrowDragItem *arrow = new ArrowDragItem(this);
|
|
||||||
|
QColor arrowColor = Qt::red;
|
||||||
|
if (event->modifiers().testFlag(Qt::ControlModifier))
|
||||||
|
arrowColor = Qt::yellow;
|
||||||
|
else if (event->modifiers().testFlag(Qt::AltModifier))
|
||||||
|
arrowColor = Qt::blue;
|
||||||
|
else if (event->modifiers().testFlag(Qt::ShiftModifier))
|
||||||
|
arrowColor = Qt::green;
|
||||||
|
|
||||||
|
ArrowDragItem *arrow = new ArrowDragItem(this, arrowColor);
|
||||||
scene()->addItem(arrow);
|
scene()->addItem(arrow);
|
||||||
arrow->grabMouse();
|
arrow->grabMouse();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -518,6 +518,11 @@ PendingCommand *Client::createArrow(int startPlayerId, const QString &startZone,
|
||||||
return cmd(QString("create_arrow|%1|%2|%3|%4|%5|%6|%7").arg(startPlayerId).arg(startZone).arg(startCardId).arg(targetPlayerId).arg(targetPlayerZone).arg(targetCardId).arg(colorToNumber(color)));
|
return cmd(QString("create_arrow|%1|%2|%3|%4|%5|%6|%7").arg(startPlayerId).arg(startZone).arg(startCardId).arg(targetPlayerId).arg(targetPlayerZone).arg(targetCardId).arg(colorToNumber(color)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PendingCommand *Client::deleteArrow(int arrowId)
|
||||||
|
{
|
||||||
|
return cmd(QString("delete_arrow|%1").arg(arrowId));
|
||||||
|
}
|
||||||
|
|
||||||
PendingCommand *Client::setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue)
|
PendingCommand *Client::setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue)
|
||||||
{
|
{
|
||||||
return cmd(QString("set_card_attr|%1|%2|%3|%4").arg(zone).arg(cardid).arg(aname).arg(avalue));
|
return cmd(QString("set_card_attr|%1|%2|%3|%4").arg(zone).arg(cardid).arg(aname).arg(avalue));
|
||||||
|
|
|
@ -397,6 +397,7 @@ public slots:
|
||||||
PendingCommand *moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false);
|
PendingCommand *moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false);
|
||||||
PendingCommand *createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y);
|
PendingCommand *createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y);
|
||||||
PendingCommand *createArrow(int startPlayerId, const QString &startZone, int startCardId, int targetPlayerId, const QString &targetPlayerZone, int targetCardId, const QColor &color);
|
PendingCommand *createArrow(int startPlayerId, const QString &startZone, int startCardId, int targetPlayerId, const QString &targetPlayerZone, int targetCardId, const QColor &color);
|
||||||
|
PendingCommand *deleteArrow(int arrowId);
|
||||||
PendingCommand *setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue);
|
PendingCommand *setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue);
|
||||||
PendingCommand *readyStart();
|
PendingCommand *readyStart();
|
||||||
PendingCommand *incCounter(int counterId, int delta);
|
PendingCommand *incCounter(int counterId, int delta);
|
||||||
|
|
|
@ -433,7 +433,6 @@ void Game::cardMenuAction()
|
||||||
QList<QGraphicsItem *> sel = scene->selectedItems();
|
QList<QGraphicsItem *> sel = scene->selectedItems();
|
||||||
while (!sel.isEmpty()) {
|
while (!sel.isEmpty()) {
|
||||||
unsigned int i = (unsigned int) (((double) sel.size()) * qrand() / (RAND_MAX + 1.0));
|
unsigned int i = (unsigned int) (((double) sel.size()) * qrand() / (RAND_MAX + 1.0));
|
||||||
qDebug(QString("%1 items left, i=%2").arg(sel.size()).arg(i).toLatin1());
|
|
||||||
CardItem *card = qgraphicsitem_cast<CardItem *>(sel.takeAt(i));
|
CardItem *card = qgraphicsitem_cast<CardItem *>(sel.takeAt(i));
|
||||||
// For each item, the handler function is called.
|
// For each item, the handler function is called.
|
||||||
(this->*handler)(card);
|
(this->*handler)(card);
|
||||||
|
|
|
@ -725,7 +725,7 @@ void Player::clearCounters()
|
||||||
|
|
||||||
void Player::addArrow(int arrowId, CardItem *startCard, CardItem *targetCard, const QColor &color)
|
void Player::addArrow(int arrowId, CardItem *startCard, CardItem *targetCard, const QColor &color)
|
||||||
{
|
{
|
||||||
ArrowItem *arrow = new ArrowItem(arrowId, startCard, targetCard, color);
|
ArrowItem *arrow = new ArrowItem(this, arrowId, startCard, targetCard, color);
|
||||||
arrows.insert(arrowId, arrow);
|
arrows.insert(arrowId, arrow);
|
||||||
scene()->addItem(arrow);
|
scene()->addItem(arrow);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "servergame.h"
|
#include "servergame.h"
|
||||||
#include "serversocket.h"
|
#include "serversocket.h"
|
||||||
|
#include "arrow.h"
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
|
|
||||||
ServerGame::ServerGame(ServerSocket *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, QObject *parent)
|
ServerGame::ServerGame(ServerSocket *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, QObject *parent)
|
||||||
|
@ -170,6 +171,15 @@ void ServerGame::setActivePlayer(int _activePlayer)
|
||||||
|
|
||||||
void ServerGame::setActivePhase(int _activePhase)
|
void ServerGame::setActivePhase(int _activePhase)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < players.size(); ++i) {
|
||||||
|
QMapIterator<int, Arrow *> arrowIterator(players[i]->getArrows());
|
||||||
|
while (arrowIterator.hasNext()) {
|
||||||
|
Arrow *a = arrowIterator.next().value();
|
||||||
|
broadcastEvent(QString("delete_arrow|%1").arg(a->getId()), players[i]);
|
||||||
|
players[i]->deleteArrow(a->getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
activePhase = _activePhase;
|
activePhase = _activePhase;
|
||||||
broadcastEvent(QString("set_active_phase|%1").arg(_activePhase), NULL);
|
broadcastEvent(QString("set_active_phase|%1").arg(_activePhase), NULL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue