[Client] Preview token edits live and preserve custom drafts (#7737)

* Preview token edits live and preserve custom drafts

* Restore the upstream reveal-random-hand-cards action

The rebase onto upstream/master took the PR side of player_actions.cpp and
dropped PlayerActions::actRevealRandomHandCards, which upstream added after
the PR merge base. Re-apply the face-down P/T fix on the current file so the
branch keeps both changes.

* Draw the token preview P/T as the hover-panel pill

The preview painted the name and P/T unconditionally: the name duplicated the
artwork, and the raw P/T text was drawn even when it matched the printed value,
which looked wrong at non-default dialog sizes.

- Suppress the card name over a token picture via a small AbstractCardItem hook;
  cards without art still show it.
- Draw only a P/T that differs from the printed getPowTough() as the #7700
  hover-panel pill: dark rounded scrim, bold white text, anchored on the printed
  P/T box and clamped inside the card.
- Use designated CardRef initializers in the new code.

The face-up draft still previews while face-down creation is selected.

---------

Co-authored-by: Lukas Brübach <44814898+BruebachL@users.noreply.github.com>
This commit is contained in:
Bryce! 2026-11-09 06:59:53 -05:00 • committed by GitHub
parent 3f3aff9408
commit 3d8c729517
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 323 additions and 31 deletions

View file

@ -4,6 +4,7 @@
#include <QString>
#include <libcockatrice/game/player/player_actions.h>
#include <libcockatrice/game/zones/table_zone_logic.h>
#include <libcockatrice/protocol/pb/command_create_token.pb.h>
#include <libcockatrice/protocol/pb/command_move_card.pb.h>
#include <libcockatrice/utility/zone_names.h>
#include <string>
@ -117,3 +118,64 @@ TEST(PlayerActionsTest, PlayCiptCreatureSendsTapped)
EXPECT_TRUE(card.has_tapped());
EXPECT_TRUE(card.tapped());
}
// These three #7737 command cases use the current shared game harness.
TEST(TokenCommandTest, FaceDownKnownTokenDoesNotRestoreDatabasePowerToughness)
{
GameHarness harness;
harness.client()->sent.clear();
TokenInfo token;
token.name = QStringLiteral("Kitten");
token.color = QString(QChar());
token.faceDown = true;
harness.player()->getPlayerActions()->actCreateToken(token);
ASSERT_EQ(harness.client()->sent.size(), 1);
ASSERT_EQ(harness.lastCommand().game_command_size(), 1);
const auto &gameCommand = harness.lastCommand().game_command(0);
ASSERT_TRUE(gameCommand.HasExtension(Command_CreateToken::ext));
const auto &command = gameCommand.GetExtension(Command_CreateToken::ext);
EXPECT_EQ(command.card_name(), "Kitten");
EXPECT_TRUE(command.face_down());
EXPECT_TRUE(command.pt().empty());
harness.player()->getPlayerActions()->actCreateAnotherToken();
ASSERT_EQ(harness.client()->sent.size(), 2);
const auto &repeat = harness.lastCommand().game_command(0).GetExtension(Command_CreateToken::ext);
EXPECT_TRUE(repeat.face_down());
EXPECT_TRUE(repeat.pt().empty());
}
TEST(TokenCommandTest, FaceUpKnownAliasKeepsCanonicalNameAndDefaultPowerToughness)
{
GameHarness harness;
harness.client()->sent.clear();
TokenInfo token;
token.name = QStringLiteral("kitten");
harness.player()->getPlayerActions()->actCreateToken(token);
ASSERT_EQ(harness.client()->sent.size(), 1);
ASSERT_EQ(harness.lastCommand().game_command_size(), 1);
const auto &gameCommand = harness.lastCommand().game_command(0);
ASSERT_TRUE(gameCommand.HasExtension(Command_CreateToken::ext));
const auto &command = gameCommand.GetExtension(Command_CreateToken::ext);
EXPECT_EQ(command.card_name(), "Kitten");
EXPECT_FALSE(command.face_down());
EXPECT_EQ(command.pt(), "1/1");
}
TEST(TokenCommandTest, FaceUpKnownTokenPreservesExplicitPowerToughness)
{
GameHarness harness;
harness.client()->sent.clear();
TokenInfo token;
token.name = QStringLiteral("Kitten");
token.pt = QStringLiteral("7/9");
token.annotation = QStringLiteral("Flying");
harness.player()->getPlayerActions()->actCreateToken(token);
ASSERT_EQ(harness.client()->sent.size(), 1);
ASSERT_EQ(harness.lastCommand().game_command_size(), 1);
const auto &gameCommand = harness.lastCommand().game_command(0);
ASSERT_TRUE(gameCommand.HasExtension(Command_CreateToken::ext));
const auto &command = gameCommand.GetExtension(Command_CreateToken::ext);
EXPECT_FALSE(command.face_down());
EXPECT_EQ(command.pt(), "7/9");
EXPECT_EQ(command.annotation(), "Flying");
}