mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -07:00
Get cardIds to update properly in bottom view (#5414)
* wip * refactor * saving before changing something * unborked * almost works * it works!!!!!!!! * cleanup
This commit is contained in:
parent
6fdee56d09
commit
db1b481ef8
5 changed files with 43 additions and 16 deletions
|
|
@ -151,7 +151,8 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneViewWidget *item = new ZoneViewWidget(player, player->getZones().value(zoneName), numberCards, false, false, {}, isReversed);
|
ZoneViewWidget *item =
|
||||||
|
new ZoneViewWidget(player, player->getZones().value(zoneName), numberCards, false, false, {}, isReversed);
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -200,12 +200,12 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/)
|
||||||
if (position >= cards.size())
|
if (position >= cards.size())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
CardItem *c = cards.takeAt(position);
|
|
||||||
|
|
||||||
for (auto *view : views) {
|
for (auto *view : views) {
|
||||||
view->removeCard(position);
|
view->removeCard(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CardItem *c = cards.takeAt(position);
|
||||||
|
|
||||||
c->setId(cardId);
|
c->setId(cardId);
|
||||||
|
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ ZoneViewZone::ZoneViewZone(Player *_p,
|
||||||
: SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0),
|
: SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0),
|
||||||
numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone),
|
numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone),
|
||||||
writeableRevealZone(_writeableRevealZone), groupBy(CardList::NoSort), sortBy(CardList::NoSort),
|
writeableRevealZone(_writeableRevealZone), groupBy(CardList::NoSort), sortBy(CardList::NoSort),
|
||||||
isReversed(_isReversed), firstCardId(-1)
|
isReversed(_isReversed)
|
||||||
{
|
{
|
||||||
if (!(revealZone && !writeableRevealZone)) {
|
if (!(revealZone && !writeableRevealZone)) {
|
||||||
origZone->getViews().append(this);
|
origZone->getViews().append(this);
|
||||||
|
|
@ -102,17 +102,14 @@ void ZoneViewZone::zoneDumpReceived(const Response &r)
|
||||||
auto cardProviderId = QString::fromStdString(cardInfo.provider_id());
|
auto cardProviderId = QString::fromStdString(cardInfo.provider_id());
|
||||||
auto *card = new CardItem(player, this, cardName, cardProviderId, cardInfo.id(), revealZone, this);
|
auto *card = new CardItem(player, this, cardName, cardProviderId, cardInfo.id(), revealZone, this);
|
||||||
cards.insert(i, card);
|
cards.insert(i, card);
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
firstCardId = cardInfo.id();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateCardIds(INITIALIZE);
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
emit cardCountChanged();
|
emit cardCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because of boundingRect(), this function must not be called before the zone was added to a scene.
|
void ZoneViewZone::updateCardIds(CardAction action)
|
||||||
void ZoneViewZone::reorganizeCards()
|
|
||||||
{
|
{
|
||||||
int cardCount = cards.size();
|
int cardCount = cards.size();
|
||||||
if (!origZone->contentsKnown()) {
|
if (!origZone->contentsKnown()) {
|
||||||
|
|
@ -120,11 +117,20 @@ void ZoneViewZone::reorganizeCards()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto startId = isReversed ? cards.first()->getId() : 0;
|
auto startId = 0;
|
||||||
|
|
||||||
if (isReversed) {
|
if (isReversed) {
|
||||||
if (cards.first()->getId() != firstCardId) {
|
// these get called after this zone's card list updates but before parent zone's card list updates
|
||||||
startId -= 1;
|
startId = origZone->getCards().size() - cards.size();
|
||||||
|
switch (action) {
|
||||||
|
case INITIALIZE:
|
||||||
|
break;
|
||||||
|
case ADD_CARD:
|
||||||
|
startId += 1;
|
||||||
|
break;
|
||||||
|
case REMOVE_CARD:
|
||||||
|
startId -= 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,7 +138,11 @@ void ZoneViewZone::reorganizeCards()
|
||||||
cards[i]->setId(i + startId);
|
cards[i]->setId(i + startId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Because of boundingRect(), this function must not be called before the zone was added to a scene.
|
||||||
|
void ZoneViewZone::reorganizeCards()
|
||||||
|
{
|
||||||
CardList cardsToDisplay(cards);
|
CardList cardsToDisplay(cards);
|
||||||
|
|
||||||
// sort cards
|
// sort cards
|
||||||
|
|
@ -231,7 +241,7 @@ ZoneViewZone::GridSize ZoneViewZone::positionCardsForDisplay(CardList &cards, Ca
|
||||||
if (cols < 2)
|
if (cols < 2)
|
||||||
cols = 2;
|
cols = 2;
|
||||||
|
|
||||||
qDebug() << "reorganizeCards: rows=" << rows << "cols=" << cols;
|
qDebug() << "reorganizeCards: rows=" << rows << "cols=" << cols;
|
||||||
|
|
||||||
for (int i = 0; i < cardCount; i++) {
|
for (int i = 0; i < cardCount; i++) {
|
||||||
CardItem *c = cards.at(i);
|
CardItem *c = cards.at(i);
|
||||||
|
|
@ -274,13 +284,18 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
if (x != 0) {
|
if (x != 0) {
|
||||||
cards.append(card);
|
cards.append(card);
|
||||||
} else {
|
} else {
|
||||||
|
updateCardIds(ADD_CARD);
|
||||||
|
reorganizeCards();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cards.insert(x, card);
|
cards.insert(x, card);
|
||||||
}
|
}
|
||||||
|
|
||||||
card->setParentItem(this);
|
card->setParentItem(this);
|
||||||
card->update();
|
card->update();
|
||||||
|
|
||||||
|
updateCardIds(ADD_CARD);
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -308,6 +323,7 @@ void ZoneViewZone::removeCard(int position)
|
||||||
if (isReversed) {
|
if (isReversed) {
|
||||||
position -= cards.first()->getId();
|
position -= cards.first()->getId();
|
||||||
if (position < 0 || position >= cards.size()) {
|
if (position < 0 || position >= cards.size()) {
|
||||||
|
updateCardIds(REMOVE_CARD);
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -319,6 +335,7 @@ void ZoneViewZone::removeCard(int position)
|
||||||
|
|
||||||
CardItem *card = cards.takeAt(position);
|
CardItem *card = cards.takeAt(position);
|
||||||
card->deleteLater();
|
card->deleteLater();
|
||||||
|
updateCardIds(REMOVE_CARD);
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,15 @@ private:
|
||||||
CardList::SortOption groupBy, sortBy;
|
CardList::SortOption groupBy, sortBy;
|
||||||
bool pileView;
|
bool pileView;
|
||||||
bool isReversed;
|
bool isReversed;
|
||||||
int firstCardId;
|
|
||||||
|
enum CardAction
|
||||||
|
{
|
||||||
|
INITIALIZE,
|
||||||
|
ADD_CARD,
|
||||||
|
REMOVE_CARD
|
||||||
|
};
|
||||||
|
|
||||||
|
void updateCardIds(CardAction action);
|
||||||
|
|
||||||
struct GridSize
|
struct GridSize
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,8 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
|
||||||
|
|
||||||
vbox->addItem(zoneHBox);
|
vbox->addItem(zoneHBox);
|
||||||
|
|
||||||
zone = new ZoneViewZone(player, _origZone, numberCards, _revealZone, _writeableRevealZone, zoneContainer, _isReversed);
|
zone =
|
||||||
|
new ZoneViewZone(player, _origZone, numberCards, _revealZone, _writeableRevealZone, zoneContainer, _isReversed);
|
||||||
connect(zone, SIGNAL(wheelEventReceived(QGraphicsSceneWheelEvent *)), scrollBarProxy,
|
connect(zone, SIGNAL(wheelEventReceived(QGraphicsSceneWheelEvent *)), scrollBarProxy,
|
||||||
SLOT(recieveWheelEvent(QGraphicsSceneWheelEvent *)));
|
SLOT(recieveWheelEvent(QGraphicsSceneWheelEvent *)));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue