more beautiful arrows; fixed server bug regarding facedown cards

This commit is contained in:
Max-Wilhelm Bruker 2010-02-24 14:43:18 +01:00
parent 2d57715a6e
commit 89fe7d2d69
4 changed files with 42 additions and 11 deletions

View file

@ -27,23 +27,39 @@ void ArrowItem::updatePath(const QPointF &endPoint)
const double arrowWidth = 15.0; const double arrowWidth = 15.0;
const double headWidth = 40.0; const double headWidth = 40.0;
const double headLength = headWidth / sqrt(2); const double headLength = headWidth / sqrt(2);
const double phi = 15;
QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2)); QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
QLineF line(startPoint, endPoint); QLineF line(startPoint, endPoint);
qreal lineLength = line.length(); qreal lineLength = line.length();
prepareGeometryChange(); prepareGeometryChange();
if (lineLength < headLength) if (lineLength < 30)
path = QPainterPath(); path = QPainterPath();
else { else {
path = QPainterPath(QPointF(0, -arrowWidth / 2)); QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength);
path.lineTo(0, arrowWidth / 2);
path.lineTo(lineLength - headLength, arrowWidth / 2); QPainterPath centerLine;
path.lineTo(lineLength - headLength, headWidth / 2); centerLine.moveTo(0, 0);
path.lineTo(lineLength, 0); centerLine.quadTo(c, QPointF(lineLength, 0));
path.lineTo(lineLength - headLength, -headWidth / 2);
path.lineTo(lineLength - headLength, -arrowWidth / 2); double percentage = 1 - headLength / lineLength;
path.lineTo(0, -arrowWidth / 2); QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage);
QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001));
qreal alpha = testLine.angle() - 90;
QPointF endPoint1 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
QPointF endPoint2 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));
QPointF point1 = endPoint1 + (headWidth - arrowWidth) / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
QPointF point2 = endPoint2 + (headWidth - arrowWidth) / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));
path = QPainterPath(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
path.quadTo(c, endPoint1);
path.lineTo(point1);
path.lineTo(QPointF(lineLength, 0));
path.lineTo(point2);
path.lineTo(endPoint2);
path.quadTo(c, arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
path.lineTo(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
} }
setPos(startPoint); setPos(startPoint);
@ -94,12 +110,15 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
for (int i = colliding.size() - 1; i >= 0; i--) for (int i = colliding.size() - 1; i >= 0; i--)
if ((cursorItem = qgraphicsitem_cast<CardItem *>(colliding.at(i)))) if ((cursorItem = qgraphicsitem_cast<CardItem *>(colliding.at(i))))
break; break;
if ((cursorItem != targetItem) && targetItem)
targetItem->setBeingPointedAt(false);
if (!cursorItem) { if (!cursorItem) {
fullColor = false; fullColor = false;
targetItem = 0; targetItem = 0;
updatePath(endPos); updatePath(endPos);
} else { } else {
fullColor = true; fullColor = true;
cursorItem->setBeingPointedAt(true);
targetItem = cursorItem; targetItem = cursorItem;
updatePath(); updatePath();
} }
@ -109,6 +128,7 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/) void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
{ {
if (targetItem && (targetItem != startItem)) { if (targetItem && (targetItem != startItem)) {
targetItem->setBeingPointedAt(false);
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());
player->sendGameCommand(new Command_CreateArrow( player->sendGameCommand(new Command_CreateArrow(

View file

@ -11,7 +11,7 @@
#include "protocol_datastructures.h" #include "protocol_datastructures.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, parent), owner(_owner), id(_cardid), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL) : AbstractCardItem(_name, parent), owner(_owner), id(_cardid), attacking(false), facedown(false), counters(0), doesntUntap(false), beingPointedAt(false), dragItem(NULL)
{ {
owner->addCard(this); owner->addCard(this);
} }
@ -27,6 +27,8 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
AbstractCardItem::paint(painter, option, widget); AbstractCardItem::paint(painter, option, widget);
if (counters) if (counters)
paintNumberEllipse(counters, painter); paintNumberEllipse(counters, painter);
if (beingPointedAt)
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
painter->restore(); painter->restore();
} }
@ -61,6 +63,12 @@ void CardItem::setDoesntUntap(bool _doesntUntap)
doesntUntap = _doesntUntap; doesntUntap = _doesntUntap;
} }
void CardItem::setBeingPointedAt(bool _beingPointedAt)
{
beingPointedAt = _beingPointedAt;
update();
}
void CardItem::resetState() void CardItem::resetState()
{ {
attacking = false; attacking = false;

View file

@ -22,6 +22,7 @@ private:
QString annotation; QString annotation;
bool doesntUntap; bool doesntUntap;
QPoint gridPoint; QPoint gridPoint;
bool beingPointedAt;
CardDragItem *dragItem; CardDragItem *dragItem;
public: public:
enum { Type = typeCard }; enum { Type = typeCard };
@ -44,6 +45,7 @@ public:
void setAnnotation(const QString &_annotation); void setAnnotation(const QString &_annotation);
bool getDoesntUntap() const { return doesntUntap; } bool getDoesntUntap() const { return doesntUntap; }
void setDoesntUntap(bool _doesntUntap); void setDoesntUntap(bool _doesntUntap);
void setBeingPointedAt(bool _beingPointedAt);
void resetState(); void resetState();
void processCardInfo(ServerInfo_Card *info); void processCardInfo(ServerInfo_Card *info);

View file

@ -268,7 +268,8 @@ QList<ServerInfo_Player *> Server_Game::getGameState(Server_Player *playerWhosAs
QListIterator<Server_Card *> cardIterator(zone->cards); QListIterator<Server_Card *> cardIterator(zone->cards);
while (cardIterator.hasNext()) { while (cardIterator.hasNext()) {
Server_Card *card = cardIterator.next(); Server_Card *card = cardIterator.next();
cardList.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getCounters(), card->getTapped(), card->getAttacking(), card->getAnnotation())); QString displayedName = card->getFaceDown() ? QString() : card->getName();
cardList.append(new ServerInfo_Card(card->getId(), displayedName, card->getX(), card->getY(), card->getCounters(), card->getTapped(), card->getAttacking(), card->getAnnotation()));
} }
} }
zoneList.append(new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), zone->cards.size(), cardList)); zoneList.append(new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), zone->cards.size(), cardList));