mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 13:33:55 -07:00
Wire command zone menu, harden counter command handling, and expand tests
- Connect aMoveToCommandZone to cmMoveToCommandZone; the menu item was
added, shown, and shortcut-bound but never wired, so it did nothing
- Extract evaluateModifyCounter() and route cmdIncCounter/cmdSetCounter
through it, replacing isCommandZoneCounterBlocked; reject inc/set on
an inactive tax counter so a hidden counter cannot accumulate value
- Reject reserved tax counter names in cmdCreateCounter to prevent a
client from spoofing a system tax counter via a user-created counter
- Route AbstractCounter::valueChanged through the virtual setValue() so
CommanderTaxCounter clamps and refreshes its tooltip on value changes
- Deduplicate actPlayAndIncreaseTax/actPlayAndIncreasePartnerTax into a
single playAndIncreaseTax(counterId) helper
- Move MINIMUM_STACKING_HEIGHT from CommandZone to the PlayerGraphicsItem
layout code, its only consumer
- Remove unused AbstractCounter forward declaration from player_logic.h
- Add EvaluateModifyCounter tests and PartnerTax cases for
evaluateSetCounterActive
- Pin the FirstUserId floor in new_counter_id_test using ids 3 and 5 so
a naive "highest id + 1" regression fails the test
This commit is contained in:
parent
0bfb0f4131
commit
bc09a19b50
11 changed files with 172 additions and 47 deletions
|
|
@ -1663,23 +1663,21 @@ void PlayerActions::playSelectedCardsImpl(QList<CardItem *> selectedCards,
|
|||
|
||||
void PlayerActions::actPlayAndIncreaseTax(QList<CardItem *> selectedCards)
|
||||
{
|
||||
playSelectedCardsImpl(selectedCards, false, [this](CardItem * /*card*/, const QString &originalZone) {
|
||||
if (originalZone == ZoneNames::COMMAND) {
|
||||
CounterState *state = player->getCounters().value(CounterIds::CommanderTax, nullptr);
|
||||
if (state && state->isActive()) {
|
||||
sendIncCounter(CounterIds::CommanderTax, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
playAndIncreaseTax(selectedCards, CounterIds::CommanderTax);
|
||||
}
|
||||
|
||||
void PlayerActions::actPlayAndIncreasePartnerTax(QList<CardItem *> selectedCards)
|
||||
{
|
||||
playSelectedCardsImpl(selectedCards, false, [this](CardItem * /*card*/, const QString &originalZone) {
|
||||
playAndIncreaseTax(selectedCards, CounterIds::PartnerTax);
|
||||
}
|
||||
|
||||
void PlayerActions::playAndIncreaseTax(QList<CardItem *> selectedCards, int counterId)
|
||||
{
|
||||
playSelectedCardsImpl(selectedCards, false, [this, counterId](CardItem * /*card*/, const QString &originalZone) {
|
||||
if (originalZone == ZoneNames::COMMAND) {
|
||||
CounterState *state = player->getCounters().value(CounterIds::PartnerTax, nullptr);
|
||||
CounterState *state = player->getCounters().value(counterId, nullptr);
|
||||
if (state && state->isActive()) {
|
||||
sendIncCounter(CounterIds::PartnerTax, 1);
|
||||
sendIncCounter(counterId, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -267,6 +267,14 @@ private:
|
|||
bool faceDown,
|
||||
const std::function<void(CardItem *, const QString &)> &postPlayCallback = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Plays the selected cards and, for each that came from the command zone,
|
||||
* increments the given (active) tax counter by one.
|
||||
* @param selectedCards Cards to play
|
||||
* @param counterId The tax counter to increment (CounterIds::CommanderTax or PartnerTax)
|
||||
*/
|
||||
void playAndIncreaseTax(QList<CardItem *> selectedCards, int counterId);
|
||||
|
||||
void cmdSetTopCard(Command_MoveCard &cmd);
|
||||
void cmdSetBottomCard(Command_MoveCard &cmd);
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ class ServerInfo_Counter;
|
|||
class ServerInfo_Player;
|
||||
class ServerInfo_User;
|
||||
class TabGame;
|
||||
class AbstractCounter;
|
||||
|
||||
const int MAX_TOKENS_PER_DIALOG = 99;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,10 +28,9 @@ AbstractCounter::AbstractCounter(CounterState *state,
|
|||
{
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
connect(state, &CounterState::valueChanged, this, [this](int, int newValue) {
|
||||
value = newValue;
|
||||
update();
|
||||
});
|
||||
// Route through the (possibly overridden) virtual setValue so subclasses such as
|
||||
// CommanderTaxCounter can clamp and refresh their tooltip on every value change.
|
||||
connect(state, &CounterState::valueChanged, this, [this](int, int newValue) { setValue(newValue); });
|
||||
|
||||
connect(state, &CounterState::activeChanged, this, [this](bool newActive) {
|
||||
setActive(newActive);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ MoveMenu::MoveMenu(PlayerGraphicsItem *player) : QMenu(tr("Move to"))
|
|||
connect(aMoveToHand, &QAction::triggered, actions, invoke(cmMoveToHand));
|
||||
connect(aMoveToGraveyard, &QAction::triggered, actions, invoke(cmMoveToGraveyard));
|
||||
connect(aMoveToExile, &QAction::triggered, actions, invoke(cmMoveToExile));
|
||||
connect(aMoveToCommandZone, &QAction::triggered, actions, invoke(cmMoveToCommandZone));
|
||||
|
||||
addAction(aMoveToTopLibrary);
|
||||
addAction(aMoveToXfromTopOfLibrary);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@
|
|||
#include <QGraphicsView>
|
||||
#include <libcockatrice/utility/counter_ids.h>
|
||||
|
||||
// Minimum height the stack zone keeps when the command zone shares its vertical space,
|
||||
// so the stack remains usable. Owned by this layout code, the sole consumer.
|
||||
static constexpr qreal MINIMUM_STACKING_HEIGHT = 50.0;
|
||||
|
||||
PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player)
|
||||
{
|
||||
connect(&SettingsCache::instance(), &SettingsCache::horizontalHandChanged, this,
|
||||
|
|
@ -278,8 +282,8 @@ void PlayerGraphicsItem::rearrangeZones()
|
|||
qreal stackHeight = tableHeight;
|
||||
if (commandZoneVisible) {
|
||||
stackHeight = tableHeight - totalCommandZoneHeight();
|
||||
if (stackHeight < CommandZone::MINIMUM_STACKING_HEIGHT) {
|
||||
stackHeight = CommandZone::MINIMUM_STACKING_HEIGHT;
|
||||
if (stackHeight < MINIMUM_STACKING_HEIGHT) {
|
||||
stackHeight = MINIMUM_STACKING_HEIGHT;
|
||||
}
|
||||
}
|
||||
stackZoneGraphicsItem->setHeight(stackHeight);
|
||||
|
|
|
|||
|
|
@ -47,9 +47,6 @@ constexpr qreal COMMAND_ZONE_WIDTH = CardDimensions::WIDTH_F * 1.5;
|
|||
class CommandZone : public SelectZone
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static constexpr qreal MINIMUM_STACKING_HEIGHT = 50.0;
|
||||
|
||||
private:
|
||||
static constexpr double MINIMIZED_HEIGHT_RATIO = 0.25;
|
||||
int zoneHeight; ///< Full height in pixels when expanded
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue