mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-07 05:53:59 -07:00
Adjust to rebase.
Took 28 minutes Took 7 seconds Took 2 minutes Took 8 minutes Took 13 seconds
This commit is contained in:
parent
b4adb20a5f
commit
cbee3726c9
16 changed files with 50 additions and 48 deletions
177
cockatrice/src/game_graphics/zones/command_zone.cpp
Normal file
177
cockatrice/src/game_graphics/zones/command_zone.cpp
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
#include "command_zone.h"
|
||||
|
||||
#include "../../client/settings/cache_settings.h"
|
||||
#include "../../game/player/player_actions.h"
|
||||
#include "../../game/player/player_logic.h"
|
||||
#include "../../interface/theme_manager.h"
|
||||
#include "../board/card_drag_item.h"
|
||||
#include "../board/card_item.h"
|
||||
#include "../board/commander_tax_counter.h"
|
||||
#include "../z_values.h"
|
||||
#include "select_zone.h"
|
||||
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <libcockatrice/protocol/pb/command_move_card.pb.h>
|
||||
#include <libcockatrice/utility/counter_ids.h>
|
||||
|
||||
CommandZone::CommandZone(CommandZoneLogic *_logic, int _zoneHeight, QGraphicsItem *parent)
|
||||
: SelectZone(_logic, parent), zoneHeight(_zoneHeight)
|
||||
{
|
||||
connect(themeManager, &ThemeManager::themeChanged, this, &CommandZone::updateBg);
|
||||
updateBg();
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
setupClipContainer(ZValues::CARD_BASE);
|
||||
}
|
||||
|
||||
void CommandZone::updateBg()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
QRectF CommandZone::boundingRect() const
|
||||
{
|
||||
return {0, 0, ZoneSizes::COMMAND_ZONE_WIDTH, currentHeight()};
|
||||
}
|
||||
|
||||
qreal CommandZone::currentHeight() const
|
||||
{
|
||||
return minimized ? qMax(zoneHeight * MINIMIZED_HEIGHT_RATIO, static_cast<double>(minimumHeight)) : zoneHeight;
|
||||
}
|
||||
|
||||
void CommandZone::setMinimumHeight(int height)
|
||||
{
|
||||
if (minimumHeight == height) {
|
||||
return;
|
||||
}
|
||||
minimumHeight = height;
|
||||
prepareGeometryChange();
|
||||
updateClipRect();
|
||||
reorganizeCards();
|
||||
update();
|
||||
// NOTE: Do NOT emit minimizedChanged here. The minimized STATE has not changed,
|
||||
// only the minimum height constraint. Emitting here causes an infinite loop:
|
||||
// rearrangeZones -> rearrangeCounters -> rearrangeTaxCounters -> setMinimumHeight
|
||||
// -> minimizedChanged -> rearrangeZones (loop!)
|
||||
}
|
||||
|
||||
bool CommandZone::isMinimized() const
|
||||
{
|
||||
return minimized;
|
||||
}
|
||||
|
||||
void CommandZone::toggleMinimized()
|
||||
{
|
||||
minimized = !minimized;
|
||||
|
||||
prepareGeometryChange();
|
||||
updateClipRect();
|
||||
reorganizeCards();
|
||||
update();
|
||||
|
||||
emit minimizedChanged(minimized);
|
||||
}
|
||||
|
||||
void CommandZone::paint(QPainter *painter,
|
||||
[[maybe_unused]] const QStyleOptionGraphicsItem *option,
|
||||
[[maybe_unused]] QWidget *widget)
|
||||
{
|
||||
QBrush brush = themeManager->getExtraBgBrush(ThemeManager::Command, getLogic()->getPlayer()->getZoneId());
|
||||
|
||||
QPointF scenePos = mapToScene(QPointF(0, 0));
|
||||
painter->setBrushOrigin(-scenePos);
|
||||
|
||||
painter->fillRect(boundingRect(), brush);
|
||||
}
|
||||
|
||||
void CommandZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
||||
CardZoneLogic *startZone,
|
||||
const QPoint &dropPoint)
|
||||
{
|
||||
if (startZone == nullptr || startZone->getPlayer() == nullptr || dragItems.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
|
||||
|
||||
// Same-zone no-op: don't move a card onto itself
|
||||
const auto &cards = getLogic()->getCards();
|
||||
if (!cards.isEmpty() && startZone == getLogic() && cards.at(index)->getId() == dragItems.at(0)->getId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Command_MoveCard cmd;
|
||||
cmd.set_start_player_id(startZone->getPlayer()->getPlayerInfo()->getId());
|
||||
cmd.set_start_zone(startZone->getName().toStdString());
|
||||
cmd.set_target_player_id(getLogic()->getPlayer()->getPlayerInfo()->getId());
|
||||
cmd.set_target_zone(getLogic()->getName().toStdString());
|
||||
cmd.set_x(index);
|
||||
cmd.set_y(0);
|
||||
|
||||
for (const CardDragItem *item : dragItems) {
|
||||
if (item) {
|
||||
auto *cardToMove = cmd.mutable_cards_to_move()->add_card();
|
||||
cardToMove->set_card_id(item->getId());
|
||||
if (item->isForceFaceDown()) {
|
||||
cardToMove->set_face_down(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getLogic()->getPlayer()->getPlayerActions()->sendGameCommand(cmd);
|
||||
}
|
||||
|
||||
void CommandZone::reorganizeCards()
|
||||
{
|
||||
restoreStaleEscapedCards();
|
||||
updateClipRect();
|
||||
|
||||
const auto &cards = getLogic()->getCards();
|
||||
if (cards.isEmpty()) {
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
auto params = buildStackParams(MIN_CARD_VISIBLE);
|
||||
params.allowBottomOverflow = true;
|
||||
layoutCardsVertically(params);
|
||||
update();
|
||||
}
|
||||
|
||||
void CommandZone::rearrangeTaxCounters()
|
||||
{
|
||||
// TODO
|
||||
/*bool commandZoneVisible = isVisible();
|
||||
int activeTaxCounterCount = 0;
|
||||
|
||||
auto *graphicsItem = getLogic()->getPlayer()->getGraphicsItem();
|
||||
if (!graphicsItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (AbstractCounter *ctr : graphicsItem->getTaxCounterWidgets()) {
|
||||
qreal y = TaxCounterSizes::TAX_COUNTER_MARGIN +
|
||||
activeTaxCounterCount * (TaxCounterSizes::TAX_COUNTER_SIZE + TaxCounterSizes::TAX_COUNTER_MARGIN);
|
||||
ctr->setPos(TaxCounterSizes::TAX_COUNTER_MARGIN, y);
|
||||
ctr->setZValue(ZValues::TAX_COUNTERS);
|
||||
bool visible = commandZoneVisible && ctr->isActive();
|
||||
ctr->setVisible(visible);
|
||||
if (visible) {
|
||||
++activeTaxCounterCount;
|
||||
}
|
||||
}
|
||||
|
||||
int minHeight = activeTaxCounterCount * (TaxCounterSizes::TAX_COUNTER_SIZE + TaxCounterSizes::TAX_COUNTER_MARGIN) +
|
||||
TaxCounterSizes::TAX_COUNTER_MARGIN;
|
||||
setMinimumHeight(minHeight);*/
|
||||
}
|
||||
|
||||
void CommandZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
toggleMinimized();
|
||||
event->accept();
|
||||
} else {
|
||||
SelectZone::mouseDoubleClickEvent(event);
|
||||
}
|
||||
}
|
||||
103
cockatrice/src/game_graphics/zones/command_zone.h
Normal file
103
cockatrice/src/game_graphics/zones/command_zone.h
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/**
|
||||
* @file command_zone.h
|
||||
* @ingroup GameGraphicsZones
|
||||
* @brief Graphics layer for the command zone, used for Commander format.
|
||||
*/
|
||||
|
||||
#ifndef COCKATRICE_COMMAND_ZONE_H
|
||||
#define COCKATRICE_COMMAND_ZONE_H
|
||||
|
||||
#include "../../game/zones/command_zone_logic.h"
|
||||
#include "../card_dimensions.h"
|
||||
#include "select_zone.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
inline Q_LOGGING_CATEGORY(CommandZoneLog, "command_zone");
|
||||
|
||||
/**
|
||||
* @namespace ZoneSizes
|
||||
* @brief Size constants for the command zone and its sub-elements.
|
||||
*/
|
||||
namespace ZoneSizes
|
||||
{
|
||||
|
||||
/** @brief Height of the command zone (accommodates a card plus padding) */
|
||||
constexpr qreal COMMAND_ZONE_HEIGHT = CardDimensions::HEIGHT + 8;
|
||||
|
||||
/** @brief Width of the command zone (matches stack zone) */
|
||||
constexpr qreal COMMAND_ZONE_WIDTH = CardDimensions::WIDTH_F * 1.5;
|
||||
|
||||
} // namespace ZoneSizes
|
||||
|
||||
/**
|
||||
* @class CommandZone
|
||||
* @brief Graphics layer for the command zone in Commander format games.
|
||||
*
|
||||
* Always visible when enabled. Supports multiple cards using a zigzag
|
||||
* horizontal stacking pattern: single cards display centered, multiple
|
||||
* cards alternate left-right with vertical overlap compression.
|
||||
* Can be minimized to 25% height via double-click.
|
||||
*
|
||||
* @see CommandZoneLogic for card data management
|
||||
* @see CommanderTaxCounter for the tax counter overlay
|
||||
*/
|
||||
class CommandZone : public SelectZone
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static constexpr qreal MINIMUM_STACKING_HEIGHT = 50.0;
|
||||
|
||||
private:
|
||||
static constexpr double MINIMIZED_HEIGHT_RATIO = 0.25;
|
||||
int zoneHeight; ///< Full height in pixels when expanded
|
||||
bool minimized = false; ///< Whether zone is at 25% height
|
||||
int minimumHeight = 0; ///< Floor for minimized height (e.g. to fit tax counters)
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a CommandZone graphics item.
|
||||
* @param _logic Logic layer managing card data
|
||||
* @param _zoneHeight Zone height in pixels
|
||||
* @param parent Parent graphics item
|
||||
*/
|
||||
CommandZone(CommandZoneLogic *_logic, int _zoneHeight, QGraphicsItem *parent);
|
||||
|
||||
/**
|
||||
* @brief Handles card drops, calculating insertion position from drop point.
|
||||
* @param dragItems Cards being dragged
|
||||
* @param startZone Source zone
|
||||
* @param dropPoint Drop position in local coordinates
|
||||
*/
|
||||
void
|
||||
handleDropEvent(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &dropPoint) override;
|
||||
|
||||
/** @brief Returns the bounding rectangle, accounting for minimized state. */
|
||||
[[nodiscard]] QRectF boundingRect() const override;
|
||||
/** @brief Paints the zone background using the Commander theme brush. */
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
/** @brief Repositions cards using zigzag horizontal stacking with overlap compression. */
|
||||
void reorganizeCards() override;
|
||||
|
||||
/** @brief Toggles between full and 25% minimized height. */
|
||||
void toggleMinimized();
|
||||
[[nodiscard]] bool isMinimized() const;
|
||||
/** @brief Returns the current display height (full or minimized). */
|
||||
[[nodiscard]] qreal currentHeight() const;
|
||||
/** @brief Sets the minimum height floor, e.g. to ensure tax counters remain visible. */
|
||||
void setMinimumHeight(int height);
|
||||
/** @brief Lays out visible tax counters vertically in the top-left corner of the command zone. */
|
||||
void rearrangeTaxCounters();
|
||||
|
||||
signals:
|
||||
/** @brief Emitted when the zone toggles between minimized and expanded states. */
|
||||
void minimizedChanged(bool isMinimized);
|
||||
|
||||
protected:
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void updateBg();
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_COMMAND_ZONE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue