mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-29 18:13:55 -07:00
Player refactor (#6112)
* Player refactor. Took 1 hour 43 minutes Took 1 minute Took 23 seconds * Tiny lint. Took 3 minutes * Hook up tap logic again. Took 13 minutes * Fix an include. Took 3 minutes * Stuff. Took 6 minutes * Fix typo. Took 7 minutes * Include. Took 1 minute * Reorganize method/variable definitions, remove unused ones. Took 1 hour 8 minutes Took 24 seconds * Clean up some unused imports. Took 6 minutes * Player holds the deck, emits deckChanged(), other elements player->getDeck() to respond to changes. Took 37 minutes * Connect player->openDeckEditor signal directly in the player constructor Took 6 minutes * Emit openDeckEditor signal in player_actions again. Took 3 minutes * Do to-do's Took 3 hours 32 minutes * Lint. Took 3 minutes * Lint again. Took 2 minutes * Fix include. Took 32 minutes * The stack should ensure card visibility. Took 21 minutes * Fine, the game can remember the tab. Took 10 minutes Took 21 seconds Took 9 seconds * zoneId is a dynamic gameplay property and thus belongs in player.cpp Took 11 minutes Took 19 seconds * Signal view removal, addition. Took 5 minutes * Ensure all players are considered local in local game. Took 10 minutes * ENSURE they are. Took 8 minutes * Bounds check data sent by QAction() Took 54 minutes * Move comment. Took 20 seconds * Reimplement logging category for game_event_handler.cpp, remove linebreaks. Took 36 seconds * PlayerGraphicsItem is responsible for retranslateUi, not Player. Took 14 seconds * Set menu for sideboard again, translate some menu titles, reimplement actIncPT action Took 54 seconds * Comment spacing. Took 43 seconds * Change message_log_widget.cpp slots to take CardZoneLogic parameters as emitted by PlayerEventHandler. Took 7 minutes Took 14 seconds * Remove unused player_logger.cpp Took 2 minutes * Query local game state correctly from tab_supervisor again Took 3 minutes * Revert Deck legality checker. Took 3 minutes * Instantiate menu before graphics item. Took 1 hour 5 minutes Took 55 minutes * Differentiate games and replays. Took 9 seconds * Lint. Took 10 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
b8e545bfa4
commit
9601a1fa4e
92 changed files with 7104 additions and 5827 deletions
19
cockatrice/src/game/player/card_menu_action_type.h
Normal file
19
cockatrice/src/game/player/card_menu_action_type.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef COCKATRICE_CARD_MENU_ACTION_TYPE_H
|
||||
#define COCKATRICE_CARD_MENU_ACTION_TYPE_H
|
||||
|
||||
enum CardMenuActionType
|
||||
{
|
||||
cmTap,
|
||||
cmUntap,
|
||||
cmDoesntUntap,
|
||||
cmFlip,
|
||||
cmPeek,
|
||||
cmClone,
|
||||
cmMoveToTopLibrary,
|
||||
cmMoveToBottomLibrary,
|
||||
cmMoveToHand,
|
||||
cmMoveToGraveyard,
|
||||
cmMoveToExile
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_CARD_MENU_ACTION_TYPE_H
|
||||
19
cockatrice/src/game/player/event_processing_options.h
Normal file
19
cockatrice/src/game/player/event_processing_options.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef COCKATRICE_EVENT_PROCESSING_OPTIONS_H
|
||||
#define COCKATRICE_EVENT_PROCESSING_OPTIONS_H
|
||||
|
||||
#include <QFlags>
|
||||
|
||||
// Define the base enum
|
||||
enum EventProcessingOption
|
||||
{
|
||||
SKIP_REVEAL_WINDOW = 0x0001,
|
||||
SKIP_TAP_ANIMATION = 0x0002
|
||||
};
|
||||
|
||||
// Wrap it in a QFlags typedef
|
||||
Q_DECLARE_FLAGS(EventProcessingOptions, EventProcessingOption)
|
||||
|
||||
// Add operator overloads (|, &, etc.)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(EventProcessingOptions)
|
||||
|
||||
#endif // COCKATRICE_EVENT_PROCESSING_OPTIONS_H
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -8,6 +8,12 @@
|
|||
#include "../filters/filter_string.h"
|
||||
#include "pb/card_attributes.pb.h"
|
||||
#include "pb/game_event.pb.h"
|
||||
#include "player_actions.h"
|
||||
#include "player_area.h"
|
||||
#include "player_event_handler.h"
|
||||
#include "player_graphics_item.h"
|
||||
#include "player_info.h"
|
||||
#include "player_menu.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QLoggingCategory>
|
||||
|
|
@ -26,476 +32,176 @@ class Message;
|
|||
} // namespace google
|
||||
class AbstractCardItem;
|
||||
class AbstractCounter;
|
||||
class AbstractGame;
|
||||
class ArrowItem;
|
||||
class ArrowTarget;
|
||||
class CardDatabase;
|
||||
class CardItem;
|
||||
class CardZone;
|
||||
class CommandContainer;
|
||||
class Command_MoveCard;
|
||||
class DeckLoader;
|
||||
class Event_AttachCard;
|
||||
class Event_ChangeZoneProperties;
|
||||
class Event_CreateArrow;
|
||||
class Event_CreateCounter;
|
||||
class Event_CreateToken;
|
||||
class Event_DelCounter;
|
||||
class Event_DeleteArrow;
|
||||
class Event_DestroyCard;
|
||||
class Event_DrawCards;
|
||||
class Event_DumpZone;
|
||||
class Event_FlipCard;
|
||||
class Event_GameSay;
|
||||
class Event_MoveCard;
|
||||
class Event_RevealCards;
|
||||
class Event_RollDie;
|
||||
class Event_SetCardAttr;
|
||||
class Event_SetCardCounter;
|
||||
class Event_SetCounter;
|
||||
class Event_Shuffle;
|
||||
class GameCommand;
|
||||
class GameEvent;
|
||||
class GameEventContext;
|
||||
class HandZone;
|
||||
class PendingCommand;
|
||||
class PlayerTarget;
|
||||
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 StackZone;
|
||||
class TabGame;
|
||||
class TableZone;
|
||||
class ZoneViewZone;
|
||||
|
||||
const int MAX_TOKENS_PER_DIALOG = 99;
|
||||
|
||||
/**
|
||||
* The entire graphical area belonging to a single player.
|
||||
*/
|
||||
class PlayerArea : public QObject, public QGraphicsItem
|
||||
class Player : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QGraphicsItem)
|
||||
private:
|
||||
QRectF bRect;
|
||||
int playerZoneId;
|
||||
private slots:
|
||||
void updateBg();
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
Type = typeOther
|
||||
};
|
||||
int type() const override
|
||||
{
|
||||
return Type;
|
||||
}
|
||||
|
||||
explicit PlayerArea(QGraphicsItem *parent = nullptr);
|
||||
QRectF boundingRect() const override
|
||||
{
|
||||
return bRect;
|
||||
}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
void setSize(qreal width, qreal height);
|
||||
|
||||
void setPlayerZoneId(int _playerZoneId);
|
||||
int getPlayerZoneId() const
|
||||
{
|
||||
return playerZoneId;
|
||||
}
|
||||
};
|
||||
|
||||
class Player : public QObject, public QGraphicsItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QGraphicsItem)
|
||||
signals:
|
||||
void openDeckEditor(const DeckLoader *deck);
|
||||
void deckChanged();
|
||||
void newCardAdded(AbstractCardItem *card);
|
||||
// Log events
|
||||
void logSay(Player *player, QString message);
|
||||
void logShuffle(Player *player, CardZone *zone, int start, int end);
|
||||
void logRollDie(Player *player, int sides, const QList<uint> &rolls);
|
||||
void logCreateArrow(Player *player,
|
||||
Player *startPlayer,
|
||||
QString startCard,
|
||||
Player *targetPlayer,
|
||||
QString targetCard,
|
||||
bool _playerTarget);
|
||||
void logCreateToken(Player *player, QString cardName, QString pt, bool faceDown);
|
||||
void logDrawCards(Player *player, int number, bool deckIsEmpty);
|
||||
void logUndoDraw(Player *player, QString cardName);
|
||||
void logMoveCard(Player *player, CardItem *card, CardZone *startZone, int oldX, CardZone *targetZone, int newX);
|
||||
void logFlipCard(Player *player, QString cardName, bool faceDown);
|
||||
void logDestroyCard(Player *player, QString cardName);
|
||||
void logAttachCard(Player *player, QString cardName, Player *targetPlayer, QString targetCardName);
|
||||
void logUnattachCard(Player *player, QString cardName);
|
||||
void logSetCardCounter(Player *player, QString cardName, int counterId, int value, int oldValue);
|
||||
void logSetTapped(Player *player, CardItem *card, bool tapped);
|
||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||
void logSetDoesntUntap(Player *player, CardItem *card, bool doesntUntap);
|
||||
void logSetPT(Player *player, CardItem *card, QString newPT);
|
||||
void logSetAnnotation(Player *player, CardItem *card, QString newAnnotation);
|
||||
void logDumpZone(Player *player, CardZone *zone, int numberCards, bool isReversed = false);
|
||||
void logRevealCards(Player *player,
|
||||
CardZone *zone,
|
||||
int cardId,
|
||||
QString cardName,
|
||||
Player *otherPlayer,
|
||||
bool faceDown,
|
||||
int amount,
|
||||
bool isLentToAnotherPlayer = false);
|
||||
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
|
||||
void logAlwaysLookAtTopCard(Player *player, CardZone *zone, bool reveal);
|
||||
|
||||
void sizeChanged();
|
||||
void playerCountChanged();
|
||||
void cardMenuUpdated(QMenu *cardMenu);
|
||||
public slots:
|
||||
void actUntapAll();
|
||||
void actRollDie();
|
||||
void actCreateToken();
|
||||
void actCreateAnotherToken();
|
||||
void actShuffle();
|
||||
void actShuffleTop();
|
||||
void actShuffleBottom();
|
||||
void actDrawCard();
|
||||
void actDrawCards();
|
||||
void actUndoDraw();
|
||||
void actMulligan();
|
||||
|
||||
void actPlay();
|
||||
void actPlayFacedown();
|
||||
void actHide();
|
||||
|
||||
void actMoveTopCardToPlay();
|
||||
void actMoveTopCardToPlayFaceDown();
|
||||
void actMoveTopCardToGrave();
|
||||
void actMoveTopCardToExile();
|
||||
void actMoveTopCardsToGrave();
|
||||
void actMoveTopCardsToExile();
|
||||
void actMoveTopCardsUntil();
|
||||
void actMoveTopCardToBottom();
|
||||
void actDrawBottomCard();
|
||||
void actDrawBottomCards();
|
||||
void actMoveBottomCardToPlay();
|
||||
void actMoveBottomCardToPlayFaceDown();
|
||||
void actMoveBottomCardToGrave();
|
||||
void actMoveBottomCardToExile();
|
||||
void actMoveBottomCardsToGrave();
|
||||
void actMoveBottomCardsToExile();
|
||||
void actMoveBottomCardToTop();
|
||||
|
||||
void actSelectAll();
|
||||
void actSelectRow();
|
||||
void actSelectColumn();
|
||||
|
||||
void actViewLibrary();
|
||||
void actViewHand();
|
||||
void actViewTopCards();
|
||||
void actViewBottomCards();
|
||||
void actAlwaysRevealTopCard();
|
||||
void actAlwaysLookAtTopCard();
|
||||
void actViewGraveyard();
|
||||
void actRevealRandomGraveyardCard();
|
||||
void actViewRfg();
|
||||
void actViewSideboard();
|
||||
|
||||
void actSayMessage();
|
||||
private slots:
|
||||
void addPlayer(Player *player);
|
||||
void removePlayer(Player *player);
|
||||
void playerListActionTriggered();
|
||||
|
||||
void updateBoundingRect();
|
||||
void rearrangeZones();
|
||||
|
||||
void actOpenDeckInDeckEditor();
|
||||
void actCreatePredefinedToken();
|
||||
void actCreateRelatedCard();
|
||||
void actCreateAllRelatedCards();
|
||||
void cardMenuAction();
|
||||
void actMoveCardXCardsFromTop();
|
||||
void actCardCounterTrigger();
|
||||
void actAttach();
|
||||
void actUnattach();
|
||||
void actDrawArrow();
|
||||
void actIncPT(int deltaP, int deltaT);
|
||||
void actResetPT();
|
||||
void actSetPT();
|
||||
void actIncP();
|
||||
void actDecP();
|
||||
void actIncT();
|
||||
void actDecT();
|
||||
void actIncPT();
|
||||
void actDecPT();
|
||||
void actFlowP();
|
||||
void actFlowT();
|
||||
void actSetAnnotation();
|
||||
void actReveal(QAction *action);
|
||||
void refreshShortcuts();
|
||||
void actSortHand();
|
||||
void initSayMenu();
|
||||
|
||||
public:
|
||||
enum EventProcessingOption
|
||||
{
|
||||
SKIP_REVEAL_WINDOW = 0x0001,
|
||||
SKIP_TAP_ANIMATION = 0x0002
|
||||
};
|
||||
Q_DECLARE_FLAGS(EventProcessingOptions, EventProcessingOption)
|
||||
|
||||
private:
|
||||
TabGame *game;
|
||||
QMenu *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu, *mRevealLibrary, *mLendLibrary, *mRevealTopCard,
|
||||
*mRevealHand, *mRevealRandomHandCard, *mRevealRandomGraveyardCard, *mCustomZones, *mCardCounters;
|
||||
TearOffMenu *moveGraveMenu, *moveRfgMenu, *graveMenu, *moveHandMenu, *handMenu, *libraryMenu, *topLibraryMenu,
|
||||
*bottomLibraryMenu, *rfgMenu, *playerMenu;
|
||||
QList<QMenu *> playerLists;
|
||||
QList<QMenu *> singlePlayerLists;
|
||||
QList<QAction *> allPlayersActions;
|
||||
QList<QPair<QString, int>> playersInfo;
|
||||
QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg,
|
||||
*aMoveGraveToTopLibrary, *aMoveGraveToBottomLibrary, *aMoveGraveToHand, *aMoveGraveToRfg, *aMoveRfgToTopLibrary,
|
||||
*aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave, *aViewHand, *aViewLibrary, *aViewTopCards,
|
||||
*aViewBottomCards, *aAlwaysRevealTopCard, *aAlwaysLookAtTopCard, *aOpenDeckInDeckEditor,
|
||||
*aMoveTopCardToGraveyard, *aMoveTopCardToExile, *aMoveTopCardsToGraveyard, *aMoveTopCardsToExile,
|
||||
*aMoveTopCardsUntil, *aMoveTopCardToBottom, *aViewGraveyard, *aViewRfg, *aViewSideboard, *aDrawCard,
|
||||
*aDrawCards, *aUndoDraw, *aMulligan, *aShuffle, *aShuffleTopCards, *aShuffleBottomCards, *aMoveTopToPlay,
|
||||
*aMoveTopToPlayFaceDown, *aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken, *aMoveBottomToPlay,
|
||||
*aMoveBottomToPlayFaceDown, *aMoveBottomCardToTop, *aMoveBottomCardToGraveyard, *aMoveBottomCardToExile,
|
||||
*aMoveBottomCardsToGraveyard, *aMoveBottomCardsToExile, *aDrawBottomCard, *aDrawBottomCards;
|
||||
|
||||
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;
|
||||
QAction *aPlay, *aPlayFacedown, *aHide, *aTap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetPT, *aResetPT,
|
||||
*aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aFlowP, *aFlowT, *aSetAnnotation, *aFlip, *aPeek, *aClone,
|
||||
*aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToHand, *aMoveToGraveyard, *aMoveToExile,
|
||||
*aMoveToXfromTopOfLibrary, *aSelectAll, *aSelectRow, *aSelectColumn, *aSortHand, *aIncrementAllCardCounters;
|
||||
|
||||
bool movingCardsUntil;
|
||||
QTimer *moveTopCardTimer;
|
||||
QStringList movingCardsUntilExprs = {};
|
||||
int movingCardsUntilNumberOfHits = 1;
|
||||
bool movingCardsUntilAutoPlay = false;
|
||||
FilterString movingCardsUntilFilter;
|
||||
int movingCardsUntilCounter = 0;
|
||||
void stopMoveTopCardsUntil();
|
||||
|
||||
bool shortcutsActive;
|
||||
int defaultNumberTopCards = 1;
|
||||
int defaultNumberTopCardsToPlaceBelow = 1;
|
||||
int defaultNumberBottomCards = 1;
|
||||
int defaultNumberDieRoll = 20;
|
||||
|
||||
TokenInfo lastTokenInfo;
|
||||
int lastTokenTableRow;
|
||||
|
||||
ServerInfo_User *userInfo;
|
||||
int id;
|
||||
bool active;
|
||||
bool local;
|
||||
bool judge;
|
||||
bool mirrored;
|
||||
bool handVisible;
|
||||
bool conceded;
|
||||
int zoneId;
|
||||
|
||||
bool dialogSemaphore;
|
||||
bool clearCardsToDelete();
|
||||
QList<CardItem *> cardsToDelete;
|
||||
|
||||
DeckLoader *deck;
|
||||
QStringList predefinedTokens;
|
||||
|
||||
PlayerArea *playerArea;
|
||||
QMap<QString, CardZone *> zones;
|
||||
StackZone *stack;
|
||||
TableZone *table;
|
||||
HandZone *hand;
|
||||
PlayerTarget *playerTarget;
|
||||
|
||||
void setCardAttrHelper(const GameEventContext &context,
|
||||
CardItem *card,
|
||||
CardAttribute attribute,
|
||||
const QString &avalue,
|
||||
bool allCards,
|
||||
EventProcessingOptions options);
|
||||
QMenu *createMoveMenu() const;
|
||||
QMenu *createPtMenu() const;
|
||||
void addRelatedCardActions(const CardItem *card, QMenu *cardMenu);
|
||||
void addRelatedCardView(const CardItem *card, QMenu *cardMenu);
|
||||
void createCard(const CardItem *sourceCard,
|
||||
const QString &dbCardName,
|
||||
CardRelation::AttachType attach = CardRelation::DoesNotAttach,
|
||||
bool persistent = false);
|
||||
bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation);
|
||||
void moveOneCardUntil(CardItem *card);
|
||||
void addPlayerToList(QMenu *playerList, Player *player);
|
||||
static void removePlayerFromList(QMenu *playerList, Player *player);
|
||||
|
||||
void playSelectedCards(bool faceDown = false);
|
||||
|
||||
QRectF bRect;
|
||||
|
||||
QMap<int, AbstractCounter *> counters;
|
||||
QMap<int, ArrowItem *> arrows;
|
||||
void rearrangeCounters();
|
||||
void activeChanged(bool active);
|
||||
void concededChanged(int playerId, bool conceded);
|
||||
void clearCustomZonesMenu();
|
||||
void addViewCustomZoneActionToCustomZoneMenu(QString zoneName);
|
||||
void resetTopCardMenuActions();
|
||||
|
||||
void initContextualPlayersMenu(QMenu *menu);
|
||||
|
||||
// void eventConnectionStateChanged(const Event_ConnectionStateChanged &event);
|
||||
void eventGameSay(const Event_GameSay &event);
|
||||
void eventShuffle(const Event_Shuffle &event);
|
||||
void eventRollDie(const Event_RollDie &event);
|
||||
void eventCreateArrow(const Event_CreateArrow &event);
|
||||
void eventDeleteArrow(const Event_DeleteArrow &event);
|
||||
void eventCreateToken(const Event_CreateToken &event);
|
||||
void
|
||||
eventSetCardAttr(const Event_SetCardAttr &event, const GameEventContext &context, EventProcessingOptions options);
|
||||
void eventSetCardCounter(const Event_SetCardCounter &event);
|
||||
void eventCreateCounter(const Event_CreateCounter &event);
|
||||
void eventSetCounter(const Event_SetCounter &event);
|
||||
void eventDelCounter(const Event_DelCounter &event);
|
||||
void eventDumpZone(const Event_DumpZone &event);
|
||||
void eventMoveCard(const Event_MoveCard &event, const GameEventContext &context);
|
||||
void eventFlipCard(const Event_FlipCard &event);
|
||||
void eventDestroyCard(const Event_DestroyCard &event);
|
||||
void eventAttachCard(const Event_AttachCard &event);
|
||||
void eventDrawCards(const Event_DrawCards &event);
|
||||
void eventRevealCards(const Event_RevealCards &event, EventProcessingOptions options);
|
||||
void eventChangeZoneProperties(const Event_ChangeZoneProperties &event);
|
||||
void cmdSetTopCard(Command_MoveCard &cmd);
|
||||
void cmdSetBottomCard(Command_MoveCard &cmd);
|
||||
|
||||
QVariantList parsePT(const QString &pt);
|
||||
public slots:
|
||||
void setActive(bool _active);
|
||||
|
||||
public:
|
||||
static const int counterAreaWidth = 55;
|
||||
enum CardMenuActionType
|
||||
{
|
||||
cmTap,
|
||||
cmUntap,
|
||||
cmDoesntUntap,
|
||||
cmFlip,
|
||||
cmPeek,
|
||||
cmClone,
|
||||
cmMoveToTopLibrary,
|
||||
cmMoveToBottomLibrary,
|
||||
cmMoveToHand,
|
||||
cmMoveToGraveyard,
|
||||
cmMoveToExile
|
||||
};
|
||||
enum CardsToReveal
|
||||
{
|
||||
RANDOM_CARD_FROM_ZONE = -2
|
||||
};
|
||||
Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, AbstractGame *_parent);
|
||||
~Player() override;
|
||||
|
||||
enum
|
||||
{
|
||||
Type = typeOther
|
||||
};
|
||||
int type() const override
|
||||
{
|
||||
return Type;
|
||||
}
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
void initializeZones();
|
||||
void updateZones();
|
||||
void clear();
|
||||
|
||||
void processPlayerInfo(const ServerInfo_Player &info);
|
||||
void processCardAttachment(const ServerInfo_Player &info);
|
||||
|
||||
void playCard(CardItem *c, bool faceDown);
|
||||
void playCardToTable(const CardItem *c, bool faceDown);
|
||||
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 DeckLoader &_deck);
|
||||
|
||||
[[nodiscard]] DeckLoader *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("deck"));
|
||||
}
|
||||
|
||||
PileZoneLogic *getGraveZone()
|
||||
{
|
||||
return qobject_cast<PileZoneLogic *>(zones.value("grave"));
|
||||
}
|
||||
|
||||
PileZoneLogic *getRfgZone()
|
||||
{
|
||||
return qobject_cast<PileZoneLogic *>(zones.value("rfg"));
|
||||
}
|
||||
|
||||
PileZoneLogic *getSideboardZone()
|
||||
{
|
||||
return qobject_cast<PileZoneLogic *>(zones.value("sb"));
|
||||
}
|
||||
|
||||
TableZoneLogic *getTableZone()
|
||||
{
|
||||
return qobject_cast<TableZoneLogic *>(zones.value("table"));
|
||||
}
|
||||
|
||||
StackZoneLogic *getStackZone()
|
||||
{
|
||||
return qobject_cast<StackZoneLogic *>(zones.value("stack"));
|
||||
}
|
||||
|
||||
HandZoneLogic *getHandZone()
|
||||
{
|
||||
return qobject_cast<HandZoneLogic *>(zones.value("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();
|
||||
PlayerTarget *getPlayerTarget() const
|
||||
{
|
||||
return playerTarget;
|
||||
}
|
||||
|
||||
Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, TabGame *_parent);
|
||||
~Player() override;
|
||||
|
||||
void retranslateUi();
|
||||
void clear();
|
||||
TabGame *getGame() const
|
||||
{
|
||||
return game;
|
||||
}
|
||||
void setDeck(const DeckLoader &_deck);
|
||||
QMenu *getPlayerMenu() const
|
||||
{
|
||||
return playerMenu;
|
||||
}
|
||||
int getId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
QString getName() const;
|
||||
ServerInfo_User *getUserInfo() const
|
||||
{
|
||||
return userInfo;
|
||||
}
|
||||
bool getLocal() const
|
||||
{
|
||||
return local;
|
||||
}
|
||||
bool getLocalOrJudge() const
|
||||
{
|
||||
return local || judge;
|
||||
}
|
||||
bool getJudge() const
|
||||
{
|
||||
return judge;
|
||||
}
|
||||
bool getMirrored() const
|
||||
{
|
||||
return mirrored;
|
||||
}
|
||||
int getZoneId() const
|
||||
{
|
||||
return zoneId;
|
||||
}
|
||||
void setZoneId(int _zoneId);
|
||||
const QMap<QString, CardZone *> &getZones() const
|
||||
{
|
||||
return zones;
|
||||
}
|
||||
const QMap<int, ArrowItem *> &getArrows() const
|
||||
{
|
||||
return arrows;
|
||||
}
|
||||
QMenu *updateCardMenu(const CardItem *card);
|
||||
QMenu *createCardMenu(const CardItem *card);
|
||||
bool getActive() const
|
||||
{
|
||||
return active;
|
||||
}
|
||||
void setActive(bool _active);
|
||||
void setShortcutsActive();
|
||||
void setShortcutsInactive();
|
||||
void updateZones();
|
||||
|
||||
void setConceded(bool _conceded);
|
||||
bool getConceded() const
|
||||
|
|
@ -505,35 +211,49 @@ public:
|
|||
|
||||
void setGameStarted();
|
||||
|
||||
qreal getMinimumWidth() const;
|
||||
void setMirrored(bool _mirrored);
|
||||
void processSceneSizeChange(int newPlayerWidth);
|
||||
void setDialogSemaphore(const bool _active)
|
||||
{
|
||||
dialogSemaphore = _active;
|
||||
}
|
||||
|
||||
void processPlayerInfo(const ServerInfo_Player &info);
|
||||
void processCardAttachment(const ServerInfo_Player &info);
|
||||
int getZoneId() const
|
||||
{
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
void processGameEvent(GameEvent::GameEventType type,
|
||||
const GameEvent &event,
|
||||
const GameEventContext &context,
|
||||
EventProcessingOptions options);
|
||||
void setZoneId(int _zoneId);
|
||||
|
||||
PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
|
||||
PendingCommand *prepareGameCommand(const QList<const ::google::protobuf::Message *> &cmdList);
|
||||
void sendGameCommand(PendingCommand *pend);
|
||||
void sendGameCommand(const google::protobuf::Message &command);
|
||||
private:
|
||||
AbstractGame *game;
|
||||
PlayerInfo *playerInfo;
|
||||
PlayerEventHandler *playerEventHandler;
|
||||
PlayerActions *playerActions;
|
||||
PlayerMenu *playerMenu;
|
||||
PlayerGraphicsItem *graphicsItem;
|
||||
|
||||
void setLastToken(CardInfoPtr cardInfo);
|
||||
bool active;
|
||||
bool conceded;
|
||||
|
||||
DeckLoader *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);
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Player::EventProcessingOptions)
|
||||
|
||||
class AnnotationDialog : public QInputDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
public:
|
||||
explicit AnnotationDialog(QWidget *parent) : QInputDialog(parent)
|
||||
explicit AnnotationDialog(QWidget *parent = nullptr) : QInputDialog(parent)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
|
|||
1895
cockatrice/src/game/player/player_actions.cpp
Normal file
1895
cockatrice/src/game/player/player_actions.cpp
Normal file
File diff suppressed because it is too large
Load diff
178
cockatrice/src/game/player/player_actions.h
Normal file
178
cockatrice/src/game/player/player_actions.h
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
#ifndef COCKATRICE_PLAYER_ACTIONS_H
|
||||
#define COCKATRICE_PLAYER_ACTIONS_H
|
||||
#include "event_processing_options.h"
|
||||
#include "player.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QObject>
|
||||
|
||||
namespace google
|
||||
{
|
||||
namespace protobuf
|
||||
{
|
||||
class Message;
|
||||
}
|
||||
} // namespace google
|
||||
|
||||
class CardItem;
|
||||
class Command_MoveCard;
|
||||
class GameEventContext;
|
||||
class PendingCommand;
|
||||
class Player;
|
||||
class PlayerActions : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void logSetTapped(Player *player, CardItem *card, bool tapped);
|
||||
void logSetAnnotation(Player *player, CardItem *card, QString newAnnotation);
|
||||
void logSetDoesntUntap(Player *player, CardItem *card, bool doesntUntap);
|
||||
void logSetPT(Player *player, CardItem *card, QString newPT);
|
||||
|
||||
public:
|
||||
enum CardsToReveal
|
||||
{
|
||||
RANDOM_CARD_FROM_ZONE = -2
|
||||
};
|
||||
|
||||
explicit PlayerActions(Player *player);
|
||||
|
||||
void sendGameCommand(PendingCommand *pend);
|
||||
void sendGameCommand(const google::protobuf::Message &command);
|
||||
|
||||
PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
|
||||
PendingCommand *prepareGameCommand(const QList<const ::google::protobuf::Message *> &cmdList);
|
||||
|
||||
void setCardAttrHelper(const GameEventContext &context,
|
||||
CardItem *card,
|
||||
CardAttribute attribute,
|
||||
const QString &avalue,
|
||||
bool allCards,
|
||||
EventProcessingOptions options);
|
||||
|
||||
void moveOneCardUntil(CardItem *card);
|
||||
void stopMoveTopCardsUntil();
|
||||
|
||||
bool isMovingCardsUntil() const
|
||||
{
|
||||
return movingCardsUntil;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void setLastToken(CardInfoPtr cardInfo);
|
||||
void playCard(CardItem *c, bool faceDown);
|
||||
void playCardToTable(const CardItem *c, bool faceDown);
|
||||
|
||||
void actUntapAll();
|
||||
void actRollDie();
|
||||
void actCreateToken();
|
||||
void actCreateAnotherToken();
|
||||
void actShuffle();
|
||||
void actShuffleTop();
|
||||
void actShuffleBottom();
|
||||
void actDrawCard();
|
||||
void actDrawCards();
|
||||
void actUndoDraw();
|
||||
void actMulligan();
|
||||
|
||||
void actPlay();
|
||||
void actPlayFacedown();
|
||||
void actHide();
|
||||
|
||||
void actMoveTopCardToPlay();
|
||||
void actMoveTopCardToPlayFaceDown();
|
||||
void actMoveTopCardToGrave();
|
||||
void actMoveTopCardToExile();
|
||||
void actMoveTopCardsToGrave();
|
||||
void actMoveTopCardsToExile();
|
||||
void actMoveTopCardsUntil();
|
||||
void actMoveTopCardToBottom();
|
||||
void actDrawBottomCard();
|
||||
void actDrawBottomCards();
|
||||
void actMoveBottomCardToPlay();
|
||||
void actMoveBottomCardToPlayFaceDown();
|
||||
void actMoveBottomCardToGrave();
|
||||
void actMoveBottomCardToExile();
|
||||
void actMoveBottomCardsToGrave();
|
||||
void actMoveBottomCardsToExile();
|
||||
void actMoveBottomCardToTop();
|
||||
|
||||
void actSelectAll();
|
||||
void actSelectRow();
|
||||
void actSelectColumn();
|
||||
|
||||
void actViewLibrary();
|
||||
void actViewHand();
|
||||
void actViewTopCards();
|
||||
void actViewBottomCards();
|
||||
void actAlwaysRevealTopCard();
|
||||
void actAlwaysLookAtTopCard();
|
||||
void actViewGraveyard();
|
||||
void actRevealRandomGraveyardCard();
|
||||
void actViewRfg();
|
||||
void actViewSideboard();
|
||||
|
||||
void actSayMessage();
|
||||
|
||||
void actOpenDeckInDeckEditor();
|
||||
void actCreatePredefinedToken();
|
||||
void actCreateRelatedCard();
|
||||
void actCreateAllRelatedCards();
|
||||
|
||||
void actMoveCardXCardsFromTop();
|
||||
void actCardCounterTrigger();
|
||||
void actAttach();
|
||||
void actUnattach();
|
||||
void actDrawArrow();
|
||||
void actIncPT(int deltaP, int deltaT);
|
||||
void actResetPT();
|
||||
void actSetPT();
|
||||
void actIncP();
|
||||
void actDecP();
|
||||
void actIncT();
|
||||
void actDecT();
|
||||
void actIncPT();
|
||||
void actDecPT();
|
||||
void actFlowP();
|
||||
void actFlowT();
|
||||
void actSetAnnotation();
|
||||
void actReveal(QAction *action);
|
||||
|
||||
void actSortHand();
|
||||
|
||||
void cardMenuAction();
|
||||
|
||||
private:
|
||||
Player *player;
|
||||
|
||||
int defaultNumberTopCards = 1;
|
||||
int defaultNumberTopCardsToPlaceBelow = 1;
|
||||
int defaultNumberBottomCards = 1;
|
||||
int defaultNumberDieRoll = 20;
|
||||
|
||||
TokenInfo lastTokenInfo;
|
||||
int lastTokenTableRow;
|
||||
|
||||
bool movingCardsUntil;
|
||||
QTimer *moveTopCardTimer;
|
||||
QStringList movingCardsUntilExprs = {};
|
||||
int movingCardsUntilNumberOfHits = 1;
|
||||
bool movingCardsUntilAutoPlay = false;
|
||||
FilterString movingCardsUntilFilter;
|
||||
int movingCardsUntilCounter = 0;
|
||||
|
||||
void createCard(const CardItem *sourceCard,
|
||||
const QString &dbCardName,
|
||||
CardRelation::AttachType attach = CardRelation::DoesNotAttach,
|
||||
bool persistent = false);
|
||||
bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation);
|
||||
|
||||
void playSelectedCards(bool faceDown = false);
|
||||
|
||||
void cmdSetTopCard(Command_MoveCard &cmd);
|
||||
void cmdSetBottomCard(Command_MoveCard &cmd);
|
||||
|
||||
QVariantList parsePT(const QString &pt);
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_ACTIONS_H
|
||||
34
cockatrice/src/game/player/player_area.cpp
Normal file
34
cockatrice/src/game/player/player_area.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "player_area.h"
|
||||
|
||||
#include "../../client/ui/theme_manager.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
PlayerArea::PlayerArea(QGraphicsItem *parentItem) : QObject(), QGraphicsItem(parentItem)
|
||||
{
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
connect(themeManager, &ThemeManager::themeChanged, this, &PlayerArea::updateBg);
|
||||
updateBg();
|
||||
}
|
||||
|
||||
void PlayerArea::updateBg()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
QBrush brush = themeManager->getExtraBgBrush(ThemeManager::Player, playerZoneId);
|
||||
painter->fillRect(boundingRect(), brush);
|
||||
}
|
||||
|
||||
void PlayerArea::setSize(qreal width, qreal height)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
bRect = QRectF(0, 0, width, height);
|
||||
}
|
||||
|
||||
void PlayerArea::setPlayerZoneId(int _playerZoneId)
|
||||
{
|
||||
playerZoneId = _playerZoneId;
|
||||
}
|
||||
46
cockatrice/src/game/player/player_area.h
Normal file
46
cockatrice/src/game/player/player_area.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#ifndef COCKATRICE_PLAYER_AREA_H
|
||||
#define COCKATRICE_PLAYER_AREA_H
|
||||
|
||||
#include "../board/graphics_item_type.h"
|
||||
#include "QGraphicsItem"
|
||||
|
||||
/**
|
||||
* The entire graphical area belonging to a single player.
|
||||
*/
|
||||
class PlayerArea : public QObject, public QGraphicsItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QGraphicsItem)
|
||||
private:
|
||||
QRectF bRect;
|
||||
int playerZoneId;
|
||||
private slots:
|
||||
void updateBg();
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
Type = typeOther
|
||||
};
|
||||
int type() const override
|
||||
{
|
||||
return Type;
|
||||
}
|
||||
|
||||
explicit PlayerArea(QGraphicsItem *parent = nullptr);
|
||||
QRectF boundingRect() const override
|
||||
{
|
||||
return bRect;
|
||||
}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
void setSize(qreal width, qreal height);
|
||||
|
||||
void setPlayerZoneId(int _playerZoneId);
|
||||
int getPlayerZoneId() const
|
||||
{
|
||||
return playerZoneId;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_AREA_H
|
||||
602
cockatrice/src/game/player/player_event_handler.cpp
Normal file
602
cockatrice/src/game/player/player_event_handler.cpp
Normal file
|
|
@ -0,0 +1,602 @@
|
|||
#include "player_event_handler.h"
|
||||
|
||||
#include "../../client/tabs/tab_game.h"
|
||||
#include "../board/arrow_item.h"
|
||||
#include "../board/card_item.h"
|
||||
#include "../board/card_list.h"
|
||||
#include "../zones/view_zone.h"
|
||||
#include "pb/command_set_card_attr.pb.h"
|
||||
#include "pb/context_move_card.pb.h"
|
||||
#include "pb/context_undo_draw.pb.h"
|
||||
#include "pb/event_attach_card.pb.h"
|
||||
#include "pb/event_change_zone_properties.pb.h"
|
||||
#include "pb/event_create_arrow.pb.h"
|
||||
#include "pb/event_create_counter.pb.h"
|
||||
#include "pb/event_create_token.pb.h"
|
||||
#include "pb/event_del_counter.pb.h"
|
||||
#include "pb/event_delete_arrow.pb.h"
|
||||
#include "pb/event_destroy_card.pb.h"
|
||||
#include "pb/event_draw_cards.pb.h"
|
||||
#include "pb/event_dump_zone.pb.h"
|
||||
#include "pb/event_flip_card.pb.h"
|
||||
#include "pb/event_game_say.pb.h"
|
||||
#include "pb/event_move_card.pb.h"
|
||||
#include "pb/event_reveal_cards.pb.h"
|
||||
#include "pb/event_roll_die.pb.h"
|
||||
#include "pb/event_set_card_attr.pb.h"
|
||||
#include "pb/event_set_card_counter.pb.h"
|
||||
#include "pb/event_set_counter.pb.h"
|
||||
#include "pb/event_shuffle.pb.h"
|
||||
#include "player.h"
|
||||
|
||||
PlayerEventHandler::PlayerEventHandler(Player *_player) : player(_player)
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventGameSay(const Event_GameSay &event)
|
||||
{
|
||||
emit logSay(player, QString::fromStdString(event.message()));
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventShuffle(const Event_Shuffle &event)
|
||||
{
|
||||
CardZoneLogic *zone = player->getZone(QString::fromStdString(event.zone_name()));
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
auto &cardList = zone->getCards();
|
||||
int absStart = event.start();
|
||||
if (absStart < 0) { // negative indexes start from the end
|
||||
absStart += cardList.length();
|
||||
}
|
||||
|
||||
// close all views that contain shuffled cards
|
||||
for (ZoneViewZone *view : zone->getViews()) {
|
||||
if (view != nullptr) {
|
||||
int length = view->getLogic()->getCards().length();
|
||||
// we want to close empty views as well
|
||||
if (length == 0 || length > absStart) { // note this assumes views always start at the top of the library
|
||||
view->close();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
qWarning() << zone->getName() << "of" << player->getPlayerInfo()->getName() << "holds empty zoneview!";
|
||||
}
|
||||
}
|
||||
|
||||
// remove revealed card name on top of decks
|
||||
if (absStart == 0 && !cardList.isEmpty()) {
|
||||
cardList.first()->setCardRef({});
|
||||
emit zone->updateGraphics();
|
||||
}
|
||||
|
||||
emit logShuffle(player, zone, event.start(), event.end());
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventRollDie(const Event_RollDie &event)
|
||||
{
|
||||
if (!event.values().empty()) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QList<uint> rolls(event.values().begin(), event.values().end());
|
||||
#else
|
||||
QList<uint> rolls;
|
||||
for (const auto &value : event.values()) {
|
||||
rolls.append(value);
|
||||
}
|
||||
#endif
|
||||
std::sort(rolls.begin(), rolls.end());
|
||||
emit logRollDie(player, static_cast<int>(event.sides()), rolls);
|
||||
} else if (event.value()) {
|
||||
// Backwards compatibility for old clients
|
||||
emit logRollDie(player, static_cast<int>(event.sides()), {event.value()});
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventCreateArrow(const Event_CreateArrow &event)
|
||||
{
|
||||
ArrowItem *arrow = player->addArrow(event.arrow_info());
|
||||
if (!arrow) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto *startCard = static_cast<CardItem *>(arrow->getStartItem());
|
||||
auto *targetCard = qgraphicsitem_cast<CardItem *>(arrow->getTargetItem());
|
||||
if (targetCard) {
|
||||
emit logCreateArrow(player, startCard->getOwner(), startCard->getName(), targetCard->getOwner(),
|
||||
targetCard->getName(), false);
|
||||
} else {
|
||||
emit logCreateArrow(player, startCard->getOwner(), startCard->getName(), arrow->getTargetItem()->getOwner(),
|
||||
QString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventDeleteArrow(const Event_DeleteArrow &event)
|
||||
{
|
||||
player->delArrow(event.arrow_id());
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventCreateToken(const Event_CreateToken &event)
|
||||
{
|
||||
CardZoneLogic *zone = player->getZone(QString::fromStdString(event.zone_name()));
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
|
||||
CardRef cardRef = {QString::fromStdString(event.card_name()), QString::fromStdString(event.card_provider_id())};
|
||||
CardItem *card = new CardItem(player, nullptr, cardRef, event.card_id());
|
||||
// use db PT if not provided in event and not face-down
|
||||
if (!QString::fromStdString(event.pt()).isEmpty()) {
|
||||
card->setPT(QString::fromStdString(event.pt()));
|
||||
} else if (!event.face_down()) {
|
||||
ExactCard dbCard = card->getCard();
|
||||
if (dbCard) {
|
||||
card->setPT(dbCard.getInfo().getPowTough());
|
||||
}
|
||||
}
|
||||
card->setColor(QString::fromStdString(event.color()));
|
||||
card->setAnnotation(QString::fromStdString(event.annotation()));
|
||||
card->setDestroyOnZoneChange(event.destroy_on_zone_change());
|
||||
card->setFaceDown(event.face_down());
|
||||
|
||||
emit logCreateToken(player, card->getName(), card->getPT(), card->getFaceDown());
|
||||
zone->addCard(card, true, event.x(), event.y());
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventSetCardAttr(const Event_SetCardAttr &event,
|
||||
const GameEventContext &context,
|
||||
EventProcessingOptions options)
|
||||
{
|
||||
CardZoneLogic *zone = player->getZone(QString::fromStdString(event.zone_name()));
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.has_card_id()) {
|
||||
const CardList &cards = zone->getCards();
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
player->getPlayerActions()->setCardAttrHelper(context, cards.at(i), event.attribute(),
|
||||
QString::fromStdString(event.attr_value()), true, options);
|
||||
}
|
||||
if (event.attribute() == AttrTapped) {
|
||||
emit logSetTapped(player, nullptr, event.attr_value() == "1");
|
||||
}
|
||||
} else {
|
||||
CardItem *card = zone->getCard(event.card_id());
|
||||
if (!card) {
|
||||
qWarning() << "PlayerEventHandler::eventSetCardAttr: card id=" << event.card_id() << "not found";
|
||||
return;
|
||||
}
|
||||
player->getPlayerActions()->setCardAttrHelper(context, card, event.attribute(),
|
||||
QString::fromStdString(event.attr_value()), false, options);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventSetCardCounter(const Event_SetCardCounter &event)
|
||||
{
|
||||
CardZoneLogic *zone = player->getZone(QString::fromStdString(event.zone_name()));
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
|
||||
CardItem *card = zone->getCard(event.card_id());
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
int oldValue = card->getCounters().value(event.counter_id(), 0);
|
||||
card->setCounter(event.counter_id(), event.counter_value());
|
||||
player->getPlayerMenu()->updateCardMenu(card);
|
||||
emit logSetCardCounter(player, card->getName(), event.counter_id(), event.counter_value(), oldValue);
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventCreateCounter(const Event_CreateCounter &event)
|
||||
{
|
||||
player->addCounter(event.counter_info());
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventSetCounter(const Event_SetCounter &event)
|
||||
{
|
||||
AbstractCounter *ctr = player->getCounters().value(event.counter_id(), 0);
|
||||
if (!ctr) {
|
||||
return;
|
||||
}
|
||||
int oldValue = ctr->getValue();
|
||||
ctr->setValue(event.value());
|
||||
emit logSetCounter(player, ctr->getName(), event.value(), oldValue);
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventDelCounter(const Event_DelCounter &event)
|
||||
{
|
||||
player->delCounter(event.counter_id());
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventDumpZone(const Event_DumpZone &event)
|
||||
{
|
||||
Player *zoneOwner = player->getGame()->getPlayerManager()->getPlayers().value(event.zone_owner_id(), 0);
|
||||
if (!zoneOwner) {
|
||||
return;
|
||||
}
|
||||
CardZoneLogic *zone = zoneOwner->getZones().value(QString::fromStdString(event.zone_name()), 0);
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
emit logDumpZone(player, zone, event.number_cards(), event.is_reversed());
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventMoveCard(const Event_MoveCard &event, const GameEventContext &context)
|
||||
{
|
||||
Player *startPlayer = player->getGame()->getPlayerManager()->getPlayers().value(event.start_player_id());
|
||||
if (!startPlayer) {
|
||||
return;
|
||||
}
|
||||
QString startZoneString = QString::fromStdString(event.start_zone());
|
||||
CardZoneLogic *startZone = startPlayer->getZones().value(startZoneString, 0);
|
||||
Player *targetPlayer = player->getGame()->getPlayerManager()->getPlayers().value(event.target_player_id());
|
||||
if (!targetPlayer) {
|
||||
return;
|
||||
}
|
||||
CardZoneLogic *targetZone;
|
||||
if (event.has_target_zone()) {
|
||||
targetZone = targetPlayer->getZones().value(QString::fromStdString(event.target_zone()), 0);
|
||||
} else {
|
||||
targetZone = startZone;
|
||||
}
|
||||
if (!startZone || !targetZone) {
|
||||
return;
|
||||
}
|
||||
|
||||
int position = event.position();
|
||||
int x = event.x();
|
||||
int y = event.y();
|
||||
|
||||
int logPosition = position;
|
||||
int logX = x;
|
||||
if (x == -1) {
|
||||
x = 0;
|
||||
}
|
||||
CardItem *card = startZone->takeCard(position, event.card_id(), startZone != targetZone);
|
||||
if (card == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (startZone != targetZone) {
|
||||
card->deleteCardInfoPopup();
|
||||
}
|
||||
if (event.has_card_name()) {
|
||||
QString name = QString::fromStdString(event.card_name());
|
||||
QString providerId =
|
||||
event.has_new_card_provider_id() ? QString::fromStdString(event.new_card_provider_id()) : "";
|
||||
card->setCardRef({name, providerId});
|
||||
}
|
||||
|
||||
if (card->getAttachedTo() && (startZone != targetZone)) {
|
||||
CardItem *parentCard = card->getAttachedTo();
|
||||
card->setAttachedTo(nullptr);
|
||||
parentCard->getZone()->reorganizeCards();
|
||||
}
|
||||
|
||||
card->deleteDragItem();
|
||||
|
||||
card->setId(event.new_card_id());
|
||||
card->setFaceDown(event.face_down());
|
||||
if (startZone != targetZone) {
|
||||
card->setBeingPointedAt(false);
|
||||
card->setHovered(false);
|
||||
|
||||
const QList<CardItem *> &attachedCards = card->getAttachedCards();
|
||||
for (auto attachedCard : attachedCards) {
|
||||
emit targetZone->cardAdded(attachedCard);
|
||||
}
|
||||
|
||||
if (startZone->getPlayer() != targetZone->getPlayer()) {
|
||||
card->setOwner(targetZone->getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
// The log event has to be sent before the card is added to the target zone
|
||||
// because the addCard function can modify the card object.
|
||||
if (context.HasExtension(Context_UndoDraw::ext)) {
|
||||
emit logUndoDraw(player, card->getName());
|
||||
} else {
|
||||
emit logMoveCard(player, card, startZone, logPosition, targetZone, logX);
|
||||
}
|
||||
|
||||
targetZone->addCard(card, true, x, y);
|
||||
|
||||
// Look at all arrows from and to the card.
|
||||
// If the card was moved to another zone, delete the arrows, otherwise update them.
|
||||
QMapIterator<int, Player *> playerIterator(player->getGame()->getPlayerManager()->getPlayers());
|
||||
while (playerIterator.hasNext()) {
|
||||
Player *p = playerIterator.next().value();
|
||||
|
||||
QList<ArrowItem *> arrowsToDelete;
|
||||
QMapIterator<int, ArrowItem *> arrowIterator(p->getArrows());
|
||||
while (arrowIterator.hasNext()) {
|
||||
ArrowItem *arrow = arrowIterator.next().value();
|
||||
if ((arrow->getStartItem() == card) || (arrow->getTargetItem() == card)) {
|
||||
if (startZone == targetZone) {
|
||||
arrow->updatePath();
|
||||
} else {
|
||||
arrowsToDelete.append(arrow);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto &i : arrowsToDelete) {
|
||||
i->delArrow();
|
||||
}
|
||||
}
|
||||
player->getPlayerMenu()->updateCardMenu(card);
|
||||
|
||||
if (player->getPlayerActions()->isMovingCardsUntil() && startZoneString == "deck" &&
|
||||
targetZone->getName() == "stack") {
|
||||
player->getPlayerActions()->moveOneCardUntil(card);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventFlipCard(const Event_FlipCard &event)
|
||||
{
|
||||
CardZoneLogic *zone = player->getZone(QString::fromStdString(event.zone_name()));
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
CardItem *card = zone->getCard(event.card_id());
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.face_down()) {
|
||||
QString cardName = QString::fromStdString(event.card_name());
|
||||
QString providerId = QString::fromStdString(event.card_provider_id());
|
||||
card->setCardRef({cardName, providerId});
|
||||
}
|
||||
|
||||
emit logFlipCard(player, card->getName(), event.face_down());
|
||||
card->setFaceDown(event.face_down());
|
||||
player->getPlayerMenu()->updateCardMenu(card);
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventDestroyCard(const Event_DestroyCard &event)
|
||||
{
|
||||
CardZoneLogic *zone = player->getZone(QString::fromStdString(event.zone_name()));
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
|
||||
CardItem *card = zone->getCard(event.card_id());
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
QList<CardItem *> attachedCards = card->getAttachedCards();
|
||||
// This list is always empty except for buggy server implementations.
|
||||
for (auto &attachedCard : attachedCards) {
|
||||
attachedCard->setAttachedTo(nullptr);
|
||||
}
|
||||
|
||||
emit logDestroyCard(player, card->getName());
|
||||
zone->takeCard(-1, event.card_id(), true);
|
||||
card->deleteLater();
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventAttachCard(const Event_AttachCard &event)
|
||||
{
|
||||
const QMap<int, Player *> &playerList = player->getGame()->getPlayerManager()->getPlayers();
|
||||
Player *targetPlayer = nullptr;
|
||||
CardZoneLogic *targetZone = nullptr;
|
||||
CardItem *targetCard = nullptr;
|
||||
if (event.has_target_player_id()) {
|
||||
targetPlayer = playerList.value(event.target_player_id(), 0);
|
||||
if (targetPlayer) {
|
||||
targetZone = targetPlayer->getZones().value(QString::fromStdString(event.target_zone()), 0);
|
||||
if (targetZone) {
|
||||
targetCard = targetZone->getCard(event.target_card_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CardZoneLogic *startZone = player->getZone(QString::fromStdString(event.start_zone()));
|
||||
if (!startZone) {
|
||||
return;
|
||||
}
|
||||
|
||||
CardItem *startCard = startZone->getCard(event.card_id());
|
||||
if (!startCard) {
|
||||
return;
|
||||
}
|
||||
|
||||
CardItem *oldParent = startCard->getAttachedTo();
|
||||
|
||||
startCard->setAttachedTo(targetCard);
|
||||
|
||||
startZone->reorganizeCards();
|
||||
if ((startZone != targetZone) && targetZone) {
|
||||
targetZone->reorganizeCards();
|
||||
}
|
||||
if (oldParent) {
|
||||
oldParent->getZone()->reorganizeCards();
|
||||
}
|
||||
|
||||
if (targetCard) {
|
||||
emit logAttachCard(player, startCard->getName(), targetPlayer, targetCard->getName());
|
||||
} else {
|
||||
emit logUnattachCard(player, startCard->getName());
|
||||
}
|
||||
player->getPlayerMenu()->updateCardMenu(startCard);
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventDrawCards(const Event_DrawCards &event)
|
||||
{
|
||||
CardZoneLogic *_deck = player->getDeckZone();
|
||||
CardZoneLogic *_hand = player->getHandZone();
|
||||
|
||||
const int listSize = event.cards_size();
|
||||
if (listSize) {
|
||||
for (int i = 0; i < listSize; ++i) {
|
||||
const ServerInfo_Card &cardInfo = event.cards(i);
|
||||
CardItem *card = _deck->takeCard(0, cardInfo.id());
|
||||
QString cardName = QString::fromStdString(cardInfo.name());
|
||||
QString providerId = QString::fromStdString(cardInfo.provider_id());
|
||||
card->setCardRef({cardName, providerId});
|
||||
_hand->addCard(card, false, -1);
|
||||
}
|
||||
} else {
|
||||
const int number = event.number();
|
||||
for (int i = 0; i < number; ++i) {
|
||||
_hand->addCard(_deck->takeCard(0, -1), false, -1);
|
||||
}
|
||||
}
|
||||
|
||||
_hand->reorganizeCards();
|
||||
_deck->reorganizeCards();
|
||||
emit logDrawCards(player, event.number(), _deck->getCards().size() == 0);
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventRevealCards(const Event_RevealCards &event, EventProcessingOptions options)
|
||||
{
|
||||
Q_UNUSED(options);
|
||||
CardZoneLogic *zone = player->getZone(QString::fromStdString(event.zone_name()));
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
Player *otherPlayer = nullptr;
|
||||
if (event.has_other_player_id()) {
|
||||
otherPlayer = player->getGame()->getPlayerManager()->getPlayers().value(event.other_player_id());
|
||||
if (!otherPlayer) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool peeking = false;
|
||||
QList<const ServerInfo_Card *> cardList;
|
||||
const int cardListSize = event.cards_size();
|
||||
for (int i = 0; i < cardListSize; ++i) {
|
||||
const ServerInfo_Card *temp = &event.cards(i);
|
||||
if (temp->face_down()) {
|
||||
peeking = true;
|
||||
}
|
||||
cardList.append(temp);
|
||||
}
|
||||
|
||||
if (peeking) {
|
||||
for (const auto &card : cardList) {
|
||||
QString cardName = QString::fromStdString(card->name());
|
||||
QString providerId = QString::fromStdString(card->provider_id());
|
||||
CardItem *cardItem = zone->getCard(card->id());
|
||||
if (!cardItem) {
|
||||
continue;
|
||||
}
|
||||
cardItem->setCardRef({cardName, providerId});
|
||||
emit logRevealCards(player, zone, card->id(), cardName, player, true, 1);
|
||||
}
|
||||
} else {
|
||||
bool showZoneView = true;
|
||||
QString cardName;
|
||||
auto cardId = event.card_id_size() == 0 ? -1 : event.card_id(0);
|
||||
if (cardList.size() == 1) {
|
||||
cardName = QString::fromStdString(cardList.first()->name());
|
||||
|
||||
// Handle case of revealing top card of library in-place
|
||||
if (cardId == 0 && dynamic_cast<PileZoneLogic *>(zone)) {
|
||||
auto card = zone->getCards().first();
|
||||
QString providerId = QString::fromStdString(cardList.first()->provider_id());
|
||||
card->setCardRef({cardName, providerId});
|
||||
|
||||
emit zone->updateGraphics();
|
||||
showZoneView = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.testFlag(SKIP_REVEAL_WINDOW) && showZoneView && !cardList.isEmpty()) {
|
||||
player->getGameScene()->addRevealedZoneView(player, zone, cardList, event.grant_write_access());
|
||||
}
|
||||
|
||||
emit logRevealCards(player, zone, cardId, cardName, otherPlayer, false,
|
||||
event.has_number_of_cards() ? event.number_of_cards() : cardList.size(),
|
||||
event.grant_write_access());
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventChangeZoneProperties(const Event_ChangeZoneProperties &event)
|
||||
{
|
||||
CardZoneLogic *zone = player->getZone(QString::fromStdString(event.zone_name()));
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.has_always_reveal_top_card()) {
|
||||
zone->setAlwaysRevealTopCard(event.always_reveal_top_card());
|
||||
emit logAlwaysRevealTopCard(player, zone, event.always_reveal_top_card());
|
||||
}
|
||||
if (event.has_always_look_at_top_card()) {
|
||||
zone->setAlwaysRevealTopCard(event.always_look_at_top_card());
|
||||
emit logAlwaysLookAtTopCard(player, zone, event.always_look_at_top_card());
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerEventHandler::processGameEvent(GameEvent::GameEventType type,
|
||||
const GameEvent &event,
|
||||
const GameEventContext &context,
|
||||
EventProcessingOptions options)
|
||||
{
|
||||
switch (type) {
|
||||
case GameEvent::GAME_SAY:
|
||||
eventGameSay(event.GetExtension(Event_GameSay::ext));
|
||||
break;
|
||||
case GameEvent::SHUFFLE:
|
||||
eventShuffle(event.GetExtension(Event_Shuffle::ext));
|
||||
break;
|
||||
case GameEvent::ROLL_DIE:
|
||||
eventRollDie(event.GetExtension(Event_RollDie::ext));
|
||||
break;
|
||||
case GameEvent::CREATE_ARROW:
|
||||
eventCreateArrow(event.GetExtension(Event_CreateArrow::ext));
|
||||
break;
|
||||
case GameEvent::DELETE_ARROW:
|
||||
eventDeleteArrow(event.GetExtension(Event_DeleteArrow::ext));
|
||||
break;
|
||||
case GameEvent::CREATE_TOKEN:
|
||||
eventCreateToken(event.GetExtension(Event_CreateToken::ext));
|
||||
break;
|
||||
case GameEvent::SET_CARD_ATTR:
|
||||
eventSetCardAttr(event.GetExtension(Event_SetCardAttr::ext), context, options);
|
||||
break;
|
||||
case GameEvent::SET_CARD_COUNTER:
|
||||
eventSetCardCounter(event.GetExtension(Event_SetCardCounter::ext));
|
||||
break;
|
||||
case GameEvent::CREATE_COUNTER:
|
||||
eventCreateCounter(event.GetExtension(Event_CreateCounter::ext));
|
||||
break;
|
||||
case GameEvent::SET_COUNTER:
|
||||
eventSetCounter(event.GetExtension(Event_SetCounter::ext));
|
||||
break;
|
||||
case GameEvent::DEL_COUNTER:
|
||||
eventDelCounter(event.GetExtension(Event_DelCounter::ext));
|
||||
break;
|
||||
case GameEvent::DUMP_ZONE:
|
||||
eventDumpZone(event.GetExtension(Event_DumpZone::ext));
|
||||
break;
|
||||
case GameEvent::MOVE_CARD:
|
||||
eventMoveCard(event.GetExtension(Event_MoveCard::ext), context);
|
||||
break;
|
||||
case GameEvent::FLIP_CARD:
|
||||
eventFlipCard(event.GetExtension(Event_FlipCard::ext));
|
||||
break;
|
||||
case GameEvent::DESTROY_CARD:
|
||||
eventDestroyCard(event.GetExtension(Event_DestroyCard::ext));
|
||||
break;
|
||||
case GameEvent::ATTACH_CARD:
|
||||
eventAttachCard(event.GetExtension(Event_AttachCard::ext));
|
||||
break;
|
||||
case GameEvent::DRAW_CARDS:
|
||||
eventDrawCards(event.GetExtension(Event_DrawCards::ext));
|
||||
break;
|
||||
case GameEvent::REVEAL_CARDS:
|
||||
eventRevealCards(event.GetExtension(Event_RevealCards::ext), options);
|
||||
break;
|
||||
case GameEvent::CHANGE_ZONE_PROPERTIES:
|
||||
eventChangeZoneProperties(event.GetExtension(Event_ChangeZoneProperties::ext));
|
||||
break;
|
||||
default: {
|
||||
qWarning() << "unhandled game event" << type;
|
||||
}
|
||||
}
|
||||
}
|
||||
109
cockatrice/src/game/player/player_event_handler.h
Normal file
109
cockatrice/src/game/player/player_event_handler.h
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
#ifndef COCKATRICE_PLAYER_EVENT_HANDLER_H
|
||||
#define COCKATRICE_PLAYER_EVENT_HANDLER_H
|
||||
#include "event_processing_options.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <pb/game_event.pb.h>
|
||||
#include <pb/game_event_context.pb.h>
|
||||
|
||||
class CardItem;
|
||||
class CardZoneLogic;
|
||||
class Player;
|
||||
class Event_AttachCard;
|
||||
class Event_ChangeZoneProperties;
|
||||
class Event_CreateArrow;
|
||||
class Event_CreateCounter;
|
||||
class Event_CreateToken;
|
||||
class Event_DelCounter;
|
||||
class Event_DeleteArrow;
|
||||
class Event_DestroyCard;
|
||||
class Event_DrawCards;
|
||||
class Event_DumpZone;
|
||||
class Event_FlipCard;
|
||||
class Event_GameSay;
|
||||
class Event_MoveCard;
|
||||
class Event_RevealCards;
|
||||
class Event_RollDie;
|
||||
class Event_SetCardAttr;
|
||||
class Event_SetCardCounter;
|
||||
class Event_SetCounter;
|
||||
class Event_Shuffle;
|
||||
class PlayerEventHandler : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void logSay(Player *player, QString message);
|
||||
void logShuffle(Player *player, CardZoneLogic *zone, int start, int end);
|
||||
void logRollDie(Player *player, int sides, const QList<uint> &rolls);
|
||||
void logCreateArrow(Player *player,
|
||||
Player *startPlayer,
|
||||
QString startCard,
|
||||
Player *targetPlayer,
|
||||
QString targetCard,
|
||||
bool _playerTarget);
|
||||
void logCreateToken(Player *player, QString cardName, QString pt, bool faceDown);
|
||||
void logDrawCards(Player *player, int number, bool deckIsEmpty);
|
||||
void logUndoDraw(Player *player, QString cardName);
|
||||
void logMoveCard(Player *player,
|
||||
CardItem *card,
|
||||
CardZoneLogic *startZone,
|
||||
int oldX,
|
||||
CardZoneLogic *targetZone,
|
||||
int newX);
|
||||
void logFlipCard(Player *player, QString cardName, bool faceDown);
|
||||
void logDestroyCard(Player *player, QString cardName);
|
||||
void logAttachCard(Player *player, QString cardName, Player *targetPlayer, QString targetCardName);
|
||||
void logUnattachCard(Player *player, QString cardName);
|
||||
void logSetCardCounter(Player *player, QString cardName, int counterId, int value, int oldValue);
|
||||
void logSetTapped(Player *player, CardItem *card, bool tapped);
|
||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||
void logSetDoesntUntap(Player *player, CardItem *card, bool doesntUntap);
|
||||
void logSetPT(Player *player, CardItem *card, QString newPT);
|
||||
void logSetAnnotation(Player *player, CardItem *card, QString newAnnotation);
|
||||
void logDumpZone(Player *player, CardZoneLogic *zone, int numberCards, bool isReversed = false);
|
||||
void logRevealCards(Player *player,
|
||||
CardZoneLogic *zone,
|
||||
int cardId,
|
||||
QString cardName,
|
||||
Player *otherPlayer,
|
||||
bool faceDown,
|
||||
int amount,
|
||||
bool isLentToAnotherPlayer = false);
|
||||
void logAlwaysRevealTopCard(Player *player, CardZoneLogic *zone, bool reveal);
|
||||
void logAlwaysLookAtTopCard(Player *player, CardZoneLogic *zone, bool reveal);
|
||||
|
||||
public:
|
||||
PlayerEventHandler(Player *player);
|
||||
|
||||
void processGameEvent(GameEvent::GameEventType type,
|
||||
const GameEvent &event,
|
||||
const GameEventContext &context,
|
||||
EventProcessingOptions options);
|
||||
|
||||
void eventGameSay(const Event_GameSay &event);
|
||||
void eventShuffle(const Event_Shuffle &event);
|
||||
void eventRollDie(const Event_RollDie &event);
|
||||
void eventCreateArrow(const Event_CreateArrow &event);
|
||||
void eventDeleteArrow(const Event_DeleteArrow &event);
|
||||
void eventCreateToken(const Event_CreateToken &event);
|
||||
void
|
||||
eventSetCardAttr(const Event_SetCardAttr &event, const GameEventContext &context, EventProcessingOptions options);
|
||||
void eventSetCardCounter(const Event_SetCardCounter &event);
|
||||
void eventCreateCounter(const Event_CreateCounter &event);
|
||||
void eventSetCounter(const Event_SetCounter &event);
|
||||
void eventDelCounter(const Event_DelCounter &event);
|
||||
void eventDumpZone(const Event_DumpZone &event);
|
||||
void eventMoveCard(const Event_MoveCard &event, const GameEventContext &context);
|
||||
void eventFlipCard(const Event_FlipCard &event);
|
||||
void eventDestroyCard(const Event_DestroyCard &event);
|
||||
void eventAttachCard(const Event_AttachCard &event);
|
||||
void eventDrawCards(const Event_DrawCards &event);
|
||||
void eventRevealCards(const Event_RevealCards &event, EventProcessingOptions options);
|
||||
void eventChangeZoneProperties(const Event_ChangeZoneProperties &event);
|
||||
|
||||
private:
|
||||
Player *player;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_EVENT_HANDLER_H
|
||||
215
cockatrice/src/game/player/player_graphics_item.cpp
Normal file
215
cockatrice/src/game/player/player_graphics_item.cpp
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
#include "player_graphics_item.h"
|
||||
|
||||
#include "../../client/tabs/tab_game.h"
|
||||
#include "../hand_counter.h"
|
||||
|
||||
PlayerGraphicsItem::PlayerGraphicsItem(Player *_player) : player(_player)
|
||||
{
|
||||
connect(&SettingsCache::instance(), &SettingsCache::horizontalHandChanged, this,
|
||||
&PlayerGraphicsItem::rearrangeZones);
|
||||
connect(&SettingsCache::instance(), &SettingsCache::handJustificationChanged, this,
|
||||
&PlayerGraphicsItem::rearrangeZones);
|
||||
connect(player, &Player::rearrangeCounters, this, &PlayerGraphicsItem::rearrangeCounters);
|
||||
|
||||
playerArea = new PlayerArea(this);
|
||||
|
||||
playerTarget = new PlayerTarget(player, playerArea);
|
||||
qreal avatarMargin = (counterAreaWidth + CARD_HEIGHT + 15 - playerTarget->boundingRect().width()) / 2.0;
|
||||
playerTarget->setPos(QPointF(avatarMargin, avatarMargin));
|
||||
|
||||
initializeZones();
|
||||
|
||||
connect(tableZoneGraphicsItem, &TableZone::sizeChanged, this, &PlayerGraphicsItem::updateBoundingRect);
|
||||
|
||||
updateBoundingRect();
|
||||
|
||||
rearrangeZones();
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::retranslateUi()
|
||||
{
|
||||
player->getPlayerMenu()->retranslateUi();
|
||||
|
||||
QMapIterator<QString, CardZoneLogic *> zoneIterator(player->getZones());
|
||||
while (zoneIterator.hasNext()) {
|
||||
emit zoneIterator.next().value()->retranslateUi();
|
||||
}
|
||||
|
||||
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
|
||||
while (counterIterator.hasNext()) {
|
||||
counterIterator.next().value()->retranslateUi();
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::onPlayerActiveChanged(bool _active)
|
||||
{
|
||||
tableZoneGraphicsItem->setActive(_active);
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::initializeZones()
|
||||
{
|
||||
deckZoneGraphicsItem = new PileZone(player->getDeckZone(), this);
|
||||
QPointF base = QPointF(counterAreaWidth + (CARD_HEIGHT - CARD_WIDTH + 15) / 2.0,
|
||||
10 + playerTarget->boundingRect().height() + 5 - (CARD_HEIGHT - CARD_WIDTH) / 2.0);
|
||||
deckZoneGraphicsItem->setPos(base);
|
||||
|
||||
qreal h = deckZoneGraphicsItem->boundingRect().width() + 5;
|
||||
|
||||
sideboardGraphicsItem = new PileZone(player->getSideboardZone(), this);
|
||||
player->getSideboardZone()->setGraphicsVisibility(false);
|
||||
|
||||
auto *handCounter = new HandCounter(playerArea);
|
||||
handCounter->setPos(base + QPointF(0, h + 10));
|
||||
qreal h2 = handCounter->boundingRect().height();
|
||||
|
||||
graveyardZoneGraphicsItem = new PileZone(player->getGraveZone(), this);
|
||||
graveyardZoneGraphicsItem->setPos(base + QPointF(0, h + h2 + 10));
|
||||
|
||||
rfgZoneGraphicsItem = new PileZone(player->getRfgZone(), this);
|
||||
rfgZoneGraphicsItem->setPos(base + QPointF(0, 2 * h + h2 + 10));
|
||||
|
||||
tableZoneGraphicsItem = new TableZone(player->getTableZone(), this);
|
||||
connect(tableZoneGraphicsItem, &TableZone::sizeChanged, this, &PlayerGraphicsItem::updateBoundingRect);
|
||||
|
||||
stackZoneGraphicsItem =
|
||||
new StackZone(player->getStackZone(), static_cast<int>(tableZoneGraphicsItem->boundingRect().height()), this);
|
||||
|
||||
handZoneGraphicsItem =
|
||||
new HandZone(player->getHandZone(), static_cast<int>(tableZoneGraphicsItem->boundingRect().height()), this);
|
||||
|
||||
connect(handZoneGraphicsItem->getLogic(), &HandZoneLogic::cardCountChanged, handCounter,
|
||||
&HandCounter::updateNumber);
|
||||
connect(handCounter, &HandCounter::showContextMenu, handZoneGraphicsItem, &HandZone::showContextMenu);
|
||||
}
|
||||
|
||||
QRectF PlayerGraphicsItem::boundingRect() const
|
||||
{
|
||||
return bRect;
|
||||
}
|
||||
|
||||
qreal PlayerGraphicsItem::getMinimumWidth() const
|
||||
{
|
||||
qreal result = tableZoneGraphicsItem->getMinimumWidth() + CARD_HEIGHT + 15 + counterAreaWidth +
|
||||
stackZoneGraphicsItem->boundingRect().width();
|
||||
if (!SettingsCache::instance().getHorizontalHand()) {
|
||||
result += handZoneGraphicsItem->boundingRect().width();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::paint(QPainter * /*painter*/,
|
||||
const QStyleOptionGraphicsItem * /*option*/,
|
||||
QWidget * /*widget*/)
|
||||
{
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::processSceneSizeChange(int newPlayerWidth)
|
||||
{
|
||||
// Extend table (and hand, if horizontal) to accommodate the new player width.
|
||||
qreal tableWidth =
|
||||
newPlayerWidth - CARD_HEIGHT - 15 - counterAreaWidth - stackZoneGraphicsItem->boundingRect().width();
|
||||
if (!SettingsCache::instance().getHorizontalHand()) {
|
||||
tableWidth -= handZoneGraphicsItem->boundingRect().width();
|
||||
}
|
||||
|
||||
tableZoneGraphicsItem->setWidth(tableWidth);
|
||||
handZoneGraphicsItem->setWidth(tableWidth + stackZoneGraphicsItem->boundingRect().width());
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::setMirrored(bool _mirrored)
|
||||
{
|
||||
if (mirrored != _mirrored) {
|
||||
mirrored = _mirrored;
|
||||
rearrangeZones();
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::rearrangeCounters()
|
||||
{
|
||||
qreal marginTop = 80;
|
||||
const qreal padding = 5;
|
||||
qreal ySize = boundingRect().y() + marginTop;
|
||||
|
||||
// Place objects
|
||||
for (const auto &counter : player->getCounters()) {
|
||||
AbstractCounter *ctr = counter;
|
||||
|
||||
if (!ctr->getShownInCounterArea()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QRectF br = ctr->boundingRect();
|
||||
ctr->setPos((counterAreaWidth - br.width()) / 2, ySize);
|
||||
ySize += br.height() + padding;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::rearrangeZones()
|
||||
{
|
||||
QPointF base = QPointF(CARD_HEIGHT + counterAreaWidth + 15, 0);
|
||||
if (SettingsCache::instance().getHorizontalHand()) {
|
||||
if (mirrored) {
|
||||
if (player->getHandZone()->contentsKnown()) {
|
||||
player->getPlayerInfo()->setHandVisible(true);
|
||||
handZoneGraphicsItem->setPos(base);
|
||||
base += QPointF(0, handZoneGraphicsItem->boundingRect().height());
|
||||
} else {
|
||||
player->getPlayerInfo()->setHandVisible(false);
|
||||
}
|
||||
|
||||
stackZoneGraphicsItem->setPos(base);
|
||||
base += QPointF(stackZoneGraphicsItem->boundingRect().width(), 0);
|
||||
|
||||
tableZoneGraphicsItem->setPos(base);
|
||||
} else {
|
||||
stackZoneGraphicsItem->setPos(base);
|
||||
|
||||
tableZoneGraphicsItem->setPos(base.x() + stackZoneGraphicsItem->boundingRect().width(), 0);
|
||||
base += QPointF(0, tableZoneGraphicsItem->boundingRect().height());
|
||||
|
||||
if (player->getHandZone()->contentsKnown()) {
|
||||
player->getPlayerInfo()->setHandVisible(true);
|
||||
handZoneGraphicsItem->setPos(base);
|
||||
} else {
|
||||
player->getPlayerInfo()->setHandVisible(false);
|
||||
}
|
||||
}
|
||||
handZoneGraphicsItem->setWidth(tableZoneGraphicsItem->getWidth() +
|
||||
stackZoneGraphicsItem->boundingRect().width());
|
||||
} else {
|
||||
player->getPlayerInfo()->setHandVisible(true);
|
||||
|
||||
handZoneGraphicsItem->setPos(base);
|
||||
base += QPointF(handZoneGraphicsItem->boundingRect().width(), 0);
|
||||
|
||||
stackZoneGraphicsItem->setPos(base);
|
||||
base += QPointF(stackZoneGraphicsItem->boundingRect().width(), 0);
|
||||
|
||||
tableZoneGraphicsItem->setPos(base);
|
||||
}
|
||||
handZoneGraphicsItem->setVisible(player->getPlayerInfo()->getHandVisible());
|
||||
handZoneGraphicsItem->updateOrientation();
|
||||
tableZoneGraphicsItem->reorganizeCards();
|
||||
updateBoundingRect();
|
||||
rearrangeCounters();
|
||||
}
|
||||
|
||||
void PlayerGraphicsItem::updateBoundingRect()
|
||||
{
|
||||
prepareGeometryChange();
|
||||
qreal width = CARD_HEIGHT + 15 + counterAreaWidth + stackZoneGraphicsItem->boundingRect().width();
|
||||
if (SettingsCache::instance().getHorizontalHand()) {
|
||||
qreal handHeight =
|
||||
player->getPlayerInfo()->getHandVisible() ? handZoneGraphicsItem->boundingRect().height() : 0;
|
||||
bRect = QRectF(0, 0, width + tableZoneGraphicsItem->boundingRect().width(),
|
||||
tableZoneGraphicsItem->boundingRect().height() + handHeight);
|
||||
} else {
|
||||
bRect = QRectF(
|
||||
0, 0, width + handZoneGraphicsItem->boundingRect().width() + tableZoneGraphicsItem->boundingRect().width(),
|
||||
tableZoneGraphicsItem->boundingRect().height());
|
||||
}
|
||||
playerArea->setSize(CARD_HEIGHT + counterAreaWidth + 15, bRect.height());
|
||||
|
||||
emit sizeChanged();
|
||||
}
|
||||
125
cockatrice/src/game/player/player_graphics_item.h
Normal file
125
cockatrice/src/game/player/player_graphics_item.h
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#ifndef COCKATRICE_PLAYER_GRAPHICS_ITEM_H
|
||||
#define COCKATRICE_PLAYER_GRAPHICS_ITEM_H
|
||||
#include "../game_scene.h"
|
||||
#include "player.h"
|
||||
|
||||
#include <QGraphicsObject>
|
||||
|
||||
class HandZone;
|
||||
class PileZone;
|
||||
class PlayerTarget;
|
||||
class StackZone;
|
||||
class TableZone;
|
||||
class ZoneViewZone;
|
||||
|
||||
class PlayerGraphicsItem : public QGraphicsObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
Type = typeOther
|
||||
};
|
||||
int type() const override
|
||||
{
|
||||
return Type;
|
||||
}
|
||||
|
||||
static constexpr int counterAreaWidth = 55;
|
||||
|
||||
explicit PlayerGraphicsItem(Player *player);
|
||||
void initializeZones();
|
||||
|
||||
[[nodiscard]] QRectF boundingRect() const override;
|
||||
qreal getMinimumWidth() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
void processSceneSizeChange(int newPlayerWidth);
|
||||
|
||||
void setMirrored(bool _mirrored);
|
||||
|
||||
bool getMirrored() const
|
||||
{
|
||||
return mirrored;
|
||||
}
|
||||
|
||||
GameScene *getGameScene() const
|
||||
{
|
||||
return static_cast<GameScene *>(scene());
|
||||
}
|
||||
|
||||
Player *getPlayer() const
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
PlayerArea *getPlayerArea() const
|
||||
{
|
||||
return playerArea;
|
||||
}
|
||||
|
||||
PlayerTarget *getPlayerTarget() const
|
||||
{
|
||||
return playerTarget;
|
||||
}
|
||||
|
||||
[[nodiscard]] PileZone *getDeckZoneGraphicsItem() const
|
||||
{
|
||||
return deckZoneGraphicsItem;
|
||||
}
|
||||
|
||||
[[nodiscard]] PileZone *getSideboardZoneGraphicsItem() const
|
||||
{
|
||||
return sideboardGraphicsItem;
|
||||
}
|
||||
|
||||
[[nodiscard]] PileZone *getGraveyardZoneGraphicsItem() const
|
||||
{
|
||||
return graveyardZoneGraphicsItem;
|
||||
}
|
||||
[[nodiscard]] PileZone *getRfgZoneGraphicsItem() const
|
||||
{
|
||||
return rfgZoneGraphicsItem;
|
||||
}
|
||||
[[nodiscard]] TableZone *getTableZoneGraphicsItem() const
|
||||
{
|
||||
return tableZoneGraphicsItem;
|
||||
}
|
||||
[[nodiscard]] StackZone *getStackZoneGraphicsItem() const
|
||||
{
|
||||
return stackZoneGraphicsItem;
|
||||
}
|
||||
[[nodiscard]] HandZone *getHandZoneGraphicsItem() const
|
||||
{
|
||||
return handZoneGraphicsItem;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void onPlayerActiveChanged(bool _active);
|
||||
void retranslateUi();
|
||||
|
||||
signals:
|
||||
void sizeChanged();
|
||||
void playerCountChanged();
|
||||
|
||||
private:
|
||||
Player *player;
|
||||
PlayerArea *playerArea;
|
||||
PlayerTarget *playerTarget;
|
||||
PileZone *deckZoneGraphicsItem;
|
||||
PileZone *sideboardGraphicsItem;
|
||||
PileZone *graveyardZoneGraphicsItem;
|
||||
PileZone *rfgZoneGraphicsItem;
|
||||
TableZone *tableZoneGraphicsItem;
|
||||
StackZone *stackZoneGraphicsItem;
|
||||
HandZone *handZoneGraphicsItem;
|
||||
QRectF bRect;
|
||||
bool mirrored;
|
||||
|
||||
private slots:
|
||||
void updateBoundingRect();
|
||||
void rearrangeZones();
|
||||
void rearrangeCounters();
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_GRAPHICS_ITEM_H
|
||||
8
cockatrice/src/game/player/player_info.cpp
Normal file
8
cockatrice/src/game/player/player_info.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "player_info.h"
|
||||
|
||||
PlayerInfo::PlayerInfo(const ServerInfo_User &info, int _id, bool _local, bool _judge)
|
||||
: id(_id), local(_local), judge(_judge), handVisible(false)
|
||||
{
|
||||
userInfo = new ServerInfo_User;
|
||||
userInfo->CopyFrom(info);
|
||||
}
|
||||
69
cockatrice/src/game/player/player_info.h
Normal file
69
cockatrice/src/game/player/player_info.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#ifndef COCKATRICE_PLAYER_INFO_H
|
||||
#define COCKATRICE_PLAYER_INFO_H
|
||||
|
||||
#include "../../../common/pb/serverinfo_user.pb.h"
|
||||
#include "../../deck/deck_loader.h"
|
||||
#include "../zones/hand_zone.h"
|
||||
#include "../zones/pile_zone.h"
|
||||
#include "../zones/stack_zone.h"
|
||||
#include "../zones/table_zone.h"
|
||||
#include "player_target.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class PlayerInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PlayerInfo(const ServerInfo_User &info, int id, bool local, bool judge);
|
||||
|
||||
ServerInfo_User *userInfo;
|
||||
int id;
|
||||
bool local;
|
||||
bool judge;
|
||||
bool handVisible;
|
||||
|
||||
int getId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
ServerInfo_User *getUserInfo() const
|
||||
{
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
void setLocal(bool _local)
|
||||
{
|
||||
local = _local;
|
||||
}
|
||||
|
||||
bool getLocal() const
|
||||
{
|
||||
return local;
|
||||
}
|
||||
bool getLocalOrJudge() const
|
||||
{
|
||||
return local || judge;
|
||||
}
|
||||
bool getJudge() const
|
||||
{
|
||||
return judge;
|
||||
}
|
||||
|
||||
void setHandVisible(bool _handVisible)
|
||||
{
|
||||
handVisible = _handVisible;
|
||||
}
|
||||
|
||||
bool getHandVisible() const
|
||||
{
|
||||
return handVisible;
|
||||
}
|
||||
|
||||
QString getName() const
|
||||
{
|
||||
return QString::fromStdString(userInfo->name());
|
||||
}
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_INFO_H
|
||||
|
|
@ -56,7 +56,7 @@ bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const
|
|||
|
||||
PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor,
|
||||
AbstractClient *_client,
|
||||
TabGame *_game,
|
||||
AbstractGame *_game,
|
||||
QWidget *parent)
|
||||
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
class ServerInfo_PlayerProperties;
|
||||
class TabSupervisor;
|
||||
class AbstractClient;
|
||||
class TabGame;
|
||||
class AbstractGame;
|
||||
class UserContextMenu;
|
||||
|
||||
class PlayerListItemDelegate : public QStyledItemDelegate
|
||||
|
|
@ -39,7 +39,7 @@ private:
|
|||
QMap<int, QTreeWidgetItem *> players;
|
||||
TabSupervisor *tabSupervisor;
|
||||
AbstractClient *client;
|
||||
TabGame *game;
|
||||
AbstractGame *game;
|
||||
UserContextMenu *userContextMenu;
|
||||
QIcon readyIcon, notReadyIcon, concededIcon, playerIcon, judgeIcon, spectatorIcon, lockIcon;
|
||||
bool gameStarted;
|
||||
|
|
@ -47,7 +47,10 @@ signals:
|
|||
void openMessageDialog(const QString &userName, bool focus);
|
||||
|
||||
public:
|
||||
PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent = nullptr);
|
||||
PlayerListWidget(TabSupervisor *_tabSupervisor,
|
||||
AbstractClient *_client,
|
||||
AbstractGame *_game,
|
||||
QWidget *parent = nullptr);
|
||||
void retranslateUi();
|
||||
void setActivePlayer(int playerId);
|
||||
void setGameStarted(bool _gameStarted, bool resuming);
|
||||
|
|
|
|||
84
cockatrice/src/game/player/player_manager.cpp
Normal file
84
cockatrice/src/game/player/player_manager.cpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
#include "player_manager.h"
|
||||
|
||||
#include "../abstract_game.h"
|
||||
#include "player.h"
|
||||
|
||||
PlayerManager::PlayerManager(AbstractGame *_game,
|
||||
int _localPlayerId,
|
||||
bool _localPlayerIsJudge,
|
||||
bool localPlayerIsSpectator)
|
||||
: QObject(_game), game(_game), players(QMap<int, Player *>()), localPlayerId(_localPlayerId),
|
||||
localPlayerIsJudge(_localPlayerIsJudge), localPlayerIsSpectator(localPlayerIsSpectator)
|
||||
{
|
||||
}
|
||||
|
||||
bool PlayerManager::isMainPlayerConceded() const
|
||||
{
|
||||
Player *player = players.value(localPlayerId, nullptr);
|
||||
return player && player->getConceded();
|
||||
}
|
||||
|
||||
Player *PlayerManager::getActiveLocalPlayer(int activePlayer) const
|
||||
{
|
||||
Player *active = players.value(activePlayer, 0);
|
||||
if (active)
|
||||
if (active->getPlayerInfo()->getLocal())
|
||||
return active;
|
||||
|
||||
QMapIterator<int, Player *> playerIterator(players);
|
||||
while (playerIterator.hasNext()) {
|
||||
Player *temp = playerIterator.next().value();
|
||||
if (temp->getPlayerInfo()->getLocal())
|
||||
return temp;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Player *PlayerManager::addPlayer(int playerId, const ServerInfo_User &info)
|
||||
{
|
||||
auto *newPlayer = new Player(info, playerId, isLocalPlayer(playerId) || game->getGameState()->getIsLocalGame(),
|
||||
isJudge(), getGame());
|
||||
connect(newPlayer, &Player::concededChanged, this, &PlayerManager::playerConceded);
|
||||
players.insert(playerId, newPlayer);
|
||||
emit playerAdded(newPlayer);
|
||||
emit playerCountChanged();
|
||||
return newPlayer;
|
||||
}
|
||||
|
||||
void PlayerManager::removePlayer(int playerId)
|
||||
{
|
||||
Player *player = getPlayer(playerId);
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
players.remove(playerId);
|
||||
emit playerCountChanged();
|
||||
emit playerRemoved(player);
|
||||
}
|
||||
|
||||
Player *PlayerManager::getPlayer(int playerId) const
|
||||
{
|
||||
Player *player = players.value(playerId, 0);
|
||||
if (!player)
|
||||
return nullptr;
|
||||
return player;
|
||||
}
|
||||
|
||||
void PlayerManager::onPlayerConceded(int playerId, bool conceded)
|
||||
{
|
||||
// GameEventHandler cares about this for sending the concede/unconcede commands
|
||||
if (playerId == getActiveLocalPlayer(playerId)->getPlayerInfo()->getId()) {
|
||||
if (conceded) {
|
||||
emit activeLocalPlayerConceded();
|
||||
} else {
|
||||
emit activeLocalPlayerUnconceded();
|
||||
}
|
||||
}
|
||||
// Everything else cares about this
|
||||
if (conceded) {
|
||||
emit playerConceded(playerId);
|
||||
} else {
|
||||
emit playerUnconceded(playerId);
|
||||
}
|
||||
}
|
||||
114
cockatrice/src/game/player/player_manager.h
Normal file
114
cockatrice/src/game/player/player_manager.h
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#ifndef COCKATRICE_PLAYER_MANAGER_H
|
||||
#define COCKATRICE_PLAYER_MANAGER_H
|
||||
|
||||
#include "pb/serverinfo_playerproperties.pb.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
class AbstractGame;
|
||||
class Player;
|
||||
class PlayerManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlayerManager(AbstractGame *_game, int _localPlayerId, bool _localPlayerIsJudge, bool localPlayerIsSpectator);
|
||||
|
||||
AbstractGame *game;
|
||||
QMap<int, Player *> players;
|
||||
int localPlayerId;
|
||||
bool localPlayerIsJudge;
|
||||
bool localPlayerIsSpectator;
|
||||
QMap<int, ServerInfo_User> spectators;
|
||||
|
||||
bool isSpectator() const
|
||||
{
|
||||
return localPlayerIsSpectator;
|
||||
}
|
||||
|
||||
bool isJudge() const
|
||||
{
|
||||
return localPlayerIsJudge;
|
||||
}
|
||||
|
||||
int getLocalPlayerId() const
|
||||
{
|
||||
return localPlayerId;
|
||||
}
|
||||
|
||||
const QMap<int, Player *> &getPlayers() const
|
||||
{
|
||||
return players;
|
||||
}
|
||||
|
||||
int getPlayerCount() const
|
||||
{
|
||||
return players.size();
|
||||
}
|
||||
|
||||
Player *getActiveLocalPlayer(int activePlayer) const;
|
||||
|
||||
Player *addPlayer(int playerId, const ServerInfo_User &info);
|
||||
|
||||
void removePlayer(int playerId);
|
||||
|
||||
Player *getPlayer(int playerId) const;
|
||||
|
||||
void onPlayerConceded(int playerId, bool conceded);
|
||||
|
||||
[[nodiscard]] bool isMainPlayerConceded() const;
|
||||
|
||||
[[nodiscard]] bool isLocalPlayer(int playerId) const
|
||||
{
|
||||
return playerId == getLocalPlayerId();
|
||||
}
|
||||
|
||||
const QMap<int, ServerInfo_User> &getSpectators() const
|
||||
{
|
||||
return spectators;
|
||||
}
|
||||
|
||||
ServerInfo_User getSpectator(int playerId) const
|
||||
{
|
||||
return spectators.value(playerId);
|
||||
}
|
||||
|
||||
QString getSpectatorName(int spectatorId) const
|
||||
{
|
||||
return QString::fromStdString(spectators.value(spectatorId).name());
|
||||
}
|
||||
|
||||
void addSpectator(int spectatorId, const ServerInfo_PlayerProperties &prop)
|
||||
{
|
||||
if (!spectators.contains(spectatorId)) {
|
||||
spectators.insert(spectatorId, prop.user_info());
|
||||
emit spectatorAdded(prop);
|
||||
}
|
||||
}
|
||||
|
||||
void removeSpectator(int spectatorId)
|
||||
{
|
||||
ServerInfo_User spectatorInfo = spectators.value(spectatorId);
|
||||
spectators.remove(spectatorId);
|
||||
emit spectatorRemoved(spectatorId, spectatorInfo);
|
||||
}
|
||||
|
||||
AbstractGame *getGame() const
|
||||
{
|
||||
return game;
|
||||
}
|
||||
|
||||
signals:
|
||||
void playerAdded(Player *player);
|
||||
void playerRemoved(Player *player);
|
||||
void activeLocalPlayerConceded();
|
||||
void activeLocalPlayerUnconceded();
|
||||
void playerConceded(int playerId);
|
||||
void playerUnconceded(int playerId);
|
||||
void playerCountChanged();
|
||||
void spectatorAdded(ServerInfo_PlayerProperties spectator);
|
||||
void spectatorRemoved(int spectatorId, ServerInfo_User spectator);
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_MANAGER_H
|
||||
1386
cockatrice/src/game/player/player_menu.cpp
Normal file
1386
cockatrice/src/game/player/player_menu.cpp
Normal file
File diff suppressed because it is too large
Load diff
131
cockatrice/src/game/player/player_menu.h
Normal file
131
cockatrice/src/game/player/player_menu.h
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
#ifndef COCKATRICE_PLAYER_MENU_H
|
||||
#define COCKATRICE_PLAYER_MENU_H
|
||||
|
||||
#include "../../client/tearoff_menu.h"
|
||||
#include "player.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QObject>
|
||||
|
||||
class PlayerMenu : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void cardMenuUpdated(QMenu *cardMenu);
|
||||
|
||||
public slots:
|
||||
QMenu *createPtMenu() const;
|
||||
QMenu *createMoveMenu() const;
|
||||
void enableOpenInDeckEditorAction() const;
|
||||
void populatePredefinedTokensMenu();
|
||||
void setMenusForGraphicItems();
|
||||
|
||||
private slots:
|
||||
void addPlayer(Player *playerToAdd);
|
||||
void removePlayer(Player *playerToRemove);
|
||||
void playerListActionTriggered();
|
||||
void refreshShortcuts();
|
||||
void clearCustomZonesMenu();
|
||||
void addViewCustomZoneActionToCustomZoneMenu(QString zoneName);
|
||||
void resetTopCardMenuActions();
|
||||
|
||||
public:
|
||||
PlayerMenu(Player *player);
|
||||
void createDrawActions();
|
||||
void createShuffleActions();
|
||||
void createMoveActions();
|
||||
void createViewActions();
|
||||
void retranslateUi();
|
||||
|
||||
void addPlayerToList(QMenu *playerList, Player *playerToAdd);
|
||||
static void removePlayerFromList(QMenu *playerList, Player *player);
|
||||
|
||||
QMenu *updateCardMenu(const CardItem *card);
|
||||
|
||||
[[nodiscard]] bool createAnotherTokenActionExists() const
|
||||
{
|
||||
return aCreateAnotherToken != nullptr;
|
||||
}
|
||||
|
||||
void setAndEnableCreateAnotherTokenAction(QString text)
|
||||
{
|
||||
aCreateAnotherToken->setText(text);
|
||||
aCreateAnotherToken->setEnabled(true);
|
||||
}
|
||||
|
||||
QStringList getPredefinedTokens() const
|
||||
{
|
||||
return predefinedTokens;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isAlwaysRevealTopCardChecked()
|
||||
{
|
||||
return aAlwaysRevealTopCard->isChecked();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isAlwaysLookAtTopCardChecked()
|
||||
{
|
||||
return aAlwaysLookAtTopCard->isChecked();
|
||||
}
|
||||
|
||||
[[nodiscard]] QMenu *getPlayerMenu() const
|
||||
{
|
||||
return playerMenu;
|
||||
}
|
||||
|
||||
[[nodiscard]] QMenu *getCountersMenu()
|
||||
{
|
||||
return countersMenu;
|
||||
}
|
||||
|
||||
bool getShortcutsActive() const
|
||||
{
|
||||
return shortcutsActive;
|
||||
}
|
||||
|
||||
void setShortcutsActive();
|
||||
void setShortcutIfItExists(QAction *action, ShortcutKey shortcut);
|
||||
void clearShortcutIfItExists(QAction *action);
|
||||
void setShortcutsInactive();
|
||||
|
||||
private:
|
||||
Player *player;
|
||||
QMenu *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu, *mRevealLibrary, *mLendLibrary, *mRevealTopCard,
|
||||
*mRevealHand, *mRevealRandomHandCard, *mRevealRandomGraveyardCard, *mCustomZones, *mCardCounters;
|
||||
TearOffMenu *moveGraveMenu, *moveRfgMenu, *graveMenu, *moveHandMenu, *handMenu, *libraryMenu, *topLibraryMenu,
|
||||
*bottomLibraryMenu, *rfgMenu, *playerMenu;
|
||||
QList<QMenu *> playerLists;
|
||||
QList<QMenu *> singlePlayerLists;
|
||||
QList<QAction *> allPlayersActions;
|
||||
QList<QPair<QString, int>> playersInfo;
|
||||
QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg,
|
||||
*aMoveGraveToTopLibrary, *aMoveGraveToBottomLibrary, *aMoveGraveToHand, *aMoveGraveToRfg, *aMoveRfgToTopLibrary,
|
||||
*aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave, *aViewHand, *aViewLibrary, *aViewTopCards,
|
||||
*aViewBottomCards, *aAlwaysRevealTopCard, *aAlwaysLookAtTopCard, *aOpenDeckInDeckEditor,
|
||||
*aMoveTopCardToGraveyard, *aMoveTopCardToExile, *aMoveTopCardsToGraveyard, *aMoveTopCardsToExile,
|
||||
*aMoveTopCardsUntil, *aMoveTopCardToBottom, *aViewGraveyard, *aViewRfg, *aViewSideboard, *aDrawCard,
|
||||
*aDrawCards, *aUndoDraw, *aMulligan, *aShuffle, *aShuffleTopCards, *aShuffleBottomCards, *aMoveTopToPlay,
|
||||
*aMoveTopToPlayFaceDown, *aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken, *aMoveBottomToPlay,
|
||||
*aMoveBottomToPlayFaceDown, *aMoveBottomCardToTop, *aMoveBottomCardToGraveyard, *aMoveBottomCardToExile,
|
||||
*aMoveBottomCardsToGraveyard, *aMoveBottomCardsToExile, *aDrawBottomCard, *aDrawBottomCards;
|
||||
|
||||
QList<QAction *> aAddCounter, aSetCounter, aRemoveCounter;
|
||||
QAction *aPlay, *aPlayFacedown, *aHide, *aTap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetPT, *aResetPT,
|
||||
*aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aFlowP, *aFlowT, *aSetAnnotation, *aFlip, *aPeek, *aClone,
|
||||
*aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToHand, *aMoveToGraveyard, *aMoveToExile,
|
||||
*aMoveToXfromTopOfLibrary, *aSelectAll, *aSelectRow, *aSelectColumn, *aSortHand, *aIncrementAllCardCounters;
|
||||
|
||||
bool shortcutsActive;
|
||||
QStringList predefinedTokens;
|
||||
|
||||
QMenu *createCardMenu(const CardItem *card);
|
||||
|
||||
void addRelatedCardActions(const CardItem *card, QMenu *cardMenu);
|
||||
void addRelatedCardView(const CardItem *card, QMenu *cardMenu);
|
||||
|
||||
void initSayMenu();
|
||||
void initContextualPlayersMenu(QMenu *menu);
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_MENU_H
|
||||
|
|
@ -9,13 +9,8 @@
|
|||
#include <QPixmapCache>
|
||||
#include <QtMath>
|
||||
|
||||
PlayerCounter::PlayerCounter(Player *_player,
|
||||
int _id,
|
||||
const QString &_name,
|
||||
int _value,
|
||||
QGraphicsItem *parent,
|
||||
QWidget *game)
|
||||
: AbstractCounter(_player, _id, _name, false, _value, false, parent, game)
|
||||
PlayerCounter::PlayerCounter(Player *_player, int _id, const QString &_name, int _value, QGraphicsItem *parent)
|
||||
: AbstractCounter(_player, _id, _name, false, _value, false, parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -52,12 +47,12 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
|
|||
painter->drawText(translatedRect, Qt::AlignCenter, QString::number(value));
|
||||
}
|
||||
|
||||
PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem, QWidget *_game)
|
||||
: ArrowTarget(_owner, parentItem), playerCounter(nullptr), game(_game)
|
||||
PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem)
|
||||
: ArrowTarget(_owner, parentItem), playerCounter(nullptr)
|
||||
{
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
|
||||
const std::string &bmp = _owner->getUserInfo()->avatar_bmp();
|
||||
const std::string &bmp = _owner->getPlayerInfo()->getUserInfo()->avatar_bmp();
|
||||
if (!fullPixmap.loadFromData((const uchar *)bmp.data(), static_cast<uint>(bmp.size()))) {
|
||||
fullPixmap = QPixmap();
|
||||
}
|
||||
|
|
@ -77,7 +72,7 @@ QRectF PlayerTarget::boundingRect() const
|
|||
|
||||
void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||
{
|
||||
const ServerInfo_User *const info = owner->getUserInfo();
|
||||
const ServerInfo_User *const info = owner->getPlayerInfo()->getUserInfo();
|
||||
|
||||
const qreal border = 2;
|
||||
|
||||
|
|
@ -160,7 +155,7 @@ AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name,
|
|||
playerCounter->delCounter();
|
||||
}
|
||||
|
||||
playerCounter = new PlayerCounter(owner, _counterId, _name, _value, this, game);
|
||||
playerCounter = new PlayerCounter(owner, _counterId, _name, _value, this);
|
||||
playerCounter->setPos(boundingRect().width() - playerCounter->boundingRect().width(),
|
||||
boundingRect().height() - playerCounter->boundingRect().height());
|
||||
connect(playerCounter, &PlayerCounter::destroyed, this, &PlayerTarget::counterDeleted);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "../board/abstract_counter.h"
|
||||
#include "../board/arrow_target.h"
|
||||
#include "../board/graphics_item_type.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QPixmap>
|
||||
|
|
@ -13,12 +14,7 @@ class PlayerCounter : public AbstractCounter
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PlayerCounter(Player *_player,
|
||||
int _id,
|
||||
const QString &_name,
|
||||
int _value,
|
||||
QGraphicsItem *parent = nullptr,
|
||||
QWidget *game = nullptr);
|
||||
PlayerCounter(Player *_player, int _id, const QString &_name, int _value, QGraphicsItem *parent = nullptr);
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
};
|
||||
|
|
@ -29,7 +25,6 @@ class PlayerTarget : public ArrowTarget
|
|||
private:
|
||||
QPixmap fullPixmap;
|
||||
PlayerCounter *playerCounter;
|
||||
QWidget *game;
|
||||
public slots:
|
||||
void counterDeleted();
|
||||
|
||||
|
|
@ -43,7 +38,7 @@ public:
|
|||
return Type;
|
||||
}
|
||||
|
||||
explicit PlayerTarget(Player *_player = nullptr, QGraphicsItem *parentItem = nullptr, QWidget *_game = nullptr);
|
||||
explicit PlayerTarget(Player *_player = nullptr, QGraphicsItem *parentItem = nullptr);
|
||||
~PlayerTarget() override;
|
||||
QRectF boundingRect() const override;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue