move checking to updateCardMenu

This commit is contained in:
RickyRister 2025-08-05 23:28:07 -03:00
parent 32d13062ff
commit 5e028abee3

View file

@ -3892,9 +3892,7 @@ void Player::refreshShortcuts()
QMenu *Player::createCardMenu(const CardItem *card) QMenu *Player::createCardMenu(const CardItem *card)
{ {
// If bad card OR is a spectator (as spectators don't need card menus), return if (card == nullptr) {
// only update the menu if the card is actually selected
if (card == nullptr || (game->isSpectator() && !judge) || game->getActiveCard() != card) {
return nullptr; return nullptr;
} }
@ -4218,18 +4216,27 @@ void Player::addRelatedCardActions(const CardItem *card, QMenu *cardMenu)
/** /**
* Creates a card menu from the given card and sets it as the currently active card menu. * Creates a card menu from the given card and sets it as the currently active card menu.
* Will first check if the card should have a card menu, and no-ops if not.
* *
* @param card The card to create the menu for. Pass nullptr to disable the card menu. * @param card The card to create the menu for. Pass nullptr to disable the card menu.
* @return The new card menu * @return The new card menu, or nullptr if failed.
*/ */
QMenu *Player::updateCardMenu(const CardItem *card) QMenu *Player::updateCardMenu(const CardItem *card)
{ {
QMenu *menu = createCardMenu(card); if (!card) {
emit cardMenuUpdated(nullptr);
if (menu) { return nullptr;
emit cardMenuUpdated(menu);
} }
// If is spectator (as spectators don't need card menus), return
// only update the menu if the card is actually selected
if ((game->isSpectator() && !judge) || game->getActiveCard() != card) {
return nullptr;
}
QMenu *menu = createCardMenu(card);
emit cardMenuUpdated(menu);
return menu; return menu;
} }