mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 18:06:26 -07:00
* Add animations toggles for the life counter and battlefield Per-effect toggles plus Enable/Disable-all buttons: a life-counter flash on loss and a crimson battlefield shimmer on damage. Took 24 seconds * Animate life changes with a counter flash and battlefield shimmer - Life loss/gain pulses the player life counter with a brief flash - The battlefield table zone shimmers crimson on damage - Respects the per-effect animation toggles Both effects drive their decay from GameScene's shared animation timer through the IAnimatedItem interface (QElapsedTimer based), instead of owning per-item QTimers. Took 8 minutes * Revert unintentional cherry picks Took 2 minutes * Lambda to re-use path calculation. Took 8 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
229 lines
5.6 KiB
C++
229 lines
5.6 KiB
C++
/**
|
|
* @file table_zone.h
|
|
* @ingroup GameGraphicsZones
|
|
*/
|
|
//! \todo Document this file.
|
|
|
|
#ifndef TABLEZONE_H
|
|
#define TABLEZONE_H
|
|
|
|
#include "../../game/zones/table_zone_logic.h"
|
|
#include "../animated_item.h"
|
|
#include "../board/abstract_card_item.h"
|
|
#include "select_zone.h"
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
/**
|
|
* @brief TableZone is the grid based rect where CardItems may be placed.
|
|
*
|
|
* It is the main play zone and can be customized with background images.
|
|
*/
|
|
//! \todo Refactor methods to make more readable, extract logic to private methods (especially reorganizeCards()).
|
|
class TableZone : public SelectZone, public IAnimatedItem
|
|
{
|
|
Q_OBJECT
|
|
|
|
signals:
|
|
void sizeChanged();
|
|
|
|
private:
|
|
static const int TABLEROWS = 3;
|
|
|
|
/*
|
|
Margins between table edges and cards, paddings between cards
|
|
*/
|
|
static const int MARGIN_LEFT = 20;
|
|
static const int MARGIN_RIGHT = 15;
|
|
static const int MARGIN_TOP = 10;
|
|
static const int MARGIN_BOTTOM = 30;
|
|
static const int PADDING_X = 35;
|
|
static const int PADDING_Y = 30;
|
|
|
|
/*
|
|
Minimum width of the table zone including margins.
|
|
*/
|
|
static const int MIN_WIDTH = MARGIN_LEFT + (5 * CardDimensions::WIDTH) + MARGIN_RIGHT;
|
|
|
|
/*
|
|
Offset sizes when cards are stacked on each other in the grid
|
|
*/
|
|
static const int STACKED_CARD_OFFSET_X = CardDimensions::WIDTH / 3;
|
|
static const int STACKED_CARD_OFFSET_Y = PADDING_Y / 3;
|
|
|
|
/*
|
|
Width of the box line drawn in the margin around the active player's area
|
|
*/
|
|
static const int BOX_LINE_WIDTH = 10;
|
|
|
|
/*
|
|
Default inactive mask and border gradient
|
|
*/
|
|
static const QColor BACKGROUND_COLOR;
|
|
static const QColor FADE_MASK;
|
|
static const QColor GRADIENT_COLOR;
|
|
static const QColor GRADIENT_COLORLESS;
|
|
|
|
/*
|
|
Size and shape variables
|
|
*/
|
|
int width;
|
|
int height;
|
|
int currentMinimumWidth;
|
|
|
|
/*
|
|
Internal cache for widths of stacks of cards by row and column.
|
|
*/
|
|
QMap<int, int> cardStackWidth;
|
|
|
|
/*
|
|
Holds any custom background image for the TableZone
|
|
*/
|
|
QPixmap backgroundPixelMap;
|
|
|
|
/*
|
|
If this TableZone is currently active
|
|
*/
|
|
bool active = false;
|
|
bool mirrored = false;
|
|
|
|
[[nodiscard]] bool isInverted() const;
|
|
|
|
private slots:
|
|
/**
|
|
Loads in any found custom background and updates
|
|
*/
|
|
void updateBg();
|
|
|
|
public slots:
|
|
/**
|
|
Reorganizes CardItems in the TableZone
|
|
*/
|
|
void reorganizeCards() override;
|
|
void setMirrored(bool isMirrored);
|
|
|
|
public:
|
|
/**
|
|
Constructs TableZone.
|
|
|
|
@param _p the Player
|
|
@param parent defaults to null
|
|
*/
|
|
explicit TableZone(TableZoneLogic *_logic, bool mirrored, QGraphicsItem *parent = nullptr);
|
|
|
|
/**
|
|
@return a QRectF of the TableZone bounding box.
|
|
*/
|
|
[[nodiscard]] QRectF boundingRect() const override;
|
|
|
|
/**
|
|
Render the TableZone
|
|
|
|
@param painter
|
|
@param option
|
|
*/
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
|
|
|
/**
|
|
Flashes the table surface after a player loses life.
|
|
|
|
Wired up through the life counter so the battlefield glows when life drops.
|
|
*/
|
|
void triggerDamageShimmer();
|
|
|
|
/** @brief Decays the damage shimmer by one timer tick. */
|
|
bool animationEvent() override;
|
|
|
|
/**
|
|
Toggles the selected items as tapped.
|
|
*/
|
|
void toggleTapped();
|
|
|
|
/**
|
|
See HandleDropEventByGrid
|
|
*/
|
|
void
|
|
handleDropEvent(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &dropPoint) override;
|
|
|
|
/**
|
|
Handles the placement of cards
|
|
*/
|
|
void
|
|
handleDropEventByGrid(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &gridPoint);
|
|
|
|
/**
|
|
@return CardItem from grid location
|
|
*/
|
|
[[nodiscard]] CardItem *getCardFromGrid(const QPoint &gridPoint) const;
|
|
|
|
/**
|
|
@return CardItem from coordinate location
|
|
*/
|
|
[[nodiscard]] CardItem *getCardFromCoords(const QPointF &point) const;
|
|
|
|
QPointF closestGridPoint(const QPointF &point) override;
|
|
|
|
static int clampValidTableRow(const int row);
|
|
|
|
/**
|
|
* Converts a card's logical table row (0=creatures, 1=noncreatures, 2=lands)
|
|
* to the corresponding grid Y coordinate. Cards with tableRow > 2 (e.g.,
|
|
* instants/sorceries) default to the noncreatures row.
|
|
*/
|
|
static int tableRowToGridY(int tableRow);
|
|
|
|
/**
|
|
Resizes the TableZone in case CardItems are within or
|
|
outside of the TableZone constraints.
|
|
*/
|
|
void resizeToContents();
|
|
|
|
[[nodiscard]] int getMinimumWidth() const
|
|
{
|
|
return currentMinimumWidth;
|
|
}
|
|
void setWidth(qreal _width)
|
|
{
|
|
prepareGeometryChange();
|
|
width = _width;
|
|
}
|
|
[[nodiscard]] qreal getWidth() const
|
|
{
|
|
return width;
|
|
}
|
|
void setActive(bool _active)
|
|
{
|
|
active = _active;
|
|
update();
|
|
}
|
|
|
|
private:
|
|
static constexpr qreal shimmerDurationMs = 450.0;
|
|
|
|
QElapsedTimer shimmerClock;
|
|
qreal damageShimmerAlpha = 0.0;
|
|
|
|
void paintZoneOutline(QPainter *painter);
|
|
void paintLandDivider(QPainter *painter);
|
|
|
|
/*
|
|
Calculates card stack widths so mapping functions work properly
|
|
*/
|
|
void computeCardStackWidths();
|
|
|
|
/*
|
|
Mapping functions for points to/from gridpoints.
|
|
*/
|
|
[[nodiscard]] QPointF mapFromGrid(QPoint gridPoint) const;
|
|
[[nodiscard]] QPoint mapToGrid(const QPointF &mapPoint) const;
|
|
|
|
/*
|
|
Helper function to create a single key from a card stack location.
|
|
*/
|
|
[[nodiscard]] int getCardStackMapKey(int x, int y) const
|
|
{
|
|
return x + (y * 1000);
|
|
}
|
|
};
|
|
|
|
#endif
|