-> The menus have the update menu thing emitted when they get triggered.
| -> works surprising well https://youtu.be/KOOmhxvHA2c is a demo on a 10000ish card deck
This commit is contained in:
Danny Piper 2021-05-12 20:40:31 +01:00
parent 0a73162bcf
commit 34d500cfaf
No known key found for this signature in database
GPG key ID: 5E365B8F351ACB38
2 changed files with 9 additions and 8 deletions

View file

@ -36,7 +36,10 @@ CardItem::CardItem(Player *_owner,
retranslateUi();
if (updateMenu) { // avoid updating card menu too often
emit updateCardMenu(this);
// Add a lambda that updates the card menu on right clicked
connect(getPTMenu(), &QMenu::triggered, this, [this] { emit updateCardMenu(this); });
connect(getCardMenu(), &QMenu::triggered, this, [this] { emit updateCardMenu(this); });
connect(getMoveMenu(), &QMenu::triggered, this, [this] { emit updateCardMenu(this); });
}
}
@ -84,7 +87,6 @@ void CardItem::deleteLater()
void CardItem::setZone(CardZone *_zone)
{
zone = _zone;
emit updateCardMenu(this);
}
void CardItem::retranslateUi()
@ -372,7 +374,6 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
if (cardMenu && !cardMenu->isEmpty() && owner != nullptr) {
owner->updateCardMenu(this);
cardMenu->exec(event->screenPos());
}
} else if ((event->modifiers() != Qt::AltModifier) && (event->button() == Qt::LeftButton) &&

View file

@ -1946,7 +1946,6 @@ void Player::eventSetCardCounter(const Event_SetCardCounter &event)
int oldValue = card->getCounters().value(event.counter_id(), 0);
card->setCounter(event.counter_id(), event.counter_value());
updateCardMenu(card);
emit logSetCardCounter(this, card->getName(), event.counter_id(), event.counter_value(), oldValue);
}
@ -3295,15 +3294,16 @@ void Player::refreshShortcuts()
{
if (shortcutsActive) {
setShortcutsActive();
for (const CardItem *cardItem : table->getCards()) {
updateCardMenu(cardItem);
}
}
}
void Player::updateCardMenu(const CardItem *card)
{
/**
* Regarding issue https://github.com/Cockatrice/Cockatrice/issues/4284
* The best fix is to add the QActions when a card is right clicked on,
* so this method is not needed
*/
// If bad card OR is a spectator (as spectators don't need card menus), return
if (card == nullptr || (game->isSpectator() && !judge)) {
return;