mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -07:00
Fix Ricky Crash
This commit is contained in:
parent
8916e049bd
commit
b8dc404de0
1 changed files with 19 additions and 8 deletions
|
|
@ -28,7 +28,7 @@ void StackZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
{
|
{
|
||||||
// if x is negative set it to add at end
|
// if x is negative set it to add at end
|
||||||
if (x < 0 || x >= cards.size()) {
|
if (x < 0 || x >= cards.size()) {
|
||||||
x = cards.size();
|
x = static_cast<int>(cards.size());
|
||||||
}
|
}
|
||||||
cards.insert(x, card);
|
cards.insert(x, card);
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ void StackZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
|
|
||||||
QRectF StackZone::boundingRect() const
|
QRectF StackZone::boundingRect() const
|
||||||
{
|
{
|
||||||
return QRectF(0, 0, 100, zoneHeight);
|
return {0, 0, 100, zoneHeight};
|
||||||
}
|
}
|
||||||
|
|
||||||
void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
|
|
@ -60,7 +60,7 @@ void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*opti
|
||||||
|
|
||||||
void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint)
|
void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint)
|
||||||
{
|
{
|
||||||
if (!startZone) {
|
if (startZone == nullptr || startZone->getPlayer() == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,19 +69,30 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
cmd.set_start_zone(startZone->getName().toStdString());
|
||||||
cmd.set_target_player_id(player->getId());
|
cmd.set_target_player_id(player->getId());
|
||||||
cmd.set_target_zone(getName().toStdString());
|
cmd.set_target_zone(getName().toStdString());
|
||||||
int index;
|
|
||||||
|
int index = 0;
|
||||||
if (cards.isEmpty()) {
|
if (cards.isEmpty()) {
|
||||||
index = 0;
|
index = 0;
|
||||||
} else {
|
} else {
|
||||||
const int cardCount = cards.size();
|
const auto cardCount = static_cast<int>(cards.size());
|
||||||
|
const auto &card = cards.at(0);
|
||||||
|
|
||||||
|
if (card == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
index = qRound(divideCardSpaceInZone(dropPoint.y(), cardCount, boundingRect().height(),
|
index = qRound(divideCardSpaceInZone(dropPoint.y(), cardCount, boundingRect().height(),
|
||||||
cards.at(0)->boundingRect().height(), true));
|
card->boundingRect().height(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startZone == this) {
|
if (startZone == this) {
|
||||||
if (dragItems.at(0) != nullptr && cards.at(index)->getId() == dragItems.at(0)->getId()) {
|
const auto &dragItem = dragItems.at(0);
|
||||||
|
const auto &card = cards.at(index);
|
||||||
|
if (card != nullptr && dragItem != nullptr && card->getId() == dragItem->getId()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.set_x(index);
|
cmd.set_x(index);
|
||||||
cmd.set_y(0);
|
cmd.set_y(0);
|
||||||
|
|
||||||
|
|
@ -99,7 +110,7 @@ void StackZone::reorganizeCards()
|
||||||
if (!cards.isEmpty()) {
|
if (!cards.isEmpty()) {
|
||||||
QSet<ArrowItem *> arrowsToUpdate;
|
QSet<ArrowItem *> arrowsToUpdate;
|
||||||
|
|
||||||
const int cardCount = cards.size();
|
const auto cardCount = static_cast<int>(cards.size());
|
||||||
qreal totalWidth = boundingRect().width();
|
qreal totalWidth = boundingRect().width();
|
||||||
qreal cardWidth = cards.at(0)->boundingRect().width();
|
qreal cardWidth = cards.at(0)->boundingRect().width();
|
||||||
qreal xspace = 5;
|
qreal xspace = 5;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue