allow multiple zoneviews (#4263)

This commit is contained in:
ebbit1q 2021-03-13 20:43:50 +01:00 committed by GitHub
parent 1811f7305e
commit 8e1d7d12e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 32 deletions

View file

@ -18,7 +18,7 @@ CardZone::CardZone(Player *_p,
bool _contentsKnown,
QGraphicsItem *parent,
bool _isView)
: AbstractGraphicsItem(parent), player(_p), name(_name), cards(_contentsKnown), view(NULL), menu(NULL),
: AbstractGraphicsItem(parent), player(_p), name(_name), cards(_contentsKnown), views{}, menu(nullptr),
doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable), isView(_isView)
{
if (!isView)
@ -28,7 +28,11 @@ CardZone::CardZone(Player *_p,
CardZone::~CardZone()
{
qDebug() << "CardZone destructor: " << name;
delete view;
for (auto *view : views) {
if (view != nullptr) {
view->deleteLater();
}
}
clearContents();
}
@ -120,9 +124,11 @@ void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
{
if (view)
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1))
for (auto *view : views) {
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) {
view->addCard(new CardItem(player, card->getName(), card->getId()), reorganize, x, y);
}
}
card->setZone(this);
addCardImpl(card, x, y);
@ -168,8 +174,9 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/)
CardItem *c = cards.takeAt(position);
if (view)
for (auto *view : views) {
view->removeCard(position);
}
c->setId(cardId);

View file

@ -21,7 +21,7 @@ protected:
Player *player;
QString name;
CardList cards;
ZoneViewZone *view;
QList<ZoneViewZone *> views;
QMenu *menu;
QAction *doubleClickAction;
bool hasCardAttr;
@ -98,13 +98,9 @@ public:
// takeCard() finds a card by position and removes it from the zone and from all of its views.
virtual CardItem *takeCard(int position, int cardId, bool canResize = true);
void removeCard(CardItem *card);
ZoneViewZone *getView() const
QList<ZoneViewZone *> &getViews()
{
return view;
}
void setView(ZoneViewZone *_view)
{
view = _view;
return views;
}
virtual void reorganizeCards() = 0;
virtual QPointF closestGridPoint(const QPointF &point);

View file

@ -144,12 +144,10 @@ void GameScene::rearrange()
void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numberCards)
{
for (int i = 0; i < zoneViews.size(); i++) {
ZoneViewZone *temp = zoneViews[i]->getZone();
if ((temp->getName() == zoneName) && (temp->getPlayer() == player)) { // view is already open
zoneViews[i]->close();
if (temp->getNumberCards() == numberCards)
return;
for (auto &view : zoneViews) {
ZoneViewZone *temp = view->getZone();
if (temp->getName() == zoneName && temp->getPlayer() == player && temp->getNumberCards() == numberCards) {
view->close();
}
}
@ -157,12 +155,13 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
zoneViews.append(item);
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeZoneView(ZoneViewWidget *)));
addItem(item);
if (zoneName == "grave")
if (zoneName == "grave") {
item->setPos(360, 100);
else if (zoneName == "rfg")
} else if (zoneName == "rfg") {
item->setPos(380, 120);
else
} else {
item->setPos(340, 80);
}
}
void GameScene::addRevealedZoneView(Player *player,

View file

@ -1552,8 +1552,10 @@ void Player::eventShuffle(const Event_Shuffle &event)
if (!zone) {
return;
}
if (zone->getView() && zone->getView()->getRevealZone()) {
zone->getView()->setWriteableRevealZone(false);
for (auto *view : zone->getViews()) {
if (view != nullptr) {
view->setWriteableRevealZone(false);
}
}
emit logShuffle(this, zone, event.start(), event.end());
}

View file

@ -26,16 +26,18 @@ ZoneViewZone::ZoneViewZone(Player *_p,
numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone),
writeableRevealZone(_writeableRevealZone), sortByName(false), sortByType(false)
{
if (!(revealZone && !writeableRevealZone))
origZone->setView(this);
if (!(revealZone && !writeableRevealZone)) {
origZone->getViews().append(this);
}
}
ZoneViewZone::~ZoneViewZone()
{
emit beingDeleted();
qDebug("ZoneViewZone destructor");
if (!(revealZone && !writeableRevealZone))
origZone->setView(NULL);
if (!(revealZone && !writeableRevealZone)) {
origZone->getViews().removeOne(this);
}
}
QRectF ZoneViewZone::boundingRect() const
@ -238,11 +240,11 @@ QSizeF ZoneViewZone::sizeHint(Qt::SizeHint /*which*/, const QSizeF & /*constrain
void ZoneViewZone::setWriteableRevealZone(bool _writeableRevealZone)
{
if (writeableRevealZone && !_writeableRevealZone)
origZone->setView(this);
else if (!writeableRevealZone && _writeableRevealZone)
origZone->setView(NULL);
if (writeableRevealZone && !_writeableRevealZone) {
origZone->getViews().append(this);
} else if (!writeableRevealZone && _writeableRevealZone) {
origZone->getViews().removeOne(this);
}
writeableRevealZone = _writeableRevealZone;
}