mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 03:23:56 -07:00
Support viewing the bottom X cards of library (#5410)
* Get cardIds to update properly in bottom view (#5414) * Get bottom view to update properly when card is inserted into known portion (#5415) --------- Co-authored-by: RickyRister <42636155+RickyRister@users.noreply.github.com>
This commit is contained in:
parent
81b85e97df
commit
6078dd092a
17 changed files with 154 additions and 41 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include "../player/player.h"
|
||||
#include "pb/command_move_card.pb.h"
|
||||
#include "pb/serverinfo_user.pb.h"
|
||||
#include "pile_zone.h"
|
||||
#include "view_zone.h"
|
||||
|
||||
#include <QAction>
|
||||
|
|
@ -151,7 +152,7 @@ void CardZone::addCard(CardItem *card, const bool reorganize, const int x, const
|
|||
}
|
||||
|
||||
for (auto *view : views) {
|
||||
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) {
|
||||
if (view->getIsReversed() || (x <= view->getCards().size()) || (view->getNumberCards() == -1)) {
|
||||
view->addCard(new CardItem(player, nullptr, card->getName(), card->getProviderId(), card->getId()),
|
||||
reorganize, x, y);
|
||||
}
|
||||
|
|
@ -199,12 +200,12 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/)
|
|||
if (position >= cards.size())
|
||||
return nullptr;
|
||||
|
||||
CardItem *c = cards.takeAt(position);
|
||||
|
||||
for (auto *view : views) {
|
||||
view->removeCard(position);
|
||||
}
|
||||
|
||||
CardItem *c = cards.takeAt(position);
|
||||
|
||||
c->setId(cardId);
|
||||
|
||||
reorganizeCards();
|
||||
|
|
|
|||
|
|
@ -28,10 +28,12 @@ ZoneViewZone::ZoneViewZone(Player *_p,
|
|||
int _numberCards,
|
||||
bool _revealZone,
|
||||
bool _writeableRevealZone,
|
||||
QGraphicsItem *parent)
|
||||
QGraphicsItem *parent,
|
||||
bool _isReversed)
|
||||
: SelectZone(_p, _origZone->getName(), false, false, true, parent, true), bRect(QRectF()), minRows(0),
|
||||
numberCards(_numberCards), origZone(_origZone), revealZone(_revealZone),
|
||||
writeableRevealZone(_writeableRevealZone), groupBy(CardList::NoSort), sortBy(CardList::NoSort)
|
||||
writeableRevealZone(_writeableRevealZone), groupBy(CardList::NoSort), sortBy(CardList::NoSort),
|
||||
isReversed(_isReversed)
|
||||
{
|
||||
if (!(revealZone && !writeableRevealZone)) {
|
||||
origZone->getViews().append(this);
|
||||
|
|
@ -72,6 +74,7 @@ void ZoneViewZone::initializeCards(const QList<const ServerInfo_Card *> &cardLis
|
|||
cmd.set_player_id(player->getId());
|
||||
cmd.set_zone_name(name.toStdString());
|
||||
cmd.set_number_cards(numberCards);
|
||||
cmd.set_is_reversed(isReversed);
|
||||
|
||||
PendingCommand *pend = player->prepareGameCommand(cmd);
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||
|
|
@ -100,18 +103,49 @@ void ZoneViewZone::zoneDumpReceived(const Response &r)
|
|||
auto *card = new CardItem(player, this, cardName, cardProviderId, cardInfo.id(), revealZone, this);
|
||||
cards.insert(i, card);
|
||||
}
|
||||
|
||||
updateCardIds(INITIALIZE);
|
||||
reorganizeCards();
|
||||
emit cardCountChanged();
|
||||
}
|
||||
|
||||
void ZoneViewZone::updateCardIds(CardAction action)
|
||||
{
|
||||
if (origZone->contentsKnown()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cards.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int cardCount = cards.size();
|
||||
|
||||
auto startId = 0;
|
||||
|
||||
if (isReversed) {
|
||||
// the card has not been added to origZone's cardList at this point
|
||||
startId = origZone->getCards().size() - cardCount;
|
||||
switch (action) {
|
||||
case INITIALIZE:
|
||||
break;
|
||||
case ADD_CARD:
|
||||
startId += 1;
|
||||
break;
|
||||
case REMOVE_CARD:
|
||||
startId -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < cardCount; ++i) {
|
||||
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()
|
||||
{
|
||||
int cardCount = cards.size();
|
||||
if (!origZone->contentsKnown())
|
||||
for (int i = 0; i < cardCount; ++i)
|
||||
cards[i]->setId(i);
|
||||
|
||||
CardList cardsToDisplay(cards);
|
||||
|
||||
// sort cards
|
||||
|
|
@ -244,13 +278,30 @@ void ZoneViewZone::setPileView(int _pileView)
|
|||
|
||||
void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||
{
|
||||
// if x is negative set it to add at end
|
||||
if (x < 0 || x >= cards.size()) {
|
||||
x = cards.size();
|
||||
if (!isReversed) {
|
||||
// if x is negative set it to add at end
|
||||
if (x < 0) {
|
||||
x = cards.size();
|
||||
}
|
||||
cards.insert(x, card);
|
||||
} else {
|
||||
// map x (which is in origZone indexes) to this viewZone's cardList index
|
||||
int firstId = cards.isEmpty() ? origZone->getCards().size() : cards.front()->getId();
|
||||
int insertionIndex = x - firstId;
|
||||
if (insertionIndex >= 0) {
|
||||
// card was put into a portion of the deck that's in the view
|
||||
cards.insert(insertionIndex, card);
|
||||
} else {
|
||||
// card was put into a portion of the deck that's not in the view
|
||||
updateCardIds(ADD_CARD);
|
||||
return;
|
||||
}
|
||||
}
|
||||
cards.insert(x, card);
|
||||
|
||||
card->setParentItem(this);
|
||||
card->update();
|
||||
|
||||
updateCardIds(ADD_CARD);
|
||||
reorganizeCards();
|
||||
}
|
||||
|
||||
|
|
@ -265,6 +316,7 @@ void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
|||
cmd.set_target_zone(getName().toStdString());
|
||||
cmd.set_x(0);
|
||||
cmd.set_y(0);
|
||||
cmd.set_is_reversed(isReversed);
|
||||
|
||||
for (int i = 0; i < dragItems.size(); ++i)
|
||||
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
|
||||
|
|
@ -274,11 +326,21 @@ void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
|||
|
||||
void ZoneViewZone::removeCard(int position)
|
||||
{
|
||||
if (position >= cards.size())
|
||||
if (isReversed) {
|
||||
position -= cards.first()->getId();
|
||||
if (position < 0 || position >= cards.size()) {
|
||||
updateCardIds(REMOVE_CARD);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (position >= cards.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CardItem *card = cards.takeAt(position);
|
||||
card->deleteLater();
|
||||
updateCardIds(REMOVE_CARD);
|
||||
reorganizeCards();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,16 @@ private:
|
|||
bool revealZone, writeableRevealZone;
|
||||
CardList::SortOption groupBy, sortBy;
|
||||
bool pileView;
|
||||
bool isReversed;
|
||||
|
||||
enum CardAction
|
||||
{
|
||||
INITIALIZE,
|
||||
ADD_CARD,
|
||||
REMOVE_CARD
|
||||
};
|
||||
|
||||
void updateCardIds(CardAction action);
|
||||
|
||||
struct GridSize
|
||||
{
|
||||
|
|
@ -49,7 +59,8 @@ public:
|
|||
int _numberCards = -1,
|
||||
bool _revealZone = false,
|
||||
bool _writeableRevealZone = false,
|
||||
QGraphicsItem *parent = nullptr);
|
||||
QGraphicsItem *parent = nullptr,
|
||||
bool _isReversed = false);
|
||||
~ZoneViewZone();
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
|
|
@ -74,6 +85,10 @@ public:
|
|||
return writeableRevealZone;
|
||||
}
|
||||
void setWriteableRevealZone(bool _writeableRevealZone);
|
||||
bool getIsReversed() const
|
||||
{
|
||||
return isReversed;
|
||||
}
|
||||
public slots:
|
||||
void setGroupBy(CardList::SortOption _groupBy);
|
||||
void setSortBy(CardList::SortOption _sortBy);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
|
|||
int numberCards,
|
||||
bool _revealZone,
|
||||
bool _writeableRevealZone,
|
||||
const QList<const ServerInfo_Card *> &cardList)
|
||||
const QList<const ServerInfo_Card *> &cardList,
|
||||
bool _isReversed)
|
||||
: QGraphicsWidget(0, Qt::Window), canBeShuffled(_origZone->getIsShufflable()), player(_player)
|
||||
{
|
||||
setAcceptHoverEvents(true);
|
||||
|
|
@ -107,7 +108,8 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
|
|||
|
||||
vbox->addItem(zoneHBox);
|
||||
|
||||
zone = new ZoneViewZone(player, _origZone, numberCards, _revealZone, _writeableRevealZone, zoneContainer);
|
||||
zone =
|
||||
new ZoneViewZone(player, _origZone, numberCards, _revealZone, _writeableRevealZone, zoneContainer, _isReversed);
|
||||
connect(zone, SIGNAL(wheelEventReceived(QGraphicsSceneWheelEvent *)), scrollBarProxy,
|
||||
SLOT(recieveWheelEvent(QGraphicsSceneWheelEvent *)));
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ public:
|
|||
int numberCards = 0,
|
||||
bool _revealZone = false,
|
||||
bool _writeableRevealZone = false,
|
||||
const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>());
|
||||
const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>(),
|
||||
bool _isReversed = false);
|
||||
ZoneViewZone *getZone() const
|
||||
{
|
||||
return zone;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue