mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 21:43:55 -07:00
Fix Command Zone graphics/logic layers separation
1. CommandZoneMenu: Changed to take PlayerGraphicsItem* instead of
PlayerLogic*, accessing logic via player->getLogic()
2. Removed getCounterWidget() from PlayerLogic;
method already exists correctly in PlayerGraphicsItem
3. PlayerMenu: CommandZoneMenu, fixed signal
connection to use player->getLogic() for commandZoneSupportChanged
4. AbstractCounter: Connects to CounterState::activeChanged signal,
removing direct graphics calls from PlayerEventHandler
5. CommandZone: Explicit tax counter registration via registerTaxCounter()
with auto-cleanup, replacing childItems()/dynamic_cast iteration
Also fixed PlayerActions to query CounterState instead of AbstractCounter
for proper layer separation.
This commit is contained in:
parent
cbee3726c9
commit
928b0a1483
11 changed files with 55 additions and 56 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#include "../../game_graphics/zones/table_zone.h"
|
||||
#include "../../interface/widgets/tabs/tab_game.h"
|
||||
#include "../../interface/widgets/utility/get_text_with_max.h"
|
||||
#include "../board/counter_state.h"
|
||||
#include "../zones/view_zone_logic.h"
|
||||
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
|
|
@ -1664,8 +1665,8 @@ void PlayerActions::actPlayAndIncreaseTax(QList<CardItem *> selectedCards)
|
|||
{
|
||||
playSelectedCardsImpl(selectedCards, false, [this](CardItem * /*card*/, const QString &originalZone) {
|
||||
if (originalZone == ZoneNames::COMMAND) {
|
||||
AbstractCounter *ctr = player->getCounterWidget(CounterIds::CommanderTax);
|
||||
if (ctr && ctr->isActive()) {
|
||||
CounterState *state = player->getCounters().value(CounterIds::CommanderTax, nullptr);
|
||||
if (state && state->isActive()) {
|
||||
sendIncCounter(CounterIds::CommanderTax, 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1676,8 +1677,8 @@ void PlayerActions::actPlayAndIncreasePartnerTax(QList<CardItem *> selectedCards
|
|||
{
|
||||
playSelectedCardsImpl(selectedCards, false, [this](CardItem * /*card*/, const QString &originalZone) {
|
||||
if (originalZone == ZoneNames::COMMAND) {
|
||||
AbstractCounter *ctr = player->getCounterWidget(CounterIds::PartnerTax);
|
||||
if (ctr && ctr->isActive()) {
|
||||
CounterState *state = player->getCounters().value(CounterIds::PartnerTax, nullptr);
|
||||
if (state && state->isActive()) {
|
||||
sendIncCounter(CounterIds::PartnerTax, 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1694,8 +1695,8 @@ void PlayerActions::sendIncCounter(int counterId, int delta)
|
|||
|
||||
void PlayerActions::actModifyTaxCounter(int counterId, int delta)
|
||||
{
|
||||
AbstractCounter *ctr = player->getCounterWidget(counterId);
|
||||
if (!ctr || !ctr->isActive()) {
|
||||
CounterState *state = player->getCounters().value(counterId, nullptr);
|
||||
if (!state || !state->isActive()) {
|
||||
return;
|
||||
}
|
||||
sendIncCounter(counterId, delta);
|
||||
|
|
@ -1703,13 +1704,13 @@ void PlayerActions::actModifyTaxCounter(int counterId, int delta)
|
|||
|
||||
void PlayerActions::actToggleTaxCounter(int counterId)
|
||||
{
|
||||
AbstractCounter *ctr = player->getCounterWidget(counterId);
|
||||
if (!ctr || (ctr->isActive() && ctr->getValue() != 0)) {
|
||||
CounterState *state = player->getCounters().value(counterId, nullptr);
|
||||
if (!state || (state->isActive() && state->getValue() != 0)) {
|
||||
return;
|
||||
}
|
||||
Command_SetCounterActive cmd;
|
||||
cmd.set_counter_id(counterId);
|
||||
cmd.set_active(!ctr->isActive());
|
||||
cmd.set_active(!state->isActive());
|
||||
sendGameCommand(cmd);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -285,13 +285,6 @@ void PlayerEventHandler::eventSetCounterActive(const Event_SetCounterActive &eve
|
|||
return;
|
||||
}
|
||||
state->setActive(event.active());
|
||||
|
||||
// TODO: The counters data should emit this and the widget hook up to it. Don't reach into graphics like this.
|
||||
/*AbstractCounter *widget = player->getGraphicsItem()->getCounterWidget(event.counter_id());
|
||||
if (widget) {
|
||||
widget->setActive(event.active());
|
||||
emit player->rearrangeCounters();
|
||||
}*/
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventDelCounter(const Event_DelCounter &event)
|
||||
|
|
|
|||
|
|
@ -316,13 +316,6 @@ CounterState *PlayerLogic::getLifeCounter() const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
AbstractCounter *PlayerLogic::getCounterWidget(int counterId) const
|
||||
{
|
||||
Q_UNUSED(counterId);
|
||||
return nullptr;
|
||||
// TODO: Do not reach into graphics like this return graphicsItem->getCounterWidget(counterId);
|
||||
}
|
||||
|
||||
bool PlayerLogic::clearCardsToDelete()
|
||||
{
|
||||
if (cardsToDelete.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -223,9 +223,6 @@ public:
|
|||
*/
|
||||
CounterState *getLifeCounter() const;
|
||||
|
||||
/** @brief Returns the counter widget for the given ID, or nullptr if not found. */
|
||||
AbstractCounter *getCounterWidget(int counterId) const;
|
||||
|
||||
void setConceded(bool _conceded);
|
||||
bool getConceded() const
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue