diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index e32158880..8df9cb1cd 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -481,7 +481,8 @@ void MessageLogWidget::logRevealCards(Player *player, QString cardName, Player *otherPlayer, bool faceDown, - int amount) + int amount, + bool isLentToAnotherPlayer) { // getFromStr uses cardname.empty() to check if it should contain the start zone, it's not actually used QPair temp = getFromStr(zone, amount == 1 ? cardName : QString::number(amount), cardId, false); @@ -507,10 +508,17 @@ void MessageLogWidget::logRevealCards(Player *player, } if (cardId == -1) { if (otherPlayer) { - appendHtmlServerMessage(tr("%1 reveals %2 to %3.") - .arg(sanitizeHtml(player->getName())) - .arg(zone->getTranslatedName(true, CaseRevealZone)) - .arg(sanitizeHtml(otherPlayer->getName()))); + if (isLentToAnotherPlayer) { + appendHtmlServerMessage(tr("%1 lends %2 to %3.") + .arg(sanitizeHtml(player->getName())) + .arg(zone->getTranslatedName(true, CaseRevealZone)) + .arg(sanitizeHtml(otherPlayer->getName()))); + } else { + appendHtmlServerMessage(tr("%1 reveals %2 to %3.") + .arg(sanitizeHtml(player->getName())) + .arg(zone->getTranslatedName(true, CaseRevealZone)) + .arg(sanitizeHtml(otherPlayer->getName()))); + } } else { appendHtmlServerMessage(tr("%1 reveals %2.") .arg(sanitizeHtml(player->getName())) @@ -845,8 +853,8 @@ void MessageLogWidget::connectToPlayer(Player *player) connect(player, SIGNAL(logDumpZone(Player *, CardZone *, int)), this, SLOT(logDumpZone(Player *, CardZone *, int))); connect(player, SIGNAL(logDrawCards(Player *, int, bool)), this, SLOT(logDrawCards(Player *, int, bool))); connect(player, SIGNAL(logUndoDraw(Player *, QString)), this, SLOT(logUndoDraw(Player *, QString))); - connect(player, SIGNAL(logRevealCards(Player *, CardZone *, int, QString, Player *, bool, int)), this, - SLOT(logRevealCards(Player *, CardZone *, int, QString, Player *, bool, int))); + connect(player, SIGNAL(logRevealCards(Player *, CardZone *, int, QString, Player *, bool, int, bool)), this, + SLOT(logRevealCards(Player *, CardZone *, int, QString, Player *, bool, int, bool))); connect(player, SIGNAL(logAlwaysRevealTopCard(Player *, CardZone *, bool)), this, SLOT(logAlwaysRevealTopCard(Player *, CardZone *, bool))); connect(player, SIGNAL(logAlwaysLookAtTopCard(Player *, CardZone *, bool)), this, diff --git a/cockatrice/src/messagelogwidget.h b/cockatrice/src/messagelogwidget.h index 9ad1808e0..7bdbde699 100644 --- a/cockatrice/src/messagelogwidget.h +++ b/cockatrice/src/messagelogwidget.h @@ -77,7 +77,8 @@ public slots: QString cardName, Player *otherPlayer, bool faceDown, - int amount); + int amount, + bool isLentToAnotherPlayer); void logReverseTurn(Player *player, bool reversed); void logRollDie(Player *player, int sides, const QList &rolls); void logSay(Player *player, QString message); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 7be6c04ef..8d0c691ca 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -314,6 +314,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T libraryMenu->addAction(aViewTopCards); libraryMenu->addSeparator(); playerLists.append(mRevealLibrary = libraryMenu->addMenu(QString())); + singlePlayerLists.append(mLendLibrary = libraryMenu->addMenu(QString())); playerLists.append(mRevealTopCard = libraryMenu->addMenu(QString())); libraryMenu->addAction(aAlwaysRevealTopCard); libraryMenu->addAction(aAlwaysLookAtTopCard); @@ -582,14 +583,22 @@ void Player::addPlayer(Player *player) } for (auto &playerList : playerLists) { - QAction *newAction = playerList->addAction(player->getName()); - newAction->setData(player->getId()); - connect(newAction, SIGNAL(triggered()), this, SLOT(playerListActionTriggered())); + addPlayerToList(playerList, player); + } + for (auto &playerList : singlePlayerLists) { + addPlayerToList(playerList, player); } playersInfo.append(qMakePair(player->getName(), player->getId())); } +void Player::addPlayerToList(QMenu *playerList, Player *player) +{ + QAction *newAction = playerList->addAction(player->getName()); + newAction->setData(player->getId()); + connect(newAction, SIGNAL(triggered()), this, SLOT(playerListActionTriggered())); +} + void Player::removePlayer(Player *player) { if (player == nullptr) { @@ -597,12 +606,10 @@ void Player::removePlayer(Player *player) } for (auto &playerList : playerLists) { - QList actionList = playerList->actions(); - for (auto &j : actionList) - if (j->data().toInt() == player->getId()) { - playerList->removeAction(j); - j->deleteLater(); - } + removePlayerFromList(playerList, player); + } + for (auto &playerList : singlePlayerLists) { + removePlayerFromList(playerList, player); } for (auto it = playersInfo.begin(); it != playersInfo.end();) { @@ -614,6 +621,16 @@ void Player::removePlayer(Player *player) } } +void Player::removePlayerFromList(QMenu *playerList, Player *player) +{ + QList actionList = playerList->actions(); + for (auto &j : actionList) + if (j->data().toInt() == player->getId()) { + playerList->removeAction(j); + j->deleteLater(); + } +} + void Player::playerListActionTriggered() { auto *action = static_cast(sender()); @@ -625,8 +642,9 @@ void Player::playerListActionTriggered() cmd.set_player_id(otherPlayerId); } - if (menu == mRevealLibrary) { + if (menu == mRevealLibrary || menu == mLendLibrary) { cmd.set_zone_name("deck"); + cmd.set_grant_write_access(menu == mLendLibrary); } else if (menu == mRevealTopCard) { int deckSize = zones.value("deck")->getCards().size(); bool ok; @@ -752,6 +770,7 @@ void Player::retranslateUi() aViewHand->setText(tr("&View hand")); aViewTopCards->setText(tr("View &top cards of library...")); mRevealLibrary->setTitle(tr("Reveal &library to...")); + mLendLibrary->setTitle(tr("Lend library to...")); mRevealTopCard->setTitle(tr("Reveal &top cards to...")); topLibraryMenu->setTitle(tr("&Top of library...")); bottomLibraryMenu->setTitle(tr("&Bottom of library...")); @@ -1974,8 +1993,7 @@ void Player::eventRollDie(const Event_RollDie &event) #endif std::sort(rolls.begin(), rolls.end()); emit logRollDie(this, static_cast(event.sides()), rolls); - } - else if (event.value()) { + } else if (event.value()) { // Backwards compatibility for old clients emit logRollDie(this, static_cast(event.sides()), {event.value()}); } @@ -2373,7 +2391,8 @@ void Player::eventRevealCards(const Event_RevealCards &event) } emit logRevealCards(this, zone, cardId, cardName, otherPlayer, false, - event.has_number_of_cards() ? event.number_of_cards() : cardList.size()); + event.has_number_of_cards() ? event.number_of_cards() : cardList.size(), + event.grant_write_access()); } } diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index fafa1ee4d..0a8cbdf95 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -142,7 +142,8 @@ signals: QString cardName, Player *otherPlayer, bool faceDown, - int amount); + int amount, + bool isLentToAnotherPlayer = false); void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal); void logAlwaysLookAtTopCard(Player *player, CardZone *zone, bool reveal); @@ -225,11 +226,12 @@ private slots: private: TabGame *game; - QMenu *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu, *mRevealLibrary, *mRevealTopCard, *mRevealHand, - *mRevealRandomHandCard, *mRevealRandomGraveyardCard; + QMenu *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu, *mRevealLibrary, *mLendLibrary, *mRevealTopCard, + *mRevealHand, *mRevealRandomHandCard, *mRevealRandomGraveyardCard; TearOffMenu *moveGraveMenu, *moveRfgMenu, *graveMenu, *moveHandMenu, *handMenu, *libraryMenu, *topLibraryMenu, *bottomLibraryMenu, *rfgMenu, *playerMenu; QList playerLists; + QList singlePlayerLists; QList allPlayersActions; QList> playersInfo; QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg, @@ -299,6 +301,8 @@ private: bool persistent = false); bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation); void moveOneCardUntil(const CardInfoPtr card); + void addPlayerToList(QMenu *playerList, Player *player); + static void removePlayerFromList(QMenu *playerList, Player *player); QRectF bRect;