Re-Add ability to share editable deck views (#5060)

- Rolls back 6811819161
- Follow up to adbb607700
This commit is contained in:
Zach H 2024-06-24 17:52:11 -04:00 committed by GitHub
parent bdcd083eea
commit e261e16d99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 56 additions and 24 deletions

View file

@ -481,7 +481,8 @@ void MessageLogWidget::logRevealCards(Player *player,
QString cardName, QString cardName,
Player *otherPlayer, Player *otherPlayer,
bool faceDown, 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 // getFromStr uses cardname.empty() to check if it should contain the start zone, it's not actually used
QPair<QString, QString> temp = getFromStr(zone, amount == 1 ? cardName : QString::number(amount), cardId, false); QPair<QString, QString> temp = getFromStr(zone, amount == 1 ? cardName : QString::number(amount), cardId, false);
@ -507,10 +508,17 @@ void MessageLogWidget::logRevealCards(Player *player,
} }
if (cardId == -1) { if (cardId == -1) {
if (otherPlayer) { if (otherPlayer) {
appendHtmlServerMessage(tr("%1 reveals %2 to %3.") if (isLentToAnotherPlayer) {
.arg(sanitizeHtml(player->getName())) appendHtmlServerMessage(tr("%1 lends %2 to %3.")
.arg(zone->getTranslatedName(true, CaseRevealZone)) .arg(sanitizeHtml(player->getName()))
.arg(sanitizeHtml(otherPlayer->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 { } else {
appendHtmlServerMessage(tr("%1 reveals %2.") appendHtmlServerMessage(tr("%1 reveals %2.")
.arg(sanitizeHtml(player->getName())) .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(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(logDrawCards(Player *, int, bool)), this, SLOT(logDrawCards(Player *, int, bool)));
connect(player, SIGNAL(logUndoDraw(Player *, QString)), this, SLOT(logUndoDraw(Player *, QString))); connect(player, SIGNAL(logUndoDraw(Player *, QString)), this, SLOT(logUndoDraw(Player *, QString)));
connect(player, SIGNAL(logRevealCards(Player *, CardZone *, int, QString, Player *, bool, int)), this, connect(player, SIGNAL(logRevealCards(Player *, CardZone *, int, QString, Player *, bool, int, bool)), this,
SLOT(logRevealCards(Player *, CardZone *, int, QString, Player *, bool, int))); SLOT(logRevealCards(Player *, CardZone *, int, QString, Player *, bool, int, bool)));
connect(player, SIGNAL(logAlwaysRevealTopCard(Player *, CardZone *, bool)), this, connect(player, SIGNAL(logAlwaysRevealTopCard(Player *, CardZone *, bool)), this,
SLOT(logAlwaysRevealTopCard(Player *, CardZone *, bool))); SLOT(logAlwaysRevealTopCard(Player *, CardZone *, bool)));
connect(player, SIGNAL(logAlwaysLookAtTopCard(Player *, CardZone *, bool)), this, connect(player, SIGNAL(logAlwaysLookAtTopCard(Player *, CardZone *, bool)), this,

View file

@ -77,7 +77,8 @@ public slots:
QString cardName, QString cardName,
Player *otherPlayer, Player *otherPlayer,
bool faceDown, bool faceDown,
int amount); int amount,
bool isLentToAnotherPlayer);
void logReverseTurn(Player *player, bool reversed); void logReverseTurn(Player *player, bool reversed);
void logRollDie(Player *player, int sides, const QList<uint> &rolls); void logRollDie(Player *player, int sides, const QList<uint> &rolls);
void logSay(Player *player, QString message); void logSay(Player *player, QString message);

View file

@ -314,6 +314,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T
libraryMenu->addAction(aViewTopCards); libraryMenu->addAction(aViewTopCards);
libraryMenu->addSeparator(); libraryMenu->addSeparator();
playerLists.append(mRevealLibrary = libraryMenu->addMenu(QString())); playerLists.append(mRevealLibrary = libraryMenu->addMenu(QString()));
singlePlayerLists.append(mLendLibrary = libraryMenu->addMenu(QString()));
playerLists.append(mRevealTopCard = libraryMenu->addMenu(QString())); playerLists.append(mRevealTopCard = libraryMenu->addMenu(QString()));
libraryMenu->addAction(aAlwaysRevealTopCard); libraryMenu->addAction(aAlwaysRevealTopCard);
libraryMenu->addAction(aAlwaysLookAtTopCard); libraryMenu->addAction(aAlwaysLookAtTopCard);
@ -582,14 +583,22 @@ void Player::addPlayer(Player *player)
} }
for (auto &playerList : playerLists) { for (auto &playerList : playerLists) {
QAction *newAction = playerList->addAction(player->getName()); addPlayerToList(playerList, player);
newAction->setData(player->getId()); }
connect(newAction, SIGNAL(triggered()), this, SLOT(playerListActionTriggered())); for (auto &playerList : singlePlayerLists) {
addPlayerToList(playerList, player);
} }
playersInfo.append(qMakePair(player->getName(), player->getId())); 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) void Player::removePlayer(Player *player)
{ {
if (player == nullptr) { if (player == nullptr) {
@ -597,12 +606,10 @@ void Player::removePlayer(Player *player)
} }
for (auto &playerList : playerLists) { for (auto &playerList : playerLists) {
QList<QAction *> actionList = playerList->actions(); removePlayerFromList(playerList, player);
for (auto &j : actionList) }
if (j->data().toInt() == player->getId()) { for (auto &playerList : singlePlayerLists) {
playerList->removeAction(j); removePlayerFromList(playerList, player);
j->deleteLater();
}
} }
for (auto it = playersInfo.begin(); it != playersInfo.end();) { 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<QAction *> actionList = playerList->actions();
for (auto &j : actionList)
if (j->data().toInt() == player->getId()) {
playerList->removeAction(j);
j->deleteLater();
}
}
void Player::playerListActionTriggered() void Player::playerListActionTriggered()
{ {
auto *action = static_cast<QAction *>(sender()); auto *action = static_cast<QAction *>(sender());
@ -625,8 +642,9 @@ void Player::playerListActionTriggered()
cmd.set_player_id(otherPlayerId); cmd.set_player_id(otherPlayerId);
} }
if (menu == mRevealLibrary) { if (menu == mRevealLibrary || menu == mLendLibrary) {
cmd.set_zone_name("deck"); cmd.set_zone_name("deck");
cmd.set_grant_write_access(menu == mLendLibrary);
} else if (menu == mRevealTopCard) { } else if (menu == mRevealTopCard) {
int deckSize = zones.value("deck")->getCards().size(); int deckSize = zones.value("deck")->getCards().size();
bool ok; bool ok;
@ -752,6 +770,7 @@ void Player::retranslateUi()
aViewHand->setText(tr("&View hand")); aViewHand->setText(tr("&View hand"));
aViewTopCards->setText(tr("View &top cards of library...")); aViewTopCards->setText(tr("View &top cards of library..."));
mRevealLibrary->setTitle(tr("Reveal &library to...")); mRevealLibrary->setTitle(tr("Reveal &library to..."));
mLendLibrary->setTitle(tr("Lend library to..."));
mRevealTopCard->setTitle(tr("Reveal &top cards to...")); mRevealTopCard->setTitle(tr("Reveal &top cards to..."));
topLibraryMenu->setTitle(tr("&Top of library...")); topLibraryMenu->setTitle(tr("&Top of library..."));
bottomLibraryMenu->setTitle(tr("&Bottom of library...")); bottomLibraryMenu->setTitle(tr("&Bottom of library..."));
@ -1974,8 +1993,7 @@ void Player::eventRollDie(const Event_RollDie &event)
#endif #endif
std::sort(rolls.begin(), rolls.end()); std::sort(rolls.begin(), rolls.end());
emit logRollDie(this, static_cast<int>(event.sides()), rolls); emit logRollDie(this, static_cast<int>(event.sides()), rolls);
} } else if (event.value()) {
else if (event.value()) {
// Backwards compatibility for old clients // Backwards compatibility for old clients
emit logRollDie(this, static_cast<int>(event.sides()), {event.value()}); emit logRollDie(this, static_cast<int>(event.sides()), {event.value()});
} }
@ -2373,7 +2391,8 @@ void Player::eventRevealCards(const Event_RevealCards &event)
} }
emit logRevealCards(this, zone, cardId, cardName, otherPlayer, false, 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());
} }
} }

View file

@ -142,7 +142,8 @@ signals:
QString cardName, QString cardName,
Player *otherPlayer, Player *otherPlayer,
bool faceDown, bool faceDown,
int amount); int amount,
bool isLentToAnotherPlayer = false);
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal); void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
void logAlwaysLookAtTopCard(Player *player, CardZone *zone, bool reveal); void logAlwaysLookAtTopCard(Player *player, CardZone *zone, bool reveal);
@ -225,11 +226,12 @@ private slots:
private: private:
TabGame *game; TabGame *game;
QMenu *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu, *mRevealLibrary, *mRevealTopCard, *mRevealHand, QMenu *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu, *mRevealLibrary, *mLendLibrary, *mRevealTopCard,
*mRevealRandomHandCard, *mRevealRandomGraveyardCard; *mRevealHand, *mRevealRandomHandCard, *mRevealRandomGraveyardCard;
TearOffMenu *moveGraveMenu, *moveRfgMenu, *graveMenu, *moveHandMenu, *handMenu, *libraryMenu, *topLibraryMenu, TearOffMenu *moveGraveMenu, *moveRfgMenu, *graveMenu, *moveHandMenu, *handMenu, *libraryMenu, *topLibraryMenu,
*bottomLibraryMenu, *rfgMenu, *playerMenu; *bottomLibraryMenu, *rfgMenu, *playerMenu;
QList<QMenu *> playerLists; QList<QMenu *> playerLists;
QList<QMenu *> singlePlayerLists;
QList<QAction *> allPlayersActions; QList<QAction *> allPlayersActions;
QList<QPair<QString, int>> playersInfo; QList<QPair<QString, int>> playersInfo;
QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg, QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg,
@ -299,6 +301,8 @@ private:
bool persistent = false); bool persistent = false);
bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation); bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation);
void moveOneCardUntil(const CardInfoPtr card); void moveOneCardUntil(const CardInfoPtr card);
void addPlayerToList(QMenu *playerList, Player *player);
static void removePlayerFromList(QMenu *playerList, Player *player);
QRectF bRect; QRectF bRect;