mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 19:13:25 -08:00
* [Refactor] Move game logic into libcockatrice_game * [Refactor] Include card_state.h in player_actions.h * [Game] Inject settings providers into libcockatrice_game, drop Widgets * [Game] Follow base rename to createCardRequested after rebase * [Game] Drop unused CardItem forward declaration * [Game] Fix includes after moving game logic into libcockatrice_game --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
144 lines
3.5 KiB
C++
144 lines
3.5 KiB
C++
#ifndef ARROWITEM_H
|
|
#define ARROWITEM_H
|
|
|
|
#include "../animated_item.h"
|
|
#include "arrow_target.h"
|
|
#include "graphics_item_type.h"
|
|
|
|
#include <QColor>
|
|
#include <QElapsedTimer>
|
|
#include <QGraphicsItem>
|
|
#include <QList>
|
|
#include <QMetaObject>
|
|
#include <QObject>
|
|
#include <QPainterPath>
|
|
#include <QPointF>
|
|
#include <QPointer>
|
|
#include <QRectF>
|
|
#include <QSharedPointer>
|
|
#include <QtGlobal>
|
|
#include <libcockatrice/game/board/arrow_data.h>
|
|
#include <qtmetamacros.h>
|
|
|
|
class CardItem;
|
|
class PlayerLogic;
|
|
template <class T> class QSharedPointer;
|
|
|
|
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;
|
|
|
|
public:
|
|
explicit ArrowAttachItem(ArrowTarget *_startItem);
|
|
void addChildArrow(ArrowAttachItem *child);
|
|
|
|
protected:
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
|
};
|
|
|
|
#endif
|