allow multiple zoneviews (#4263)
This commit is contained in:
parent
1811f7305e
commit
8e1d7d12e0
5 changed files with 38 additions and 32 deletions
|
@ -18,7 +18,7 @@ CardZone::CardZone(Player *_p,
|
||||||
bool _contentsKnown,
|
bool _contentsKnown,
|
||||||
QGraphicsItem *parent,
|
QGraphicsItem *parent,
|
||||||
bool _isView)
|
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)
|
doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable), isView(_isView)
|
||||||
{
|
{
|
||||||
if (!isView)
|
if (!isView)
|
||||||
|
@ -28,7 +28,11 @@ CardZone::CardZone(Player *_p,
|
||||||
CardZone::~CardZone()
|
CardZone::~CardZone()
|
||||||
{
|
{
|
||||||
qDebug() << "CardZone destructor: " << name;
|
qDebug() << "CardZone destructor: " << name;
|
||||||
delete view;
|
for (auto *view : views) {
|
||||||
|
if (view != nullptr) {
|
||||||
|
view->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
clearContents();
|
clearContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +124,11 @@ void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
|
||||||
void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
||||||
{
|
{
|
||||||
if (view)
|
for (auto *view : views) {
|
||||||
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1))
|
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) {
|
||||||
view->addCard(new CardItem(player, card->getName(), card->getId()), reorganize, x, y);
|
view->addCard(new CardItem(player, card->getName(), card->getId()), reorganize, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
card->setZone(this);
|
card->setZone(this);
|
||||||
addCardImpl(card, x, y);
|
addCardImpl(card, x, y);
|
||||||
|
@ -168,8 +174,9 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/)
|
||||||
|
|
||||||
CardItem *c = cards.takeAt(position);
|
CardItem *c = cards.takeAt(position);
|
||||||
|
|
||||||
if (view)
|
for (auto *view : views) {
|
||||||
view->removeCard(position);
|
view->removeCard(position);
|
||||||
|
}
|
||||||
|
|
||||||
c->setId(cardId);
|
c->setId(cardId);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ protected:
|
||||||
Player *player;
|
Player *player;
|
||||||
QString name;
|
QString name;
|
||||||
CardList cards;
|
CardList cards;
|
||||||
ZoneViewZone *view;
|
QList<ZoneViewZone *> views;
|
||||||
QMenu *menu;
|
QMenu *menu;
|
||||||
QAction *doubleClickAction;
|
QAction *doubleClickAction;
|
||||||
bool hasCardAttr;
|
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.
|
// 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);
|
virtual CardItem *takeCard(int position, int cardId, bool canResize = true);
|
||||||
void removeCard(CardItem *card);
|
void removeCard(CardItem *card);
|
||||||
ZoneViewZone *getView() const
|
QList<ZoneViewZone *> &getViews()
|
||||||
{
|
{
|
||||||
return view;
|
return views;
|
||||||
}
|
|
||||||
void setView(ZoneViewZone *_view)
|
|
||||||
{
|
|
||||||
view = _view;
|
|
||||||
}
|
}
|
||||||
virtual void reorganizeCards() = 0;
|
virtual void reorganizeCards() = 0;
|
||||||
virtual QPointF closestGridPoint(const QPointF &point);
|
virtual QPointF closestGridPoint(const QPointF &point);
|
||||||
|
|
|
@ -144,12 +144,10 @@ void GameScene::rearrange()
|
||||||
|
|
||||||
void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numberCards)
|
void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numberCards)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < zoneViews.size(); i++) {
|
for (auto &view : zoneViews) {
|
||||||
ZoneViewZone *temp = zoneViews[i]->getZone();
|
ZoneViewZone *temp = view->getZone();
|
||||||
if ((temp->getName() == zoneName) && (temp->getPlayer() == player)) { // view is already open
|
if (temp->getName() == zoneName && temp->getPlayer() == player && temp->getNumberCards() == numberCards) {
|
||||||
zoneViews[i]->close();
|
view->close();
|
||||||
if (temp->getNumberCards() == numberCards)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,12 +155,13 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
|
||||||
zoneViews.append(item);
|
zoneViews.append(item);
|
||||||
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeZoneView(ZoneViewWidget *)));
|
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeZoneView(ZoneViewWidget *)));
|
||||||
addItem(item);
|
addItem(item);
|
||||||
if (zoneName == "grave")
|
if (zoneName == "grave") {
|
||||||
item->setPos(360, 100);
|
item->setPos(360, 100);
|
||||||
else if (zoneName == "rfg")
|
} else if (zoneName == "rfg") {
|
||||||
item->setPos(380, 120);
|
item->setPos(380, 120);
|
||||||
else
|
} else {
|
||||||
item->setPos(340, 80);
|
item->setPos(340, 80);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::addRevealedZoneView(Player *player,
|
void GameScene::addRevealedZoneView(Player *player,
|
||||||
|
|
|
@ -1552,8 +1552,10 @@ void Player::eventShuffle(const Event_Shuffle &event)
|
||||||
if (!zone) {
|
if (!zone) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (zone->getView() && zone->getView()->getRevealZone()) {
|
for (auto *view : zone->getViews()) {
|
||||||
zone->getView()->setWriteableRevealZone(false);
|
if (view != nullptr) {
|
||||||
|
view->setWriteableRevealZone(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
emit logShuffle(this, zone, event.start(), event.end());
|
emit logShuffle(this, zone, event.start(), event.end());
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,16 +26,18 @@ ZoneViewZone::ZoneViewZone(Player *_p,
|
||||||
numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone),
|
numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone),
|
||||||
writeableRevealZone(_writeableRevealZone), sortByName(false), sortByType(false)
|
writeableRevealZone(_writeableRevealZone), sortByName(false), sortByType(false)
|
||||||
{
|
{
|
||||||
if (!(revealZone && !writeableRevealZone))
|
if (!(revealZone && !writeableRevealZone)) {
|
||||||
origZone->setView(this);
|
origZone->getViews().append(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneViewZone::~ZoneViewZone()
|
ZoneViewZone::~ZoneViewZone()
|
||||||
{
|
{
|
||||||
emit beingDeleted();
|
emit beingDeleted();
|
||||||
qDebug("ZoneViewZone destructor");
|
qDebug("ZoneViewZone destructor");
|
||||||
if (!(revealZone && !writeableRevealZone))
|
if (!(revealZone && !writeableRevealZone)) {
|
||||||
origZone->setView(NULL);
|
origZone->getViews().removeOne(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF ZoneViewZone::boundingRect() const
|
QRectF ZoneViewZone::boundingRect() const
|
||||||
|
@ -238,11 +240,11 @@ QSizeF ZoneViewZone::sizeHint(Qt::SizeHint /*which*/, const QSizeF & /*constrain
|
||||||
|
|
||||||
void ZoneViewZone::setWriteableRevealZone(bool _writeableRevealZone)
|
void ZoneViewZone::setWriteableRevealZone(bool _writeableRevealZone)
|
||||||
{
|
{
|
||||||
if (writeableRevealZone && !_writeableRevealZone)
|
if (writeableRevealZone && !_writeableRevealZone) {
|
||||||
origZone->setView(this);
|
origZone->getViews().append(this);
|
||||||
else if (!writeableRevealZone && _writeableRevealZone)
|
} else if (!writeableRevealZone && _writeableRevealZone) {
|
||||||
origZone->setView(NULL);
|
origZone->getViews().removeOne(this);
|
||||||
|
}
|
||||||
writeableRevealZone = _writeableRevealZone;
|
writeableRevealZone = _writeableRevealZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue