mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
* [Settings] Split cache_settings into multiple files Took 9 minutes Took 4 minutes * [Settings] Fwd declare settings classes in cache_settings Took 15 minutes * Fix oracle includes. Took 8 minutes * Address comments, fix windows CI Took 8 minutes * fix copy constructor visibility Took 3 minutes * lint Took 2 minutes * Fix native format tests. Took 5 minutes * Remove test header guard Took 4 seconds * Remove tests invalid in CI environ Took 24 seconds * Adjust to rebase. Took 11 minutes * Change settings file name. Took 8 minutes --------- Co-authored-by: Lukas Brübach <lukas.bruebach@bdosecurity.de> Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
139 lines
4.6 KiB
C++
139 lines
4.6 KiB
C++
#include "pile_zone.h"
|
|
|
|
#include "../../client/settings/cache_settings.h"
|
|
#include "../../game/player/player_actions.h"
|
|
#include "../../game/player/player_logic.h"
|
|
#include "../../game/zones/pile_zone_logic.h"
|
|
#include "../board/card_drag_item.h"
|
|
#include "../board/card_item.h"
|
|
#include "view_zone.h"
|
|
|
|
#include <QApplication>
|
|
#include <QGraphicsSceneMouseEvent>
|
|
#include <QPainter>
|
|
#include <libcockatrice/protocol/pb/command_move_card.pb.h>
|
|
#include <libcockatrice/settings/cards_display_settings.h>
|
|
|
|
PileZone::PileZone(PileZoneLogic *_logic, QGraphicsItem *parent) : CardZone(_logic, parent)
|
|
{
|
|
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
|
setAcceptHoverEvents(true);
|
|
setCursor(Qt::OpenHandCursor);
|
|
|
|
setTransform(QTransform()
|
|
.translate(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F)
|
|
.rotate(90)
|
|
.translate(-CardDimensions::WIDTH_HALF_F, -CardDimensions::HEIGHT_HALF_F));
|
|
|
|
connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::roundCardCornersChanged, this,
|
|
[this](bool _roundCardCorners) {
|
|
Q_UNUSED(_roundCardCorners);
|
|
|
|
prepareGeometryChange();
|
|
update();
|
|
});
|
|
}
|
|
|
|
QRectF PileZone::boundingRect() const
|
|
{
|
|
return QRectF(0, 0, CardDimensions::WIDTH_F, CardDimensions::HEIGHT_F);
|
|
}
|
|
|
|
QPainterPath PileZone::shape() const
|
|
{
|
|
QPainterPath shape;
|
|
qreal cardCornerRadius =
|
|
SettingsCache::instance().cardsDisplay().getRoundCardCorners() ? 0.05 * CardDimensions::WIDTH_F : 0.0;
|
|
shape.addRoundedRect(boundingRect(), cardCornerRadius, cardCornerRadius);
|
|
return shape;
|
|
}
|
|
|
|
void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
|
{
|
|
painter->drawPath(shape());
|
|
|
|
if (!getLogic()->getCards().isEmpty()) {
|
|
getLogic()->getCards().at(0)->paintPicture(painter, getLogic()->getCards().at(0)->getTranslatedSize(painter),
|
|
90);
|
|
}
|
|
|
|
painter->translate(CardDimensions::WIDTH_HALF_F, CardDimensions::HEIGHT_HALF_F);
|
|
painter->rotate(-90);
|
|
painter->translate(-CardDimensions::WIDTH_HALF_F, -CardDimensions::HEIGHT_HALF_F);
|
|
paintNumberEllipse(getLogic()->getCards().size(), 28, Qt::white, -1, -1, painter);
|
|
}
|
|
|
|
void PileZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &)
|
|
{
|
|
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(0);
|
|
cmd.set_y(0);
|
|
|
|
for (int i = 0; i < dragItems.size(); ++i) {
|
|
auto cardToMove = cmd.mutable_cards_to_move()->add_card();
|
|
cardToMove->set_card_id(dragItems[i]->getId());
|
|
if (dragItems[i]->isForceFaceDown()) {
|
|
cardToMove->set_face_down(true);
|
|
}
|
|
}
|
|
|
|
getLogic()->getPlayer()->getPlayerActions()->sendGameCommand(cmd);
|
|
}
|
|
|
|
void PileZone::reorganizeCards()
|
|
{
|
|
update();
|
|
}
|
|
|
|
void PileZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
CardZone::mousePressEvent(event);
|
|
if (event->isAccepted()) {
|
|
return;
|
|
}
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
setCursor(Qt::ClosedHandCursor);
|
|
event->accept();
|
|
} else {
|
|
event->ignore();
|
|
}
|
|
}
|
|
|
|
void PileZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() <
|
|
QApplication::startDragDistance()) {
|
|
return;
|
|
}
|
|
|
|
if (getLogic()->getCards().isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
|
bool bottomCard = event->modifiers().testFlag(Qt::ControlModifier);
|
|
CardItem *card = bottomCard ? getLogic()->getCards().last() : getLogic()->getCards().first();
|
|
const int cardid =
|
|
getLogic()->contentsKnown() ? card->getId() : (bottomCard ? getLogic()->getCards().size() - 1 : 0);
|
|
CardDragItem *drag = card->createDragItem(cardid, event->pos(), event->scenePos(), forceFaceDown);
|
|
drag->grabMouse();
|
|
setCursor(Qt::OpenHandCursor);
|
|
}
|
|
|
|
void PileZone::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
|
{
|
|
setCursor(Qt::OpenHandCursor);
|
|
}
|
|
|
|
void PileZone::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
{
|
|
if (!getLogic()->getCards().isEmpty()) {
|
|
getLogic()->getCards()[0]->processHoverEvent();
|
|
}
|
|
QGraphicsItem::hoverEnterEvent(event);
|
|
}
|