mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-08 17:13:57 -07:00
* Add ZoneNames constants for protocol zone identifiers. Introduce a centralized ZoneNames namespace providing constexpr constants for zone identifiers used in the client-server protocol. This establishes a single source of truth for zone names like TABLE, GRAVE, EXILE, HAND, DECK, SIDEBOARD, and STACK. The protocol values remain unchanged (e.g., EXILE maps to rfg for backwards compatibility) while providing meaningful constant names. * refactor(server): use ZoneNames constants in server game logic Replace hardcoded zone name strings with ZoneNames:: constants in: - server_player.cpp: zone setup, draw, shuffle, mulligan operations - server_abstract_player.cpp: card movement and token destruction - server_game.cpp: returning cards when players leave No functional changes - purely mechanical string literal replacement. * refactor(client): use ZoneNames constants in core player/zone logic Update the foundational player and zone classes to use ZoneNames:: constants instead of string literals. Changes include: - player.h/cpp: zone initialization and builtinZones set - card_zone_logic.cpp: zone name translation for UI display - table_zone.cpp: table zone operations No functional changes - purely mechanical string literal replacement. * refactor(client): use ZoneNames constants in player actions and events Replace zone name strings with ZoneNames:: constants in the player action and event handling code. player_actions.cpp contains the most extensive changes (~90+ replacements) covering all card movement commands. No functional changes - purely mechanical string literal replacement. * refactor(client): use ZoneNames constants in zone menu handlers Update all zone-specific menu files to use ZoneNames:: constants for QAction data values and zone targeting. This covers context menus for cards, graveyard, hand, and exile (RFG) zones. No functional changes - purely mechanical string literal replacement. * 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. * formatting fix
269 lines
6.1 KiB
C++
269 lines
6.1 KiB
C++
/**
|
|
* @file player.h
|
|
* @ingroup GameLogicPlayers
|
|
* @brief TODO: Document this.
|
|
*/
|
|
|
|
#ifndef PLAYER_H
|
|
#define PLAYER_H
|
|
|
|
#include "../../game_graphics/board/abstract_graphics_item.h"
|
|
#include "../../interface/widgets/menus/tearoff_menu.h"
|
|
#include "../interface/deck_loader/loaded_deck.h"
|
|
#include "../zones/logic/hand_zone_logic.h"
|
|
#include "../zones/logic/pile_zone_logic.h"
|
|
#include "../zones/logic/stack_zone_logic.h"
|
|
#include "../zones/logic/table_zone_logic.h"
|
|
#include "menu/player_menu.h"
|
|
#include "player_area.h"
|
|
#include "player_event_handler.h"
|
|
#include "player_graphics_item.h"
|
|
#include "player_info.h"
|
|
|
|
#include <QInputDialog>
|
|
#include <QLoggingCategory>
|
|
#include <QMap>
|
|
#include <QTimer>
|
|
#include <libcockatrice/filters/filter_string.h>
|
|
#include <libcockatrice/protocol/pb/card_attributes.pb.h>
|
|
#include <libcockatrice/protocol/pb/game_event.pb.h>
|
|
#include <libcockatrice/utility/zone_names.h>
|
|
|
|
inline Q_LOGGING_CATEGORY(PlayerLog, "player");
|
|
|
|
namespace google
|
|
{
|
|
namespace protobuf
|
|
{
|
|
class Message;
|
|
}
|
|
} // namespace google
|
|
class AbstractCardItem;
|
|
class AbstractCounter;
|
|
class AbstractGame;
|
|
class ArrowItem;
|
|
class ArrowTarget;
|
|
class CardDatabase;
|
|
class CardZone;
|
|
class CommandContainer;
|
|
class GameCommand;
|
|
class GameEvent;
|
|
class PlayerInfo;
|
|
class PlayerEventHandler;
|
|
class PlayerActions;
|
|
class PlayerMenu;
|
|
class QAction;
|
|
class QMenu;
|
|
class ServerInfo_Arrow;
|
|
class ServerInfo_Counter;
|
|
class ServerInfo_Player;
|
|
class ServerInfo_User;
|
|
class TabGame;
|
|
|
|
const int MAX_TOKENS_PER_DIALOG = 99;
|
|
|
|
class Player : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
signals:
|
|
void openDeckEditor(const LoadedDeck &deck);
|
|
void deckChanged();
|
|
void newCardAdded(AbstractCardItem *card);
|
|
void rearrangeCounters();
|
|
void activeChanged(bool active);
|
|
void concededChanged(int playerId, bool conceded);
|
|
void clearCustomZonesMenu();
|
|
void addViewCustomZoneActionToCustomZoneMenu(QString zoneName);
|
|
void resetTopCardMenuActions();
|
|
|
|
public slots:
|
|
void setActive(bool _active);
|
|
|
|
public:
|
|
Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, AbstractGame *_parent);
|
|
void forwardActionSignalsToEventHandler();
|
|
~Player() override;
|
|
|
|
void initializeZones();
|
|
void updateZones();
|
|
void clear();
|
|
|
|
void processPlayerInfo(const ServerInfo_Player &info);
|
|
void processCardAttachment(const ServerInfo_Player &info);
|
|
|
|
void addCard(CardItem *c);
|
|
void deleteCard(CardItem *c);
|
|
|
|
bool clearCardsToDelete();
|
|
|
|
bool getActive() const
|
|
{
|
|
return active;
|
|
}
|
|
|
|
AbstractGame *getGame() const
|
|
{
|
|
return game;
|
|
}
|
|
|
|
GameScene *getGameScene();
|
|
|
|
[[nodiscard]] PlayerGraphicsItem *getGraphicsItem();
|
|
|
|
[[nodiscard]] PlayerActions *getPlayerActions() const
|
|
{
|
|
return playerActions;
|
|
}
|
|
|
|
[[nodiscard]] PlayerEventHandler *getPlayerEventHandler() const
|
|
{
|
|
return playerEventHandler;
|
|
}
|
|
|
|
[[nodiscard]] PlayerInfo *getPlayerInfo() const
|
|
{
|
|
return playerInfo;
|
|
}
|
|
|
|
[[nodiscard]] PlayerMenu *getPlayerMenu() const
|
|
{
|
|
return playerMenu;
|
|
}
|
|
|
|
void setDeck(const DeckList &_deck);
|
|
|
|
[[nodiscard]] const DeckList &getDeck() const
|
|
{
|
|
return deck;
|
|
}
|
|
|
|
template <typename T> T *addZone(T *zone)
|
|
{
|
|
zones.insert(zone->getName(), zone);
|
|
return zone;
|
|
}
|
|
|
|
CardZoneLogic *getZone(const QString zoneName)
|
|
{
|
|
return zones.value(zoneName);
|
|
}
|
|
|
|
const QMap<QString, CardZoneLogic *> &getZones() const
|
|
{
|
|
return zones;
|
|
}
|
|
|
|
PileZoneLogic *getDeckZone()
|
|
{
|
|
return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::DECK));
|
|
}
|
|
|
|
PileZoneLogic *getGraveZone()
|
|
{
|
|
return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::GRAVE));
|
|
}
|
|
|
|
PileZoneLogic *getRfgZone()
|
|
{
|
|
return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::EXILE));
|
|
}
|
|
|
|
PileZoneLogic *getSideboardZone()
|
|
{
|
|
return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::SIDEBOARD));
|
|
}
|
|
|
|
TableZoneLogic *getTableZone()
|
|
{
|
|
return qobject_cast<TableZoneLogic *>(zones.value(ZoneNames::TABLE));
|
|
}
|
|
|
|
StackZoneLogic *getStackZone()
|
|
{
|
|
return qobject_cast<StackZoneLogic *>(zones.value(ZoneNames::STACK));
|
|
}
|
|
|
|
HandZoneLogic *getHandZone()
|
|
{
|
|
return qobject_cast<HandZoneLogic *>(zones.value(ZoneNames::HAND));
|
|
}
|
|
|
|
AbstractCounter *addCounter(const ServerInfo_Counter &counter);
|
|
AbstractCounter *addCounter(int counterId, const QString &name, QColor color, int radius, int value);
|
|
void delCounter(int counterId);
|
|
void clearCounters();
|
|
void incrementAllCardCounters();
|
|
|
|
QMap<int, AbstractCounter *> getCounters()
|
|
{
|
|
return counters;
|
|
}
|
|
|
|
ArrowItem *addArrow(const ServerInfo_Arrow &arrow);
|
|
ArrowItem *addArrow(int arrowId, CardItem *startCard, ArrowTarget *targetItem, const QColor &color);
|
|
void delArrow(int arrowId);
|
|
void removeArrow(ArrowItem *arrow);
|
|
void clearArrows();
|
|
|
|
const QMap<int, ArrowItem *> &getArrows() const
|
|
{
|
|
return arrows;
|
|
}
|
|
|
|
void setConceded(bool _conceded);
|
|
bool getConceded() const
|
|
{
|
|
return conceded;
|
|
}
|
|
|
|
void setGameStarted();
|
|
|
|
void setDialogSemaphore(const bool _active)
|
|
{
|
|
dialogSemaphore = _active;
|
|
}
|
|
|
|
int getZoneId() const
|
|
{
|
|
return zoneId;
|
|
}
|
|
|
|
void setZoneId(int _zoneId);
|
|
|
|
private:
|
|
AbstractGame *game;
|
|
PlayerInfo *playerInfo;
|
|
PlayerEventHandler *playerEventHandler;
|
|
PlayerActions *playerActions;
|
|
PlayerMenu *playerMenu;
|
|
PlayerGraphicsItem *graphicsItem;
|
|
|
|
bool active;
|
|
bool conceded;
|
|
|
|
DeckList deck;
|
|
|
|
int zoneId;
|
|
QMap<QString, CardZoneLogic *> zones;
|
|
QMap<int, AbstractCounter *> counters;
|
|
QMap<int, ArrowItem *> arrows;
|
|
|
|
bool dialogSemaphore;
|
|
QList<CardItem *> cardsToDelete;
|
|
|
|
// void eventConnectionStateChanged(const Event_ConnectionStateChanged &event);
|
|
};
|
|
|
|
class AnnotationDialog : public QInputDialog
|
|
{
|
|
Q_OBJECT
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
public:
|
|
explicit AnnotationDialog(QWidget *parent = nullptr) : QInputDialog(parent)
|
|
{
|
|
}
|
|
};
|
|
|
|
#endif
|