mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 14:32:15 -07:00
Do to-do's
Took 3 hours 32 minutes
This commit is contained in:
parent
f7919d3d88
commit
b478026f6c
45 changed files with 620 additions and 506 deletions
|
|
@ -207,6 +207,7 @@ set(cockatrice_SOURCES
|
||||||
src/game/filters/filter_tree.cpp
|
src/game/filters/filter_tree.cpp
|
||||||
src/game/filters/filter_tree_model.cpp
|
src/game/filters/filter_tree_model.cpp
|
||||||
src/game/filters/syntax_help.cpp
|
src/game/filters/syntax_help.cpp
|
||||||
|
src/game/game.cpp
|
||||||
src/game/game_event_handler.cpp
|
src/game/game_event_handler.cpp
|
||||||
src/game/game_meta_info.cpp
|
src/game/game_meta_info.cpp
|
||||||
src/game/game_scene.cpp
|
src/game/game_scene.cpp
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include "replay_timeline_widget.h"
|
#include "replay_timeline_widget.h"
|
||||||
|
|
||||||
|
#include "../../settings/cache_settings.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef REPLAY_TIMELINE_WIDGET
|
#ifndef REPLAY_TIMELINE_WIDGET
|
||||||
#define REPLAY_TIMELINE_WIDGET
|
#define REPLAY_TIMELINE_WIDGET
|
||||||
|
|
||||||
#include "../../game/player/player.h"
|
#include "../../game/player/event_processing_options.h"
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ ReplayManager::ReplayManager(TabGame *parent, GameReplay *_replay)
|
||||||
aReplaySkipBackwardBig(nullptr)
|
aReplaySkipBackwardBig(nullptr)
|
||||||
{
|
{
|
||||||
if (replay) {
|
if (replay) {
|
||||||
game->loadReplay(replay);
|
game->getGame()->loadReplay(replay);
|
||||||
|
|
||||||
// Create list: event number -> time [ms]
|
// Create list: event number -> time [ms]
|
||||||
// Distribute simultaneous events evenly across 1 second.
|
// Distribute simultaneous events evenly across 1 second.
|
||||||
|
|
@ -95,8 +95,8 @@ ReplayManager::ReplayManager(TabGame *parent, GameReplay *_replay)
|
||||||
|
|
||||||
void ReplayManager::replayNextEvent(EventProcessingOptions options)
|
void ReplayManager::replayNextEvent(EventProcessingOptions options)
|
||||||
{
|
{
|
||||||
game->getGameEventHandler()->processGameEventContainer(replay->event_list(timelineWidget->getCurrentEvent()),
|
game->getGame()->getGameEventHandler()->processGameEventContainer(
|
||||||
nullptr, options);
|
replay->event_list(timelineWidget->getCurrentEvent()), nullptr, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplayManager::replayFinished()
|
void ReplayManager::replayFinished()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define REPLAY_MANAGER_H
|
#define REPLAY_MANAGER_H
|
||||||
#include "network/replay_timeline_widget.h"
|
#include "network/replay_timeline_widget.h"
|
||||||
#include "pb/game_replay.pb.h"
|
#include "pb/game_replay.pb.h"
|
||||||
|
#include "tabs/tab_game.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,18 +46,18 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
||||||
: Tab(_tabSupervisor), activeCard(nullptr), sayLabel(nullptr), sayEdit(nullptr)
|
: Tab(_tabSupervisor), sayLabel(nullptr), sayEdit(nullptr)
|
||||||
{
|
{
|
||||||
// THIS CTOR IS USED ON REPLAY
|
// THIS CTOR IS USED ON REPLAY
|
||||||
|
|
||||||
gameMetaInfo = new GameMetaInfo();
|
/*game->getGameMetaInfo() = new GameMetaInfo();
|
||||||
gameState =
|
game->getGameState() =
|
||||||
new GameState(0, -1, _tabSupervisor->getIsLocalGame(), QList<AbstractClient *>(), false, false, -1, false);
|
new GameState(0, -1, _tabSupervisor->getIsLocalGame(), QList<AbstractClient *>(), false, false, -1, false);
|
||||||
connectToGameState();
|
connectToGameState();
|
||||||
|
|
||||||
playerManager = new PlayerManager(this, -1, true, false);
|
game->getPlayerManager() = new PlayerManager(this, -1, true, false);
|
||||||
|
|
||||||
gameEventHandler = new GameEventHandler(this);
|
game->getGameEventHandler() = new GameEventHandler(this);*/
|
||||||
connectToGameEventHandler();
|
connectToGameEventHandler();
|
||||||
|
|
||||||
createCardInfoDock(true);
|
createCardInfoDock(true);
|
||||||
|
|
@ -85,7 +85,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
||||||
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
||||||
&TabGame::refreshShortcuts);
|
&TabGame::refreshShortcuts);
|
||||||
refreshShortcuts();
|
refreshShortcuts();
|
||||||
messageLog->logReplayStarted(gameMetaInfo->gameId());
|
messageLog->logReplayStarted(game->getGameMetaInfo()->gameId());
|
||||||
|
|
||||||
QTimer::singleShot(0, this, &TabGame::loadLayout);
|
QTimer::singleShot(0, this, &TabGame::loadLayout);
|
||||||
}
|
}
|
||||||
|
|
@ -94,32 +94,14 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor,
|
||||||
QList<AbstractClient *> &_clients,
|
QList<AbstractClient *> &_clients,
|
||||||
const Event_GameJoined &event,
|
const Event_GameJoined &event,
|
||||||
const QMap<int, QString> &_roomGameTypes)
|
const QMap<int, QString> &_roomGameTypes)
|
||||||
: Tab(_tabSupervisor), userListProxy(_tabSupervisor->getUserListManager()), activeCard(nullptr)
|
: Tab(_tabSupervisor), userListProxy(_tabSupervisor->getUserListManager())
|
||||||
{
|
{
|
||||||
|
|
||||||
gameMetaInfo = new GameMetaInfo();
|
|
||||||
gameMetaInfo->setFromProto(event.game_info());
|
|
||||||
gameMetaInfo->setRoomGameTypes(_roomGameTypes);
|
|
||||||
gameState = new GameState(0, event.host_id(), _tabSupervisor->getIsLocalGame(), _clients, false, event.resuming(),
|
|
||||||
-1, false);
|
|
||||||
connectToGameState();
|
|
||||||
|
|
||||||
playerManager = new PlayerManager(this, event.player_id(), event.spectator(), event.judge());
|
|
||||||
connectToPlayerManager();
|
|
||||||
|
|
||||||
// THIS CTOR IS USED ON GAMES
|
// THIS CTOR IS USED ON GAMES
|
||||||
gameMetaInfo->setStarted(false);
|
game = new Game(_clients, event, _roomGameTypes);
|
||||||
|
|
||||||
connect(gameMetaInfo, &GameMetaInfo::startedChanged, gameState, &GameState::onStartedChanged);
|
|
||||||
|
|
||||||
gameEventHandler = new GameEventHandler(this);
|
|
||||||
connectToGameEventHandler();
|
|
||||||
|
|
||||||
createCardInfoDock();
|
createCardInfoDock();
|
||||||
createPlayerListDock();
|
createPlayerListDock();
|
||||||
connectPlayerListToGameEventHandler();
|
|
||||||
createMessageDock();
|
createMessageDock();
|
||||||
connectMessageLogToGameEventHandler();
|
|
||||||
createPlayAreaWidget();
|
createPlayAreaWidget();
|
||||||
createDeckViewContainerWidget();
|
createDeckViewContainerWidget();
|
||||||
createReplayDock(nullptr);
|
createReplayDock(nullptr);
|
||||||
|
|
@ -137,102 +119,117 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor,
|
||||||
|
|
||||||
createMenuItems();
|
createMenuItems();
|
||||||
createViewMenuItems();
|
createViewMenuItems();
|
||||||
|
|
||||||
|
connectToGameState();
|
||||||
|
connectToPlayerManager();
|
||||||
|
connectToGameEventHandler();
|
||||||
|
connectPlayerListToGameEventHandler();
|
||||||
|
connectMessageLogToGameEventHandler();
|
||||||
|
connectMessageLogToPlayerHandler();
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
||||||
&TabGame::refreshShortcuts);
|
&TabGame::refreshShortcuts);
|
||||||
refreshShortcuts();
|
refreshShortcuts();
|
||||||
|
|
||||||
// append game to rooms game list for others to see
|
// append game to rooms game list for others to see
|
||||||
for (int i = gameMetaInfo->gameTypesSize() - 1; i >= 0; i--)
|
for (int i = game->getGameMetaInfo()->gameTypesSize() - 1; i >= 0; i--)
|
||||||
gameTypes.append(gameMetaInfo->findRoomGameType(i));
|
gameTypes.append(game->getGameMetaInfo()->findRoomGameType(i));
|
||||||
|
|
||||||
QTimer::singleShot(0, this, &TabGame::loadLayout);
|
QTimer::singleShot(0, this, &TabGame::loadLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::connectToGameState()
|
void TabGame::connectToGameState()
|
||||||
{
|
{
|
||||||
connect(gameState, &GameState::playerAdded, this, &TabGame::addPlayer);
|
connect(game->getGameState(), &GameState::gameStarted, this, &TabGame::startGame);
|
||||||
connect(gameState, &GameState::gameStarted, this, &TabGame::startGame);
|
connect(game->getGameState(), &GameState::activePhaseChanged, this, &TabGame::setActivePhase);
|
||||||
connect(gameState, &GameState::activePhaseChanged, this, &TabGame::setActivePhase);
|
connect(game->getGameState(), &GameState::activePlayerChanged, this, &TabGame::setActivePlayer);
|
||||||
connect(gameState, &GameState::activePlayerChanged, this, &TabGame::setActivePlayer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::connectToPlayerManager()
|
void TabGame::connectToPlayerManager()
|
||||||
{
|
{
|
||||||
connect(playerManager, &PlayerManager::playerAdded, this, &TabGame::addPlayer);
|
connect(game->getPlayerManager(), &PlayerManager::playerAdded, this, &TabGame::addPlayer);
|
||||||
|
// update menu text when player concedes so that "concede" gets updated to "unconcede"
|
||||||
|
connect(game->getPlayerManager(), &PlayerManager::playerConceded, this, &TabGame::retranslateUi);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::connectToGameEventHandler()
|
void TabGame::connectToGameEventHandler()
|
||||||
{
|
{
|
||||||
connect(this, &TabGame::gameLeft, gameEventHandler, &GameEventHandler::handleGameLeft);
|
connect(this, &TabGame::gameLeft, game->getGameEventHandler(), &GameEventHandler::handleGameLeft);
|
||||||
connect(gameEventHandler, &GameEventHandler::gameStopped, this, &TabGame::stopGame);
|
connect(game->getGameEventHandler(), &GameEventHandler::emitUserEvent, this, &TabGame::emitUserEvent);
|
||||||
connect(gameEventHandler, &GameEventHandler::gameClosed, this, &TabGame::closeGame);
|
connect(game->getGameEventHandler(), &GameEventHandler::gameStopped, this, &TabGame::stopGame);
|
||||||
connect(gameEventHandler, &GameEventHandler::localPlayerReadyStateChanged, this,
|
connect(game->getGameEventHandler(), &GameEventHandler::gameClosed, this, &TabGame::closeGame);
|
||||||
|
connect(game->getGameEventHandler(), &GameEventHandler::localPlayerReadyStateChanged, this,
|
||||||
&TabGame::processLocalPlayerReadyStateChanged);
|
&TabGame::processLocalPlayerReadyStateChanged);
|
||||||
connect(gameEventHandler, &GameEventHandler::localPlayerSideboardLocked, this,
|
connect(game->getGameEventHandler(), &GameEventHandler::localPlayerSideboardLocked, this,
|
||||||
&TabGame::processLocalPlayerSideboardLocked);
|
&TabGame::processLocalPlayerSideboardLocked);
|
||||||
connect(gameEventHandler, &GameEventHandler::localPlayerDeckSelected, this, &TabGame::processLocalPlayerDeckSelect);
|
connect(game->getGameEventHandler(), &GameEventHandler::localPlayerDeckSelected, this,
|
||||||
|
&TabGame::processLocalPlayerDeckSelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::connectMessageLogToGameEventHandler()
|
void TabGame::connectMessageLogToGameEventHandler()
|
||||||
{
|
{
|
||||||
// connect(gameEventHandler, &GameEventHandler:: , messageLog, &MessageLogWidget::);
|
// connect(game->getGameEventHandler(), &GameEventHandler:: , messageLog, &MessageLogWidget::);
|
||||||
connect(gameEventHandler, &GameEventHandler::gameFlooded, messageLog, &MessageLogWidget::logGameFlooded);
|
connect(game->getGameEventHandler(), &GameEventHandler::gameFlooded, messageLog, &MessageLogWidget::logGameFlooded);
|
||||||
connect(gameEventHandler, &GameEventHandler::containerProcessingStarted, messageLog,
|
connect(game->getGameEventHandler(), &GameEventHandler::containerProcessingStarted, messageLog,
|
||||||
&MessageLogWidget::containerProcessingStarted);
|
&MessageLogWidget::containerProcessingStarted);
|
||||||
connect(gameEventHandler, &GameEventHandler::containerProcessingDone, messageLog,
|
connect(game->getGameEventHandler(), &GameEventHandler::containerProcessingDone, messageLog,
|
||||||
&MessageLogWidget::containerProcessingDone);
|
&MessageLogWidget::containerProcessingDone);
|
||||||
connect(gameEventHandler, &GameEventHandler::setContextJudgeName, messageLog,
|
connect(game->getGameEventHandler(), &GameEventHandler::setContextJudgeName, messageLog,
|
||||||
&MessageLogWidget::setContextJudgeName);
|
&MessageLogWidget::setContextJudgeName);
|
||||||
connect(gameEventHandler, &GameEventHandler::logSpectatorSay, messageLog, &MessageLogWidget::logSpectatorSay);
|
connect(game->getGameEventHandler(), &GameEventHandler::logSpectatorSay, messageLog,
|
||||||
|
&MessageLogWidget::logSpectatorSay);
|
||||||
|
|
||||||
connect(gameEventHandler, &GameEventHandler::logJoinPlayer, messageLog, &MessageLogWidget::logJoin);
|
connect(game->getGameEventHandler(), &GameEventHandler::logJoinPlayer, messageLog, &MessageLogWidget::logJoin);
|
||||||
connect(gameEventHandler, &GameEventHandler::logJoinSpectator, messageLog, &MessageLogWidget::logJoinSpectator);
|
connect(game->getGameEventHandler(), &GameEventHandler::logJoinSpectator, messageLog,
|
||||||
connect(gameEventHandler, &GameEventHandler::logLeave, messageLog, &MessageLogWidget::logLeave);
|
&MessageLogWidget::logJoinSpectator);
|
||||||
connect(gameEventHandler, &GameEventHandler::logKicked, messageLog, &MessageLogWidget::logKicked);
|
connect(game->getGameEventHandler(), &GameEventHandler::logLeave, messageLog, &MessageLogWidget::logLeave);
|
||||||
connect(gameEventHandler, &GameEventHandler::logConnectionStateChanged, messageLog,
|
connect(game->getGameEventHandler(), &GameEventHandler::logKicked, messageLog, &MessageLogWidget::logKicked);
|
||||||
|
connect(game->getGameEventHandler(), &GameEventHandler::logConnectionStateChanged, messageLog,
|
||||||
&MessageLogWidget::logConnectionStateChanged);
|
&MessageLogWidget::logConnectionStateChanged);
|
||||||
|
|
||||||
connect(gameEventHandler, &GameEventHandler::logDeckSelect, messageLog, &MessageLogWidget::logDeckSelect);
|
connect(game->getGameEventHandler(), &GameEventHandler::logDeckSelect, messageLog,
|
||||||
connect(gameEventHandler, &GameEventHandler::logSideboardLockSet, messageLog,
|
&MessageLogWidget::logDeckSelect);
|
||||||
|
connect(game->getGameEventHandler(), &GameEventHandler::logSideboardLockSet, messageLog,
|
||||||
&MessageLogWidget::logSetSideboardLock);
|
&MessageLogWidget::logSetSideboardLock);
|
||||||
connect(gameEventHandler, &GameEventHandler::logReadyStart, messageLog, &MessageLogWidget::logReadyStart);
|
connect(game->getGameEventHandler(), &GameEventHandler::logReadyStart, messageLog,
|
||||||
connect(gameEventHandler, &GameEventHandler::logNotReadyStart, messageLog, &MessageLogWidget::logNotReadyStart);
|
&MessageLogWidget::logReadyStart);
|
||||||
connect(gameEventHandler, &GameEventHandler::logGameStart, messageLog, &MessageLogWidget::logGameStart);
|
connect(game->getGameEventHandler(), &GameEventHandler::logNotReadyStart, messageLog,
|
||||||
|
&MessageLogWidget::logNotReadyStart);
|
||||||
|
connect(game->getGameEventHandler(), &GameEventHandler::logGameStart, messageLog, &MessageLogWidget::logGameStart);
|
||||||
|
|
||||||
connect(gameEventHandler, &GameEventHandler::playerConceded, messageLog, &MessageLogWidget::logConcede);
|
connect(game->getGameEventHandler(), &GameEventHandler::logActivePlayer, messageLog,
|
||||||
connect(gameEventHandler, &GameEventHandler::playerUnconceded, messageLog, &MessageLogWidget::logUnconcede);
|
&MessageLogWidget::logSetActivePlayer);
|
||||||
|
connect(game->getGameEventHandler(), &GameEventHandler::logActivePhaseChanged, messageLog,
|
||||||
connect(gameEventHandler, &GameEventHandler::logActivePlayer, messageLog, &MessageLogWidget::logSetActivePlayer);
|
|
||||||
connect(gameEventHandler, &GameEventHandler::logActivePhaseChanged, messageLog,
|
|
||||||
&MessageLogWidget::logSetActivePhase);
|
&MessageLogWidget::logSetActivePhase);
|
||||||
|
|
||||||
connect(gameEventHandler, &GameEventHandler::logTurnReversed, messageLog, &MessageLogWidget::logReverseTurn);
|
connect(game->getGameEventHandler(), &GameEventHandler::logTurnReversed, messageLog,
|
||||||
|
&MessageLogWidget::logReverseTurn);
|
||||||
|
|
||||||
connect(gameEventHandler, &GameEventHandler::logGameClosed, messageLog, &MessageLogWidget::logGameClosed);
|
connect(game->getGameEventHandler(), &GameEventHandler::logGameClosed, messageLog,
|
||||||
|
&MessageLogWidget::logGameClosed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabGame::connectMessageLogToPlayerHandler()
|
||||||
|
{
|
||||||
|
connect(game->getPlayerManager(), &PlayerManager::playerConceded, messageLog, &MessageLogWidget::logConcede);
|
||||||
|
connect(game->getPlayerManager(), &PlayerManager::playerUnconceded, messageLog, &MessageLogWidget::logUnconcede);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::connectPlayerListToGameEventHandler()
|
void TabGame::connectPlayerListToGameEventHandler()
|
||||||
{
|
{
|
||||||
connect(gameEventHandler, &GameEventHandler::playerJoined, playerListWidget, &PlayerListWidget::addPlayer);
|
connect(game->getGameEventHandler(), &GameEventHandler::playerJoined, playerListWidget,
|
||||||
connect(gameEventHandler, &GameEventHandler::playerLeft, playerListWidget, &PlayerListWidget::removePlayer);
|
&PlayerListWidget::addPlayer);
|
||||||
connect(gameEventHandler, &GameEventHandler::spectatorJoined, playerListWidget, &PlayerListWidget::addPlayer);
|
connect(game->getGameEventHandler(), &GameEventHandler::playerLeft, playerListWidget,
|
||||||
connect(gameEventHandler, &GameEventHandler::spectatorLeft, playerListWidget, &PlayerListWidget::removePlayer);
|
&PlayerListWidget::removePlayer);
|
||||||
connect(gameEventHandler, &GameEventHandler::playerPropertiesChanged, playerListWidget,
|
connect(game->getGameEventHandler(), &GameEventHandler::spectatorJoined, playerListWidget,
|
||||||
|
&PlayerListWidget::addPlayer);
|
||||||
|
connect(game->getGameEventHandler(), &GameEventHandler::spectatorLeft, playerListWidget,
|
||||||
|
&PlayerListWidget::removePlayer);
|
||||||
|
connect(game->getGameEventHandler(), &GameEventHandler::playerPropertiesChanged, playerListWidget,
|
||||||
&PlayerListWidget::updatePlayerProperties);
|
&PlayerListWidget::updatePlayerProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TabGame::isHost() const
|
|
||||||
{
|
|
||||||
return gameState->getHostId() == playerManager->getLocalPlayerId();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGame::loadReplay(GameReplay *replay)
|
|
||||||
{
|
|
||||||
gameMetaInfo->setFromProto(replay->game_info());
|
|
||||||
gameMetaInfo->setSpectatorsOmniscient(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGame::addMentionTag(const QString &value)
|
void TabGame::addMentionTag(const QString &value)
|
||||||
{
|
{
|
||||||
sayEdit->insert(value + " ");
|
sayEdit->insert(value + " ");
|
||||||
|
|
@ -251,12 +248,12 @@ void TabGame::resetChatAndPhase()
|
||||||
messageLog->clearChat();
|
messageLog->clearChat();
|
||||||
|
|
||||||
// reset phase markers
|
// reset phase markers
|
||||||
gameState->setCurrentPhase(-1);
|
game->getGameState()->setCurrentPhase(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::emitUserEvent()
|
void TabGame::emitUserEvent()
|
||||||
{
|
{
|
||||||
bool globalEvent = !playerManager->isSpectator() || SettingsCache::instance().getSpectatorNotificationsEnabled();
|
bool globalEvent = !game->getPlayerManager()->isSpectator() || SettingsCache::instance().getSpectatorNotificationsEnabled();
|
||||||
emit userEvent(globalEvent);
|
emit userEvent(globalEvent);
|
||||||
updatePlayerListDockTitle();
|
updatePlayerListDockTitle();
|
||||||
}
|
}
|
||||||
|
|
@ -268,9 +265,9 @@ TabGame::~TabGame()
|
||||||
|
|
||||||
void TabGame::updatePlayerListDockTitle()
|
void TabGame::updatePlayerListDockTitle()
|
||||||
{
|
{
|
||||||
QString tabText =
|
QString tabText = " | " + (replayManager->replay ? tr("Replay") : tr("Game")) + " #" +
|
||||||
" | " + (replayManager->replay ? tr("Replay") : tr("Game")) + " #" + QString::number(gameMetaInfo->gameId());
|
QString::number(game->getGameMetaInfo()->gameId());
|
||||||
QString userCountInfo = QString(" %1/%2").arg(playerManager->getPlayerCount()).arg(gameMetaInfo->maxPlayers());
|
QString userCountInfo = QString(" %1/%2").arg(game->getPlayerManager()->getPlayerCount()).arg(game->getGameMetaInfo()->maxPlayers());
|
||||||
playerListDock->setWindowTitle(tr("Player List") + userCountInfo +
|
playerListDock->setWindowTitle(tr("Player List") + userCountInfo +
|
||||||
(playerListDock->isWindow() ? tabText : QString()));
|
(playerListDock->isWindow() ? tabText : QString()));
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +275,7 @@ void TabGame::updatePlayerListDockTitle()
|
||||||
void TabGame::retranslateUi()
|
void TabGame::retranslateUi()
|
||||||
{
|
{
|
||||||
QString tabText =
|
QString tabText =
|
||||||
" | " + (replayManager->replay ? tr("Replay") : tr("Game")) + " #" + QString::number(gameMetaInfo->gameId());
|
" | " + (replayManager->replay ? tr("Replay") : tr("Game")) + " #" + QString::number(game->getGameMetaInfo()->gameId());
|
||||||
|
|
||||||
updatePlayerListDockTitle();
|
updatePlayerListDockTitle();
|
||||||
cardInfoDock->setWindowTitle(tr("Card Info") + (cardInfoDock->isWindow() ? tabText : QString()));
|
cardInfoDock->setWindowTitle(tr("Card Info") + (cardInfoDock->isWindow() ? tabText : QString()));
|
||||||
|
|
@ -317,7 +314,7 @@ void TabGame::retranslateUi()
|
||||||
if (aGameInfo)
|
if (aGameInfo)
|
||||||
aGameInfo->setText(tr("Game &information"));
|
aGameInfo->setText(tr("Game &information"));
|
||||||
if (aConcede) {
|
if (aConcede) {
|
||||||
if (playerManager->isMainPlayerConceded()) {
|
if (game->getPlayerManager()->isMainPlayerConceded()) {
|
||||||
aConcede->setText(tr("Un&concede"));
|
aConcede->setText(tr("Un&concede"));
|
||||||
} else {
|
} else {
|
||||||
aConcede->setText(tr("&Concede"));
|
aConcede->setText(tr("&Concede"));
|
||||||
|
|
@ -364,7 +361,7 @@ void TabGame::retranslateUi()
|
||||||
|
|
||||||
cardInfoFrameWidget->retranslateUi();
|
cardInfoFrameWidget->retranslateUi();
|
||||||
|
|
||||||
QMapIterator<int, Player *> i(playerManager->getPlayers());
|
QMapIterator<int, Player *> i(game->getPlayerManager()->getPlayers());
|
||||||
|
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
i.next().value()->retranslateUi();
|
i.next().value()->retranslateUi();
|
||||||
|
|
@ -478,35 +475,34 @@ void TabGame::updateTimeElapsedLabel(const QString newTime)
|
||||||
|
|
||||||
void TabGame::adminLockChanged(bool lock)
|
void TabGame::adminLockChanged(bool lock)
|
||||||
{
|
{
|
||||||
bool v = !(playerManager->isSpectator() && !gameMetaInfo->spectatorsCanChat() && lock);
|
bool v = !(game->getPlayerManager()->isSpectator() && !game->getGameMetaInfo()->spectatorsCanChat() && lock);
|
||||||
sayLabel->setVisible(v);
|
sayLabel->setVisible(v);
|
||||||
sayEdit->setVisible(v);
|
sayEdit->setVisible(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::actGameInfo()
|
void TabGame::actGameInfo()
|
||||||
{
|
{
|
||||||
DlgCreateGame dlg(gameMetaInfo->proto(), gameMetaInfo->getRoomGameTypes(), this);
|
DlgCreateGame dlg(game->getGameMetaInfo()->proto(), game->getGameMetaInfo()->getRoomGameTypes(), this);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::actConcede()
|
void TabGame::actConcede()
|
||||||
{
|
{
|
||||||
Player *player = playerManager->getActiveLocalPlayer(gameState->getActivePlayer());
|
Player *player = game->getPlayerManager()->getActiveLocalPlayer(game->getGameState()->getActivePlayer());
|
||||||
if (player == nullptr)
|
if (player == nullptr)
|
||||||
return;
|
return;
|
||||||
if (!player->getPlayerInfo()->getConceded()) {
|
if (!player->getConceded()) {
|
||||||
if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"),
|
if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"),
|
||||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
||||||
return;
|
return;
|
||||||
|
player->setConceded(true);
|
||||||
emit playerConceded();
|
|
||||||
} else {
|
} else {
|
||||||
if (QMessageBox::question(this, tr("Unconcede"),
|
if (QMessageBox::question(this, tr("Unconcede"),
|
||||||
tr("You have already conceded. Do you want to return to this game?"),
|
tr("You have already conceded. Do you want to return to this game?"),
|
||||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit playerUnconceded();
|
player->setConceded(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -517,8 +513,8 @@ void TabGame::actConcede()
|
||||||
*/
|
*/
|
||||||
bool TabGame::leaveGame()
|
bool TabGame::leaveGame()
|
||||||
{
|
{
|
||||||
if (!gameState->isGameClosed()) {
|
if (!game->getGameState()->isGameClosed()) {
|
||||||
if (!playerManager->isSpectator()) {
|
if (!game->getPlayerManager()->isSpectator()) {
|
||||||
tabSupervisor->setCurrentWidget(this);
|
tabSupervisor->setCurrentWidget(this);
|
||||||
if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"),
|
if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"),
|
||||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
||||||
|
|
@ -566,7 +562,7 @@ void TabGame::removePlayerFromAutoCompleteList(QString playerName)
|
||||||
void TabGame::removeSpectator(int spectatorId, ServerInfo_User spectator)
|
void TabGame::removeSpectator(int spectatorId, ServerInfo_User spectator)
|
||||||
{
|
{
|
||||||
Q_UNUSED(spectator);
|
Q_UNUSED(spectator);
|
||||||
QString playerName = "@" + gameState->getSpectatorName(spectatorId);
|
QString playerName = "@" + game->getPlayerManager()->getSpectatorName(spectatorId);
|
||||||
removePlayerFromAutoCompleteList(playerName);
|
removePlayerFromAutoCompleteList(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -578,7 +574,7 @@ void TabGame::actPhaseAction()
|
||||||
|
|
||||||
void TabGame::actNextPhase()
|
void TabGame::actNextPhase()
|
||||||
{
|
{
|
||||||
int phase = gameState->getCurrentPhase();
|
int phase = game->getGameState()->getCurrentPhase();
|
||||||
if (++phase >= phasesToolbar->phaseCount())
|
if (++phase >= phasesToolbar->phaseCount())
|
||||||
phase = 0;
|
phase = 0;
|
||||||
|
|
||||||
|
|
@ -587,7 +583,7 @@ void TabGame::actNextPhase()
|
||||||
|
|
||||||
void TabGame::actNextPhaseAction()
|
void TabGame::actNextPhaseAction()
|
||||||
{
|
{
|
||||||
int phase = gameState->getCurrentPhase() + 1;
|
int phase = game->getGameState()->getCurrentPhase() + 1;
|
||||||
if (phase >= phasesToolbar->phaseCount()) {
|
if (phase >= phasesToolbar->phaseCount()) {
|
||||||
phase = 0;
|
phase = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -603,7 +599,7 @@ void TabGame::actNextPhaseAction()
|
||||||
|
|
||||||
void TabGame::actRemoveLocalArrows()
|
void TabGame::actRemoveLocalArrows()
|
||||||
{
|
{
|
||||||
QMapIterator<int, Player *> playerIterator(playerManager->getPlayers());
|
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||||
while (playerIterator.hasNext()) {
|
while (playerIterator.hasNext()) {
|
||||||
Player *player = playerIterator.next().value();
|
Player *player = playerIterator.next().value();
|
||||||
if (!player->getPlayerInfo()->getLocal())
|
if (!player->getPlayerInfo()->getLocal())
|
||||||
|
|
@ -635,7 +631,7 @@ void TabGame::actCompleterChanged()
|
||||||
void TabGame::notifyPlayerJoin(QString playerName)
|
void TabGame::notifyPlayerJoin(QString playerName)
|
||||||
{
|
{
|
||||||
if (trayIcon) {
|
if (trayIcon) {
|
||||||
QString gameId(QString::number(gameMetaInfo->gameId()));
|
QString gameId(QString::number(game->getGameMetaInfo()->gameId()));
|
||||||
trayIcon->showMessage(tr("A player has joined game #%1").arg(gameId),
|
trayIcon->showMessage(tr("A player has joined game #%1").arg(gameId),
|
||||||
tr("%1 has joined the game").arg(playerName));
|
tr("%1 has joined the game").arg(playerName));
|
||||||
}
|
}
|
||||||
|
|
@ -671,7 +667,8 @@ Player *TabGame::addPlayer(Player *newPlayer)
|
||||||
|
|
||||||
messageLog->connectToPlayerEventHandler(newPlayer->getPlayerEventHandler());
|
messageLog->connectToPlayerEventHandler(newPlayer->getPlayerEventHandler());
|
||||||
|
|
||||||
if (playerManager->isLocalPlayer(newPlayer->getPlayerInfo()->getId()) && !playerManager->isSpectator()) {
|
if (game->getGameState()->getIsLocalGame() ||
|
||||||
|
(game->getPlayerManager()->isLocalPlayer(newPlayer->getPlayerInfo()->getId()) && !game->getPlayerManager()->isSpectator())) {
|
||||||
addLocalPlayer(newPlayer, newPlayer->getPlayerInfo()->getId());
|
addLocalPlayer(newPlayer, newPlayer->getPlayerInfo()->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -679,17 +676,12 @@ Player *TabGame::addPlayer(Player *newPlayer)
|
||||||
|
|
||||||
createZoneForPlayer(newPlayer, newPlayer->getPlayerInfo()->getId());
|
createZoneForPlayer(newPlayer, newPlayer->getPlayerInfo()->getId());
|
||||||
|
|
||||||
// update menu text when player concedes so that "concede" gets updated to "unconcede"
|
|
||||||
// TODO: Hook this back up
|
|
||||||
// connect(newPlayer, &Player::playerCountChanged, this, &TabGame::retranslateUi);
|
|
||||||
|
|
||||||
emit playerAdded(newPlayer);
|
|
||||||
return newPlayer;
|
return newPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::addLocalPlayer(Player *newPlayer, int playerId)
|
void TabGame::addLocalPlayer(Player *newPlayer, int playerId)
|
||||||
{
|
{
|
||||||
if (gameState->getClients().size() == 1) {
|
if (game->getGameState()->getClients().size() == 1) {
|
||||||
newPlayer->getPlayerMenu()->setShortcutsActive();
|
newPlayer->getPlayerMenu()->setShortcutsActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -765,12 +757,12 @@ void TabGame::processLocalPlayerReadyStateChanged(int playerId, bool ready)
|
||||||
|
|
||||||
void TabGame::createZoneForPlayer(Player *newPlayer, int playerId)
|
void TabGame::createZoneForPlayer(Player *newPlayer, int playerId)
|
||||||
{
|
{
|
||||||
if (!gameState->getSpectators().contains(playerId)) {
|
if (!game->getPlayerManager()->getSpectators().contains(playerId)) {
|
||||||
|
|
||||||
// Loop for each player, the idea is to have one assigned zone for each non-spectator player
|
// Loop for each player, the idea is to have one assigned zone for each non-spectator player
|
||||||
for (int i = 1; i <= playerManager->getPlayerCount(); ++i) {
|
for (int i = 1; i <= game->getPlayerManager()->getPlayerCount(); ++i) {
|
||||||
bool aPlayerHasThisZone = false;
|
bool aPlayerHasThisZone = false;
|
||||||
for (auto &player : playerManager->getPlayers()) {
|
for (auto &player : game->getPlayerManager()->getPlayers()) {
|
||||||
if (player->getPlayerInfo()->getZoneId() == i) {
|
if (player->getPlayerInfo()->getZoneId() == i) {
|
||||||
aPlayerHasThisZone = true;
|
aPlayerHasThisZone = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -784,23 +776,9 @@ void TabGame::createZoneForPlayer(Player *newPlayer, int playerId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractClient *TabGame::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 TabGame::startGame(bool _resuming)
|
void TabGame::startGame(bool _resuming)
|
||||||
{
|
{
|
||||||
gameState->setCurrentPhase(-1);
|
game->getGameState()->setCurrentPhase(-1);
|
||||||
|
|
||||||
QMapIterator<int, TabbedDeckViewContainer *> i(deckViewContainers);
|
QMapIterator<int, TabbedDeckViewContainer *> i(deckViewContainers);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
|
|
@ -813,13 +791,13 @@ void TabGame::startGame(bool _resuming)
|
||||||
mainWidget->setCurrentWidget(gamePlayAreaWidget);
|
mainWidget->setCurrentWidget(gamePlayAreaWidget);
|
||||||
|
|
||||||
if (!_resuming) {
|
if (!_resuming) {
|
||||||
QMapIterator<int, Player *> playerIterator(playerManager->getPlayers());
|
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||||
while (playerIterator.hasNext())
|
while (playerIterator.hasNext())
|
||||||
playerIterator.next().value()->setGameStarted();
|
playerIterator.next().value()->setGameStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
playerListWidget->setGameStarted(true, gameState->isResuming());
|
playerListWidget->setGameStarted(true, game->getGameState()->isResuming());
|
||||||
gameMetaInfo->setStarted(true);
|
game->getGameMetaInfo()->setStarted(true);
|
||||||
static_cast<GameScene *>(gameView->scene())->rearrange();
|
static_cast<GameScene *>(gameView->scene())->rearrange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -847,27 +825,27 @@ void TabGame::closeGame()
|
||||||
|
|
||||||
Player *TabGame::setActivePlayer(int id)
|
Player *TabGame::setActivePlayer(int id)
|
||||||
{
|
{
|
||||||
Player *player = playerManager->getPlayer(id);
|
Player *player = game->getPlayerManager()->getPlayer(id);
|
||||||
if (!player)
|
if (!player)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
playerListWidget->setActivePlayer(id);
|
playerListWidget->setActivePlayer(id);
|
||||||
QMapIterator<int, Player *> i(playerManager->getPlayers());
|
QMapIterator<int, Player *> i(game->getPlayerManager()->getPlayers());
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
if (i.value() == player) {
|
if (i.value() == player) {
|
||||||
i.value()->setActive(true);
|
i.value()->setActive(true);
|
||||||
if (gameState->getClients().size() > 1) {
|
if (game->getGameState()->getClients().size() > 1) {
|
||||||
i.value()->getPlayerMenu()->setShortcutsActive();
|
i.value()->getPlayerMenu()->setShortcutsActive();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
i.value()->setActive(false);
|
i.value()->setActive(false);
|
||||||
if (gameState->getClients().size() > 1) {
|
if (game->getGameState()->getClients().size() > 1) {
|
||||||
i.value()->getPlayerMenu()->setShortcutsInactive();
|
i.value()->getPlayerMenu()->setShortcutsInactive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gameState->setCurrentPhase(-1);
|
game->getGameState()->setCurrentPhase(-1);
|
||||||
emitUserEvent();
|
emitUserEvent();
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
@ -886,19 +864,6 @@ void TabGame::newCardAdded(AbstractCardItem *card)
|
||||||
connect(card, &AbstractCardItem::cardShiftClicked, this, &TabGame::linkCardToChat);
|
connect(card, &AbstractCardItem::cardShiftClicked, this, &TabGame::linkCardToChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
CardItem *TabGame::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);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TabGame::getTabText() const
|
QString TabGame::getTabText() const
|
||||||
{
|
{
|
||||||
QString gameTypeInfo;
|
QString gameTypeInfo;
|
||||||
|
|
@ -908,8 +873,8 @@ QString TabGame::getTabText() const
|
||||||
gameTypeInfo.append("...");
|
gameTypeInfo.append("...");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString gameDesc(gameMetaInfo->description());
|
QString gameDesc(game->getGameMetaInfo()->description());
|
||||||
QString gameId(QString::number(gameMetaInfo->gameId()));
|
QString gameId(QString::number(game->getGameMetaInfo()->gameId()));
|
||||||
|
|
||||||
QString tabText;
|
QString tabText;
|
||||||
if (replayManager->replay)
|
if (replayManager->replay)
|
||||||
|
|
@ -929,11 +894,6 @@ QString TabGame::getTabText() const
|
||||||
return tabText;
|
return tabText;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::setActiveCard(CardItem *card)
|
|
||||||
{
|
|
||||||
activeCard = card;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param menu The menu to set. Pass in nullptr to set the menu to empty.
|
* @param menu The menu to set. Pass in nullptr to set the menu to empty.
|
||||||
*/
|
*/
|
||||||
|
|
@ -954,17 +914,17 @@ void TabGame::createMenuItems()
|
||||||
{
|
{
|
||||||
aNextPhase = new QAction(this);
|
aNextPhase = new QAction(this);
|
||||||
connect(aNextPhase, &QAction::triggered, this, &TabGame::actNextPhase);
|
connect(aNextPhase, &QAction::triggered, this, &TabGame::actNextPhase);
|
||||||
connect(this, &TabGame::phaseChanged, gameEventHandler, &GameEventHandler::handleActivePhaseChanged);
|
connect(this, &TabGame::phaseChanged, game->getGameEventHandler(), &GameEventHandler::handleActivePhaseChanged);
|
||||||
aNextPhaseAction = new QAction(this);
|
aNextPhaseAction = new QAction(this);
|
||||||
connect(aNextPhaseAction, &QAction::triggered, this, &TabGame::actNextPhaseAction);
|
connect(aNextPhaseAction, &QAction::triggered, this, &TabGame::actNextPhaseAction);
|
||||||
connect(this, &TabGame::turnAdvanced, gameEventHandler, &GameEventHandler::handleNextTurn);
|
connect(this, &TabGame::turnAdvanced, game->getGameEventHandler(), &GameEventHandler::handleNextTurn);
|
||||||
aNextTurn = new QAction(this);
|
aNextTurn = new QAction(this);
|
||||||
connect(aNextTurn, &QAction::triggered, gameEventHandler, &GameEventHandler::handleNextTurn);
|
connect(aNextTurn, &QAction::triggered, game->getGameEventHandler(), &GameEventHandler::handleNextTurn);
|
||||||
aReverseTurn = new QAction(this);
|
aReverseTurn = new QAction(this);
|
||||||
connect(aReverseTurn, &QAction::triggered, gameEventHandler, &GameEventHandler::handleReverseTurn);
|
connect(aReverseTurn, &QAction::triggered, game->getGameEventHandler(), &GameEventHandler::handleReverseTurn);
|
||||||
aRemoveLocalArrows = new QAction(this);
|
aRemoveLocalArrows = new QAction(this);
|
||||||
connect(aRemoveLocalArrows, &QAction::triggered, this, &TabGame::actRemoveLocalArrows);
|
connect(aRemoveLocalArrows, &QAction::triggered, this, &TabGame::actRemoveLocalArrows);
|
||||||
connect(this, &TabGame::arrowDeletionRequested, gameEventHandler, &GameEventHandler::handleArrowDeletion);
|
connect(this, &TabGame::arrowDeletionRequested, game->getGameEventHandler(), &GameEventHandler::handleArrowDeletion);
|
||||||
aRotateViewCW = new QAction(this);
|
aRotateViewCW = new QAction(this);
|
||||||
connect(aRotateViewCW, &QAction::triggered, this, &TabGame::actRotateViewCW);
|
connect(aRotateViewCW, &QAction::triggered, this, &TabGame::actRotateViewCW);
|
||||||
aRotateViewCCW = new QAction(this);
|
aRotateViewCCW = new QAction(this);
|
||||||
|
|
@ -973,8 +933,10 @@ void TabGame::createMenuItems()
|
||||||
connect(aGameInfo, &QAction::triggered, this, &TabGame::actGameInfo);
|
connect(aGameInfo, &QAction::triggered, this, &TabGame::actGameInfo);
|
||||||
aConcede = new QAction(this);
|
aConcede = new QAction(this);
|
||||||
connect(aConcede, &QAction::triggered, this, &TabGame::actConcede);
|
connect(aConcede, &QAction::triggered, this, &TabGame::actConcede);
|
||||||
connect(this, &TabGame::playerConceded, gameEventHandler, &GameEventHandler::handlePlayerConceded);
|
connect(game->getPlayerManager(), &PlayerManager::activeLocalPlayerConceded, game->getGameEventHandler(),
|
||||||
connect(this, &TabGame::playerUnconceded, gameEventHandler, &GameEventHandler::handlePlayerUnconceded);
|
&GameEventHandler::handleActiveLocalPlayerConceded);
|
||||||
|
connect(game->getPlayerManager(), &PlayerManager::activeLocalPlayerUnconceded, game->getGameEventHandler(),
|
||||||
|
&GameEventHandler::handleActiveLocalPlayerUnconceded);
|
||||||
aLeaveGame = new QAction(this);
|
aLeaveGame = new QAction(this);
|
||||||
connect(aLeaveGame, &QAction::triggered, this, &TabGame::closeRequest);
|
connect(aLeaveGame, &QAction::triggered, this, &TabGame::closeRequest);
|
||||||
aFocusChat = new QAction(this);
|
aFocusChat = new QAction(this);
|
||||||
|
|
@ -1209,9 +1171,11 @@ void TabGame::createPlayAreaWidget(bool bReplay)
|
||||||
{
|
{
|
||||||
phasesToolbar = new PhasesToolbar;
|
phasesToolbar = new PhasesToolbar;
|
||||||
if (!bReplay)
|
if (!bReplay)
|
||||||
connect(phasesToolbar, &PhasesToolbar::sendGameCommand, gameEventHandler,
|
connect(phasesToolbar, &PhasesToolbar::sendGameCommand, game->getGameEventHandler(),
|
||||||
qOverload<const ::google::protobuf::Message &, int>(&GameEventHandler::sendGameCommand));
|
qOverload<const ::google::protobuf::Message &, int>(&GameEventHandler::sendGameCommand));
|
||||||
scene = new GameScene(phasesToolbar, this);
|
scene = new GameScene(phasesToolbar, this);
|
||||||
|
connect(game->getPlayerManager(), &PlayerManager::playerConceded, scene, &GameScene::rearrange);
|
||||||
|
connect(game->getPlayerManager(), &PlayerManager::playerCountChanged, scene, &GameScene::rearrange);
|
||||||
gameView = new GameView(scene);
|
gameView = new GameView(scene);
|
||||||
|
|
||||||
auto gamePlayAreaVBox = new QVBoxLayout;
|
auto gamePlayAreaVBox = new QVBoxLayout;
|
||||||
|
|
@ -1282,9 +1246,9 @@ void TabGame::createCardInfoDock(bool bReplay)
|
||||||
void TabGame::createPlayerListDock(bool bReplay)
|
void TabGame::createPlayerListDock(bool bReplay)
|
||||||
{
|
{
|
||||||
if (bReplay) {
|
if (bReplay) {
|
||||||
playerListWidget = new PlayerListWidget(nullptr, nullptr, this);
|
playerListWidget = new PlayerListWidget(nullptr, nullptr, game);
|
||||||
} else {
|
} else {
|
||||||
playerListWidget = new PlayerListWidget(tabSupervisor, gameState->getClients().first(), this);
|
playerListWidget = new PlayerListWidget(tabSupervisor, game->getGameState()->getClients().first(), game);
|
||||||
connect(playerListWidget, SIGNAL(openMessageDialog(QString, bool)), this,
|
connect(playerListWidget, SIGNAL(openMessageDialog(QString, bool)), this,
|
||||||
SIGNAL(openMessageDialog(QString, bool)));
|
SIGNAL(openMessageDialog(QString, bool)));
|
||||||
}
|
}
|
||||||
|
|
@ -1310,14 +1274,14 @@ void TabGame::createMessageDock(bool bReplay)
|
||||||
if (!bReplay) {
|
if (!bReplay) {
|
||||||
timeElapsedLabel = new QLabel;
|
timeElapsedLabel = new QLabel;
|
||||||
timeElapsedLabel->setAlignment(Qt::AlignCenter);
|
timeElapsedLabel->setAlignment(Qt::AlignCenter);
|
||||||
connect(gameState, &GameState::updateTimeElapsedLabel, this, &TabGame::updateTimeElapsedLabel);
|
connect(game->getGameState(), &GameState::updateTimeElapsedLabel, this, &TabGame::updateTimeElapsedLabel);
|
||||||
gameState->startGameTimer();
|
game->getGameState()->startGameTimer();
|
||||||
|
|
||||||
messageLogLayout->addWidget(timeElapsedLabel);
|
messageLogLayout->addWidget(timeElapsedLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// message log
|
// message log
|
||||||
messageLog = new MessageLogWidget(tabSupervisor, this);
|
messageLog = new MessageLogWidget(tabSupervisor, game);
|
||||||
connect(messageLog, &MessageLogWidget::cardNameHovered, cardInfoFrameWidget,
|
connect(messageLog, &MessageLogWidget::cardNameHovered, cardInfoFrameWidget,
|
||||||
qOverload<const QString &>(&CardInfoFrameWidget::setCard));
|
qOverload<const QString &>(&CardInfoFrameWidget::setCard));
|
||||||
connect(messageLog, &MessageLogWidget::showCardInfoPopup, this, &TabGame::showCardInfoPopup);
|
connect(messageLog, &MessageLogWidget::showCardInfoPopup, this, &TabGame::showCardInfoPopup);
|
||||||
|
|
@ -1338,7 +1302,7 @@ void TabGame::createMessageDock(bool bReplay)
|
||||||
sayEdit = new LineEditCompleter;
|
sayEdit = new LineEditCompleter;
|
||||||
sayEdit->setMaxLength(MAX_TEXT_LENGTH);
|
sayEdit->setMaxLength(MAX_TEXT_LENGTH);
|
||||||
sayLabel->setBuddy(sayEdit);
|
sayLabel->setBuddy(sayEdit);
|
||||||
connect(this, &TabGame::chatMessageSent, gameEventHandler, &GameEventHandler::handleChatMessageSent);
|
connect(this, &TabGame::chatMessageSent, game->getGameEventHandler(), &GameEventHandler::handleChatMessageSent);
|
||||||
completer = new QCompleter(autocompleteUserList, sayEdit);
|
completer = new QCompleter(autocompleteUserList, sayEdit);
|
||||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
completer->setMaxVisibleItems(5);
|
completer->setMaxVisibleItems(5);
|
||||||
|
|
@ -1347,14 +1311,14 @@ void TabGame::createMessageDock(bool bReplay)
|
||||||
sayEdit->setCompleter(completer);
|
sayEdit->setCompleter(completer);
|
||||||
actCompleterChanged();
|
actCompleterChanged();
|
||||||
|
|
||||||
if (playerManager->isSpectator()) {
|
if (game->getPlayerManager()->isSpectator()) {
|
||||||
/* Spectators can only talk if:
|
/* Spectators can only talk if:
|
||||||
* (a) the game creator allows it
|
* (a) the game creator allows it
|
||||||
* (b) the spectator is a moderator/administrator
|
* (b) the spectator is a moderator/administrator
|
||||||
* (c) the spectator is a judge
|
* (c) the spectator is a judge
|
||||||
*/
|
*/
|
||||||
bool isModOrJudge = !tabSupervisor->getAdminLocked() || playerManager->isJudge();
|
bool isModOrJudge = !tabSupervisor->getAdminLocked() || game->getPlayerManager()->isJudge();
|
||||||
if (!isModOrJudge && !gameMetaInfo->spectatorsCanChat()) {
|
if (!isModOrJudge && !game->getGameMetaInfo()->spectatorsCanChat()) {
|
||||||
sayLabel->hide();
|
sayLabel->hide();
|
||||||
sayEdit->hide();
|
sayEdit->hide();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,9 @@
|
||||||
#define TAB_GAME_H
|
#define TAB_GAME_H
|
||||||
|
|
||||||
#include "../../client/tearoff_menu.h"
|
#include "../../client/tearoff_menu.h"
|
||||||
#include "../../game/game_event_handler.h"
|
#include "../../game/game.h"
|
||||||
#include "../../game/game_meta_info.h"
|
|
||||||
#include "../../game/game_state.h"
|
|
||||||
#include "../../game/player/player.h"
|
#include "../../game/player/player.h"
|
||||||
#include "../../game/player/player_manager.h"
|
#include "../../server/message_log_widget.h"
|
||||||
#include "../replay_manager.h"
|
#include "../replay_manager.h"
|
||||||
#include "../ui/widgets/visual_deck_storage/visual_deck_storage_widget.h"
|
#include "../ui/widgets/visual_deck_storage/visual_deck_storage_widget.h"
|
||||||
#include "pb/event_leave.pb.h"
|
#include "pb/event_leave.pb.h"
|
||||||
|
|
@ -53,12 +51,8 @@ class TabGame : public Tab
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
GameMetaInfo *gameMetaInfo;
|
Game *game;
|
||||||
GameState *gameState;
|
|
||||||
GameEventHandler *gameEventHandler;
|
|
||||||
PlayerManager *playerManager;
|
|
||||||
const UserListProxy *userListProxy;
|
const UserListProxy *userListProxy;
|
||||||
CardItem *activeCard;
|
|
||||||
ReplayManager *replayManager;
|
ReplayManager *replayManager;
|
||||||
QStringList gameTypes;
|
QStringList gameTypes;
|
||||||
QCompleter *completer;
|
QCompleter *completer;
|
||||||
|
|
@ -116,16 +110,12 @@ private:
|
||||||
void createReplayDock(GameReplay *replay);
|
void createReplayDock(GameReplay *replay);
|
||||||
signals:
|
signals:
|
||||||
void gameClosing(TabGame *tab);
|
void gameClosing(TabGame *tab);
|
||||||
void playerAdded(Player *player);
|
|
||||||
void playerRemoved(Player *player);
|
|
||||||
void containerProcessingStarted(const GameEventContext &context);
|
void containerProcessingStarted(const GameEventContext &context);
|
||||||
void containerProcessingDone();
|
void containerProcessingDone();
|
||||||
void openMessageDialog(const QString &userName, bool focus);
|
void openMessageDialog(const QString &userName, bool focus);
|
||||||
void openDeckEditor(const DeckLoader *deck);
|
void openDeckEditor(const DeckLoader *deck);
|
||||||
void notIdle();
|
void notIdle();
|
||||||
|
|
||||||
void playerConceded();
|
|
||||||
void playerUnconceded();
|
|
||||||
void phaseChanged(int phase);
|
void phaseChanged(int phase);
|
||||||
void gameLeft();
|
void gameLeft();
|
||||||
void chatMessageSent(QString chatMessage);
|
void chatMessageSent(QString chatMessage);
|
||||||
|
|
@ -178,46 +168,19 @@ public:
|
||||||
void connectToPlayerManager();
|
void connectToPlayerManager();
|
||||||
void connectToGameEventHandler();
|
void connectToGameEventHandler();
|
||||||
void connectMessageLogToGameEventHandler();
|
void connectMessageLogToGameEventHandler();
|
||||||
|
void connectMessageLogToPlayerHandler();
|
||||||
void connectPlayerListToGameEventHandler();
|
void connectPlayerListToGameEventHandler();
|
||||||
void loadReplay(GameReplay *replay);
|
|
||||||
TabGame(TabSupervisor *_tabSupervisor, GameReplay *replay);
|
TabGame(TabSupervisor *_tabSupervisor, GameReplay *replay);
|
||||||
~TabGame() override;
|
~TabGame() override;
|
||||||
void retranslateUi() override;
|
void retranslateUi() override;
|
||||||
void updatePlayerListDockTitle();
|
void updatePlayerListDockTitle();
|
||||||
bool closeRequest() override;
|
bool closeRequest() override;
|
||||||
|
|
||||||
GameMetaInfo *getGameMetaInfo()
|
|
||||||
{
|
|
||||||
return gameMetaInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameState *getGameState() const
|
|
||||||
{
|
|
||||||
return gameState;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameEventHandler *getGameEventHandler() const
|
|
||||||
{
|
|
||||||
return gameEventHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerManager *getPlayerManager() const
|
|
||||||
{
|
|
||||||
return playerManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isHost() const;
|
|
||||||
|
|
||||||
CardItem *getCard(int playerId, const QString &zoneName, int cardId) const;
|
|
||||||
|
|
||||||
QString getTabText() const override;
|
QString getTabText() const override;
|
||||||
|
|
||||||
AbstractClient *getClientForPlayer(int playerId) const;
|
Game *getGame() const
|
||||||
|
|
||||||
void setActiveCard(CardItem *card);
|
|
||||||
CardItem *getActiveCard() const
|
|
||||||
{
|
{
|
||||||
return activeCard;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
||||||
|
|
@ -707,7 +707,7 @@ void TabSupervisor::gameLeft(TabGame *tab)
|
||||||
if (tab == currentWidget())
|
if (tab == currentWidget())
|
||||||
emit setMenu();
|
emit setMenu();
|
||||||
|
|
||||||
gameTabs.remove(tab->getGameMetaInfo()->gameId());
|
gameTabs.remove(tab->getGame()->getGameMetaInfo()->gameId());
|
||||||
removeTab(indexOf(tab));
|
removeTab(indexOf(tab));
|
||||||
|
|
||||||
if (!localClients.isEmpty())
|
if (!localClients.isEmpty())
|
||||||
|
|
@ -916,7 +916,8 @@ void TabSupervisor::processGameEventContainer(const GameEventContainer &cont)
|
||||||
{
|
{
|
||||||
TabGame *tab = gameTabs.value(cont.game_id());
|
TabGame *tab = gameTabs.value(cont.game_id());
|
||||||
if (tab)
|
if (tab)
|
||||||
tab->getGameEventHandler()->processGameEventContainer(cont, qobject_cast<AbstractClient *>(sender()), {});
|
tab->getGame()->getGameEventHandler()->processGameEventContainer(cont, qobject_cast<AbstractClient *>(sender()),
|
||||||
|
{});
|
||||||
else
|
else
|
||||||
qCInfo(TabSupervisorLog) << "gameEvent: invalid gameId" << cont.game_id();
|
qCInfo(TabSupervisorLog) << "gameEvent: invalid gameId" << cont.game_id();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,10 @@ AbstractCounter::AbstractCounter(Player *_player,
|
||||||
bool _shownInCounterArea,
|
bool _shownInCounterArea,
|
||||||
int _value,
|
int _value,
|
||||||
bool _useNameForShortcut,
|
bool _useNameForShortcut,
|
||||||
QGraphicsItem *parent,
|
QGraphicsItem *parent)
|
||||||
QWidget *_game)
|
|
||||||
: QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value),
|
: QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value),
|
||||||
useNameForShortcut(_useNameForShortcut), hovered(false), aDec(nullptr), aInc(nullptr), dialogSemaphore(false),
|
useNameForShortcut(_useNameForShortcut), hovered(false), aDec(nullptr), aInc(nullptr), dialogSemaphore(false),
|
||||||
deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea), game(_game)
|
deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea)
|
||||||
{
|
{
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
|
|
||||||
|
|
@ -173,7 +172,7 @@ void AbstractCounter::incrementCounter()
|
||||||
void AbstractCounter::setCounter()
|
void AbstractCounter::setCounter()
|
||||||
{
|
{
|
||||||
dialogSemaphore = true;
|
dialogSemaphore = true;
|
||||||
AbstractCounterDialog dialog(name, QString::number(value), game);
|
AbstractCounterDialog dialog(name, QString::number(value) /*, game */);
|
||||||
const int ok = dialog.exec();
|
const int ok = dialog.exec();
|
||||||
|
|
||||||
if (deleteAfterDialog) {
|
if (deleteAfterDialog) {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ private:
|
||||||
bool dialogSemaphore, deleteAfterDialog;
|
bool dialogSemaphore, deleteAfterDialog;
|
||||||
bool shownInCounterArea;
|
bool shownInCounterArea;
|
||||||
bool shortcutActive;
|
bool shortcutActive;
|
||||||
QWidget *game;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void refreshShortcuts();
|
void refreshShortcuts();
|
||||||
|
|
@ -48,8 +47,7 @@ public:
|
||||||
bool _shownInCounterArea,
|
bool _shownInCounterArea,
|
||||||
int _value,
|
int _value,
|
||||||
bool _useNameForShortcut = false,
|
bool _useNameForShortcut = false,
|
||||||
QGraphicsItem *parent = nullptr,
|
QGraphicsItem *parent = nullptr);
|
||||||
QWidget *game = nullptr);
|
|
||||||
~AbstractCounter() override;
|
~AbstractCounter() override;
|
||||||
|
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,15 @@
|
||||||
/**
|
/**
|
||||||
* Parent class of all objects that appear in a game.
|
* Parent class of all objects that appear in a game.
|
||||||
*/
|
*/
|
||||||
class AbstractGraphicsItem : public QObject, public QGraphicsItem
|
class AbstractGraphicsItem : public QGraphicsObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_INTERFACES(QGraphicsItem)
|
|
||||||
protected:
|
protected:
|
||||||
void paintNumberEllipse(int number, int radius, const QColor &color, int position, int count, QPainter *painter);
|
void paintNumberEllipse(int number, int radius, const QColor &color, int position, int count, QPainter *painter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AbstractGraphicsItem(QGraphicsItem *parent = nullptr) : QGraphicsItem(parent)
|
explicit AbstractGraphicsItem(QGraphicsItem *parent = nullptr) : QGraphicsObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -260,13 +260,15 @@ void CardItem::deleteDragItem()
|
||||||
|
|
||||||
void CardItem::drawArrow(const QColor &arrowColor)
|
void CardItem::drawArrow(const QColor &arrowColor)
|
||||||
{
|
{
|
||||||
if (static_cast<TabGame *>(owner->parent())->getPlayerManager()->isSpectator())
|
if (static_cast<TabGame *>(owner->parent())->getGame()->getPlayerManager()->isSpectator())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player *arrowOwner =
|
Player *arrowOwner =
|
||||||
static_cast<TabGame *>(owner->parent())
|
static_cast<TabGame *>(owner->parent())
|
||||||
->getPlayerManager()
|
->getGame()
|
||||||
->getActiveLocalPlayer(static_cast<TabGame *>(owner->parent())->getGameState()->getActivePlayer());
|
->getPlayerManager()
|
||||||
|
->getActiveLocalPlayer(
|
||||||
|
static_cast<TabGame *>(owner->parent())->getGame()->getGameState()->getActivePlayer());
|
||||||
ArrowDragItem *arrow = new ArrowDragItem(arrowOwner, this, arrowColor);
|
ArrowDragItem *arrow = new ArrowDragItem(arrowOwner, this, arrowColor);
|
||||||
scene()->addItem(arrow);
|
scene()->addItem(arrow);
|
||||||
arrow->grabMouse();
|
arrow->grabMouse();
|
||||||
|
|
@ -286,7 +288,7 @@ void CardItem::drawArrow(const QColor &arrowColor)
|
||||||
|
|
||||||
void CardItem::drawAttachArrow()
|
void CardItem::drawAttachArrow()
|
||||||
{
|
{
|
||||||
if (static_cast<TabGame *>(owner->parent())->getPlayerManager()->isSpectator())
|
if (static_cast<TabGame *>(owner->parent())->getGame()->getPlayerManager()->isSpectator())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto *arrow = new ArrowAttachItem(this);
|
auto *arrow = new ArrowAttachItem(this);
|
||||||
|
|
@ -474,6 +476,7 @@ QVariant CardItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||||
owner->getGame()->setActiveCard(this);
|
owner->getGame()->setActiveCard(this);
|
||||||
owner->getPlayerMenu()->updateCardMenu(this);
|
owner->getPlayerMenu()->updateCardMenu(this);
|
||||||
} else if (owner->getGameScene()->selectedItems().isEmpty()) {
|
} else if (owner->getGameScene()->selectedItems().isEmpty()) {
|
||||||
|
|
||||||
owner->getGame()->setActiveCard(nullptr);
|
owner->getGame()->setActiveCard(nullptr);
|
||||||
owner->getPlayerMenu()->updateCardMenu(nullptr);
|
owner->getPlayerMenu()->updateCardMenu(nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,8 @@ GeneralCounter::GeneralCounter(Player *_player,
|
||||||
int _radius,
|
int _radius,
|
||||||
int _value,
|
int _value,
|
||||||
bool useNameForShortcut,
|
bool useNameForShortcut,
|
||||||
QGraphicsItem *parent,
|
QGraphicsItem *parent)
|
||||||
QWidget *game)
|
: AbstractCounter(_player, _id, _name, true, _value, useNameForShortcut, parent), color(_color), radius(_radius)
|
||||||
: AbstractCounter(_player, _id, _name, true, _value, useNameForShortcut, parent, game), color(_color),
|
|
||||||
radius(_radius)
|
|
||||||
{
|
{
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,7 @@ public:
|
||||||
int _radius,
|
int _radius,
|
||||||
int _value,
|
int _value,
|
||||||
bool useNameForShortcut = false,
|
bool useNameForShortcut = false,
|
||||||
QGraphicsItem *parent = nullptr,
|
QGraphicsItem *parent = nullptr);
|
||||||
QWidget *game = nullptr);
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ void DeckViewContainer::switchToDeckSelectView()
|
||||||
deckViewLayout->update();
|
deckViewLayout->update();
|
||||||
|
|
||||||
setVisibility(loadLocalButton, true);
|
setVisibility(loadLocalButton, true);
|
||||||
setVisibility(loadRemoteButton, !parentGame->getGameState()->getIsLocalGame());
|
setVisibility(loadRemoteButton, !parentGame->getGame()->getGameState()->getIsLocalGame());
|
||||||
setVisibility(loadFromClipboardButton, true);
|
setVisibility(loadFromClipboardButton, true);
|
||||||
setVisibility(loadFromWebsiteButton, true);
|
setVisibility(loadFromWebsiteButton, true);
|
||||||
setVisibility(unloadDeckButton, false);
|
setVisibility(unloadDeckButton, false);
|
||||||
|
|
@ -190,7 +190,7 @@ void DeckViewContainer::switchToDeckLoadedView()
|
||||||
setVisibility(readyStartButton, true);
|
setVisibility(readyStartButton, true);
|
||||||
setVisibility(sideboardLockButton, true);
|
setVisibility(sideboardLockButton, true);
|
||||||
|
|
||||||
if (parentGame->isHost()) {
|
if (parentGame->getGame()->isHost()) {
|
||||||
setVisibility(forceStartGameButton, true);
|
setVisibility(forceStartGameButton, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -287,20 +287,20 @@ void DeckViewContainer::loadDeckFromDeckLoader(const DeckLoader *deck)
|
||||||
|
|
||||||
Command_DeckSelect cmd;
|
Command_DeckSelect cmd;
|
||||||
cmd.set_deck(deckString.toStdString());
|
cmd.set_deck(deckString.toStdString());
|
||||||
PendingCommand *pend = parentGame->getGameEventHandler()->prepareGameCommand(cmd);
|
PendingCommand *pend = parentGame->getGame()->getGameEventHandler()->prepareGameCommand(cmd);
|
||||||
connect(pend, &PendingCommand::finished, this, &DeckViewContainer::deckSelectFinished);
|
connect(pend, &PendingCommand::finished, this, &DeckViewContainer::deckSelectFinished);
|
||||||
parentGame->getGameEventHandler()->sendGameCommand(pend, playerId);
|
parentGame->getGame()->getGameEventHandler()->sendGameCommand(pend, playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewContainer::loadRemoteDeck()
|
void DeckViewContainer::loadRemoteDeck()
|
||||||
{
|
{
|
||||||
DlgLoadRemoteDeck dlg(parentGame->getClientForPlayer(playerId), this);
|
DlgLoadRemoteDeck dlg(parentGame->getGame()->getClientForPlayer(playerId), this);
|
||||||
if (dlg.exec()) {
|
if (dlg.exec()) {
|
||||||
Command_DeckSelect cmd;
|
Command_DeckSelect cmd;
|
||||||
cmd.set_deck_id(dlg.getDeckId());
|
cmd.set_deck_id(dlg.getDeckId());
|
||||||
PendingCommand *pend = parentGame->getGameEventHandler()->prepareGameCommand(cmd);
|
PendingCommand *pend = parentGame->getGame()->getGameEventHandler()->prepareGameCommand(cmd);
|
||||||
connect(pend, &PendingCommand::finished, this, &DeckViewContainer::deckSelectFinished);
|
connect(pend, &PendingCommand::finished, this, &DeckViewContainer::deckSelectFinished);
|
||||||
parentGame->getGameEventHandler()->sendGameCommand(pend, playerId);
|
parentGame->getGame()->getGameEventHandler()->sendGameCommand(pend, playerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -354,7 +354,7 @@ void DeckViewContainer::forceStart()
|
||||||
Command_ReadyStart cmd;
|
Command_ReadyStart cmd;
|
||||||
cmd.set_force_start(true);
|
cmd.set_force_start(true);
|
||||||
cmd.set_ready(true);
|
cmd.set_ready(true);
|
||||||
parentGame->getGameEventHandler()->sendGameCommand(cmd, playerId);
|
parentGame->getGame()->getGameEventHandler()->sendGameCommand(cmd, playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewContainer::sideboardLockButtonClicked()
|
void DeckViewContainer::sideboardLockButtonClicked()
|
||||||
|
|
@ -362,7 +362,7 @@ void DeckViewContainer::sideboardLockButtonClicked()
|
||||||
Command_SetSideboardLock cmd;
|
Command_SetSideboardLock cmd;
|
||||||
cmd.set_locked(sideboardLockButton->getState());
|
cmd.set_locked(sideboardLockButton->getState());
|
||||||
|
|
||||||
parentGame->getGameEventHandler()->sendGameCommand(cmd, playerId);
|
parentGame->getGame()->getGameEventHandler()->sendGameCommand(cmd, playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewContainer::sideboardPlanChanged()
|
void DeckViewContainer::sideboardPlanChanged()
|
||||||
|
|
@ -371,7 +371,7 @@ void DeckViewContainer::sideboardPlanChanged()
|
||||||
const QList<MoveCard_ToZone> &newPlan = deckView->getSideboardPlan();
|
const QList<MoveCard_ToZone> &newPlan = deckView->getSideboardPlan();
|
||||||
for (const auto &i : newPlan)
|
for (const auto &i : newPlan)
|
||||||
cmd.add_move_list()->CopyFrom(i);
|
cmd.add_move_list()->CopyFrom(i);
|
||||||
parentGame->getGameEventHandler()->sendGameCommand(cmd, playerId);
|
parentGame->getGame()->getGameEventHandler()->sendGameCommand(cmd, playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -381,7 +381,7 @@ void DeckViewContainer::sendReadyStartCommand(bool ready)
|
||||||
{
|
{
|
||||||
Command_ReadyStart cmd;
|
Command_ReadyStart cmd;
|
||||||
cmd.set_ready(ready);
|
cmd.set_ready(ready);
|
||||||
parentGame->getGameEventHandler()->sendGameCommand(cmd, playerId);
|
parentGame->getGame()->getGameEventHandler()->sendGameCommand(cmd, playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
63
cockatrice/src/game/game.cpp
Normal file
63
cockatrice/src/game/game.cpp
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
#include "pb/event_game_joined.pb.h"
|
||||||
|
|
||||||
|
Game::Game(QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes)
|
||||||
|
{
|
||||||
|
gameMetaInfo = new GameMetaInfo(this);
|
||||||
|
gameMetaInfo->setFromProto(event.game_info());
|
||||||
|
gameMetaInfo->setRoomGameTypes(_roomGameTypes);
|
||||||
|
gameState = new GameState(this, 0, event.host_id(), /* _tabSupervisor->getIsLocalGame() */ true, _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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
62
cockatrice/src/game/game.h
Normal file
62
cockatrice/src/game/game.h
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#ifndef COCKATRICE_GAME_H
|
||||||
|
#define COCKATRICE_GAME_H
|
||||||
|
|
||||||
|
#include "../../../cmake-build-debug/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 <QObject>
|
||||||
|
|
||||||
|
class CardItem;
|
||||||
|
class GameMetaInfo;
|
||||||
|
class Game : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Game(QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes);
|
||||||
|
|
||||||
|
GameMetaInfo *gameMetaInfo;
|
||||||
|
GameState *gameState;
|
||||||
|
GameEventHandler *gameEventHandler;
|
||||||
|
PlayerManager *playerManager;
|
||||||
|
CardItem *activeCard;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "../server/abstract_client.h"
|
#include "../server/abstract_client.h"
|
||||||
#include "../server/message_log_widget.h"
|
#include "../server/message_log_widget.h"
|
||||||
#include "../server/pending_command.h"
|
#include "../server/pending_command.h"
|
||||||
|
#include "game.h"
|
||||||
#include "get_pb_extension.h"
|
#include "get_pb_extension.h"
|
||||||
#include "pb/command_concede.pb.h"
|
#include "pb/command_concede.pb.h"
|
||||||
#include "pb/command_delete_arrow.pb.h"
|
#include "pb/command_delete_arrow.pb.h"
|
||||||
|
|
@ -28,7 +29,7 @@
|
||||||
#include "pb/event_set_active_player.pb.h"
|
#include "pb/event_set_active_player.pb.h"
|
||||||
#include "pb/game_event_container.pb.h"
|
#include "pb/game_event_container.pb.h"
|
||||||
|
|
||||||
GameEventHandler::GameEventHandler(TabGame *_game) : game(_game), gameState(_game->getGameState())
|
GameEventHandler::GameEventHandler(Game *_game) : QObject(_game), game(_game)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,12 +99,13 @@ void GameEventHandler::processGameEventContainer(const GameEventContainer &cont,
|
||||||
Player *judgep = game->getPlayerManager()->getPlayers().value(id, nullptr);
|
Player *judgep = game->getPlayerManager()->getPlayers().value(id, nullptr);
|
||||||
if (judgep) {
|
if (judgep) {
|
||||||
emit setContextJudgeName(judgep->getPlayerInfo()->getName());
|
emit setContextJudgeName(judgep->getPlayerInfo()->getName());
|
||||||
} else if (gameState->getSpectators().contains(id)) {
|
} else if (game->getPlayerManager()->getSpectators().contains(id)) {
|
||||||
emit setContextJudgeName(QString::fromStdString(gameState->getSpectators().value(id).name()));
|
emit setContextJudgeName(
|
||||||
|
QString::fromStdString(game->getPlayerManager()->getSpectators().value(id).name()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameState->getSpectators().contains(playerId)) {
|
if (game->getPlayerManager()->getSpectators().contains(playerId)) {
|
||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
case GameEvent::GAME_SAY:
|
case GameEvent::GAME_SAY:
|
||||||
eventSpectatorSay(event.GetExtension(Event_GameSay::ext), playerId, context);
|
eventSpectatorSay(event.GetExtension(Event_GameSay::ext), playerId, context);
|
||||||
|
|
@ -115,8 +117,8 @@ void GameEventHandler::processGameEventContainer(const GameEventContainer &cont,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((gameState->getClients().size() > 1) && (playerId != -1))
|
if ((game->getGameState()->getClients().size() > 1) && (playerId != -1))
|
||||||
if (gameState->getClients().at(playerId) != client)
|
if (game->getGameState()->getClients().at(playerId) != client)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
|
|
@ -169,7 +171,7 @@ void GameEventHandler::processGameEventContainer(const GameEventContainer &cont,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
player->getPlayerEventHandler()->processGameEvent(eventType, event, context, options);
|
player->getPlayerEventHandler()->processGameEvent(eventType, event, context, options);
|
||||||
game->emitUserEvent();
|
emitUserEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -187,12 +189,12 @@ void GameEventHandler::handleReverseTurn()
|
||||||
sendGameCommand(Command_ReverseTurn());
|
sendGameCommand(Command_ReverseTurn());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::handlePlayerConceded()
|
void GameEventHandler::handleActiveLocalPlayerConceded()
|
||||||
{
|
{
|
||||||
sendGameCommand(Command_Concede());
|
sendGameCommand(Command_Concede());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::handlePlayerUnconceded()
|
void GameEventHandler::handleActiveLocalPlayerUnconceded()
|
||||||
{
|
{
|
||||||
sendGameCommand(Command_Unconcede());
|
sendGameCommand(Command_Unconcede());
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +229,7 @@ void GameEventHandler::eventSpectatorSay(const Event_GameSay &event,
|
||||||
int eventPlayerId,
|
int eventPlayerId,
|
||||||
const GameEventContext & /*context*/)
|
const GameEventContext & /*context*/)
|
||||||
{
|
{
|
||||||
const ServerInfo_User &userInfo = gameState->getSpectators().value(eventPlayerId);
|
const ServerInfo_User &userInfo = game->getPlayerManager()->getSpectators().value(eventPlayerId);
|
||||||
emit logSpectatorSay(userInfo, QString::fromStdString(event.message()));
|
emit logSpectatorSay(userInfo, QString::fromStdString(event.message()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -235,13 +237,13 @@ void GameEventHandler::eventSpectatorLeave(const Event_Leave &event,
|
||||||
int eventPlayerId,
|
int eventPlayerId,
|
||||||
const GameEventContext & /*context*/)
|
const GameEventContext & /*context*/)
|
||||||
{
|
{
|
||||||
emit logSpectatorLeave(gameState->getSpectatorName(eventPlayerId), getLeaveReason(event.reason()));
|
emit logSpectatorLeave(game->getPlayerManager()->getSpectatorName(eventPlayerId), getLeaveReason(event.reason()));
|
||||||
|
|
||||||
emit spectatorLeft(eventPlayerId);
|
emit spectatorLeft(eventPlayerId);
|
||||||
|
|
||||||
gameState->removeSpectator(eventPlayerId);
|
game->getPlayerManager()->removeSpectator(eventPlayerId);
|
||||||
|
|
||||||
game->emitUserEvent();
|
emitUserEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::eventGameStateChanged(const Event_GameStateChanged &event,
|
void GameEventHandler::eventGameStateChanged(const Event_GameStateChanged &event,
|
||||||
|
|
@ -257,13 +259,13 @@ void GameEventHandler::eventGameStateChanged(const Event_GameStateChanged &event
|
||||||
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
|
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
|
||||||
const int playerId = prop.player_id();
|
const int playerId = prop.player_id();
|
||||||
QString playerName = "@" + QString::fromStdString(prop.user_info().name());
|
QString playerName = "@" + QString::fromStdString(prop.user_info().name());
|
||||||
game->addPlayerToAutoCompleteList(playerName);
|
emit addPlayerToAutoCompleteList(playerName);
|
||||||
if (prop.spectator()) {
|
if (prop.spectator()) {
|
||||||
gameState->addSpectator(playerId, prop);
|
game->getPlayerManager()->addSpectator(playerId, prop);
|
||||||
} else {
|
} else {
|
||||||
Player *player = game->getPlayerManager()->getPlayers().value(playerId, 0);
|
Player *player = game->getPlayerManager()->getPlayers().value(playerId, 0);
|
||||||
if (!player) {
|
if (!player) {
|
||||||
player = game->getPlayerManager()->addPlayer(playerId, prop.user_info(), game);
|
player = game->getPlayerManager()->addPlayer(playerId, prop.user_info());
|
||||||
emit playerJoined(prop);
|
emit playerJoined(prop);
|
||||||
emit logJoinPlayer(player);
|
emit logJoinPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
@ -285,23 +287,23 @@ void GameEventHandler::eventGameStateChanged(const Event_GameStateChanged &event
|
||||||
|
|
||||||
emit remotePlayersDecksSelected(opponentDecksToDisplay);
|
emit remotePlayersDecksSelected(opponentDecksToDisplay);
|
||||||
|
|
||||||
gameState->setGameTime(event.seconds_elapsed());
|
game->getGameState()->setGameTime(event.seconds_elapsed());
|
||||||
|
|
||||||
if (event.game_started() && !game->getGameMetaInfo()->started()) {
|
if (event.game_started() && !game->getGameMetaInfo()->started()) {
|
||||||
gameState->setResuming(!gameState->isGameStateKnown());
|
game->getGameState()->setResuming(!game->getGameState()->isGameStateKnown());
|
||||||
game->getGameMetaInfo()->setStarted(event.game_started());
|
game->getGameMetaInfo()->setStarted(event.game_started());
|
||||||
if (gameState->isGameStateKnown())
|
if (game->getGameState()->isGameStateKnown())
|
||||||
emit logGameStart();
|
emit logGameStart();
|
||||||
gameState->setActivePlayer(event.active_player_id());
|
game->getGameState()->setActivePlayer(event.active_player_id());
|
||||||
gameState->setCurrentPhase(event.active_phase());
|
game->getGameState()->setCurrentPhase(event.active_phase());
|
||||||
} else if (!event.game_started() && game->getGameMetaInfo()->started()) {
|
} else if (!event.game_started() && game->getGameMetaInfo()->started()) {
|
||||||
gameState->setCurrentPhase(-1);
|
game->getGameState()->setCurrentPhase(-1);
|
||||||
gameState->setActivePlayer(-1);
|
game->getGameState()->setActivePlayer(-1);
|
||||||
game->getGameMetaInfo()->setStarted(false);
|
game->getGameMetaInfo()->setStarted(false);
|
||||||
emit gameStopped();
|
emit gameStopped();
|
||||||
}
|
}
|
||||||
gameState->setGameStateKnown(true);
|
game->getGameState()->setGameStateKnown(true);
|
||||||
game->emitUserEvent();
|
emitUserEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::processCardAttachmentsForPlayers(const Event_GameStateChanged &event)
|
void GameEventHandler::processCardAttachmentsForPlayers(const Event_GameStateChanged &event)
|
||||||
|
|
@ -342,8 +344,7 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GameEventContext::CONCEDE: {
|
case GameEventContext::CONCEDE: {
|
||||||
emit playerConceded(player);
|
player->setConceded(true);
|
||||||
player->getPlayerInfo()->setConceded(true);
|
|
||||||
|
|
||||||
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||||
while (playerIterator.hasNext())
|
while (playerIterator.hasNext())
|
||||||
|
|
@ -352,8 +353,7 @@ void GameEventHandler::eventPlayerPropertiesChanged(const Event_PlayerProperties
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GameEventContext::UNCONCEDE: {
|
case GameEventContext::UNCONCEDE: {
|
||||||
emit playerUnconceded(player);
|
player->setConceded(false);
|
||||||
player->getPlayerInfo()->setConceded(false);
|
|
||||||
|
|
||||||
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
QMapIterator<int, Player *> playerIterator(game->getPlayerManager()->getPlayers());
|
||||||
while (playerIterator.hasNext())
|
while (playerIterator.hasNext())
|
||||||
|
|
@ -391,22 +391,22 @@ void GameEventHandler::eventJoin(const Event_Join &event, int /*eventPlayerId*/,
|
||||||
const ServerInfo_PlayerProperties &playerInfo = event.player_properties();
|
const ServerInfo_PlayerProperties &playerInfo = event.player_properties();
|
||||||
const int playerId = playerInfo.player_id();
|
const int playerId = playerInfo.player_id();
|
||||||
QString playerName = QString::fromStdString(playerInfo.user_info().name());
|
QString playerName = QString::fromStdString(playerInfo.user_info().name());
|
||||||
game->addPlayerToAutoCompleteList(playerName);
|
emit addPlayerToAutoCompleteList(playerName);
|
||||||
|
|
||||||
if (game->getPlayerManager()->getPlayers().contains(playerId))
|
if (game->getPlayerManager()->getPlayers().contains(playerId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (playerInfo.spectator()) {
|
if (playerInfo.spectator()) {
|
||||||
gameState->addSpectator(playerId, playerInfo);
|
game->getPlayerManager()->addSpectator(playerId, playerInfo);
|
||||||
emit logJoinSpectator(playerName);
|
emit logJoinSpectator(playerName);
|
||||||
emit spectatorJoined(playerInfo);
|
emit spectatorJoined(playerInfo);
|
||||||
} else {
|
} else {
|
||||||
Player *newPlayer = game->getPlayerManager()->addPlayer(playerId, playerInfo.user_info(), game);
|
Player *newPlayer = game->getPlayerManager()->addPlayer(playerId, playerInfo.user_info());
|
||||||
emit logJoinPlayer(newPlayer);
|
emit logJoinPlayer(newPlayer);
|
||||||
emit playerJoined(playerInfo);
|
emit playerJoined(playerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
game->emitUserEvent();
|
emitUserEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GameEventHandler::getLeaveReason(Event_Leave::LeaveReason reason)
|
QString GameEventHandler::getLeaveReason(Event_Leave::LeaveReason reason)
|
||||||
|
|
@ -447,7 +447,7 @@ void GameEventHandler::eventLeave(const Event_Leave &event, int eventPlayerId, c
|
||||||
while (playerIterator.hasNext())
|
while (playerIterator.hasNext())
|
||||||
playerIterator.next().value()->updateZones();
|
playerIterator.next().value()->updateZones();
|
||||||
|
|
||||||
game->emitUserEvent();
|
emitUserEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::eventKicked(const Event_Kicked & /*event*/,
|
void GameEventHandler::eventKicked(const Event_Kicked & /*event*/,
|
||||||
|
|
@ -460,7 +460,7 @@ void GameEventHandler::eventKicked(const Event_Kicked & /*event*/,
|
||||||
|
|
||||||
emit playerKicked();
|
emit playerKicked();
|
||||||
|
|
||||||
game->emitUserEvent();
|
emitUserEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::eventReverseTurn(const Event_ReverseTurn &event,
|
void GameEventHandler::eventReverseTurn(const Event_ReverseTurn &event,
|
||||||
|
|
@ -478,7 +478,7 @@ void GameEventHandler::eventGameHostChanged(const Event_GameHostChanged & /*even
|
||||||
int eventPlayerId,
|
int eventPlayerId,
|
||||||
const GameEventContext & /*context*/)
|
const GameEventContext & /*context*/)
|
||||||
{
|
{
|
||||||
gameState->setHostId(eventPlayerId);
|
game->getGameState()->setHostId(eventPlayerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::eventGameClosed(const Event_GameClosed & /*event*/,
|
void GameEventHandler::eventGameClosed(const Event_GameClosed & /*event*/,
|
||||||
|
|
@ -486,22 +486,22 @@ void GameEventHandler::eventGameClosed(const Event_GameClosed & /*event*/,
|
||||||
const GameEventContext & /*context*/)
|
const GameEventContext & /*context*/)
|
||||||
{
|
{
|
||||||
game->getGameMetaInfo()->setStarted(false);
|
game->getGameMetaInfo()->setStarted(false);
|
||||||
gameState->setGameClosed(true);
|
game->getGameState()->setGameClosed(true);
|
||||||
emit gameClosed();
|
emit gameClosed();
|
||||||
emit logGameClosed();
|
emit logGameClosed();
|
||||||
game->emitUserEvent();
|
emitUserEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::eventSetActivePlayer(const Event_SetActivePlayer &event,
|
void GameEventHandler::eventSetActivePlayer(const Event_SetActivePlayer &event,
|
||||||
int /*eventPlayerId*/,
|
int /*eventPlayerId*/,
|
||||||
const GameEventContext & /*context*/)
|
const GameEventContext & /*context*/)
|
||||||
{
|
{
|
||||||
gameState->setActivePlayer(event.active_player_id());
|
game->getGameState()->setActivePlayer(event.active_player_id());
|
||||||
Player *player = game->getPlayerManager()->getPlayer(event.active_player_id());
|
Player *player = game->getPlayerManager()->getPlayer(event.active_player_id());
|
||||||
if (!player)
|
if (!player)
|
||||||
return;
|
return;
|
||||||
emit logActivePlayer(player);
|
emit logActivePlayer(player);
|
||||||
game->emitUserEvent();
|
emitUserEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameEventHandler::eventSetActivePhase(const Event_SetActivePhase &event,
|
void GameEventHandler::eventSetActivePhase(const Event_SetActivePhase &event,
|
||||||
|
|
@ -509,9 +509,9 @@ void GameEventHandler::eventSetActivePhase(const Event_SetActivePhase &event,
|
||||||
const GameEventContext & /*context*/)
|
const GameEventContext & /*context*/)
|
||||||
{
|
{
|
||||||
const int phase = event.phase();
|
const int phase = event.phase();
|
||||||
if (gameState->getCurrentPhase() != phase) {
|
if (game->getGameState()->getCurrentPhase() != phase) {
|
||||||
emit logActivePhaseChanged(phase);
|
emit logActivePhaseChanged(phase);
|
||||||
}
|
}
|
||||||
gameState->setCurrentPhase(phase);
|
game->getGameState()->setCurrentPhase(phase);
|
||||||
game->emitUserEvent();
|
emitUserEvent();
|
||||||
}
|
}
|
||||||
|
|
@ -3,12 +3,11 @@
|
||||||
|
|
||||||
#include "pb/event_leave.pb.h"
|
#include "pb/event_leave.pb.h"
|
||||||
#include "pb/serverinfo_player.pb.h"
|
#include "pb/serverinfo_player.pb.h"
|
||||||
#include "player/player.h"
|
#include "player/event_processing_options.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class AbstractClient;
|
class AbstractClient;
|
||||||
class TabGame;
|
|
||||||
class Response;
|
class Response;
|
||||||
class GameEventContainer;
|
class GameEventContainer;
|
||||||
class GameEventContext;
|
class GameEventContext;
|
||||||
|
|
@ -30,24 +29,25 @@ class Event_Ping;
|
||||||
class Event_GameSay;
|
class Event_GameSay;
|
||||||
class Event_Kicked;
|
class Event_Kicked;
|
||||||
class Event_ReverseTurn;
|
class Event_ReverseTurn;
|
||||||
|
class Game;
|
||||||
class PendingCommand;
|
class PendingCommand;
|
||||||
|
class Player;
|
||||||
|
|
||||||
class GameEventHandler : public QObject
|
class GameEventHandler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TabGame *game;
|
Game *game;
|
||||||
GameState *gameState;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameEventHandler(TabGame *game);
|
explicit GameEventHandler(Game *_game);
|
||||||
|
|
||||||
void handleNextTurn();
|
void handleNextTurn();
|
||||||
void handleReverseTurn();
|
void handleReverseTurn();
|
||||||
|
|
||||||
void handlePlayerConceded();
|
void handleActiveLocalPlayerConceded();
|
||||||
void handlePlayerUnconceded();
|
void handleActiveLocalPlayerUnconceded();
|
||||||
void handleActivePhaseChanged(int phase);
|
void handleActivePhaseChanged(int phase);
|
||||||
void handleGameLeft();
|
void handleGameLeft();
|
||||||
void handleChatMessageSent(const QString &chatMessage);
|
void handleChatMessageSent(const QString &chatMessage);
|
||||||
|
|
@ -84,6 +84,8 @@ public slots:
|
||||||
void sendGameCommand(const ::google::protobuf::Message &command, int playerId = -1);
|
void sendGameCommand(const ::google::protobuf::Message &command, int playerId = -1);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void emitUserEvent();
|
||||||
|
void addPlayerToAutoCompleteList(QString playerName);
|
||||||
void localPlayerDeckSelected(Player *localPlayer, int playerId, ServerInfo_Player playerInfo);
|
void localPlayerDeckSelected(Player *localPlayer, int playerId, ServerInfo_Player playerInfo);
|
||||||
void remotePlayerDeckSelected(QString deckList, int playerId, QString playerName);
|
void remotePlayerDeckSelected(QString deckList, int playerId, QString playerName);
|
||||||
void remotePlayersDecksSelected(QVector<QPair<int, QPair<QString, QString>>> opponentDecks);
|
void remotePlayersDecksSelected(QVector<QPair<int, QPair<QString, QString>>> opponentDecks);
|
||||||
|
|
@ -106,8 +108,6 @@ signals:
|
||||||
void logGameStart();
|
void logGameStart();
|
||||||
void logReadyStart(Player *player);
|
void logReadyStart(Player *player);
|
||||||
void logNotReadyStart(Player *player);
|
void logNotReadyStart(Player *player);
|
||||||
void playerConceded(Player *player);
|
|
||||||
void playerUnconceded(Player *player);
|
|
||||||
void logDeckSelect(Player *player, QString deckHash, int sideboardSize);
|
void logDeckSelect(Player *player, QString deckHash, int sideboardSize);
|
||||||
void logSideboardLockSet(Player *player, bool sideboardLocked);
|
void logSideboardLockSet(Player *player, bool sideboardLocked);
|
||||||
void logConnectionStateChanged(Player *player, bool connected);
|
void logConnectionStateChanged(Player *player, bool connected);
|
||||||
|
|
|
||||||
|
|
@ -1 +1,7 @@
|
||||||
#include "game_meta_info.h"
|
#include "game_meta_info.h"
|
||||||
|
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
GameMetaInfo::GameMetaInfo(Game *_game) : QObject(_game), game(_game)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,12 @@
|
||||||
// This class de-couples the domain object (i.e. the GameMetaInfo) from the network object.
|
// 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.
|
// If the network object changes, only this class needs to be adjusted.
|
||||||
|
|
||||||
|
class Game;
|
||||||
class GameMetaInfo : public QObject
|
class GameMetaInfo : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GameMetaInfo(QObject *parent = nullptr) : QObject(parent)
|
explicit GameMetaInfo(Game *_game);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<int, QString> roomGameTypes;
|
QMap<int, QString> roomGameTypes;
|
||||||
|
|
||||||
|
|
@ -80,6 +79,11 @@ public:
|
||||||
return roomGameTypes.find(gameInfo_.game_types(index)).value();
|
return roomGameTypes.find(gameInfo_.game_types(index)).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Game *getGame() const
|
||||||
|
{
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setStarted(bool s)
|
void setStarted(bool s)
|
||||||
{
|
{
|
||||||
|
|
@ -101,6 +105,7 @@ signals:
|
||||||
void spectatorsOmniscienceChanged(bool omniscient);
|
void spectatorsOmniscienceChanged(bool omniscient);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Game *game;
|
||||||
ServerInfo_Game gameInfo_;
|
ServerInfo_Game gameInfo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,6 @@ void GameScene::addPlayer(Player *player)
|
||||||
players << player->getGraphicsItem();
|
players << player->getGraphicsItem();
|
||||||
addItem(player->getGraphicsItem());
|
addItem(player->getGraphicsItem());
|
||||||
connect(player->getGraphicsItem(), &PlayerGraphicsItem::sizeChanged, this, &GameScene::rearrange);
|
connect(player->getGraphicsItem(), &PlayerGraphicsItem::sizeChanged, this, &GameScene::rearrange);
|
||||||
// TODO: game scene really shouldn't cue off of this
|
|
||||||
// connect(player, &Player::playerCountChanged, this, &GameScene::rearrange);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::removePlayer(Player *player)
|
void GameScene::removePlayer(Player *player)
|
||||||
|
|
@ -85,7 +83,7 @@ void GameScene::rearrange()
|
||||||
QListIterator<PlayerGraphicsItem *> playersIter(players);
|
QListIterator<PlayerGraphicsItem *> playersIter(players);
|
||||||
while (playersIter.hasNext()) {
|
while (playersIter.hasNext()) {
|
||||||
Player *p = playersIter.next()->getPlayer();
|
Player *p = playersIter.next()->getPlayer();
|
||||||
if (p && !p->getPlayerInfo()->getConceded()) {
|
if (p && !p->getConceded()) {
|
||||||
playersPlaying.append(p);
|
playersPlaying.append(p);
|
||||||
if (!firstPlayerFound && (p->getPlayerInfo()->getLocal())) {
|
if (!firstPlayerFound && (p->getPlayerInfo()->getLocal())) {
|
||||||
firstPlayerIndex = playersPlaying.size() - 1;
|
firstPlayerIndex = playersPlaying.size() - 1;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "game_state.h"
|
#include "game_state.h"
|
||||||
|
|
||||||
GameState::GameState(int _secondsElapsed,
|
GameState::GameState(Game *_game,
|
||||||
|
int _secondsElapsed,
|
||||||
int _hostId,
|
int _hostId,
|
||||||
bool _isLocalGame,
|
bool _isLocalGame,
|
||||||
const QList<AbstractClient *> _clients,
|
const QList<AbstractClient *> _clients,
|
||||||
|
|
@ -8,8 +9,9 @@ GameState::GameState(int _secondsElapsed,
|
||||||
bool _resuming,
|
bool _resuming,
|
||||||
int _currentPhase,
|
int _currentPhase,
|
||||||
bool _gameClosed)
|
bool _gameClosed)
|
||||||
: secondsElapsed(_secondsElapsed), hostId(_hostId), isLocalGame(_isLocalGame), clients(_clients),
|
: QObject(_game), game(_game), secondsElapsed(_secondsElapsed), hostId(_hostId), isLocalGame(_isLocalGame),
|
||||||
gameStateKnown(_gameStateKnown), resuming(_resuming), currentPhase(_currentPhase), gameClosed(_gameClosed)
|
clients(_clients), gameStateKnown(_gameStateKnown), resuming(_resuming), currentPhase(_currentPhase),
|
||||||
|
gameClosed(_gameClosed)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ class GameState : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GameState(int secondsElapsed,
|
explicit GameState(Game *_game,
|
||||||
|
int secondsElapsed,
|
||||||
int hostId,
|
int hostId,
|
||||||
bool isLocalGame,
|
bool isLocalGame,
|
||||||
QList<AbstractClient *> clients,
|
QList<AbstractClient *> clients,
|
||||||
|
|
@ -25,36 +26,6 @@ public:
|
||||||
int currentPhase,
|
int currentPhase,
|
||||||
bool gameClosed);
|
bool gameClosed);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setHostId(int _hostId)
|
void setHostId(int _hostId)
|
||||||
{
|
{
|
||||||
hostId = _hostId;
|
hostId = _hostId;
|
||||||
|
|
@ -151,10 +122,6 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updateTimeElapsedLabel(QString newTime);
|
void updateTimeElapsedLabel(QString newTime);
|
||||||
void playerAdded(Player *player);
|
|
||||||
void playerRemoved(Player *player);
|
|
||||||
void spectatorAdded(ServerInfo_PlayerProperties spectator);
|
|
||||||
void spectatorRemoved(int spectatorId, ServerInfo_User spectator);
|
|
||||||
void gameStarted(bool resuming);
|
void gameStarted(bool resuming);
|
||||||
void gameStopped();
|
void gameStopped();
|
||||||
void activePhaseChanged(int activePhase);
|
void activePhaseChanged(int activePhase);
|
||||||
|
|
@ -165,12 +132,12 @@ public slots:
|
||||||
void setGameTime(int _secondsElapsed);
|
void setGameTime(int _secondsElapsed);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Game *game;
|
||||||
QTimer *gameTimer;
|
QTimer *gameTimer;
|
||||||
int secondsElapsed;
|
int secondsElapsed;
|
||||||
QMap<int, QString> roomGameTypes;
|
QMap<int, QString> roomGameTypes;
|
||||||
int hostId;
|
int hostId;
|
||||||
const bool isLocalGame;
|
const bool isLocalGame;
|
||||||
QMap<int, ServerInfo_User> spectators;
|
|
||||||
QList<AbstractClient *> clients;
|
QList<AbstractClient *> clients;
|
||||||
bool gameStateKnown;
|
bool gameStateKnown;
|
||||||
bool resuming;
|
bool resuming;
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,10 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, TabGame *_parent)
|
Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, Game *_parent)
|
||||||
: QObject(_parent), game(_parent), playerInfo(new PlayerInfo(info, _id, _local, _judge)),
|
: QObject(_parent), game(_parent), playerInfo(new PlayerInfo(info, _id, _local, _judge)),
|
||||||
playerEventHandler(new PlayerEventHandler(this)), playerActions(new PlayerActions(this)), active(false),
|
playerEventHandler(new PlayerEventHandler(this)), playerActions(new PlayerActions(this)), active(false),
|
||||||
deck(nullptr), dialogSemaphore(false)
|
conceded(false), deck(nullptr), dialogSemaphore(false)
|
||||||
{
|
{
|
||||||
initializeZones();
|
initializeZones();
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T
|
||||||
connect(this, &Player::deckChanged, playerMenu, &PlayerMenu::enableOpenInDeckEditorAction);
|
connect(this, &Player::deckChanged, playerMenu, &PlayerMenu::enableOpenInDeckEditorAction);
|
||||||
connect(this, &Player::deckChanged, playerMenu, &PlayerMenu::populatePredefinedTokensMenu);
|
connect(this, &Player::deckChanged, playerMenu, &PlayerMenu::populatePredefinedTokensMenu);
|
||||||
|
|
||||||
connect(this, &Player::openDeckEditor, game, &TabGame::openDeckEditor);
|
// connect(this, &Player::openDeckEditor, game, &TabGame::openDeckEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::initializeZones()
|
void Player::initializeZones()
|
||||||
|
|
@ -55,7 +55,6 @@ void Player::initializeZones()
|
||||||
addZone(new PileZoneLogic(this, "sb", false, false, false, this));
|
addZone(new PileZoneLogic(this, "sb", false, false, false, this));
|
||||||
addZone(new TableZoneLogic(this, "table", true, false, true, this));
|
addZone(new TableZoneLogic(this, "table", true, false, true, this));
|
||||||
addZone(new StackZoneLogic(this, "stack", true, false, true, this));
|
addZone(new StackZoneLogic(this, "stack", true, false, true, this));
|
||||||
// TODO: Contentsknown is probably not true for other players
|
|
||||||
addZone(new HandZoneLogic(this, "hand", false, false, true, this));
|
addZone(new HandZoneLogic(this, "hand", false, false, true, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,6 +96,19 @@ void Player::clear()
|
||||||
clearCounters();
|
clearCounters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::setConceded(bool _conceded)
|
||||||
|
{
|
||||||
|
if (conceded != _conceded) {
|
||||||
|
conceded = _conceded;
|
||||||
|
|
||||||
|
getGraphicsItem()->setVisible(!conceded);
|
||||||
|
if (conceded) {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
emit concededChanged(getPlayerInfo()->getId(), conceded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Player::processPlayerInfo(const ServerInfo_Player &info)
|
void Player::processPlayerInfo(const ServerInfo_Player &info)
|
||||||
{
|
{
|
||||||
static QSet<QString> builtinZones{/* PileZones */
|
static QSet<QString> builtinZones{/* PileZones */
|
||||||
|
|
@ -160,8 +172,7 @@ void Player::processPlayerInfo(const ServerInfo_Player &info)
|
||||||
|
|
||||||
// Non-builtin zones are hidden by default and can't be interacted
|
// Non-builtin zones are hidden by default and can't be interacted
|
||||||
// with, except through menus.
|
// with, except through menus.
|
||||||
// TODO: worry about this (later)
|
emit zone->setGraphicsVisibility(false);
|
||||||
// zone->setVisible(false);
|
|
||||||
|
|
||||||
emit addViewCustomZoneActionToCustomZoneMenu(zoneName);
|
emit addViewCustomZoneActionToCustomZoneMenu(zoneName);
|
||||||
|
|
||||||
|
|
@ -193,7 +204,7 @@ void Player::processPlayerInfo(const ServerInfo_Player &info)
|
||||||
addCounter(info.counter_list(i));
|
addCounter(info.counter_list(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
playerInfo->setConceded(info.properties().conceded());
|
setConceded(info.properties().conceded());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::processCardAttachment(const ServerInfo_Player &info)
|
void Player::processCardAttachment(const ServerInfo_Player &info)
|
||||||
|
|
@ -268,7 +279,7 @@ AbstractCounter *Player::addCounter(int counterId, const QString &name, QColor c
|
||||||
if (name == "life") {
|
if (name == "life") {
|
||||||
ctr = getGraphicsItem()->getPlayerTarget()->addCounter(counterId, name, value);
|
ctr = getGraphicsItem()->getPlayerTarget()->addCounter(counterId, name, value);
|
||||||
} else {
|
} else {
|
||||||
ctr = new GeneralCounter(this, counterId, name, color, radius, value, true, graphicsItem, game);
|
ctr = new GeneralCounter(this, counterId, name, color, radius, value, true, graphicsItem);
|
||||||
}
|
}
|
||||||
counters.insert(counterId, ctr);
|
counters.insert(counterId, ctr);
|
||||||
|
|
||||||
|
|
@ -387,8 +398,8 @@ ArrowItem *Player::addArrow(int arrowId, CardItem *startCard, ArrowTarget *targe
|
||||||
{
|
{
|
||||||
auto *arrow = new ArrowItem(this, arrowId, startCard, targetItem, color);
|
auto *arrow = new ArrowItem(this, arrowId, startCard, targetItem, color);
|
||||||
arrows.insert(arrowId, arrow);
|
arrows.insert(arrowId, arrow);
|
||||||
// TODO: consider this in the graphics item
|
|
||||||
// scene()->addItem(arrow);
|
getGameScene()->addItem(arrow);
|
||||||
return arrow;
|
return arrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -467,5 +478,5 @@ void Player::setGameStarted()
|
||||||
if (playerInfo->local) {
|
if (playerInfo->local) {
|
||||||
emit resetTopCardMenuActions();
|
emit resetTopCardMenuActions();
|
||||||
}
|
}
|
||||||
playerInfo->setConceded(false);
|
setConceded(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "../board/abstract_graphics_item.h"
|
#include "../board/abstract_graphics_item.h"
|
||||||
#include "../cards/card_info.h"
|
#include "../cards/card_info.h"
|
||||||
#include "../filters/filter_string.h"
|
#include "../filters/filter_string.h"
|
||||||
|
#include "../game.h"
|
||||||
#include "pb/card_attributes.pb.h"
|
#include "pb/card_attributes.pb.h"
|
||||||
#include "pb/game_event.pb.h"
|
#include "pb/game_event.pb.h"
|
||||||
#include "player_actions.h"
|
#include "player_actions.h"
|
||||||
|
|
@ -63,7 +64,8 @@ signals:
|
||||||
void deckChanged();
|
void deckChanged();
|
||||||
void newCardAdded(AbstractCardItem *card);
|
void newCardAdded(AbstractCardItem *card);
|
||||||
void rearrangeCounters();
|
void rearrangeCounters();
|
||||||
void activeChanged(bool _active);
|
void activeChanged(bool active);
|
||||||
|
void concededChanged(int playerId, bool conceded);
|
||||||
void clearCustomZonesMenu();
|
void clearCustomZonesMenu();
|
||||||
void addViewCustomZoneActionToCustomZoneMenu(QString zoneName);
|
void addViewCustomZoneActionToCustomZoneMenu(QString zoneName);
|
||||||
void resetTopCardMenuActions();
|
void resetTopCardMenuActions();
|
||||||
|
|
@ -72,7 +74,7 @@ public slots:
|
||||||
void setActive(bool _active);
|
void setActive(bool _active);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, TabGame *_parent);
|
Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, Game *_parent);
|
||||||
~Player() override;
|
~Player() override;
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
||||||
|
|
@ -93,7 +95,7 @@ public:
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
TabGame *getGame() const
|
Game *getGame() const
|
||||||
{
|
{
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
@ -202,6 +204,12 @@ public:
|
||||||
return arrows;
|
return arrows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setConceded(bool _conceded);
|
||||||
|
bool getConceded() const
|
||||||
|
{
|
||||||
|
return conceded;
|
||||||
|
}
|
||||||
|
|
||||||
void setGameStarted();
|
void setGameStarted();
|
||||||
|
|
||||||
void setDialogSemaphore(const bool _active)
|
void setDialogSemaphore(const bool _active)
|
||||||
|
|
@ -210,7 +218,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TabGame *game;
|
Game *game;
|
||||||
PlayerInfo *playerInfo;
|
PlayerInfo *playerInfo;
|
||||||
PlayerEventHandler *playerEventHandler;
|
PlayerEventHandler *playerEventHandler;
|
||||||
PlayerActions *playerActions;
|
PlayerActions *playerActions;
|
||||||
|
|
@ -218,6 +226,7 @@ private:
|
||||||
PlayerGraphicsItem *graphicsItem;
|
PlayerGraphicsItem *graphicsItem;
|
||||||
|
|
||||||
bool active;
|
bool active;
|
||||||
|
bool conceded;
|
||||||
|
|
||||||
DeckLoader *deck;
|
DeckLoader *deck;
|
||||||
|
|
||||||
|
|
@ -237,7 +246,7 @@ class AnnotationDialog : public QInputDialog
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AnnotationDialog(QWidget *parent) : QInputDialog(parent)
|
explicit AnnotationDialog(QWidget *parent = nullptr) : QInputDialog(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,8 @@ void PlayerActions::actViewTopCards()
|
||||||
{
|
{
|
||||||
int deckSize = player->getDeckZone()->getCards().size();
|
int deckSize = player->getDeckZone()->getCards().size();
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("View top cards of library"),
|
// TODO: Signal this
|
||||||
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("View top cards of library"),
|
||||||
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1,
|
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1,
|
||||||
deckSize, 1, &ok);
|
deckSize, 1, &ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
|
|
@ -159,7 +160,7 @@ void PlayerActions::actViewBottomCards()
|
||||||
{
|
{
|
||||||
int deckSize = player->getDeckZone()->getCards().size();
|
int deckSize = player->getDeckZone()->getCards().size();
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("View bottom cards of library"),
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("View bottom cards of library"),
|
||||||
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberBottomCards, 1,
|
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberBottomCards, 1,
|
||||||
deckSize, 1, &ok);
|
deckSize, 1, &ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
|
|
@ -232,7 +233,7 @@ void PlayerActions::actShuffleTop()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("Shuffle top cards of library"),
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Shuffle top cards of library"),
|
||||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
||||||
maxCards, 1, &ok);
|
maxCards, 1, &ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
|
@ -261,7 +262,7 @@ void PlayerActions::actShuffleBottom()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("Shuffle bottom cards of library"),
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Shuffle bottom cards of library"),
|
||||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
||||||
maxCards, 1, &ok);
|
maxCards, 1, &ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
|
@ -295,7 +296,7 @@ void PlayerActions::actMulligan()
|
||||||
int handSize = player->getHandZone()->getCards().size();
|
int handSize = player->getHandZone()->getCards().size();
|
||||||
int deckSize = player->getDeckZone()->getCards().size() + handSize; // hand is shuffled back into the deck
|
int deckSize = player->getDeckZone()->getCards().size() + handSize; // hand is shuffled back into the deck
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("Draw hand"),
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Draw hand"),
|
||||||
tr("Number of cards: (max. %1)").arg(deckSize) + '\n' +
|
tr("Number of cards: (max. %1)").arg(deckSize) + '\n' +
|
||||||
tr("0 and lower are in comparison to current hand size"),
|
tr("0 and lower are in comparison to current hand size"),
|
||||||
startSize, -handSize, deckSize, 1, &ok);
|
startSize, -handSize, deckSize, 1, &ok);
|
||||||
|
|
@ -321,9 +322,8 @@ void PlayerActions::actDrawCards()
|
||||||
{
|
{
|
||||||
int deckSize = player->getDeckZone()->getCards().size();
|
int deckSize = player->getDeckZone()->getCards().size();
|
||||||
bool ok;
|
bool ok;
|
||||||
int number =
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Draw cards"),
|
||||||
QInputDialog::getInt(player->getGame(), tr("Draw cards"), tr("Number of cards: (max. %1)").arg(deckSize),
|
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1, deckSize, 1, &ok);
|
||||||
defaultNumberTopCards, 1, deckSize, 1, &ok);
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
defaultNumberTopCards = number;
|
defaultNumberTopCards = number;
|
||||||
Command_DrawCards cmd;
|
Command_DrawCards cmd;
|
||||||
|
|
@ -393,7 +393,7 @@ void PlayerActions::actMoveTopCardsToGrave()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("Move top cards to grave"),
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Move top cards to grave"),
|
||||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
||||||
maxCards, 1, &ok);
|
maxCards, 1, &ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
|
@ -425,7 +425,7 @@ void PlayerActions::actMoveTopCardsToExile()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("Move top cards to exile"),
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Move top cards to exile"),
|
||||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
||||||
maxCards, 1, &ok);
|
maxCards, 1, &ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
|
@ -453,7 +453,7 @@ void PlayerActions::actMoveTopCardsUntil()
|
||||||
{
|
{
|
||||||
stopMoveTopCardsUntil();
|
stopMoveTopCardsUntil();
|
||||||
|
|
||||||
DlgMoveTopCardsUntil dlg(player->getGame(), movingCardsUntilExprs, movingCardsUntilNumberOfHits,
|
DlgMoveTopCardsUntil dlg(/* player->getGame() */ nullptr, movingCardsUntilExprs, movingCardsUntilNumberOfHits,
|
||||||
movingCardsUntilAutoPlay);
|
movingCardsUntilAutoPlay);
|
||||||
if (!dlg.exec()) {
|
if (!dlg.exec()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -597,7 +597,7 @@ void PlayerActions::actMoveBottomCardsToGrave()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("Move bottom cards to grave"),
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Move bottom cards to grave"),
|
||||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
||||||
maxCards, 1, &ok);
|
maxCards, 1, &ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
|
@ -629,7 +629,7 @@ void PlayerActions::actMoveBottomCardsToExile()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("Move bottom cards to exile"),
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Move bottom cards to exile"),
|
||||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
||||||
maxCards, 1, &ok);
|
maxCards, 1, &ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
|
@ -746,9 +746,8 @@ void PlayerActions::actDrawBottomCards()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int number =
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Draw bottom cards"),
|
||||||
QInputDialog::getInt(player->getGame(), tr("Draw bottom cards"), tr("Number of cards: (max. %1)").arg(maxCards),
|
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1, maxCards, 1, &ok);
|
||||||
defaultNumberBottomCards, 1, maxCards, 1, &ok);
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return;
|
return;
|
||||||
} else if (number > maxCards) {
|
} else if (number > maxCards) {
|
||||||
|
|
@ -820,7 +819,7 @@ void PlayerActions::actUntapAll()
|
||||||
|
|
||||||
void PlayerActions::actRollDie()
|
void PlayerActions::actRollDie()
|
||||||
{
|
{
|
||||||
DlgRollDice dlg(player->getGame());
|
DlgRollDice dlg(/* player->getGame() */ nullptr);
|
||||||
if (!dlg.exec()) {
|
if (!dlg.exec()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -833,7 +832,7 @@ void PlayerActions::actRollDie()
|
||||||
|
|
||||||
void PlayerActions::actCreateToken()
|
void PlayerActions::actCreateToken()
|
||||||
{
|
{
|
||||||
DlgCreateToken dlg(player->getPlayerMenu()->getPredefinedTokens(), player->getGame());
|
DlgCreateToken dlg(player->getPlayerMenu()->getPredefinedTokens(), /* player->getGame() */ nullptr);
|
||||||
if (!dlg.exec()) {
|
if (!dlg.exec()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1021,7 +1020,7 @@ bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard, const
|
||||||
if (cardRelation->getIsVariable()) {
|
if (cardRelation->getIsVariable()) {
|
||||||
bool ok;
|
bool ok;
|
||||||
player->setDialogSemaphore(true);
|
player->setDialogSemaphore(true);
|
||||||
int count = QInputDialog::getInt(player->getGame(), tr("Create tokens"), tr("Number:"),
|
int count = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Create tokens"), tr("Number:"),
|
||||||
cardRelation->getDefaultCount(), 1, MAX_TOKENS_PER_DIALOG, 1, &ok);
|
cardRelation->getDefaultCount(), 1, MAX_TOKENS_PER_DIALOG, 1, &ok);
|
||||||
player->setDialogSemaphore(false);
|
player->setDialogSemaphore(false);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
|
@ -1187,7 +1186,7 @@ void PlayerActions::actMoveCardXCardsFromTop()
|
||||||
int deckSize = player->getDeckZone()->getCards().size() + 1; // add the card to move to the deck
|
int deckSize = player->getDeckZone()->getCards().size() + 1; // add the card to move to the deck
|
||||||
bool ok;
|
bool ok;
|
||||||
int number =
|
int number =
|
||||||
QInputDialog::getInt(player->getGame(), tr("Place card X cards from top of library"),
|
QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Place card X cards from top of library"),
|
||||||
tr("Which position should this card be placed:") + "\n" + tr("(max. %1)").arg(deckSize),
|
tr("Which position should this card be placed:") + "\n" + tr("(max. %1)").arg(deckSize),
|
||||||
defaultNumberTopCardsToPlaceBelow, 1, deckSize, 1, &ok);
|
defaultNumberTopCardsToPlaceBelow, 1, deckSize, 1, &ok);
|
||||||
number -= 1; // indexes start at 0
|
number -= 1; // indexes start at 0
|
||||||
|
|
@ -1347,7 +1346,7 @@ void PlayerActions::actSetPT()
|
||||||
}
|
}
|
||||||
bool ok;
|
bool ok;
|
||||||
player->setDialogSemaphore(true);
|
player->setDialogSemaphore(true);
|
||||||
QString pt = getTextWithMax(player->getGame(), tr("Change power/toughness"), tr("Change stats to:"),
|
QString pt = getTextWithMax(/* player->getGame() */ nullptr, tr("Change power/toughness"), tr("Change stats to:"),
|
||||||
QLineEdit::Normal, oldPT, &ok);
|
QLineEdit::Normal, oldPT, &ok);
|
||||||
player->setDialogSemaphore(false);
|
player->setDialogSemaphore(false);
|
||||||
if (player->clearCardsToDelete() || !ok) {
|
if (player->clearCardsToDelete() || !ok) {
|
||||||
|
|
@ -1465,7 +1464,7 @@ void PlayerActions::actSetAnnotation()
|
||||||
}
|
}
|
||||||
|
|
||||||
player->setDialogSemaphore(true);
|
player->setDialogSemaphore(true);
|
||||||
AnnotationDialog *dialog = new AnnotationDialog(player->getGame());
|
AnnotationDialog *dialog = new AnnotationDialog(/* player->getGame() */);
|
||||||
dialog->setOptions(QInputDialog::UsePlainTextEditForTextInput);
|
dialog->setOptions(QInputDialog::UsePlainTextEditForTextInput);
|
||||||
dialog->setWindowTitle(tr("Set annotation"));
|
dialog->setWindowTitle(tr("Set annotation"));
|
||||||
dialog->setLabelText(tr("Please enter the new annotation:"));
|
dialog->setLabelText(tr("Please enter the new annotation:"));
|
||||||
|
|
@ -1561,8 +1560,8 @@ void PlayerActions::actCardCounterTrigger()
|
||||||
auto *card = static_cast<CardItem *>(player->getGameScene()->selectedItems().first());
|
auto *card = static_cast<CardItem *>(player->getGameScene()->selectedItems().first());
|
||||||
oldValue = card->getCounters().value(counterId, 0);
|
oldValue = card->getCounters().value(counterId, 0);
|
||||||
}
|
}
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("Set counters"), tr("Number:"), oldValue, 0,
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Set counters"), tr("Number:"),
|
||||||
MAX_COUNTERS_ON_CARD, 1, &ok);
|
oldValue, 0, MAX_COUNTERS_ON_CARD, 1, &ok);
|
||||||
player->setDialogSemaphore(false);
|
player->setDialogSemaphore(false);
|
||||||
if (player->clearCardsToDelete() || !ok) {
|
if (player->clearCardsToDelete() || !ok) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ PlayerGraphicsItem::PlayerGraphicsItem(Player *_player) : player(_player)
|
||||||
|
|
||||||
playerArea = new PlayerArea(this);
|
playerArea = new PlayerArea(this);
|
||||||
|
|
||||||
playerTarget = new PlayerTarget(player, playerArea, player->getGame());
|
playerTarget = new PlayerTarget(player, playerArea);
|
||||||
qreal avatarMargin = (counterAreaWidth + CARD_HEIGHT + 15 - playerTarget->boundingRect().width()) / 2.0;
|
qreal avatarMargin = (counterAreaWidth + CARD_HEIGHT + 15 - playerTarget->boundingRect().width()) / 2.0;
|
||||||
playerTarget->setPos(QPointF(avatarMargin, avatarMargin));
|
playerTarget->setPos(QPointF(avatarMargin, avatarMargin));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,12 @@
|
||||||
#include "player_info.h"
|
#include "player_info.h"
|
||||||
|
|
||||||
PlayerInfo::PlayerInfo(const ServerInfo_User &info, int _id, bool _local, bool _judge)
|
PlayerInfo::PlayerInfo(const ServerInfo_User &info, int _id, bool _local, bool _judge)
|
||||||
: id(_id), local(_local), judge(_judge), handVisible(false), conceded(false), zoneId(0)
|
: id(_id), local(_local), judge(_judge), handVisible(false), zoneId(0)
|
||||||
{
|
{
|
||||||
userInfo = new ServerInfo_User;
|
userInfo = new ServerInfo_User;
|
||||||
userInfo->CopyFrom(info);
|
userInfo->CopyFrom(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerInfo::setConceded(bool _conceded)
|
|
||||||
{
|
|
||||||
conceded = _conceded;
|
|
||||||
// TODO: deal with this
|
|
||||||
/*setVisible(!conceded);
|
|
||||||
if (conceded) {
|
|
||||||
clear();
|
|
||||||
}
|
|
||||||
emit playerCountChanged();*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerInfo::setZoneId(int _zoneId)
|
void PlayerInfo::setZoneId(int _zoneId)
|
||||||
{
|
{
|
||||||
// TODO: deal with this
|
// TODO: deal with this
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ public:
|
||||||
bool local;
|
bool local;
|
||||||
bool judge;
|
bool judge;
|
||||||
bool handVisible;
|
bool handVisible;
|
||||||
bool conceded;
|
|
||||||
int zoneId;
|
int zoneId;
|
||||||
|
|
||||||
int getZoneId() const
|
int getZoneId() const
|
||||||
|
|
@ -32,12 +31,6 @@ public:
|
||||||
|
|
||||||
void setZoneId(int _zoneId);
|
void setZoneId(int _zoneId);
|
||||||
|
|
||||||
void setConceded(bool _conceded);
|
|
||||||
bool getConceded() const
|
|
||||||
{
|
|
||||||
return conceded;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getId() const
|
int getId() const
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,7 @@ bool PlayerListTWI::operator<(const QTreeWidgetItem &other) const
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor,
|
PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor,
|
||||||
AbstractClient *_client,
|
AbstractClient *_client, Game *_game, QWidget *parent)
|
||||||
TabGame *_game,
|
|
||||||
QWidget *parent)
|
|
||||||
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false)
|
: QTreeWidget(parent), tabSupervisor(_tabSupervisor), client(_client), game(_game), gameStarted(false)
|
||||||
{
|
{
|
||||||
readyIcon = QPixmap("theme:icons/ready_start");
|
readyIcon = QPixmap("theme:icons/ready_start");
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
class ServerInfo_PlayerProperties;
|
class ServerInfo_PlayerProperties;
|
||||||
class TabSupervisor;
|
class TabSupervisor;
|
||||||
class AbstractClient;
|
class AbstractClient;
|
||||||
class TabGame;
|
class Game;
|
||||||
class UserContextMenu;
|
class UserContextMenu;
|
||||||
|
|
||||||
class PlayerListItemDelegate : public QStyledItemDelegate
|
class PlayerListItemDelegate : public QStyledItemDelegate
|
||||||
|
|
@ -39,7 +39,7 @@ private:
|
||||||
QMap<int, QTreeWidgetItem *> players;
|
QMap<int, QTreeWidgetItem *> players;
|
||||||
TabSupervisor *tabSupervisor;
|
TabSupervisor *tabSupervisor;
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
TabGame *game;
|
Game *game;
|
||||||
UserContextMenu *userContextMenu;
|
UserContextMenu *userContextMenu;
|
||||||
QIcon readyIcon, notReadyIcon, concededIcon, playerIcon, judgeIcon, spectatorIcon, lockIcon;
|
QIcon readyIcon, notReadyIcon, concededIcon, playerIcon, judgeIcon, spectatorIcon, lockIcon;
|
||||||
bool gameStarted;
|
bool gameStarted;
|
||||||
|
|
@ -47,7 +47,7 @@ signals:
|
||||||
void openMessageDialog(const QString &userName, bool focus);
|
void openMessageDialog(const QString &userName, bool focus);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent = nullptr);
|
PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, Game *_game, QWidget *parent = nullptr);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void setActivePlayer(int playerId);
|
void setActivePlayer(int playerId);
|
||||||
void setGameStarted(bool _gameStarted, bool resuming);
|
void setGameStarted(bool _gameStarted, bool resuming);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,80 @@
|
||||||
#include "player_manager.h"
|
#include "player_manager.h"
|
||||||
|
|
||||||
PlayerManager::PlayerManager(QObject *parent, int _localPlayerId, bool _localPlayerIsJudge, bool localPlayerIsSpectator)
|
#include "../game.h"
|
||||||
: QObject(parent), localPlayerId(_localPlayerId), localPlayerIsJudge(_localPlayerIsJudge),
|
#include "player.h"
|
||||||
localPlayerIsSpectator(localPlayerIsSpectator)
|
|
||||||
|
PlayerManager::PlayerManager(Game *_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), 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,21 +1,26 @@
|
||||||
#ifndef COCKATRICE_PLAYER_MANAGER_H
|
#ifndef COCKATRICE_PLAYER_MANAGER_H
|
||||||
#define COCKATRICE_PLAYER_MANAGER_H
|
#define COCKATRICE_PLAYER_MANAGER_H
|
||||||
|
|
||||||
#include "player.h"
|
#include "pb/serverinfo_playerproperties.pb.h"
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
class Game;
|
||||||
|
class Player;
|
||||||
class PlayerManager : public QObject
|
class PlayerManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlayerManager(QObject *parent, int _localPlayerId, bool _localPlayerIsJudge, bool localPlayerIsSpectator);
|
PlayerManager(Game *_game, int _localPlayerId, bool _localPlayerIsJudge, bool localPlayerIsSpectator);
|
||||||
|
|
||||||
|
Game *game;
|
||||||
QMap<int, Player *> players;
|
QMap<int, Player *> players;
|
||||||
int localPlayerId;
|
int localPlayerId;
|
||||||
bool localPlayerIsJudge;
|
bool localPlayerIsJudge;
|
||||||
bool localPlayerIsSpectator;
|
bool localPlayerIsSpectator;
|
||||||
|
QMap<int, ServerInfo_User> spectators;
|
||||||
|
|
||||||
bool isSpectator() const
|
bool isSpectator() const
|
||||||
{
|
{
|
||||||
|
|
@ -42,66 +47,68 @@ public:
|
||||||
return players.size();
|
return players.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Player *getActiveLocalPlayer(int activePlayer) const
|
Player *getActiveLocalPlayer(int activePlayer) const;
|
||||||
{
|
|
||||||
Player *active = players.value(activePlayer, 0);
|
|
||||||
if (active)
|
|
||||||
if (active->getPlayerInfo()->getLocal())
|
|
||||||
return active;
|
|
||||||
|
|
||||||
QMapIterator<int, Player *> playerIterator(players);
|
Player *addPlayer(int playerId, const ServerInfo_User &info);
|
||||||
while (playerIterator.hasNext()) {
|
|
||||||
Player *temp = playerIterator.next().value();
|
|
||||||
if (temp->getPlayerInfo()->getLocal())
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
void removePlayer(int playerId);
|
||||||
}
|
|
||||||
|
|
||||||
Player *addPlayer(int playerId, const ServerInfo_User &info, TabGame *game)
|
Player *getPlayer(int playerId) const;
|
||||||
{
|
|
||||||
auto *newPlayer = new Player(info, playerId, isLocalPlayer(playerId), isJudge(), game);
|
|
||||||
players.insert(playerId, newPlayer);
|
|
||||||
emit playerAdded(newPlayer);
|
|
||||||
emit playerCountChanged();
|
|
||||||
return newPlayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removePlayer(int playerId)
|
void onPlayerConceded(int playerId, bool conceded);
|
||||||
{
|
|
||||||
Player *player = getPlayer(playerId);
|
|
||||||
if (!player) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
players.remove(playerId);
|
|
||||||
emit playerCountChanged();
|
|
||||||
emit playerRemoved(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
Player *getPlayer(int playerId) const
|
[[nodiscard]] bool isMainPlayerConceded() const;
|
||||||
{
|
|
||||||
Player *player = players.value(playerId, 0);
|
|
||||||
if (!player)
|
|
||||||
return nullptr;
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool isMainPlayerConceded() const
|
|
||||||
{
|
|
||||||
Player *player = players.value(localPlayerId, nullptr);
|
|
||||||
return player && player->getPlayerInfo()->getConceded();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool isLocalPlayer(int playerId) const
|
[[nodiscard]] bool isLocalPlayer(int playerId) const
|
||||||
{
|
{
|
||||||
return playerId == getLocalPlayerId();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Game *getGame() const
|
||||||
|
{
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void playerAdded(Player *player);
|
void playerAdded(Player *player);
|
||||||
void playerRemoved(Player *player);
|
void playerRemoved(Player *player);
|
||||||
|
void activeLocalPlayerConceded();
|
||||||
|
void activeLocalPlayerUnconceded();
|
||||||
|
void playerConceded(int playerId);
|
||||||
|
void playerUnconceded(int playerId);
|
||||||
void playerCountChanged();
|
void playerCountChanged();
|
||||||
|
void spectatorAdded(ServerInfo_PlayerProperties spectator);
|
||||||
|
void spectatorRemoved(int spectatorId, ServerInfo_User spectator);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COCKATRICE_PLAYER_MANAGER_H
|
#endif // COCKATRICE_PLAYER_MANAGER_H
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,8 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
||||||
// TODO
|
connect(player->getGame()->getPlayerManager(), &PlayerManager::playerAdded, this, &PlayerMenu::addPlayer);
|
||||||
// connect(_parent, &TabGame::playerAdded, this, &Player::addPlayer);
|
connect(player->getGame()->getPlayerManager(), &PlayerManager::playerRemoved, this, &PlayerMenu::removePlayer);
|
||||||
// connect(_parent, &TabGame::playerRemoved, this, &Player::removePlayer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<Player *> &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
const QList<Player *> &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||||
|
|
@ -520,7 +519,8 @@ void PlayerMenu::playerListActionTriggered()
|
||||||
} else if (menu == mRevealTopCard) {
|
} else if (menu == mRevealTopCard) {
|
||||||
int deckSize = player->getDeckZone()->getCards().size();
|
int deckSize = player->getDeckZone()->getCards().size();
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = QInputDialog::getInt(player->getGame(), tr("Reveal top cards of library"),
|
// TODO: Correctly parent this
|
||||||
|
int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Reveal top cards of library"),
|
||||||
tr("Number of cards: (max. %1)").arg(deckSize), /* defaultNumberTopCards */ 1,
|
tr("Number of cards: (max. %1)").arg(deckSize), /* defaultNumberTopCards */ 1,
|
||||||
1, deckSize, 1, &ok);
|
1, deckSize, 1, &ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
|
|
@ -821,8 +821,10 @@ void PlayerMenu::addRelatedCardView(const CardItem *card, QMenu *cardMenu)
|
||||||
QString relatedCardName = relatedCard->getName();
|
QString relatedCardName = relatedCard->getName();
|
||||||
CardRef cardRef = {relatedCardName, exactCard.getPrinting().getUuid()};
|
CardRef cardRef = {relatedCardName, exactCard.getPrinting().getUuid()};
|
||||||
QAction *viewCard = viewRelatedCards->addAction(relatedCardName);
|
QAction *viewCard = viewRelatedCards->addAction(relatedCardName);
|
||||||
connect(viewCard, &QAction::triggered, player->getGame(),
|
Q_UNUSED(viewCard);
|
||||||
[this, cardRef] { player->getGame()->viewCardInfo(cardRef); });
|
// TODO: Signal this
|
||||||
|
/*connect(viewCard, &QAction::triggered, player->getGame(),
|
||||||
|
[this, cardRef] { player->getGame()->viewCardInfo(cardRef); });*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1200,7 +1202,8 @@ void PlayerMenu::setShortcutsActive()
|
||||||
if (!player->getGame()->getGameState()->getIsLocalGame()) {
|
if (!player->getGame()->getGameState()->getIsLocalGame()) {
|
||||||
// unattach action is only active in card menu if the active card is attached.
|
// unattach action is only active in card menu if the active card is attached.
|
||||||
// make unattach shortcut always active so that it consistently works when multiple cards are selected.
|
// make unattach shortcut always active so that it consistently works when multiple cards are selected.
|
||||||
player->getGame()->addAction(aUnattach);
|
// TODO: Signal this
|
||||||
|
// player->getGame()->addAction(aUnattach);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,8 @@
|
||||||
PlayerCounter::PlayerCounter(Player *_player,
|
PlayerCounter::PlayerCounter(Player *_player,
|
||||||
int _id,
|
int _id,
|
||||||
const QString &_name,
|
const QString &_name,
|
||||||
int _value,
|
int _value, QGraphicsItem *parent)
|
||||||
QGraphicsItem *parent,
|
: AbstractCounter(_player, _id, _name, false, _value, false, parent)
|
||||||
QWidget *game)
|
|
||||||
: AbstractCounter(_player, _id, _name, false, _value, false, parent, game)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,8 +50,8 @@ void PlayerCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*
|
||||||
painter->drawText(translatedRect, Qt::AlignCenter, QString::number(value));
|
painter->drawText(translatedRect, Qt::AlignCenter, QString::number(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem, QWidget *_game)
|
PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem)
|
||||||
: ArrowTarget(_owner, parentItem), playerCounter(nullptr), game(_game)
|
: ArrowTarget(_owner, parentItem), playerCounter(nullptr)
|
||||||
{
|
{
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
|
||||||
|
|
@ -160,7 +158,7 @@ AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name,
|
||||||
playerCounter->delCounter();
|
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(),
|
playerCounter->setPos(boundingRect().width() - playerCounter->boundingRect().width(),
|
||||||
boundingRect().height() - playerCounter->boundingRect().height());
|
boundingRect().height() - playerCounter->boundingRect().height());
|
||||||
connect(playerCounter, &PlayerCounter::destroyed, this, &PlayerTarget::counterDeleted);
|
connect(playerCounter, &PlayerCounter::destroyed, this, &PlayerTarget::counterDeleted);
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,7 @@ class PlayerCounter : public AbstractCounter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
PlayerCounter(Player *_player,
|
PlayerCounter(Player *_player, int _id, const QString &_name, int _value, QGraphicsItem *parent = nullptr);
|
||||||
int _id,
|
|
||||||
const QString &_name,
|
|
||||||
int _value,
|
|
||||||
QGraphicsItem *parent = nullptr,
|
|
||||||
QWidget *game = nullptr);
|
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
};
|
};
|
||||||
|
|
@ -30,7 +25,6 @@ class PlayerTarget : public ArrowTarget
|
||||||
private:
|
private:
|
||||||
QPixmap fullPixmap;
|
QPixmap fullPixmap;
|
||||||
PlayerCounter *playerCounter;
|
PlayerCounter *playerCounter;
|
||||||
QWidget *game;
|
|
||||||
public slots:
|
public slots:
|
||||||
void counterDeleted();
|
void counterDeleted();
|
||||||
|
|
||||||
|
|
@ -44,7 +38,7 @@ public:
|
||||||
return Type;
|
return Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit PlayerTarget(Player *_player = nullptr, QGraphicsItem *parentItem = nullptr, QWidget *_game = nullptr);
|
explicit PlayerTarget(Player *_player = nullptr, QGraphicsItem *parentItem = nullptr);
|
||||||
~PlayerTarget() override;
|
~PlayerTarget() override;
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ CardZone::CardZone(CardZoneLogic *_logic, QGraphicsItem *parent)
|
||||||
{
|
{
|
||||||
connect(logic, &CardZoneLogic::retranslateUi, this, &CardZone::retranslateUi);
|
connect(logic, &CardZoneLogic::retranslateUi, this, &CardZone::retranslateUi);
|
||||||
connect(logic, &CardZoneLogic::cardAdded, this, &CardZone::onCardAdded);
|
connect(logic, &CardZoneLogic::cardAdded, this, &CardZone::onCardAdded);
|
||||||
|
connect(logic, &CardZoneLogic::setGraphicsVisibility, this, [this](bool v) { this->setVisible(v); });
|
||||||
connect(logic, &CardZoneLogic::updateGraphics, this, [this]() { update(); });
|
connect(logic, &CardZoneLogic::updateGraphics, this, [this]() { update(); });
|
||||||
connect(logic, &CardZoneLogic::reorganizeCards, this, &CardZone::reorganizeCards);
|
connect(logic, &CardZoneLogic::reorganizeCards, this, &CardZone::reorganizeCards);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ signals:
|
||||||
void cardCountChanged();
|
void cardCountChanged();
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void updateGraphics();
|
void updateGraphics();
|
||||||
|
void setGraphicsVisibility(bool visible);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ UserMessagePosition::UserMessagePosition(QTextCursor &cursor)
|
||||||
relativePosition = cursor.position() - block.position();
|
relativePosition = cursor.position() - block.position();
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatView::ChatView(TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent)
|
ChatView::ChatView(TabSupervisor *_tabSupervisor, Game *_game, bool _showTimestamps, QWidget *parent)
|
||||||
: QTextBrowser(parent), tabSupervisor(_tabSupervisor), game(_game),
|
: QTextBrowser(parent), tabSupervisor(_tabSupervisor), game(_game),
|
||||||
userListProxy(_tabSupervisor->getUserListManager()), evenNumber(true), showTimestamps(_showTimestamps),
|
userListProxy(_tabSupervisor->getUserListManager()), evenNumber(true), showTimestamps(_showTimestamps),
|
||||||
hoveredItemType(HoveredNothing)
|
hoveredItemType(HoveredNothing)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class QTextTable;
|
||||||
class QMouseEvent;
|
class QMouseEvent;
|
||||||
class UserContextMenu;
|
class UserContextMenu;
|
||||||
class UserListProxy;
|
class UserListProxy;
|
||||||
class TabGame;
|
class Game;
|
||||||
|
|
||||||
class UserMessagePosition
|
class UserMessagePosition
|
||||||
{
|
{
|
||||||
|
|
@ -34,7 +34,7 @@ class ChatView : public QTextBrowser
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
TabSupervisor *const tabSupervisor;
|
TabSupervisor *const tabSupervisor;
|
||||||
TabGame *const game;
|
Game *const game;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum HoveredItemType
|
enum HoveredItemType
|
||||||
|
|
@ -83,7 +83,7 @@ private slots:
|
||||||
void actMessageClicked();
|
void actMessageClicked();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChatView(TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent = nullptr);
|
ChatView(TabSupervisor *_tabSupervisor, Game *_game, bool _showTimestamps, QWidget *parent = nullptr);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void appendHtml(const QString &html);
|
void appendHtml(const QString &html);
|
||||||
void virtual appendHtmlServerMessage(const QString &html,
|
void virtual appendHtmlServerMessage(const QString &html,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "message_log_widget.h"
|
#include "message_log_widget.h"
|
||||||
|
|
||||||
#include "../client/sound_engine.h"
|
#include "../client/sound_engine.h"
|
||||||
|
#include "../client/tabs/tab_game.h"
|
||||||
#include "../client/translate_counter_name.h"
|
#include "../client/translate_counter_name.h"
|
||||||
#include "../game/board/card_item.h"
|
#include "../game/board/card_item.h"
|
||||||
#include "../game/phase.h"
|
#include "../game/phase.h"
|
||||||
|
|
@ -141,18 +142,22 @@ void MessageLogWidget::logAttachCard(Player *player, QString cardName, Player *t
|
||||||
.arg(cardLink(std::move(targetCardName))));
|
.arg(cardLink(std::move(targetCardName))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLogWidget::logConcede(Player *player)
|
void MessageLogWidget::logConcede(int playerId)
|
||||||
{
|
{
|
||||||
soundEngine->playSound("player_concede");
|
soundEngine->playSound("player_concede");
|
||||||
appendHtmlServerMessage(tr("%1 has conceded the game.").arg(sanitizeHtml(player->getPlayerInfo()->getName())),
|
appendHtmlServerMessage(
|
||||||
true);
|
tr("%1 has conceded the game.")
|
||||||
|
.arg(sanitizeHtml(game->getPlayerManager()->getPlayer(playerId)->getPlayerInfo()->getName())),
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLogWidget::logUnconcede(Player *player)
|
void MessageLogWidget::logUnconcede(int playerId)
|
||||||
{
|
{
|
||||||
soundEngine->playSound("player_concede");
|
soundEngine->playSound("player_concede");
|
||||||
appendHtmlServerMessage(tr("%1 has unconceded the game.").arg(sanitizeHtml(player->getPlayerInfo()->getName())),
|
appendHtmlServerMessage(
|
||||||
true);
|
tr("%1 has unconceded the game.")
|
||||||
|
.arg(sanitizeHtml(game->getPlayerManager()->getPlayer(playerId)->getPlayerInfo()->getName())),
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLogWidget::logConnectionStateChanged(Player *player, bool connectionState)
|
void MessageLogWidget::logConnectionStateChanged(Player *player, bool connectionState)
|
||||||
|
|
@ -834,7 +839,7 @@ void MessageLogWidget::connectToPlayerEventHandler(PlayerEventHandler *playerEve
|
||||||
// &PlayerEventHandler::logAlwaysLookAtTopCard, this, &MessageLogWidget::logAlwaysLookAtTopCard);
|
// &PlayerEventHandler::logAlwaysLookAtTopCard, this, &MessageLogWidget::logAlwaysLookAtTopCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent)
|
MessageLogWidget::MessageLogWidget(TabSupervisor *_tabSupervisor, Game *_game, QWidget *parent)
|
||||||
: ChatView(_tabSupervisor, _game, true, parent), currentContext(MessageContext_None)
|
: ChatView(_tabSupervisor, _game, true, parent), currentContext(MessageContext_None)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
class Player;
|
class Player;
|
||||||
class PlayerEventHandler;
|
class PlayerEventHandler;
|
||||||
class CardZone;
|
class CardZone;
|
||||||
|
class Game;
|
||||||
class GameEventContext;
|
class GameEventContext;
|
||||||
class CardItem;
|
class CardItem;
|
||||||
|
|
||||||
|
|
@ -27,14 +28,18 @@ private:
|
||||||
|
|
||||||
static QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange);
|
static QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void connectToPlayerEventHandler(PlayerEventHandler *player);
|
||||||
|
MessageLogWidget(TabSupervisor *_tabSupervisor, Game *_game, QWidget *parent = nullptr);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void containerProcessingDone();
|
void containerProcessingDone();
|
||||||
void containerProcessingStarted(const GameEventContext &context);
|
void containerProcessingStarted(const GameEventContext &context);
|
||||||
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
|
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
|
||||||
void logAlwaysLookAtTopCard(Player *player, CardZone *zone, bool reveal);
|
void logAlwaysLookAtTopCard(Player *player, CardZone *zone, bool reveal);
|
||||||
void logAttachCard(Player *player, QString cardName, Player *targetPlayer, QString targetCardName);
|
void logAttachCard(Player *player, QString cardName, Player *targetPlayer, QString targetCardName);
|
||||||
void logConcede(Player *player);
|
void logConcede(int playerId);
|
||||||
void logUnconcede(Player *player);
|
void logUnconcede(int playerId);
|
||||||
void logConnectionStateChanged(Player *player, bool connectionState);
|
void logConnectionStateChanged(Player *player, bool connectionState);
|
||||||
void logCreateArrow(Player *player,
|
void logCreateArrow(Player *player,
|
||||||
Player *startPlayer,
|
Player *startPlayer,
|
||||||
|
|
@ -89,10 +94,6 @@ public slots:
|
||||||
void appendHtmlServerMessage(const QString &html,
|
void appendHtmlServerMessage(const QString &html,
|
||||||
bool optionalIsBold = false,
|
bool optionalIsBold = false,
|
||||||
QString optionalFontColor = QString()) override;
|
QString optionalFontColor = QString()) override;
|
||||||
|
|
||||||
public:
|
|
||||||
void connectToPlayerEventHandler(PlayerEventHandler *player);
|
|
||||||
MessageLogWidget(TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent = nullptr);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|
||||||
UserContextMenu::UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *parent, TabGame *_game)
|
UserContextMenu::UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *parent, Game *_game)
|
||||||
: QObject(parent), client(_tabSupervisor->getClient()), tabSupervisor(_tabSupervisor),
|
: QObject(parent), client(_tabSupervisor->getClient()), tabSupervisor(_tabSupervisor),
|
||||||
userListProxy(_tabSupervisor->getUserListManager()), game(_game)
|
userListProxy(_tabSupervisor->getUserListManager()), game(_game)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class QMenu;
|
||||||
class QPoint;
|
class QPoint;
|
||||||
class Response;
|
class Response;
|
||||||
class ServerInfo_User;
|
class ServerInfo_User;
|
||||||
class TabGame;
|
class Game;
|
||||||
class TabSupervisor;
|
class TabSupervisor;
|
||||||
|
|
||||||
class UserContextMenu : public QObject
|
class UserContextMenu : public QObject
|
||||||
|
|
@ -24,7 +24,7 @@ private:
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
TabSupervisor *tabSupervisor;
|
TabSupervisor *tabSupervisor;
|
||||||
const UserListProxy *userListProxy;
|
const UserListProxy *userListProxy;
|
||||||
TabGame *game;
|
Game *game;
|
||||||
|
|
||||||
QAction *aUserName;
|
QAction *aUserName;
|
||||||
QAction *aDetails;
|
QAction *aDetails;
|
||||||
|
|
@ -54,7 +54,7 @@ private slots:
|
||||||
void gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer);
|
void gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *_parent, TabGame *_game = 0);
|
UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *_parent, Game *_game = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void showContextMenu(const QPoint &pos,
|
void showContextMenu(const QPoint &pos,
|
||||||
const QString &userName,
|
const QString &userName,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue