diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 74869b4cc..01ae93962 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -207,6 +207,7 @@ set(cockatrice_SOURCES src/game/filters/filter_tree.cpp src/game/filters/filter_tree_model.cpp src/game/filters/syntax_help.cpp + src/game/abstract_game.cpp src/game/game.cpp src/game/game_event_handler.cpp src/game/game_meta_info.cpp @@ -228,6 +229,7 @@ set(cockatrice_SOURCES src/game/player/player_manager.cpp src/game/player/player_menu.cpp src/game/player/player_target.cpp + src/game/replay.cpp src/game/zones/card_zone.cpp src/game/zones/hand_zone.cpp src/game/zones/pile_zone.cpp diff --git a/cockatrice/src/client/tabs/tab_game.cpp b/cockatrice/src/client/tabs/tab_game.cpp index 391870ab4..8b521634f 100644 --- a/cockatrice/src/client/tabs/tab_game.cpp +++ b/cockatrice/src/client/tabs/tab_game.cpp @@ -8,10 +8,12 @@ #include "../../game/cards/card_database_manager.h" #include "../../game/deckview/deck_view_container.h" #include "../../game/deckview/tabbed_deck_view_container.h" +#include "../../game/game.h" #include "../../game/game_scene.h" #include "../../game/game_view.h" #include "../../game/player/player.h" #include "../../game/player/player_list_widget.h" +#include "../../game/replay.h" #include "../../game/zones/card_zone.h" #include "../../main.h" #include "../../server/abstract_client.h" @@ -49,22 +51,11 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay) : Tab(_tabSupervisor), sayLabel(nullptr), sayEdit(nullptr) { // THIS CTOR IS USED ON REPLAY - - /*game->getGameMetaInfo() = new GameMetaInfo(); - game->getGameState() = - new GameState(0, -1, _tabSupervisor->getIsLocalGame(), QList(), false, false, -1, false); - connectToGameState(); - - game->getPlayerManager() = new PlayerManager(this, -1, true, false); - - game->getGameEventHandler() = new GameEventHandler(this);*/ - connectToGameEventHandler(); + game = new Replay(this, _replay); createCardInfoDock(true); createPlayerListDock(true); - connectPlayerListToGameEventHandler(); createMessageDock(true); - connectMessageLogToGameEventHandler(); createPlayAreaWidget(true); createDeckViewContainerWidget(true); createReplayDock(_replay); @@ -81,6 +72,14 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay) createReplayMenuItems(); createViewMenuItems(); + + connectToGameState(); + connectToPlayerManager(); + connectToGameEventHandler(); + connectPlayerListToGameEventHandler(); + connectMessageLogToGameEventHandler(); + connectMessageLogToPlayerHandler(); + retranslateUi(); connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this, &TabGame::refreshShortcuts); diff --git a/cockatrice/src/client/tabs/tab_game.h b/cockatrice/src/client/tabs/tab_game.h index c3677772e..1ebbef9d2 100644 --- a/cockatrice/src/client/tabs/tab_game.h +++ b/cockatrice/src/client/tabs/tab_game.h @@ -2,7 +2,7 @@ #define TAB_GAME_H #include "../../client/tearoff_menu.h" -#include "../../game/game.h" +#include "../../game/abstract_game.h" #include "../../game/player/player.h" #include "../../server/message_log_widget.h" #include "../replay_manager.h" @@ -51,7 +51,7 @@ class TabGame : public Tab { Q_OBJECT private: - Game *game; + AbstractGame *game; const UserListProxy *userListProxy; ReplayManager *replayManager; QStringList gameTypes; @@ -178,7 +178,7 @@ public: QString getTabText() const override; - Game *getGame() const + AbstractGame *getGame() const { return game; } diff --git a/cockatrice/src/game/abstract_game.cpp b/cockatrice/src/game/abstract_game.cpp new file mode 100644 index 000000000..a047e3a51 --- /dev/null +++ b/cockatrice/src/game/abstract_game.cpp @@ -0,0 +1,55 @@ +#include "abstract_game.h" + +#include "player/player.h" + +AbstractGame::AbstractGame(TabGame *_tab) + : tab(_tab) +{ + gameMetaInfo = new GameMetaInfo(this); + gameEventHandler = new GameEventHandler(this); + + activeCard = nullptr; +} + +bool AbstractGame::isHost() const +{ + return gameState->getHostId() == playerManager->getLocalPlayerId(); +} + +AbstractClient *AbstractGame::getClientForPlayer(int playerId) const +{ + if (gameState->getClients().size() > 1) { + if (playerId == -1) { + playerId = playerManager->getActiveLocalPlayer(gameState->getActivePlayer())->getPlayerInfo()->getId(); + } + + return gameState->getClients().at(playerId); + } else if (gameState->getClients().isEmpty()) + return nullptr; + else + return gameState->getClients().first(); +} + +void AbstractGame::loadReplay(GameReplay *replay) +{ + gameMetaInfo->setFromProto(replay->game_info()); + gameMetaInfo->setSpectatorsOmniscient(true); +} + +void AbstractGame::setActiveCard(CardItem *card) +{ + activeCard = card; +} + +CardItem *AbstractGame::getCard(int playerId, const QString &zoneName, int cardId) const +{ + Player *player = playerManager->getPlayer(playerId); + if (!player) + return nullptr; + + CardZoneLogic *zone = player->getZones().value(zoneName, 0); + if (!zone) + return nullptr; + + return zone->getCard(cardId); +} \ No newline at end of file diff --git a/cockatrice/src/game/abstract_game.h b/cockatrice/src/game/abstract_game.h new file mode 100644 index 000000000..386b2ee8e --- /dev/null +++ b/cockatrice/src/game/abstract_game.h @@ -0,0 +1,68 @@ +#ifndef COCKATRICE_ABSTRACT_GAME_H +#define COCKATRICE_ABSTRACT_GAME_H + +#include "../../../common/pb/game_replay.pb.h" +#include "game_event_handler.h" +#include "game_meta_info.h" +#include "game_state.h" +#include "player/player_manager.h" + +#include + +class CardItem; +class TabGame; +class AbstractGame : public QObject +{ + Q_OBJECT + +public: + explicit AbstractGame(TabGame *tab); + + TabGame *tab; + GameMetaInfo *gameMetaInfo; + GameState *gameState; + GameEventHandler *gameEventHandler; + PlayerManager *playerManager; + CardItem *activeCard; + + TabGame *getTab() const + { + return tab; + } + + GameMetaInfo *getGameMetaInfo() + { + return gameMetaInfo; + } + + GameState *getGameState() const + { + return gameState; + } + + GameEventHandler *getGameEventHandler() const + { + return gameEventHandler; + } + + PlayerManager *getPlayerManager() const + { + return playerManager; + } + + bool isHost() const; + + AbstractClient *getClientForPlayer(int playerId) const; + + void loadReplay(GameReplay *replay); + + CardItem *getCard(int playerId, const QString &zoneName, int cardId) const; + + void setActiveCard(CardItem *card); + CardItem *getActiveCard() const + { + return activeCard; + } +}; + +#endif // COCKATRICE_ABSTRACT_GAME_H diff --git a/cockatrice/src/game/board/abstract_counter.cpp b/cockatrice/src/game/board/abstract_counter.cpp index d13203f8d..be5398029 100644 --- a/cockatrice/src/game/board/abstract_counter.cpp +++ b/cockatrice/src/game/board/abstract_counter.cpp @@ -1,5 +1,6 @@ #include "abstract_counter.h" +#include "../../client/tabs/tab_game.h" #include "../../client/translate_counter_name.h" #include "../../settings/cache_settings.h" #include "../player/player.h" diff --git a/cockatrice/src/game/game.cpp b/cockatrice/src/game/game.cpp index 71ec71652..1a429f3c2 100644 --- a/cockatrice/src/game/game.cpp +++ b/cockatrice/src/game/game.cpp @@ -1,67 +1,20 @@ #include "game.h" +#include "../client/tabs/tab_game.h" #include "pb/event_game_joined.pb.h" Game::Game(TabGame *_tab, QList &_clients, const Event_GameJoined &event, const QMap &_roomGameTypes) - : tab(_tab) + : AbstractGame(_tab) { - gameMetaInfo = new GameMetaInfo(this); gameMetaInfo->setFromProto(event.game_info()); gameMetaInfo->setRoomGameTypes(_roomGameTypes); gameState = new GameState(this, 0, event.host_id(), tab->getTabSupervisor()->getIsLocalGame(), _clients, false, event.resuming(), -1, false); - playerManager = new PlayerManager(this, event.player_id(), event.spectator(), event.judge()); - gameMetaInfo->setStarted(false); - connect(gameMetaInfo, &GameMetaInfo::startedChanged, gameState, &GameState::onStartedChanged); - - gameEventHandler = new GameEventHandler(this); - - activeCard = nullptr; + playerManager = new PlayerManager(this, event.player_id(), event.judge(), event.spectator()); + gameMetaInfo->setStarted(false); } -bool Game::isHost() const -{ - return gameState->getHostId() == playerManager->getLocalPlayerId(); -} - -AbstractClient *Game::getClientForPlayer(int playerId) const -{ - if (gameState->getClients().size() > 1) { - if (playerId == -1) { - playerId = playerManager->getActiveLocalPlayer(gameState->getActivePlayer())->getPlayerInfo()->getId(); - } - - return gameState->getClients().at(playerId); - } else if (gameState->getClients().isEmpty()) - return nullptr; - else - return gameState->getClients().first(); -} - -void Game::loadReplay(GameReplay *replay) -{ - gameMetaInfo->setFromProto(replay->game_info()); - gameMetaInfo->setSpectatorsOmniscient(true); -} - -void Game::setActiveCard(CardItem *card) -{ - activeCard = card; -} - -CardItem *Game::getCard(int playerId, const QString &zoneName, int cardId) const -{ - Player *player = playerManager->getPlayer(playerId); - if (!player) - return nullptr; - - CardZoneLogic *zone = player->getZones().value(zoneName, 0); - if (!zone) - return nullptr; - - return zone->getCard(cardId); -} diff --git a/cockatrice/src/game/game.h b/cockatrice/src/game/game.h index 82a098e7a..d62090c27 100644 --- a/cockatrice/src/game/game.h +++ b/cockatrice/src/game/game.h @@ -1,18 +1,10 @@ #ifndef COCKATRICE_GAME_H #define COCKATRICE_GAME_H -#include "../../../common/pb/game_replay.pb.h" -#include "game_event_handler.h" -#include "game_meta_info.h" -#include "game_state.h" -#include "player/player_manager.h" - +#include "abstract_game.h" #include -class CardItem; -class GameMetaInfo; -class TabGame; -class Game : public QObject +class Game : public AbstractGame { Q_OBJECT @@ -21,52 +13,6 @@ public: QList &_clients, const Event_GameJoined &event, const QMap &_roomGameTypes); - - TabGame *tab; - GameMetaInfo *gameMetaInfo; - GameState *gameState; - GameEventHandler *gameEventHandler; - PlayerManager *playerManager; - CardItem *activeCard; - - TabGame *getTab() const - { - return tab; - } - - GameMetaInfo *getGameMetaInfo() - { - return gameMetaInfo; - } - - GameState *getGameState() const - { - return gameState; - } - - GameEventHandler *getGameEventHandler() const - { - return gameEventHandler; - } - - PlayerManager *getPlayerManager() const - { - return playerManager; - } - - bool isHost() const; - - AbstractClient *getClientForPlayer(int playerId) const; - - void loadReplay(GameReplay *replay); - - CardItem *getCard(int playerId, const QString &zoneName, int cardId) const; - - void setActiveCard(CardItem *card); - CardItem *getActiveCard() const - { - return activeCard; - } }; #endif // COCKATRICE_GAME_H diff --git a/cockatrice/src/game/game_event_handler.cpp b/cockatrice/src/game/game_event_handler.cpp index eb1dc73f2..d06ae828e 100644 --- a/cockatrice/src/game/game_event_handler.cpp +++ b/cockatrice/src/game/game_event_handler.cpp @@ -4,7 +4,7 @@ #include "../server/abstract_client.h" #include "../server/message_log_widget.h" #include "../server/pending_command.h" -#include "game.h" +#include "abstract_game.h" #include "get_pb_extension.h" #include "pb/command_concede.pb.h" #include "pb/command_delete_arrow.pb.h" @@ -29,7 +29,7 @@ #include "pb/event_set_active_player.pb.h" #include "pb/game_event_container.pb.h" -GameEventHandler::GameEventHandler(Game *_game) : QObject(_game), game(_game) +GameEventHandler::GameEventHandler(AbstractGame *_game) : QObject(_game), game(_game) { } diff --git a/cockatrice/src/game/game_event_handler.h b/cockatrice/src/game/game_event_handler.h index 7ffe85aa7..251273dc7 100644 --- a/cockatrice/src/game/game_event_handler.h +++ b/cockatrice/src/game/game_event_handler.h @@ -30,7 +30,7 @@ class Event_Ping; class Event_GameSay; class Event_Kicked; class Event_ReverseTurn; -class Game; +class AbstractGame; class PendingCommand; class Player; @@ -41,10 +41,10 @@ class GameEventHandler : public QObject Q_OBJECT private: - Game *game; + AbstractGame *game; public: - explicit GameEventHandler(Game *_game); + explicit GameEventHandler(AbstractGame *_game); void handleNextTurn(); void handleReverseTurn(); diff --git a/cockatrice/src/game/game_meta_info.cpp b/cockatrice/src/game/game_meta_info.cpp index face4cf76..45146dad9 100644 --- a/cockatrice/src/game/game_meta_info.cpp +++ b/cockatrice/src/game/game_meta_info.cpp @@ -1,7 +1,7 @@ #include "game_meta_info.h" -#include "game.h" +#include "abstract_game.h" -GameMetaInfo::GameMetaInfo(Game *_game) : QObject(_game), game(_game) +GameMetaInfo::GameMetaInfo(AbstractGame *_game) : QObject(_game), game(_game) { } diff --git a/cockatrice/src/game/game_meta_info.h b/cockatrice/src/game/game_meta_info.h index 642c3c55a..39d589c65 100644 --- a/cockatrice/src/game/game_meta_info.h +++ b/cockatrice/src/game/game_meta_info.h @@ -10,12 +10,12 @@ // This class de-couples the domain object (i.e. the GameMetaInfo) from the network object. // If the network object changes, only this class needs to be adjusted. -class Game; +class AbstractGame; class GameMetaInfo : public QObject { Q_OBJECT public: - explicit GameMetaInfo(Game *_game); + explicit GameMetaInfo(AbstractGame *_game); QMap roomGameTypes; @@ -79,7 +79,7 @@ public: return roomGameTypes.find(gameInfo_.game_types(index)).value(); } - Game *getGame() const + AbstractGame *getGame() const { return game; } @@ -105,7 +105,7 @@ signals: void spectatorsOmniscienceChanged(bool omniscient); private: - Game *game; + AbstractGame *game; ServerInfo_Game gameInfo_; }; diff --git a/cockatrice/src/game/game_state.cpp b/cockatrice/src/game/game_state.cpp index c71fe3ad0..dc656ff79 100644 --- a/cockatrice/src/game/game_state.cpp +++ b/cockatrice/src/game/game_state.cpp @@ -1,6 +1,7 @@ #include "game_state.h" +#include "abstract_game.h" -GameState::GameState(Game *_game, +GameState::GameState(AbstractGame *_game, int _secondsElapsed, int _hostId, bool _isLocalGame, diff --git a/cockatrice/src/game/game_state.h b/cockatrice/src/game/game_state.h index 095c74a7f..4f1cd4b17 100644 --- a/cockatrice/src/game/game_state.h +++ b/cockatrice/src/game/game_state.h @@ -1,13 +1,13 @@ #ifndef COCKATRICE_GAME_STATE_H #define COCKATRICE_GAME_STATE_H -#include "../client/tabs/tab_game.h" #include "../server/abstract_client.h" #include "pb/serverinfo_game.pb.h" -#include "pb/serverinfo_playerproperties.pb.h" #include +#include +class AbstractGame; class ServerInfo_PlayerProperties; class ServerInfo_User; @@ -16,7 +16,7 @@ class GameState : public QObject Q_OBJECT public: - explicit GameState(Game *_game, + explicit GameState(AbstractGame *_game, int secondsElapsed, int hostId, bool isLocalGame, @@ -132,7 +132,7 @@ public slots: void setGameTime(int _secondsElapsed); private: - Game *game; + AbstractGame *game; QTimer *gameTimer; int secondsElapsed; QMap roomGameTypes; diff --git a/cockatrice/src/game/player/player.cpp b/cockatrice/src/game/player/player.cpp index 44b108718..e9a1b52c8 100644 --- a/cockatrice/src/game/player/player.cpp +++ b/cockatrice/src/game/player/player.cpp @@ -29,7 +29,7 @@ #include #include -Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, Game *_parent) +Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, AbstractGame *_parent) : QObject(_parent), game(_parent), playerInfo(new PlayerInfo(info, _id, _local, _judge)), playerEventHandler(new PlayerEventHandler(this)), playerActions(new PlayerActions(this)), active(false), conceded(false), deck(nullptr), zoneId(0), dialogSemaphore(false) diff --git a/cockatrice/src/game/player/player.h b/cockatrice/src/game/player/player.h index 6598b4a04..cd7d3f818 100644 --- a/cockatrice/src/game/player/player.h +++ b/cockatrice/src/game/player/player.h @@ -6,7 +6,6 @@ #include "../board/abstract_graphics_item.h" #include "../cards/card_info.h" #include "../filters/filter_string.h" -#include "../game.h" #include "pb/card_attributes.pb.h" #include "pb/game_event.pb.h" #include "player_actions.h" @@ -33,6 +32,7 @@ class Message; } // namespace google class AbstractCardItem; class AbstractCounter; +class AbstractGame; class ArrowItem; class ArrowTarget; class CardDatabase; @@ -74,7 +74,7 @@ public slots: void setActive(bool _active); public: - Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, Game *_parent); + Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, AbstractGame *_parent); ~Player() override; void initializeZones(); @@ -94,7 +94,7 @@ public: return active; } - Game *getGame() const + AbstractGame *getGame() const { return game; } @@ -224,7 +224,7 @@ public: void setZoneId(int _zoneId); private: - Game *game; + AbstractGame *game; PlayerInfo *playerInfo; PlayerEventHandler *playerEventHandler; PlayerActions *playerActions; diff --git a/cockatrice/src/game/player/player_list_widget.cpp b/cockatrice/src/game/player/player_list_widget.cpp index 5b97d6613..f43974805 100644 --- a/cockatrice/src/game/player/player_list_widget.cpp +++ b/cockatrice/src/game/player/player_list_widget.cpp @@ -54,7 +54,7 @@ bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const return data(4, Qt::UserRole + 1).toInt() < other.data(4, Qt::UserRole + 1).toInt(); } -PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, Game *_game, QWidget *parent) +PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, AbstractGame *_game, QWidget *parent) : QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false) { readyIcon = QPixmap("theme:icons/ready_start"); diff --git a/cockatrice/src/game/player/player_list_widget.h b/cockatrice/src/game/player/player_list_widget.h index 8b70db27a..6310c05ef 100644 --- a/cockatrice/src/game/player/player_list_widget.h +++ b/cockatrice/src/game/player/player_list_widget.h @@ -11,7 +11,7 @@ class ServerInfo_PlayerProperties; class TabSupervisor; class AbstractClient; -class Game; +class AbstractGame; class UserContextMenu; class PlayerListItemDelegate : public QStyledItemDelegate @@ -39,7 +39,7 @@ private: QMap players; TabSupervisor *tabSupervisor; AbstractClient *client; - Game *game; + AbstractGame *game; UserContextMenu *userContextMenu; QIcon readyIcon, notReadyIcon, concededIcon, playerIcon, judgeIcon, spectatorIcon, lockIcon; bool gameStarted; @@ -47,7 +47,7 @@ signals: void openMessageDialog(const QString &userName, bool focus); public: - PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, Game *_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); diff --git a/cockatrice/src/game/player/player_manager.cpp b/cockatrice/src/game/player/player_manager.cpp index 3d91f51b9..9724c28b7 100644 --- a/cockatrice/src/game/player/player_manager.cpp +++ b/cockatrice/src/game/player/player_manager.cpp @@ -1,9 +1,9 @@ #include "player_manager.h" -#include "../game.h" +#include "../abstract_game.h" #include "player.h" -PlayerManager::PlayerManager(Game *_game, int _localPlayerId, bool _localPlayerIsJudge, bool localPlayerIsSpectator) +PlayerManager::PlayerManager(AbstractGame *_game, int _localPlayerId, bool _localPlayerIsJudge, bool localPlayerIsSpectator) : QObject(_game), game(_game), players(QMap()), localPlayerId(_localPlayerId), localPlayerIsJudge(_localPlayerIsJudge), localPlayerIsSpectator(localPlayerIsSpectator) { diff --git a/cockatrice/src/game/player/player_manager.h b/cockatrice/src/game/player/player_manager.h index c72dece6d..92e492510 100644 --- a/cockatrice/src/game/player/player_manager.h +++ b/cockatrice/src/game/player/player_manager.h @@ -6,16 +6,16 @@ #include #include -class Game; +class AbstractGame; class Player; class PlayerManager : public QObject { Q_OBJECT public: - PlayerManager(Game *_game, int _localPlayerId, bool _localPlayerIsJudge, bool localPlayerIsSpectator); + PlayerManager(AbstractGame *_game, int _localPlayerId, bool _localPlayerIsJudge, bool localPlayerIsSpectator); - Game *game; + AbstractGame *game; QMap players; int localPlayerId; bool localPlayerIsJudge; @@ -94,7 +94,7 @@ public: emit spectatorRemoved(spectatorId, spectatorInfo); } - Game *getGame() const + AbstractGame *getGame() const { return game; } diff --git a/cockatrice/src/game/player/player_menu.cpp b/cockatrice/src/game/player/player_menu.cpp index 5fd69093b..f91b421c5 100644 --- a/cockatrice/src/game/player/player_menu.cpp +++ b/cockatrice/src/game/player/player_menu.cpp @@ -370,7 +370,8 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player) retranslateUi(); } -void PlayerMenu::setMenusForGraphicItems(){ +void PlayerMenu::setMenusForGraphicItems() +{ player->getGraphicsItem()->getTableZoneGraphicsItem()->setMenu(playerMenu); player->getGraphicsItem()->getGraveyardZoneGraphicsItem()->setMenu(graveMenu, aViewGraveyard); player->getGraphicsItem()->getRfgZoneGraphicsItem()->setMenu(rfgMenu, aViewRfg); diff --git a/cockatrice/src/game/replay.cpp b/cockatrice/src/game/replay.cpp new file mode 100644 index 000000000..891d97df5 --- /dev/null +++ b/cockatrice/src/game/replay.cpp @@ -0,0 +1,12 @@ +#include "replay.h" + +#include "../client/tabs/tab_game.h" + + Replay::Replay(TabGame *_tab, GameReplay *_replay) : AbstractGame(_tab) +{ + gameState = new GameState(this, 0, -1, tab->getTabSupervisor()->getIsLocalGame(), {}, false, + false, -1, false); + connect(gameMetaInfo, &GameMetaInfo::startedChanged, gameState, &GameState::onStartedChanged); + playerManager = new PlayerManager(this, -1, false, true); + loadReplay(_replay); +} diff --git a/cockatrice/src/game/replay.h b/cockatrice/src/game/replay.h new file mode 100644 index 000000000..2f7508a0d --- /dev/null +++ b/cockatrice/src/game/replay.h @@ -0,0 +1,13 @@ +#ifndef COCKATRICE_REPLAY_H +#define COCKATRICE_REPLAY_H + +#include "abstract_game.h" + +class Replay : public AbstractGame { + Q_OBJECT + +public: + explicit Replay(TabGame *_tab, GameReplay *_replay); +}; + +#endif // COCKATRICE_REPLAY_H diff --git a/cockatrice/src/server/chat_view/chat_view.cpp b/cockatrice/src/server/chat_view/chat_view.cpp index 105be5913..2945127b7 100644 --- a/cockatrice/src/server/chat_view/chat_view.cpp +++ b/cockatrice/src/server/chat_view/chat_view.cpp @@ -23,7 +23,7 @@ UserMessagePosition::UserMessagePosition(QTextCursor &cursor) relativePosition = cursor.position() - block.position(); } -ChatView::ChatView(TabSupervisor *_tabSupervisor, Game *_game, bool _showTimestamps, QWidget *parent) +ChatView::ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _showTimestamps, QWidget *parent) : QTextBrowser(parent), tabSupervisor(_tabSupervisor), game(_game), userListProxy(_tabSupervisor->getUserListManager()), evenNumber(true), showTimestamps(_showTimestamps), hoveredItemType(HoveredNothing) diff --git a/cockatrice/src/server/chat_view/chat_view.h b/cockatrice/src/server/chat_view/chat_view.h index 7ba3db9b8..fb601b4f1 100644 --- a/cockatrice/src/server/chat_view/chat_view.h +++ b/cockatrice/src/server/chat_view/chat_view.h @@ -12,11 +12,11 @@ #include #include +class AbstractGame; class QTextTable; class QMouseEvent; class UserContextMenu; class UserListProxy; -class Game; class UserMessagePosition { @@ -34,7 +34,7 @@ class ChatView : public QTextBrowser Q_OBJECT protected: TabSupervisor *const tabSupervisor; - Game *const game; + AbstractGame *const game; private: enum HoveredItemType @@ -83,7 +83,7 @@ private slots: void actMessageClicked(); public: - ChatView(TabSupervisor *_tabSupervisor, Game *_game, bool _showTimestamps, QWidget *parent = nullptr); + ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _showTimestamps, QWidget *parent = nullptr); void retranslateUi(); void appendHtml(const QString &html); void virtual appendHtmlServerMessage(const QString &html, diff --git a/cockatrice/src/server/message_log_widget.cpp b/cockatrice/src/server/message_log_widget.cpp index 68e20bceb..7cf8522d9 100644 --- a/cockatrice/src/server/message_log_widget.cpp +++ b/cockatrice/src/server/message_log_widget.cpp @@ -58,8 +58,7 @@ MessageLogWidget::getFromStr(CardZoneLogic *zone, QString cardName, int position cardNameContainsStartZone = true; } else { if (ownerChange) { - fromStr = tr(" from the top of %1's library") - .arg(zone->getPlayer()->getPlayerInfo()->getName()); + fromStr = tr(" from the top of %1's library").arg(zone->getPlayer()->getPlayerInfo()->getName()); } else { fromStr = tr(" from the top of their library"); } @@ -67,16 +66,14 @@ MessageLogWidget::getFromStr(CardZoneLogic *zone, QString cardName, int position } else if (position >= zone->getCards().size() - 1) { if (cardName.isEmpty()) { if (ownerChange) { - cardName = tr("the bottom card of %1's library") - .arg(zone->getPlayer()->getPlayerInfo()->getName()); + cardName = tr("the bottom card of %1's library").arg(zone->getPlayer()->getPlayerInfo()->getName()); } else { cardName = tr("the bottom card of their library"); } cardNameContainsStartZone = true; } else { if (ownerChange) { - fromStr = tr(" from the bottom of %1's library") - .arg(zone->getPlayer()->getPlayerInfo()->getName()); + fromStr = tr(" from the bottom of %1's library").arg(zone->getPlayer()->getPlayerInfo()->getName()); } else { fromStr = tr(" from the bottom of their library"); } @@ -375,10 +372,9 @@ void MessageLogWidget::logDrawCards(Player *player, int number, bool deckIsEmpty void MessageLogWidget::logDumpZone(Player *player, CardZoneLogic *zone, int numberCards, bool isReversed) { if (numberCards == -1) { - appendHtmlServerMessage( - tr("%1 is looking at %2.") - .arg(sanitizeHtml(player->getPlayerInfo()->getName())) - .arg(zone->getTranslatedName(zone->getPlayer() == player, CaseLookAtZone))); + appendHtmlServerMessage(tr("%1 is looking at %2.") + .arg(sanitizeHtml(player->getPlayerInfo()->getName())) + .arg(zone->getTranslatedName(zone->getPlayer() == player, CaseLookAtZone))); } else { appendHtmlServerMessage( tr("%1 is looking at the %4 %3 card(s) %2.", "top card for singular, top %3 cards for plural", numberCards) @@ -840,7 +836,7 @@ void MessageLogWidget::connectToPlayerEventHandler(PlayerEventHandler *playerEve &MessageLogWidget::logAlwaysLookAtTopCard); } -MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, Game *_game, QWidget *parent) +MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, AbstractGame *_game, QWidget *parent) : ChatView(_tabSupervisor, _game, true, parent), currentContext(MessageContext_None) { } diff --git a/cockatrice/src/server/message_log_widget.h b/cockatrice/src/server/message_log_widget.h index 652bbea47..e496bb4e9 100644 --- a/cockatrice/src/server/message_log_widget.h +++ b/cockatrice/src/server/message_log_widget.h @@ -6,11 +6,11 @@ #include "chat_view/chat_view.h" #include "user_level.h" +class AbstractGame; +class CardItem; +class GameEventContext; class Player; class PlayerEventHandler; -class Game; -class GameEventContext; -class CardItem; class MessageLogWidget : public ChatView { @@ -30,7 +30,7 @@ private: public: void connectToPlayerEventHandler(PlayerEventHandler *player); - MessageLogWidget(TabSupervisor *_tabSupervisor, Game *_game, QWidget *parent = nullptr); + MessageLogWidget(TabSupervisor *_tabSupervisor, AbstractGame *_game, QWidget *parent = nullptr); public slots: void containerProcessingDone(); diff --git a/cockatrice/src/server/user/user_context_menu.cpp b/cockatrice/src/server/user/user_context_menu.cpp index 0a514f557..e4df15fdf 100644 --- a/cockatrice/src/server/user/user_context_menu.cpp +++ b/cockatrice/src/server/user/user_context_menu.cpp @@ -29,7 +29,7 @@ #include #include -UserContextMenu::UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *parent, Game *_game) +UserContextMenu::UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *parent, AbstractGame *_game) : QObject(parent), client(_tabSupervisor->getClient()), tabSupervisor(_tabSupervisor), userListProxy(_tabSupervisor->getUserListManager()), game(_game) { diff --git a/cockatrice/src/server/user/user_context_menu.h b/cockatrice/src/server/user/user_context_menu.h index a00862d6a..730cfd185 100644 --- a/cockatrice/src/server/user/user_context_menu.h +++ b/cockatrice/src/server/user/user_context_menu.h @@ -5,6 +5,7 @@ #include +class AbstractGame; class UserListProxy; class AbstractClient; class ChatView; @@ -14,7 +15,6 @@ class QMenu; class QPoint; class Response; class ServerInfo_User; -class Game; class TabSupervisor; class UserContextMenu : public QObject @@ -24,7 +24,7 @@ private: AbstractClient *client; TabSupervisor *tabSupervisor; const UserListProxy *userListProxy; - Game *game; + AbstractGame *game; QAction *aUserName; QAction *aDetails; @@ -54,7 +54,7 @@ private slots: void gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer); public: - UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *_parent, Game *_game = 0); + UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *_parent, AbstractGame *_game = 0); void retranslateUi(); void showContextMenu(const QPoint &pos, const QString &userName,