Route random hand reveals through PlayerActions

Keep command creation, dispatch and response handling in the game action
layer. HandMenu requests the typed operation and presents the count and
failure dialogs. Show the chosen recipient, distinguish the count action
from the immediate single-card reveal, and use the game window as parent.
This commit is contained in:
Bryce! 2026-11-03 16:36:54 -05:00
parent ccdee18db2
commit afe9bf77af
5 changed files with 59 additions and 28 deletions

View file

@ -32,6 +32,7 @@
#include <QMetaType>
#include <QPoint>
#include <QPointF>
#include <QPointer>
#include <QSharedPointer>
#include <QTimer>
#include <QVariant>
@ -47,6 +48,7 @@
#include <libcockatrice/deck_list/loaded_deck.h>
#include <libcockatrice/interfaces/interface_card_preference_provider.h>
#include <libcockatrice/interfaces/interface_interface_settings_provider.h>
#include <libcockatrice/network/client/abstract/abstract_client.h>
#include <libcockatrice/protocol/pb/command_attach_card.pb.h>
#include <libcockatrice/protocol/pb/command_change_zone_properties.pb.h>
#include <libcockatrice/protocol/pb/command_create_arrow.pb.h>
@ -66,6 +68,8 @@
#include <libcockatrice/protocol/pb/command_shuffle.pb.h>
#include <libcockatrice/protocol/pb/command_undo_draw.pb.h>
#include <libcockatrice/protocol/pb/context_move_card.pb.h>
#include <libcockatrice/protocol/pb/response.pb.h>
#include <libcockatrice/protocol/pending_command.h>
#include <libcockatrice/utility/clamped_arithmetic.h>
#include <libcockatrice/utility/color.h>
#include <libcockatrice/utility/counter_limits.h>
@ -1756,15 +1760,25 @@ void PlayerActions::actRevealRandomHandCard(int revealToPlayerId)
sendGameCommand(cmd);
}
PendingCommand *PlayerActions::prepareRandomHandReveal(int revealToPlayerId, int amount)
void PlayerActions::actRevealRandomHandCards(int revealToPlayerId, int amount)
{
QPointer<AbstractClient> client = player->getGame()->getClientForPlayer(player->getPlayerInfo()->getId());
if (!client) {
return;
}
Command_RevealRandomCards cmd;
if (revealToPlayerId != -1) {
cmd.set_player_id(revealToPlayerId);
}
cmd.set_zone_name(ZoneNames::HAND);
cmd.set_number_of_cards(amount);
return prepareGameCommand(cmd);
auto *pending = prepareGameCommand(cmd);
connect(pending, &PendingCommand::finished, this, [this, client](const Response &response) {
if (client && response.response_code() != Response::RespOk) {
emit randomHandRevealFailed(response.response_code() == Response::RespInvalidCommand);
}
});
sendGameCommand(pending);
}
void PlayerActions::actRevealLibrary(int revealToPlayerId)

View file

@ -83,7 +83,6 @@ public:
* @param numberCards How many cards to dump, -1 for all.
*/
PendingCommand *prepareZoneDump(CardZoneLogic *zone, int numberCards);
PendingCommand *prepareRandomHandReveal(int revealToPlayerId, int amount);
/**
* @brief Sets the tapped state of the cards that do not already have it.
@ -121,6 +120,7 @@ public:
}
signals:
void randomHandRevealFailed(bool unsupported);
void requestViewTopCardsDialog(int defaultNumberTopCards, int deckSize);
void requestViewBottomCardsDialog(int defaultNumberBottomCards, int deckSize);
void requestShuffleTopDialog(int defaultNumberTopCards, int maxCards);
@ -280,6 +280,7 @@ public slots:
void actReveal(QList<CardState *> selectedCards, QAction *action);
void actRevealHand(int revealToPlayerId);
void actRevealRandomHandCard(int revealToPlayerId);
void actRevealRandomHandCards(int revealToPlayerId, int amount);
void actRevealLibrary(int revealToPlayerId);
void actSortHand();