implement a maximum amount of cardmenus generated for views (#4262)
This commit is contained in:
parent
8e1d7d12e0
commit
00ed5c370c
3 changed files with 23 additions and 9 deletions
|
@ -18,9 +18,15 @@
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, bool _revealedCard, QGraphicsItem *parent)
|
CardItem::CardItem(Player *_owner,
|
||||||
: AbstractCardItem(_name, _owner, _cardid, parent), zone(0), revealedCard(_revealedCard), attacking(false),
|
const QString &_name,
|
||||||
destroyOnZoneChange(false), doesntUntap(false), dragItem(0), attachedTo(0)
|
int _cardid,
|
||||||
|
bool _revealedCard,
|
||||||
|
QGraphicsItem *parent,
|
||||||
|
CardZone *_zone,
|
||||||
|
bool updateMenu)
|
||||||
|
: AbstractCardItem(_name, _owner, _cardid, parent), zone(_zone), revealedCard(_revealedCard), attacking(false),
|
||||||
|
destroyOnZoneChange(false), doesntUntap(false), dragItem(nullptr), attachedTo(nullptr)
|
||||||
{
|
{
|
||||||
owner->addCard(this);
|
owner->addCard(this);
|
||||||
|
|
||||||
|
@ -29,7 +35,9 @@ CardItem::CardItem(Player *_owner, const QString &_name, int _cardid, bool _reve
|
||||||
moveMenu = new QMenu;
|
moveMenu = new QMenu;
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
if (updateMenu) { // avoid updating card menu too often
|
||||||
emit updateCardMenu(this);
|
emit updateCardMenu(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CardItem::~CardItem()
|
CardItem::~CardItem()
|
||||||
|
@ -382,7 +390,7 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (owner != nullptr){ // cards without owner will be deleted
|
if (owner != nullptr) { // cards without owner will be deleted
|
||||||
setCursor(Qt::OpenHandCursor);
|
setCursor(Qt::OpenHandCursor);
|
||||||
}
|
}
|
||||||
AbstractCardItem::mouseReleaseEvent(event);
|
AbstractCardItem::mouseReleaseEvent(event);
|
||||||
|
|
|
@ -52,7 +52,9 @@ public:
|
||||||
const QString &_name = QString(),
|
const QString &_name = QString(),
|
||||||
int _cardid = -1,
|
int _cardid = -1,
|
||||||
bool revealedCard = false,
|
bool revealedCard = false,
|
||||||
QGraphicsItem *parent = nullptr);
|
QGraphicsItem *parent = nullptr,
|
||||||
|
CardZone *_zone = nullptr,
|
||||||
|
bool updateMenu = false);
|
||||||
~CardItem();
|
~CardItem();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
CardZone *getZone() const
|
CardZone *getZone() const
|
||||||
|
|
|
@ -83,15 +83,19 @@ void ZoneViewZone::initializeCards(const QList<const ServerInfo_Card *> &cardLis
|
||||||
|
|
||||||
void ZoneViewZone::zoneDumpReceived(const Response &r)
|
void ZoneViewZone::zoneDumpReceived(const Response &r)
|
||||||
{
|
{
|
||||||
|
static constexpr int MAX_VIEW_MENU = 300;
|
||||||
const Response_DumpZone &resp = r.GetExtension(Response_DumpZone::ext);
|
const Response_DumpZone &resp = r.GetExtension(Response_DumpZone::ext);
|
||||||
const int respCardListSize = resp.zone_info().card_list_size();
|
const int respCardListSize = resp.zone_info().card_list_size();
|
||||||
for (int i = 0; i < respCardListSize; ++i) {
|
for (int i = 0; i < respCardListSize; ++i) {
|
||||||
const ServerInfo_Card &cardInfo = resp.zone_info().card_list(i);
|
const ServerInfo_Card &cardInfo = resp.zone_info().card_list(i);
|
||||||
CardItem *card = new CardItem(player, QString::fromStdString(cardInfo.name()), cardInfo.id(), revealZone, this);
|
auto cardName = QString::fromStdString(cardInfo.name());
|
||||||
addCard(card, false, i);
|
// stop updating card menus after MAX_VIEW_MENU cards
|
||||||
|
// this means only the first cards in the menu have actions but others can still be dragged
|
||||||
|
auto *card = new CardItem(player, cardName, cardInfo.id(), revealZone, this, this, i < MAX_VIEW_MENU);
|
||||||
|
cards.insert(i, card);
|
||||||
}
|
}
|
||||||
|
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
|
emit cardCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because of boundingRect(), this function must not be called before the zone was added to a scene.
|
// Because of boundingRect(), this function must not be called before the zone was added to a scene.
|
||||||
|
|
Loading…
Reference in a new issue