mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-07 05:53:59 -07:00
refactor(client): use ZoneNames constants in game scene components
Update remaining game scene components to use ZoneNames:: constants: - arrow_item.cpp: arrow drawing between cards - game_scene.cpp: zone view positioning - message_log_widget.cpp: removes duplicate local static constants that were previously defining zone names redundantly - phases_toolbar.cpp: phase actions (untap all) Notable: message_log_widget.cpp previously had its own local constants (TABLE_ZONE_NAME, GRAVE_ZONE_NAME, etc.) which are now removed in favor of the centralized ZoneNames:: constants.
This commit is contained in:
parent
1316aa73dc
commit
163173285a
4 changed files with 33 additions and 37 deletions
|
|
@ -19,6 +19,7 @@
|
|||
#include <libcockatrice/protocol/pb/command_create_arrow.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_delete_arrow.pb.h>
|
||||
#include <libcockatrice/utility/color.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
|
||||
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), targetLocked(false),
|
||||
|
|
@ -239,16 +240,16 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
}
|
||||
|
||||
// if the card is in hand then we will move the card to stack or table as part of drawing the arrow
|
||||
if (startZone->getName() == "hand") {
|
||||
if (startZone->getName() == ZoneNames::HAND) {
|
||||
startCard->playCard(false);
|
||||
CardInfoPtr ci = startCard->getCard().getCardPtr();
|
||||
bool playToStack = SettingsCache::instance().getPlayToStack();
|
||||
if (ci &&
|
||||
((!playToStack && ci->getUiAttributes().tableRow == 3) ||
|
||||
(playToStack && ci->getUiAttributes().tableRow != 0 && startCard->getZone()->getName() != "stack")))
|
||||
cmd.set_start_zone("stack");
|
||||
if (ci && ((!playToStack && ci->getUiAttributes().tableRow == 3) ||
|
||||
(playToStack && ci->getUiAttributes().tableRow != 0 &&
|
||||
startCard->getZone()->getName() != ZoneNames::STACK)))
|
||||
cmd.set_start_zone(ZoneNames::STACK);
|
||||
else
|
||||
cmd.set_start_zone(playToStack ? "stack" : "table");
|
||||
cmd.set_start_zone(playToStack ? ZoneNames::STACK : ZoneNames::TABLE);
|
||||
}
|
||||
|
||||
if (deleteInPhase != 0) {
|
||||
|
|
@ -318,7 +319,7 @@ void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCard)
|
||||
{
|
||||
// do nothing if target is already attached to another card or is not in play
|
||||
if (targetCard->getAttachedTo() || targetCard->getZone()->getName() != "table") {
|
||||
if (targetCard->getAttachedTo() || targetCard->getZone()->getName() != ZoneNames::TABLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -326,12 +327,12 @@ void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCar
|
|||
CardZoneLogic *targetZone = targetCard->getZone();
|
||||
|
||||
// move card onto table first if attaching from some other zone
|
||||
if (startZone->getName() != "table") {
|
||||
if (startZone->getName() != ZoneNames::TABLE) {
|
||||
player->getPlayerActions()->playCardToTable(startCard, false);
|
||||
}
|
||||
|
||||
Command_AttachCard cmd;
|
||||
cmd.set_start_zone("table");
|
||||
cmd.set_start_zone(ZoneNames::TABLE);
|
||||
cmd.set_card_id(startCard->getId());
|
||||
cmd.set_target_player_id(targetZone->getPlayer()->getPlayerInfo()->getId());
|
||||
cmd.set_target_zone(targetZone->getName().toStdString());
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <QGraphicsView>
|
||||
#include <QSet>
|
||||
#include <QtMath>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
#include <numeric>
|
||||
|
||||
/**
|
||||
|
|
@ -410,9 +411,9 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
|
|||
connect(item, &ZoneViewWidget::closePressed, this, &GameScene::removeZoneView);
|
||||
addItem(item);
|
||||
|
||||
if (zoneName == "grave")
|
||||
if (zoneName == ZoneNames::GRAVE)
|
||||
item->setPos(360, 100);
|
||||
else if (zoneName == "rfg")
|
||||
else if (zoneName == ZoneNames::EXILE)
|
||||
item->setPos(380, 120);
|
||||
else
|
||||
item->setPos(340, 80);
|
||||
|
|
|
|||
|
|
@ -10,16 +10,9 @@
|
|||
#include <../../client/settings/card_counter_settings.h>
|
||||
#include <libcockatrice/protocol/pb/context_move_card.pb.h>
|
||||
#include <libcockatrice/protocol/pb/context_mulligan.pb.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
#include <utility>
|
||||
|
||||
static const QString TABLE_ZONE_NAME = "table";
|
||||
static const QString GRAVE_ZONE_NAME = "grave";
|
||||
static const QString EXILE_ZONE_NAME = "rfg";
|
||||
static const QString HAND_ZONE_NAME = "hand";
|
||||
static const QString DECK_ZONE_NAME = "deck";
|
||||
static const QString SIDEBOARD_ZONE_NAME = "sb";
|
||||
static const QString STACK_ZONE_NAME = "stack";
|
||||
|
||||
static QString sanitizeHtml(QString dirty)
|
||||
{
|
||||
return dirty.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """);
|
||||
|
|
@ -37,15 +30,15 @@ MessageLogWidget::getFromStr(CardZoneLogic *zone, QString cardName, int position
|
|||
QString fromStr;
|
||||
QString zoneName = zone->getName();
|
||||
|
||||
if (zoneName == TABLE_ZONE_NAME) {
|
||||
if (zoneName == ZoneNames::TABLE) {
|
||||
fromStr = tr(" from play");
|
||||
} else if (zoneName == GRAVE_ZONE_NAME) {
|
||||
} else if (zoneName == ZoneNames::GRAVE) {
|
||||
fromStr = tr(" from their graveyard");
|
||||
} else if (zoneName == EXILE_ZONE_NAME) {
|
||||
} else if (zoneName == ZoneNames::EXILE) {
|
||||
fromStr = tr(" from exile");
|
||||
} else if (zoneName == HAND_ZONE_NAME) {
|
||||
} else if (zoneName == ZoneNames::HAND) {
|
||||
fromStr = tr(" from their hand");
|
||||
} else if (zoneName == DECK_ZONE_NAME) {
|
||||
} else if (zoneName == ZoneNames::DECK) {
|
||||
if (position == 0) {
|
||||
if (cardName.isEmpty()) {
|
||||
if (ownerChange) {
|
||||
|
|
@ -83,9 +76,9 @@ MessageLogWidget::getFromStr(CardZoneLogic *zone, QString cardName, int position
|
|||
fromStr = tr(" from their library");
|
||||
}
|
||||
}
|
||||
} else if (zoneName == SIDEBOARD_ZONE_NAME) {
|
||||
} else if (zoneName == ZoneNames::SIDEBOARD) {
|
||||
fromStr = tr(" from sideboard");
|
||||
} else if (zoneName == STACK_ZONE_NAME) {
|
||||
} else if (zoneName == ZoneNames::STACK) {
|
||||
fromStr = tr(" from the stack");
|
||||
} else {
|
||||
fromStr = tr(" from custom zone '%1'").arg(zoneName);
|
||||
|
|
@ -275,9 +268,9 @@ void MessageLogWidget::logMoveCard(Player *player,
|
|||
bool ownerChanged = startZone->getPlayer() != targetZone->getPlayer();
|
||||
|
||||
// do not log if moved within the same zone
|
||||
if ((startZoneName == TABLE_ZONE_NAME && targetZoneName == TABLE_ZONE_NAME && !ownerChanged) ||
|
||||
(startZoneName == HAND_ZONE_NAME && targetZoneName == HAND_ZONE_NAME) ||
|
||||
(startZoneName == EXILE_ZONE_NAME && targetZoneName == EXILE_ZONE_NAME)) {
|
||||
if ((startZoneName == ZoneNames::TABLE && targetZoneName == ZoneNames::TABLE && !ownerChanged) ||
|
||||
(startZoneName == ZoneNames::HAND && targetZoneName == ZoneNames::HAND) ||
|
||||
(startZoneName == ZoneNames::EXILE && targetZoneName == ZoneNames::EXILE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -306,28 +299,28 @@ void MessageLogWidget::logMoveCard(Player *player,
|
|||
|
||||
QString finalStr;
|
||||
std::optional<QString> fourthArg;
|
||||
if (targetZoneName == TABLE_ZONE_NAME) {
|
||||
if (targetZoneName == ZoneNames::TABLE) {
|
||||
soundEngine->playSound("play_card");
|
||||
if (card->getFaceDown()) {
|
||||
finalStr = tr("%1 puts %2 into play%3 face down.");
|
||||
} else {
|
||||
finalStr = tr("%1 puts %2 into play%3.");
|
||||
}
|
||||
} else if (targetZoneName == GRAVE_ZONE_NAME) {
|
||||
} else if (targetZoneName == ZoneNames::GRAVE) {
|
||||
if (card->getFaceDown()) {
|
||||
finalStr = tr("%1 puts %2%3 into their graveyard face down.");
|
||||
} else {
|
||||
finalStr = tr("%1 puts %2%3 into their graveyard.");
|
||||
}
|
||||
} else if (targetZoneName == EXILE_ZONE_NAME) {
|
||||
} else if (targetZoneName == ZoneNames::EXILE) {
|
||||
if (card->getFaceDown()) {
|
||||
finalStr = tr("%1 exiles %2%3 face down.");
|
||||
} else {
|
||||
finalStr = tr("%1 exiles %2%3.");
|
||||
}
|
||||
} else if (targetZoneName == HAND_ZONE_NAME) {
|
||||
} else if (targetZoneName == ZoneNames::HAND) {
|
||||
finalStr = tr("%1 moves %2%3 to their hand.");
|
||||
} else if (targetZoneName == DECK_ZONE_NAME) {
|
||||
} else if (targetZoneName == ZoneNames::DECK) {
|
||||
if (newX == -1) {
|
||||
finalStr = tr("%1 puts %2%3 into their library.");
|
||||
} else if (newX >= targetZone->getCards().size()) {
|
||||
|
|
@ -339,9 +332,9 @@ void MessageLogWidget::logMoveCard(Player *player,
|
|||
fourthArg = QString::number(newX);
|
||||
finalStr = tr("%1 puts %2%3 into their library %4 cards from the top.");
|
||||
}
|
||||
} else if (targetZoneName == SIDEBOARD_ZONE_NAME) {
|
||||
} else if (targetZoneName == ZoneNames::SIDEBOARD) {
|
||||
finalStr = tr("%1 moves %2%3 to sideboard.");
|
||||
} else if (targetZoneName == STACK_ZONE_NAME) {
|
||||
} else if (targetZoneName == ZoneNames::STACK) {
|
||||
soundEngine->playSound("play_card");
|
||||
if (card->getFaceDown()) {
|
||||
finalStr = tr("%1 plays %2%3 face down.");
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <libcockatrice/protocol/pb/command_next_turn.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_set_active_phase.pb.h>
|
||||
#include <libcockatrice/protocol/pb/command_set_card_attr.pb.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_doubleClickAction, bool _highlightable)
|
||||
: QObject(), QGraphicsItem(parent), name(_name), active(false), highlightable(_highlightable),
|
||||
|
|
@ -259,7 +260,7 @@ void PhasesToolbar::actNextTurn()
|
|||
void PhasesToolbar::actUntapAll()
|
||||
{
|
||||
Command_SetCardAttr cmd;
|
||||
cmd.set_zone("table");
|
||||
cmd.set_zone(ZoneNames::TABLE);
|
||||
cmd.set_attribute(AttrTapped);
|
||||
cmd.set_attr_value("0");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue