Commit 564ae4db authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

some cleanups and fixes

parent 6ba2e983
......@@ -50,6 +50,7 @@ HEADERS += src/counter.h \
src/remotedecklist_treewidget.h \
src/deckview.h \
src/playerlistwidget.h \
src/pingpixmapgenerator.h \
../common/serializable_item.h \
../common/decklist.h \
../common/protocol.h \
......@@ -99,6 +100,7 @@ SOURCES += src/counter.cpp \
src/remotedecklist_treewidget.cpp \
src/deckview.cpp \
src/playerlistwidget.cpp \
src/pingpixmapgenerator.cpp \
../common/serializable_item.cpp \
../common/decklist.cpp \
../common/protocol.cpp \
......
......@@ -37,7 +37,7 @@
CardDatabase *db;
QTranslator *translator;
void myMessageOutput(QtMsgType type, const char *msg)
void myMessageOutput(QtMsgType /*type*/, const char *msg)
{
static FILE *f = NULL;
if (!f)
......
#include "pingpixmapgenerator.h"
#include <QPainter>
QPixmap PingPixmapGenerator::generatePixmap(int size, int value, int max)
{
QPixmap pixmap(size, size);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
QColor color;
if (max == -1)
color = Qt::black;
else
color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255);
QRadialGradient g(QPointF((double) pixmap.width() / 2, (double) pixmap.height() / 2), qMin(pixmap.width(), pixmap.height()) / 2.0);
g.setColorAt(0, color);
g.setColorAt(1, Qt::transparent);
painter.fillRect(0, 0, pixmap.width(), pixmap.height(), QBrush(g));
return pixmap;
}
#ifndef PINGPIXMAPGENERATOR_H
#define PINGPIXMAPGENERATOR_H
#include <QPixmap>
class PingPixmapGenerator {
public:
static QPixmap generatePixmap(int size, int value, int max);
};
#endif
......@@ -363,22 +363,6 @@ void Player::initSayMenu()
}
}
void Player::prepareForGame()
{
if (local) {
sendGameCommand(new Command_CreateCounter(-1, "life", Qt::white, 25, 20));
sendGameCommand(new Command_CreateCounter(-1, "w", QColor(255, 255, 150), 20, 0));
sendGameCommand(new Command_CreateCounter(-1, "u", QColor(150, 150, 255), 20, 0));
sendGameCommand(new Command_CreateCounter(-1, "b", QColor(150, 150, 150), 20, 0));
sendGameCommand(new Command_CreateCounter(-1, "r", QColor(250, 150, 150), 20, 0));
sendGameCommand(new Command_CreateCounter(-1, "g", QColor(150, 255, 150), 20, 0));
sendGameCommand(new Command_CreateCounter(-1, "x", QColor(255, 255, 255), 20, 0));
sendGameCommand(new Command_CreateCounter(-1, "storm", QColor(255, 255, 255), 20, 0));
mulliganCards = 7;
}
}
void Player::actViewLibrary()
{
emit toggleZoneView(this, "deck", -1);
......@@ -421,14 +405,7 @@ void Player::actDrawCard()
void Player::actMulligan()
{
if (mulliganCards <= 0)
return;
const CardList &handCards = hand->getCards();
for (int i = 0; i < handCards.size(); i++)
sendGameCommand(new Command_MoveCard(-1, "hand", handCards.at(i)->getId(), "deck", 0, -1, false));
sendGameCommand(new Command_Shuffle);
sendGameCommand(new Command_DrawCards(-1, mulliganCards--));
sendGameCommand(new Command_Mulligan);
}
void Player::actDrawCards()
......
......@@ -114,7 +114,6 @@ private:
void actMoveToExile(CardItem *card);
int defaultNumberTopCards;
int mulliganCards;
QString name;
int id;
bool active;
......@@ -188,7 +187,6 @@ public:
bool getActive() const { return active; }
void setActive(bool _active);
void prepareForGame();
void processPlayerInfo(ServerInfo_Player *info);
void processGameEvent(GameEvent *event);
void sendGameCommand(GameCommand *command);
......
#include "playerlistwidget.h"
#include "protocol_datastructures.h"
#include "pingpixmapgenerator.h"
PlayerListWidget::PlayerListWidget(QWidget *parent)
: QTreeWidget(parent)
{
setColumnCount(1);
setColumnCount(2);
setRootIsDecorated(false);
retranslateUi();
}
......@@ -12,12 +13,14 @@ PlayerListWidget::PlayerListWidget(QWidget *parent)
void PlayerListWidget::retranslateUi()
{
headerItem()->setText(0, tr("Player name"));
headerItem()->setText(1, tr("Role"));
}
void PlayerListWidget::addPlayer(ServerInfo_Player *player)
{
QTreeWidgetItem *newPlayer = new QTreeWidgetItem;
newPlayer->setText(0, player->getName());
newPlayer->setText(1, player->getSpectator() ? tr("Spectator") : tr("Player"));
addTopLevelItem(newPlayer);
players.insert(player->getPlayerId(), newPlayer);
}
......@@ -37,6 +40,16 @@ void PlayerListWidget::setActivePlayer(int playerId)
while (i.hasNext()) {
i.next();
QTreeWidgetItem *twi = i.value();
twi->setBackground(0, i.key() == playerId ? QColor(150, 255, 150) : Qt::white);
QColor c = i.key() == playerId ? QColor(150, 255, 150) : Qt::white;
twi->setBackground(0, c);
twi->setBackground(1, c);
}
}
void PlayerListWidget::updatePing(int playerId, int pingTime)
{
QTreeWidgetItem *twi = players.value(playerId, 0);
if (!twi)
return;
twi->setIcon(0, QIcon(PingPixmapGenerator::generatePixmap(10, pingTime, 10)));
}
......@@ -16,6 +16,7 @@ public:
void addPlayer(ServerInfo_Player *player);
void removePlayer(int playerId);
void setActivePlayer(int playerId);
void updatePing(int playerId, int pingTime);
};
#endif
......@@ -102,7 +102,10 @@ void TabDeckStorage::actUpload()
if (!deck->loadFromFile(filePath, DeckList::CockatriceFormat))
return;
if (deck->getName().isEmpty()) {
QString deckName = QInputDialog::getText(this, tr("Enter deck name"), tr("This decklist does not have a name.\nPlease enter a name:"), QLineEdit::Normal, tr("Unnamed deck"));
bool ok;
QString deckName = QInputDialog::getText(this, tr("Enter deck name"), tr("This decklist does not have a name.\nPlease enter a name:"), QLineEdit::Normal, tr("Unnamed deck"), &ok);
if (!ok)
return;
if (deckName.isEmpty())
deckName = tr("Unnamed deck");
deck->setName(deckName);
......
......@@ -20,8 +20,8 @@
#include "arrowitem.h"
#include "main.h"
TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator)
: Tab(), client(_client), gameId(_gameId), localPlayerId(_localPlayerId), spectator(_spectator), started(false), currentPhase(-1)
TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator, bool _resuming)
: Tab(), client(_client), gameId(_gameId), localPlayerId(_localPlayerId), spectator(_spectator), started(false), resuming(_resuming), currentPhase(-1)
{
zoneLayout = new ZoneViewLayout;
scene = new GameScene(zoneLayout, this);
......@@ -31,6 +31,7 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
loadLocalButton = new QPushButton;
loadRemoteButton = new QPushButton;
readyStartButton = new QPushButton;
readyStartButton->setEnabled(false);
QHBoxLayout *buttonHBox = new QHBoxLayout;
buttonHBox->addWidget(loadLocalButton);
......@@ -50,7 +51,7 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
sayLabel = new QLabel;
sayEdit = new QLineEdit;
sayLabel->setBuddy(sayEdit);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addWidget(sayLabel);
hLayout->addWidget(sayEdit);
......@@ -71,6 +72,14 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
mainLayout->addWidget(deckViewContainer, 10);
mainLayout->addLayout(verticalLayout);
if (spectator) {
sayLabel->hide();
sayEdit->hide();
loadLocalButton->hide();
loadRemoteButton->hide();
readyStartButton->hide();
}
aCloseMostRecentZoneView = new QAction(this);
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), zoneLayout, SLOT(closeMostRecentZoneView()));
addAction(aCloseMostRecentZoneView);
......@@ -214,13 +223,14 @@ Player *TabGame::addPlayer(int playerId, const QString &playerName)
void TabGame::processGameEvent(GameEvent *event)
{
switch (event->getItemId()) {
case ItemId_Event_GameStart: eventGameStart(qobject_cast<Event_GameStart *>(event)); break;
case ItemId_Event_GameStateChanged: eventGameStateChanged(qobject_cast<Event_GameStateChanged *>(event)); break;
case ItemId_Event_Join: eventJoin(qobject_cast<Event_Join *>(event)); break;
case ItemId_Event_Leave: eventLeave(qobject_cast<Event_Leave *>(event)); break;
case ItemId_Event_GameClosed: eventGameClosed(qobject_cast<Event_GameClosed *>(event)); break;
case ItemId_Event_SetActivePlayer: eventSetActivePlayer(qobject_cast<Event_SetActivePlayer *>(event)); break;
case ItemId_Event_SetActivePhase: eventSetActivePhase(qobject_cast<Event_SetActivePhase *>(event)); break;
case ItemId_Event_Ping: eventPing(qobject_cast<Event_Ping *>(event)); break;
default: {
Player *player = players.value(event->getPlayerId(), 0);
if (!player) {
......@@ -257,34 +267,33 @@ void TabGame::stopGame()
deckViewContainer->show();
}
void TabGame::eventGameStart(Event_GameStart * /*event*/)
{
startGame();
messageLog->logGameStart();
QMapIterator<int, Player *> i(players);
while (i.hasNext())
i.next().value()->prepareForGame();
}
void TabGame::eventGameStateChanged(Event_GameStateChanged *event)
{
const QList<ServerInfo_Player *> &plList = event->getPlayerList();
for (int i = 0; i < plList.size(); ++i) {
ServerInfo_Player *pl = plList[i];
Player *player = players.value(pl->getPlayerId(), 0);
if (!player) {
player = addPlayer(pl->getPlayerId(), pl->getName());
playerListWidget->addPlayer(pl);
}
player->processPlayerInfo(pl);
if (player->getLocal() && pl->getDeck()) {
Deck_PictureCacher::cachePictures(pl->getDeck(), this);
deckView->setDeck(new DeckList(pl->getDeck()));
if (pl->getSpectator()) {
if (!spectators.contains(pl->getPlayerId())) {
spectators.insert(pl->getPlayerId(), pl->getName());
playerListWidget->addPlayer(pl);
}
} else {
Player *player = players.value(pl->getPlayerId(), 0);
if (!player) {
player = addPlayer(pl->getPlayerId(), pl->getName());
playerListWidget->addPlayer(pl);
}
player->processPlayerInfo(pl);
if (player->getLocal() && pl->getDeck()) {
Deck_PictureCacher::cachePictures(pl->getDeck(), this);
deckView->setDeck(new DeckList(pl->getDeck()));
}
}
}
if (event->getGameStarted() && !started) {
startGame();
if (!resuming)
messageLog->logGameStart();
setActivePlayer(event->getActivePlayer());
setActivePhase(event->getActivePhase());
} else if (!event->getGameStarted() && started) {
......@@ -297,8 +306,9 @@ void TabGame::eventJoin(Event_Join *event)
{
ServerInfo_Player *playerInfo = event->getPlayer();
if (playerInfo->getSpectator()) {
spectatorList.append(playerInfo->getName());
spectators.insert(playerInfo->getPlayerId(), playerInfo->getName());
messageLog->logJoinSpectator(playerInfo->getName());
playerListWidget->addPlayer(playerInfo);
} else {
Player *newPlayer = addPlayer(playerInfo->getPlayerId(), playerInfo->getName());
messageLog->logJoin(newPlayer);
......@@ -309,12 +319,18 @@ void TabGame::eventJoin(Event_Join *event)
void TabGame::eventLeave(Event_Leave *event)
{
int playerId = event->getPlayerId();
Player *player = players.value(playerId, 0);
if (!player)
return;
messageLog->logLeave(player);
playerListWidget->removePlayer(playerId);
if (player) {
messageLog->logLeave(player);
playerListWidget->removePlayer(playerId);
players.remove(playerId);
delete player;
} else if (spectators.contains(playerId)) {
messageLog->logLeaveSpectator(spectators.value(playerId));
playerListWidget->removePlayer(playerId);
spectators.remove(playerId);
}
}
void TabGame::eventGameClosed(Event_GameClosed * /*event*/)
......@@ -362,6 +378,13 @@ void TabGame::eventSetActivePhase(Event_SetActivePhase *event)
setActivePhase(phase);
}
void TabGame::eventPing(Event_Ping *event)
{
const QList<ServerInfo_PlayerPing *> &pingList = event->getPingList();
for (int i = 0; i < pingList.size(); ++i)
playerListWidget->updatePing(pingList[i]->getPlayerId(), pingList[i]->getPingTime());
}
void TabGame::loadLocalDeck()
{
QFileDialog dialog(this, tr("Load deck"));
......@@ -403,6 +426,7 @@ void TabGame::deckSelectFinished(ProtocolResponse *r)
Deck_PictureCacher::cachePictures(resp->getDeck(), this);
deckView->setDeck(new DeckList(resp->getDeck()));
readyStartButton->setEnabled(true);
}
void TabGame::readyStart()
......
......@@ -22,7 +22,6 @@ class PlayerListWidget;
class ProtocolResponse;
class GameEvent;
class GameCommand;
class Event_GameStart;
class Event_GameStateChanged;
class Event_Join;
class Event_Leave;
......@@ -30,6 +29,7 @@ class Event_GameClosed;
class Event_GameStart;
class Event_SetActivePlayer;
class Event_SetActivePhase;
class Event_Ping;
class Player;
class CardZone;
class CardItem;
......@@ -41,9 +41,10 @@ private:
int gameId;
int localPlayerId;
bool spectator;
QStringList spectatorList;
QMap<int, Player *> players;
QMap<int, QString> spectators;
bool started;
bool resuming;
int currentPhase;
QPushButton *loadLocalButton, *loadRemoteButton, *readyStartButton;
......@@ -68,7 +69,6 @@ private:
void startGame();
void stopGame();
void eventGameStart(Event_GameStart *event);
void eventGameStateChanged(Event_GameStateChanged *event);
void eventJoin(Event_Join *event);
void eventLeave(Event_Leave *event);
......@@ -77,6 +77,7 @@ private:
void eventSetActivePlayer(Event_SetActivePlayer *event);
void setActivePhase(int phase);
void eventSetActivePhase(Event_SetActivePhase *event);
void eventPing(Event_Ping *event);
signals:
void gameClosing(TabGame *tab);
private slots:
......@@ -93,7 +94,7 @@ private slots:
void actNextPhase();
void actNextTurn();
public:
TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator);
TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator, bool _resuming);
~TabGame();
void retranslateUi();
const QMap<int, Player *> &getPlayers() const { return players; }
......
......@@ -5,7 +5,7 @@
#include "tab_game.h"
#include "tab_deck_storage.h"
#include "protocol_items.h"
#include <QPainter>
#include "pingpixmapgenerator.h"
TabSupervisor:: TabSupervisor(QWidget *parent)
: QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0)
......@@ -83,26 +83,13 @@ void TabSupervisor::updatePingTime(int value, int max)
{
if (!tabServer)
return;
QPixmap pixmap(15, 15);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
QColor color;
if (max == -1)
color = Qt::black;
else
color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255);
QRadialGradient g(QPointF((double) pixmap.width() / 2, (double) pixmap.height() / 2), qMin(pixmap.width(), pixmap.height()) / 2.0);
g.setColorAt(0, color);
g.setColorAt(1, Qt::transparent);
painter.fillRect(0, 0, pixmap.width(), pixmap.height(), QBrush(g));
setTabIcon(0, QIcon(pixmap));
setTabIcon(0, QIcon(PingPixmapGenerator::generatePixmap(15, value, max)));
}
void TabSupervisor::gameJoined(Event_GameJoined *event)
{
TabGame *tab = new TabGame(client, event->getGameId(), event->getPlayerId(), event->getSpectator());
TabGame *tab = new TabGame(client, event->getGameId(), event->getPlayerId(), event->getSpectator(), event->getResuming());
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
addTab(tab, tr("Game %1").arg(event->getGameId()));
gameTabs.insert(event->getGameId(), tab);
......
......@@ -22,6 +22,7 @@ void ProtocolItem::initializeHash()
registerSerializableItem("counter", ServerInfo_Counter::newItem);
registerSerializableItem("arrow", ServerInfo_Arrow::newItem);
registerSerializableItem("player", ServerInfo_Player::newItem);
registerSerializableItem("player_ping", ServerInfo_PlayerPing::newItem);
registerSerializableItem("file", DeckList_File::newItem);
registerSerializableItem("directory", DeckList_Directory::newItem);
......@@ -42,6 +43,7 @@ void ProtocolItem::initializeHash()
registerSerializableItem("game_eventcreate_arrows", Event_CreateArrows::newItem);
registerSerializableItem("game_eventcreate_counters", Event_CreateCounters::newItem);
registerSerializableItem("game_eventdraw_cards", Event_DrawCards::newItem);
registerSerializableItem("game_eventping", Event_Ping::newItem);
registerSerializableItem("chat_eventchat_list_players", Event_ChatListPlayers::newItem);
}
......@@ -234,6 +236,13 @@ Event_GameStateChanged::Event_GameStateChanged(int _gameId, bool _gameStarted, i
itemList.append(_playerList[i]);
}
Event_Ping::Event_Ping(int _gameId, const QList<ServerInfo_PlayerPing *> &_pingList)
: GameEvent("ping", _gameId, -1)
{
for (int i = 0; i < _pingList.size(); ++i)
itemList.append(_pingList[i]);
}
Event_CreateArrows::Event_CreateArrows(int _gameId, int _playerId, const QList<ServerInfo_Arrow *> &_arrowList)
: GameEvent("create_arrows", _gameId, _playerId)
{
......
......@@ -27,6 +27,7 @@ enum ItemId {
ItemId_Event_CreateCounters = ItemId_Other + 205,
ItemId_Event_DrawCards = ItemId_Other + 206,
ItemId_Event_Join = ItemId_Other + 207,
ItemId_Event_Ping = ItemId_Other + 208,
ItemId_Response_DeckList = ItemId_Other + 300,
ItemId_Response_DeckDownload = ItemId_Other + 301,
ItemId_Response_DeckUpload = ItemId_Other + 302,
......@@ -257,6 +258,15 @@ public:
int getActivePhase() const { return static_cast<SerializableItem_Int *>(itemMap.value("active_phase"))->getData(); }
};
class Event_Ping : public GameEvent {
Q_OBJECT
public:
Event_Ping(int _gameId = -1, const QList<ServerInfo_PlayerPing *> &_pingList = QList<ServerInfo_PlayerPing *>());
static SerializableItem *newItem() { return new Event_Ping; }
int getItemId() const { return ItemId_Event_Ping; }
QList<ServerInfo_PlayerPing *> getPingList() const { return typecastItemList<ServerInfo_PlayerPing *>(); }
};
class Event_CreateArrows : public GameEvent {
Q_OBJECT
public:
......
......@@ -148,6 +148,13 @@ DeckList *ServerInfo_Player::getDeck() const
return static_cast<DeckList *>(itemMap.value("cockatrice_deck"));
}
ServerInfo_PlayerPing::ServerInfo_PlayerPing(int _playerId, int _pingTime)
: SerializableItem_Map("player_ping")
{
insertItem(new SerializableItem_Int("player_id", _playerId));
insertItem(new SerializableItem_Int("ping_time", _pingTime));
}
DeckList_TreeItem::DeckList_TreeItem(const QString &_itemType, const QString &_name, int _id)
: SerializableItem_Map(_itemType)
{
......
......@@ -124,6 +124,14 @@ public:
const QList<ServerInfo_Arrow *> &getArrowList() const { return arrowList; }
};
class ServerInfo_PlayerPing : public SerializableItem_Map {
public:
ServerInfo_PlayerPing(int _playerId = -1, int _pingTime = -1);
static SerializableItem *newItem() { return new ServerInfo_PlayerPing; }
int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); }
int getPingTime() const { return static_cast<SerializableItem_Int *>(itemMap.value("ping_time"))->getData(); }
};
class DeckList_TreeItem : public SerializableItem_Map {
public:
DeckList_TreeItem(const QString &_itemType, const QString &_name, int _id);
......
......@@ -16,30 +16,30 @@ ItemId_Command_JoinGame = 1014,
ItemId_Command_LeaveGame = 1015,
ItemId_Command_Say = 1016,
ItemId_Command_Shuffle = 1017,
ItemId_Command_RollDie = 1018,
ItemId_Command_DrawCards = 1019,
ItemId_Command_MoveCard = 1020,
ItemId_Command_CreateToken = 1021,
ItemId_Command_CreateArrow = 1022,
ItemId_Command_DeleteArrow = 1023,
ItemId_Command_SetCardAttr = 1024,
ItemId_Command_ReadyStart = 1025,
ItemId_Command_Concede = 1026,
ItemId_Command_IncCounter = 1027,
ItemId_Command_CreateCounter = 1028,
ItemId_Command_SetCounter = 1029,
ItemId_Command_DelCounter = 1030,
ItemId_Command_NextTurn = 1031,
ItemId_Command_SetActivePhase = 1032,
ItemId_Command_DumpZone = 1033,
ItemId_Command_StopDumpZone = 1034,
ItemId_Event_Say = 1035,
ItemId_Event_Leave = 1036,
ItemId_Event_DeckSelect = 1037,
ItemId_Event_GameClosed = 1038,
ItemId_Event_ReadyStart = 1039,
ItemId_Event_Concede = 1040,
ItemId_Event_GameStart = 1041,
ItemId_Command_Mulligan = 1018,
ItemId_Command_RollDie = 1019,
ItemId_Command_DrawCards = 1020,
ItemId_Command_MoveCard = 1021,
ItemId_Command_CreateToken = 1022,
ItemId_Command_CreateArrow = 1023,
ItemId_Command_DeleteArrow = 1024,
ItemId_Command_SetCardAttr = 1025,
ItemId_Command_ReadyStart = 1026,
ItemId_Command_Concede = 1027,
ItemId_Command_IncCounter = 1028,
ItemId_Command_CreateCounter = 1029,
ItemId_Command_SetCounter = 1030,
ItemId_Command_DelCounter = 1031,
ItemId_Command_NextTurn = 1032,
ItemId_Command_SetActivePhase = 1033,
ItemId_Command_DumpZone = 1034,
ItemId_Command_StopDumpZone = 1035,
ItemId_Event_Say = 1036,
ItemId_Event_Leave = 1037,
ItemId_Event_DeckSelect = 1038,
ItemId_Event_GameClosed = 1039,
ItemId_Event_ReadyStart = 1040,
ItemId_Event_Concede = 1041,
ItemId_Event_Shuffle = 1042,
ItemId_Event_RollDie = 1043,
ItemId_Event_MoveCard = 1044,
......
......@@ -86,6 +86,10 @@ Command_Shuffle::Command_Shuffle(int _gameId)
: GameCommand("shuffle", _gameId)
{
}
Command_Mulligan::Command_Mulligan(int _gameId)
: GameCommand("mulligan", _gameId)
{
}
Command_RollDie::Command_RollDie(int _gameId, int _sides)
: GameCommand("roll_die", _gameId)
{
......@@ -220,10 +224,6 @@ Event_Concede::Event_Concede(int _gameId, int _playerId)
: GameEvent("concede", _gameId, _playerId)
{
}
Event_GameStart::Event_GameStart(int _gameId, int _playerId)
: GameEvent("game_start", _gameId, _playerId)
{
}
Event_Shuffle::Event_Shuffle(int _gameId, int _playerId)
: GameEvent("shuffle", _gameId, _playerId)
{
......@@ -308,12 +308,13 @@ Event_ServerMessage::Event_ServerMessage(const QString &_message)
{
insertItem(new SerializableItem_String("message", _message));
}
Event_GameJoined::Event_GameJoined(int _gameId, int _playerId, bool _spectator)
Event_GameJoined::Event_GameJoined(int _gameId, int _playerId, bool _spectator, bool _resuming)
: GenericEvent("game_joined")
{
insertItem(new SerializableItem_Int("game_id", _gameId));
insertItem(new SerializableItem_Int("player_id", _playerId));
insertItem(new SerializableItem_Bool("spectator", _spectator));
insertItem(new SerializableItem_Bool("resuming", _resuming));
}
Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName)
: ChatEvent("chat_join_channel", _channel)
......@@ -350,6 +351,7 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("cmdleave_game", Command_LeaveGame::newItem);
itemNameHash.insert("cmdsay", Command_Say::newItem);
itemNameHash.insert("cmdshuffle", Command_Shuffle::newItem);
itemNameHash.insert("cmdmulligan", Command_Mulligan::newItem);
itemNameHash.insert("cmdroll_die", Command_RollDie::newItem);
itemNameHash.insert("cmddraw_cards", Command_DrawCards::newItem);
itemNameHash.insert("cmdmove_card", Command_MoveCard::newItem);
......@@ -373,7 +375,6 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("game_eventgame_closed", Event_GameClosed::newItem);
itemNameHash.insert("game_eventready_start", Event_ReadyStart::newItem);
itemNameHash.insert("game_eventconcede", Event_Concede::newItem);
itemNameHash.insert("game_eventgame_start", Event_GameStart::newItem);
itemNameHash.insert("game_eventshuffle", Event_Shuffle::newItem);
itemNameHash.insert("game_eventroll_die", Event_RollDie::newItem);
itemNameHash.insert("game_eventmove_card", Event_MoveCard::newItem);
......
......@@ -15,6 +15,7 @@
2:leave_game
2:say:s,message
2:shuffle
2:mulligan
2:roll_die:i,sides
2:draw_cards:i,number
2:move_card:s,start_zone:i,card_id:s,target_zone:i,x:i,y:b,face_down
......@@ -38,7 +39,6 @@
3:game_closed
3:ready_start
3:concede
3:game_start
3:shuffle
3:roll_die:i,sides:i,value
3:move_card:i,card_id:s,card_name:s,start_zone:i,position:s,target_zone:i,x:i,y:b,face_down
......@@ -52,7 +52,7 @@
3:dump_zone:i,zone_owner_id:s,zone:i,number_cards
3:stop_dump_zone:i,zone_owner_id:s,zone
4:server_message:s,message
4:game_joined:i,game_id:i,player_id:b,spectator
4:game_joined:i,game_id:i,player_id:b,spectator:b,resuming
5:chat_join_channel:s,player_name
5:chat_leave_channel:s,player_name
5:chat_say:s,player_name:s,message
......@@ -139,6 +139,13 @@ public:
static SerializableItem *newItem() { return new Command_Shuffle; }
int getItemId() const { return ItemId_Command_Shuffle; }
};
class Command_Mulligan : public GameCommand {
Q_OBJECT
public:
Command_Mulligan(int _gameId = -1);
static SerializableItem *newItem() { return new Command_Mulligan; }
int getItemId() const { return ItemId_Command_Mulligan; }
};
class Command_RollDie : public GameCommand {
Q_OBJECT
public:
......@@ -342,13 +349,6 @@ public:
static SerializableItem *newItem() { return new Event_Concede; }
int getItemId() const { return ItemId_Event_Concede; }
};
class Event_GameStart : public GameEvent {
Q_OBJECT
public:
Event_GameStart(int _gameId = -1, int _playerId = -1);
static SerializableItem *newItem() { return new Event_GameStart; }
int getItemId() const { return ItemId_Event_GameStart; }
};
class Event_Shuffle : public GameEvent {
Q_OBJECT
public:
......@@ -475,10 +475,11 @@ public:
class Event_GameJoined : public GenericEvent {
Q_OBJECT
public:
Event_GameJoined(int _gameId = -1, int _playerId = -1, bool _spectator = false);
Event_GameJoined(int _gameId = -1, int _playerId = -1, bool _spectator = false, bool _resuming = false);
int getGameId() const { return static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->getData(); };
int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); };
bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); };
bool getResuming() const { return static_cast<SerializableItem_Bool *>(itemMap.value("resuming"))->getData(); };
static SerializableItem *newItem() { return new Event_GameJoined; }
int getItemId() const { return ItemId_Event_GameJoined; }
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment