From 59c08344279f3a7cae5bae810f56fb1e3654cab0 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Mon, 4 May 2015 10:49:49 +0200 Subject: [PATCH 1/4] Reveal top x cards Updated reveal top card to reveal top x cards Sometimes you want to reveal more than only the top 1 card. --- cockatrice/src/player.cpp | 17 ++++++++++++++--- common/pb/command_reveal_cards.proto | 1 + common/server_player.cpp | 9 ++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 0a851de5..276e8ebe 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -515,8 +515,19 @@ void Player::playerListActionTriggered() if (menu == mRevealLibrary) { cmd.set_zone_name("deck"); } else if (menu == mRevealTopCard) { - cmd.set_zone_name("deck"); - cmd.set_card_id(0); + bool ok; + int number = +#if QT_VERSION < 0x050000 + QInputDialog::getInteger( +#else + QInputDialog::getInt( +#endif + 0, tr("Reveal top cards of library"), tr("Number of cards:"), defaultNumberTopCards, 1, 2000000000, 1, &ok); + if (ok) { + cmd.set_zone_name("deck"); + cmd.set_top_cards(number); + } + } else if (menu == mRevealHand) cmd.set_zone_name("hand"); else if (menu == mRevealRandomHandCard) { @@ -624,7 +635,7 @@ void Player::retranslateUi() aViewLibrary->setText(tr("&View library")); aViewTopCards->setText(tr("View &top cards of library...")); mRevealLibrary->setTitle(tr("Reveal &library to...")); - mRevealTopCard->setTitle(tr("Reveal t&op card to...")); + mRevealTopCard->setTitle(tr("Reveal t&op cards to...")); aAlwaysRevealTopCard->setText(tr("&Always reveal top card")); aOpenDeckInDeckEditor->setText(tr("O&pen deck in deck editor")); aViewSideboard->setText(tr("&View sideboard")); diff --git a/common/pb/command_reveal_cards.proto b/common/pb/command_reveal_cards.proto index af108abc..263fef63 100644 --- a/common/pb/command_reveal_cards.proto +++ b/common/pb/command_reveal_cards.proto @@ -7,4 +7,5 @@ message Command_RevealCards { optional sint32 card_id = 2 [default = -1]; optional sint32 player_id = 3 [default = -1]; optional bool grant_write_access = 4; + optional sint32 top_cards = 5 [default = -1]; } diff --git a/common/server_player.cpp b/common/server_player.cpp index 644d02c7..8347a4eb 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -1522,7 +1522,14 @@ Response::ResponseCode Server_Player::cmdRevealCards(const Command_RevealCards & return Response::RespNameNotFound; QList cardsToReveal; - if (!cmd.has_card_id()) + if (cmd.top_cards() != -1) { + for (int i = 0; i < cmd.top_cards(); i++) { + Server_Card *card = zone->getCard(i); + if (!card) + return Response::RespNameNotFound; + cardsToReveal.append(card); + } + } else if (!cmd.has_card_id()) cardsToReveal = zone->getCards(); else if (cmd.card_id() == -2) { if (zone->getCards().isEmpty()) From 45d214aa1993c85bd69a2033cebe374aca5636ad Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Mon, 4 May 2015 16:21:59 +0200 Subject: [PATCH 2/4] Added deck size limit Updated to use the current deck size limit --- cockatrice/src/player.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 276e8ebe..a44f6953 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -515,6 +515,7 @@ void Player::playerListActionTriggered() if (menu == mRevealLibrary) { cmd.set_zone_name("deck"); } else if (menu == mRevealTopCard) { + int decksize = zones.value("deck")->getCards().size(); bool ok; int number = #if QT_VERSION < 0x050000 @@ -522,7 +523,7 @@ void Player::playerListActionTriggered() #else QInputDialog::getInt( #endif - 0, tr("Reveal top cards of library"), tr("Number of cards:"), defaultNumberTopCards, 1, 2000000000, 1, &ok); + 0, tr("Reveal top cards of library"), tr("Number of cards: (max %1)").arg(decksize), defaultNumberTopCards, 1, decksize, 1, &ok); if (ok) { cmd.set_zone_name("deck"); cmd.set_top_cards(number); From 5dfef6215c2e8975ce146d3578da369668ef2e11 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Wed, 6 May 2015 14:19:01 +0200 Subject: [PATCH 3/4] Added punctuation mark --- cockatrice/src/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index a44f6953..1be7fb16 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -523,7 +523,7 @@ void Player::playerListActionTriggered() #else QInputDialog::getInt( #endif - 0, tr("Reveal top cards of library"), tr("Number of cards: (max %1)").arg(decksize), defaultNumberTopCards, 1, decksize, 1, &ok); + 0, tr("Reveal top cards of library"), tr("Number of cards: (max. %1)").arg(decksize), defaultNumberTopCards, 1, decksize, 1, &ok); if (ok) { cmd.set_zone_name("deck"); cmd.set_top_cards(number); From 2299fa1ac48ae175dbd1a1aecb914c03039fdb88 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Fri, 15 May 2015 18:18:25 +0200 Subject: [PATCH 4/4] Add backward compatibility for new client on old servers --- cockatrice/src/player.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 1be7fb16..6d016beb 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -527,6 +527,8 @@ void Player::playerListActionTriggered() if (ok) { cmd.set_zone_name("deck"); cmd.set_top_cards(number); + // backward compatibility: servers before #1051 only permits to reveal the first card + cmd.set_card_id(0); } } else if (menu == mRevealHand)