more beautiful arrows; fixed server bug regarding facedown cards
This commit is contained in:
parent
2d57715a6e
commit
89fe7d2d69
4 changed files with 42 additions and 11 deletions
|
@ -27,23 +27,39 @@ void ArrowItem::updatePath(const QPointF &endPoint)
|
|||
const double arrowWidth = 15.0;
|
||||
const double headWidth = 40.0;
|
||||
const double headLength = headWidth / sqrt(2);
|
||||
const double phi = 15;
|
||||
|
||||
QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
|
||||
QLineF line(startPoint, endPoint);
|
||||
qreal lineLength = line.length();
|
||||
|
||||
prepareGeometryChange();
|
||||
if (lineLength < headLength)
|
||||
if (lineLength < 30)
|
||||
path = QPainterPath();
|
||||
else {
|
||||
path = QPainterPath(QPointF(0, -arrowWidth / 2));
|
||||
path.lineTo(0, arrowWidth / 2);
|
||||
path.lineTo(lineLength - headLength, arrowWidth / 2);
|
||||
path.lineTo(lineLength - headLength, headWidth / 2);
|
||||
path.lineTo(lineLength, 0);
|
||||
path.lineTo(lineLength - headLength, -headWidth / 2);
|
||||
path.lineTo(lineLength - headLength, -arrowWidth / 2);
|
||||
path.lineTo(0, -arrowWidth / 2);
|
||||
QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength);
|
||||
|
||||
QPainterPath centerLine;
|
||||
centerLine.moveTo(0, 0);
|
||||
centerLine.quadTo(c, QPointF(lineLength, 0));
|
||||
|
||||
double percentage = 1 - headLength / lineLength;
|
||||
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);
|
||||
|
@ -94,12 +110,15 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||
if ((cursorItem = qgraphicsitem_cast<CardItem *>(colliding.at(i))))
|
||||
break;
|
||||
if ((cursorItem != targetItem) && targetItem)
|
||||
targetItem->setBeingPointedAt(false);
|
||||
if (!cursorItem) {
|
||||
fullColor = false;
|
||||
targetItem = 0;
|
||||
updatePath(endPos);
|
||||
} else {
|
||||
fullColor = true;
|
||||
cursorItem->setBeingPointedAt(true);
|
||||
targetItem = cursorItem;
|
||||
updatePath();
|
||||
}
|
||||
|
@ -109,6 +128,7 @@ void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
||||
{
|
||||
if (targetItem && (targetItem != startItem)) {
|
||||
targetItem->setBeingPointedAt(false);
|
||||
CardZone *startZone = static_cast<CardZone *>(startItem->parentItem());
|
||||
CardZone *targetZone = static_cast<CardZone *>(targetItem->parentItem());
|
||||
player->sendGameCommand(new Command_CreateArrow(
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "protocol_datastructures.h"
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|||
AbstractCardItem::paint(painter, option, widget);
|
||||
if (counters)
|
||||
paintNumberEllipse(counters, painter);
|
||||
if (beingPointedAt)
|
||||
painter->fillRect(boundingRect(), QBrush(QColor(255, 0, 0, 100)));
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
@ -61,6 +63,12 @@ void CardItem::setDoesntUntap(bool _doesntUntap)
|
|||
doesntUntap = _doesntUntap;
|
||||
}
|
||||
|
||||
void CardItem::setBeingPointedAt(bool _beingPointedAt)
|
||||
{
|
||||
beingPointedAt = _beingPointedAt;
|
||||
update();
|
||||
}
|
||||
|
||||
void CardItem::resetState()
|
||||
{
|
||||
attacking = false;
|
||||
|
|
|
@ -22,6 +22,7 @@ private:
|
|||
QString annotation;
|
||||
bool doesntUntap;
|
||||
QPoint gridPoint;
|
||||
bool beingPointedAt;
|
||||
CardDragItem *dragItem;
|
||||
public:
|
||||
enum { Type = typeCard };
|
||||
|
@ -44,6 +45,7 @@ public:
|
|||
void setAnnotation(const QString &_annotation);
|
||||
bool getDoesntUntap() const { return doesntUntap; }
|
||||
void setDoesntUntap(bool _doesntUntap);
|
||||
void setBeingPointedAt(bool _beingPointedAt);
|
||||
void resetState();
|
||||
void processCardInfo(ServerInfo_Card *info);
|
||||
|
||||
|
|
|
@ -268,7 +268,8 @@ QList<ServerInfo_Player *> Server_Game::getGameState(Server_Player *playerWhosAs
|
|||
QListIterator<Server_Card *> cardIterator(zone->cards);
|
||||
while (cardIterator.hasNext()) {
|
||||
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));
|
||||
|
|
Loading…
Reference in a new issue