mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -07:00
Rework card menu handling (#6069)
* extract cardMenu from CardItem * move cardMenu saving to TabGame * delete TabGame::updateCardMenu * move checking to updateCardMenu * unset activeCard when all cards are unselected
This commit is contained in:
parent
1649f30389
commit
03bebbe4c2
6 changed files with 106 additions and 123 deletions
|
|
@ -261,6 +261,10 @@ void TabGame::retranslateUi()
|
|||
sayLabel->setText(tr("&Say:"));
|
||||
}
|
||||
|
||||
if (aCardMenu) {
|
||||
aCardMenu->setText(tr("Selected cards"));
|
||||
}
|
||||
|
||||
viewMenu->setTitle(tr("&View"));
|
||||
cardInfoDockMenu->setTitle(tr("Card Info"));
|
||||
messageLayoutDockMenu->setTitle(tr("Messages"));
|
||||
|
|
@ -576,6 +580,7 @@ Player *TabGame::addPlayer(int playerId, const ServerInfo_User &info)
|
|||
scene->addPlayer(newPlayer);
|
||||
|
||||
connect(newPlayer, &Player::newCardAdded, this, &TabGame::newCardAdded);
|
||||
connect(newPlayer, &Player::cardMenuUpdated, this, &TabGame::setCardMenu);
|
||||
messageLog->connectToPlayer(newPlayer);
|
||||
|
||||
if (local && !spectator) {
|
||||
|
|
@ -1213,22 +1218,17 @@ Player *TabGame::getActiveLocalPlayer() const
|
|||
void TabGame::setActiveCard(CardItem *card)
|
||||
{
|
||||
activeCard = card;
|
||||
updateCardMenu(card);
|
||||
}
|
||||
|
||||
void TabGame::updateCardMenu(AbstractCardItem *card)
|
||||
/**
|
||||
* @param menu The menu to set. Pass in nullptr to set the menu to empty.
|
||||
*/
|
||||
void TabGame::setCardMenu(QMenu *menu)
|
||||
{
|
||||
if (card == nullptr) {
|
||||
return;
|
||||
}
|
||||
Player *player;
|
||||
if ((clients.size() > 1) || !players.contains(localPlayerId)) {
|
||||
player = card->getOwner();
|
||||
if (menu) {
|
||||
aCardMenu->setMenu(menu);
|
||||
} else {
|
||||
player = players.value(localPlayerId);
|
||||
}
|
||||
if (player != nullptr) {
|
||||
player->updateCardMenu(static_cast<CardItem *>(card));
|
||||
aCardMenu->setMenu(new QMenu);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1285,6 +1285,11 @@ void TabGame::createMenuItems()
|
|||
gameMenu->addAction(aConcede);
|
||||
gameMenu->addAction(aFocusChat);
|
||||
gameMenu->addAction(aLeaveGame);
|
||||
|
||||
gameMenu->addSeparator();
|
||||
|
||||
aCardMenu = gameMenu->addMenu(new QMenu(this));
|
||||
|
||||
addTabMenu(gameMenu);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue