mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 10:05:10 -07:00
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run
Took 23 minutes Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
137 lines
3.4 KiB
C++
137 lines
3.4 KiB
C++
#ifndef ARROWITEM_H
|
|
#define ARROWITEM_H
|
|
|
|
#include "../../game/board/arrow_data.h"
|
|
#include "../animated_item.h"
|
|
#include "arrow_target.h"
|
|
#include "graphics_item_type.h"
|
|
|
|
#include <QElapsedTimer>
|
|
#include <QGraphicsItem>
|
|
#include <QPainterPath>
|
|
#include <QPointer>
|
|
#include <QSharedPointer>
|
|
|
|
class CardItem;
|
|
class QGraphicsSceneMouseEvent;
|
|
class PlayerLogic;
|
|
|
|
class ArrowItem : public QObject, public QGraphicsItem, public IAnimatedItem
|
|
{
|
|
Q_OBJECT
|
|
Q_INTERFACES(QGraphicsItem)
|
|
signals:
|
|
void requestDeletion(int creatorId, int id);
|
|
|
|
private:
|
|
QPainterPath path;
|
|
QPainterPath bodyPath;
|
|
QPainterPath headPath;
|
|
QPainterPath shaftOutlinePath;
|
|
QPainterPath centerLine;
|
|
qreal headBaseFraction = 1.0;
|
|
QElapsedTimer animationClock;
|
|
qreal strokeDurationMs = 0;
|
|
qreal glowFadeDurationMs = 0;
|
|
qreal drawProgress = 1.0;
|
|
qreal glowAlpha = 0.0;
|
|
bool animationStarted = false;
|
|
|
|
static constexpr qreal glowExtent = 12.0;
|
|
|
|
protected:
|
|
QSharedPointer<const ArrowData> data;
|
|
QPointer<ArrowTarget> startItem;
|
|
QPointer<ArrowTarget> targetItem;
|
|
bool targetLocked = false;
|
|
bool fullColor = true;
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
public:
|
|
enum
|
|
{
|
|
Type = typeArrow
|
|
};
|
|
[[nodiscard]] int type() const override
|
|
{
|
|
return Type;
|
|
}
|
|
ArrowItem(QSharedPointer<const ArrowData> _data, ArrowTarget *_startItem, ArrowTarget *_targetItem);
|
|
~ArrowItem() override;
|
|
|
|
void onTargetDestroyed();
|
|
void delArrow();
|
|
void updatePath();
|
|
void updatePath(const QPointF &endPoint);
|
|
void startDrawAnimation();
|
|
bool animationEvent() override;
|
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
|
[[nodiscard]] QRectF boundingRect() const override
|
|
{
|
|
return path.boundingRect().adjusted(-glowExtent, -glowExtent, glowExtent, glowExtent);
|
|
}
|
|
[[nodiscard]] QPainterPath shape() const override
|
|
{
|
|
return path;
|
|
}
|
|
[[nodiscard]] int getId() const
|
|
{
|
|
return data->id;
|
|
}
|
|
[[nodiscard]] int getCreatorId() const
|
|
{
|
|
return data->creatorId;
|
|
}
|
|
[[nodiscard]] ArrowTarget *getStartItem() const
|
|
{
|
|
return startItem;
|
|
}
|
|
[[nodiscard]] ArrowTarget *getTargetItem() const
|
|
{
|
|
return targetItem;
|
|
}
|
|
void setTargetLocked(bool _targetLocked)
|
|
{
|
|
targetLocked = _targetLocked;
|
|
}
|
|
};
|
|
|
|
class ArrowDragItem : public ArrowItem
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
PlayerLogic *player;
|
|
int deleteInPhase;
|
|
QList<ArrowDragItem *> childArrows;
|
|
QMetaObject::Connection positionConnection;
|
|
|
|
public:
|
|
ArrowDragItem(PlayerLogic *_owner, ArrowTarget *_startItem, const QColor &_color, int _deleteInPhase);
|
|
void addChildArrow(ArrowDragItem *child);
|
|
|
|
protected:
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
|
};
|
|
|
|
class ArrowAttachItem : public ArrowItem
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
PlayerLogic *player;
|
|
QList<ArrowAttachItem *> childArrows;
|
|
QMetaObject::Connection positionConnection;
|
|
void attachCards(CardItem *startCard, const CardItem *targetCard);
|
|
|
|
public:
|
|
explicit ArrowAttachItem(ArrowTarget *_startItem);
|
|
void addChildArrow(ArrowAttachItem *child);
|
|
|
|
protected:
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
|
};
|
|
|
|
#endif
|