diff --git a/cockatrice/src/gamescene.cpp b/cockatrice/src/gamescene.cpp index 6f844251..93f7e2f3 100644 --- a/cockatrice/src/gamescene.cpp +++ b/cockatrice/src/gamescene.cpp @@ -11,6 +11,7 @@ GameScene::GameScene(ZoneViewLayout *_zvLayout, QObject *parent) void GameScene::addPlayer(Player *player) { + qDebug("GameScene::addPlayer"); players << player; addItem(player); rearrange(); @@ -19,6 +20,7 @@ void GameScene::addPlayer(Player *player) void GameScene::removePlayer(Player *player) { + qDebug("GameScene::removePlayer"); players.removeAt(players.indexOf(player)); removeItem(player); rearrange(); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index f8ec49cc..a047b607 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -11,6 +11,7 @@ #include "cardlist.h" #include "tab_game.h" #include "protocol_items.h" +#include "gamescene.h" #include #include #include @@ -252,6 +253,8 @@ Player::~Player() { qDebug("Player destructor"); + static_cast(scene())->removePlayer(this); + QMapIterator i(zones); while (i.hasNext()) delete i.next().value(); @@ -619,6 +622,7 @@ void Player::eventMoveCard(Event_MoveCard *event) card->deleteDragItem(); + card->setId(event->getNewCardId()); card->setFaceDown(event->getFaceDown()); // The log event has to be sent before the card is added to the target zone diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 33b3729d..91304b57 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -120,6 +120,11 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat TabGame::~TabGame() { + QMapIterator i(players); + while (i.hasNext()) + delete i.next().value(); + players.clear(); + emit gameClosing(this); } @@ -287,6 +292,7 @@ void TabGame::eventGameStateChanged(Event_GameStateChanged *event) if (player->getLocal() && pl->getDeck()) { Deck_PictureCacher::cachePictures(pl->getDeck(), this); deckView->setDeck(new DeckList(pl->getDeck())); + readyStartButton->setEnabled(true); } } } diff --git a/cockatrice/src/zoneviewwidget.cpp b/cockatrice/src/zoneviewwidget.cpp index 19233851..9581fff1 100644 --- a/cockatrice/src/zoneviewwidget.cpp +++ b/cockatrice/src/zoneviewwidget.cpp @@ -52,6 +52,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC zone = new ZoneViewZone(player, _origZone, numberCards, this); connect(zone, SIGNAL(contentsChanged()), this, SLOT(resizeToZoneContents())); + connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted())); zone->dumpObjectInfo(); vbox->addItem(zone); zone->initializeCards(); @@ -91,6 +92,7 @@ void ZoneViewWidget::resizeToZoneContents() void ZoneViewWidget::closeEvent(QCloseEvent *event) { + disconnect(zone, SIGNAL(beingDeleted()), this, 0); player->sendGameCommand(new Command_StopDumpZone(-1, player->getId(), zone->getName())); if (shuffleCheckBox) if (shuffleCheckBox->isChecked()) @@ -99,3 +101,10 @@ void ZoneViewWidget::closeEvent(QCloseEvent *event) deleteLater(); event->accept(); } + +void ZoneViewWidget::zoneDeleted() +{ + emit closePressed(this); + qDebug("foo"); + deleteLater(); +} diff --git a/cockatrice/src/zoneviewwidget.h b/cockatrice/src/zoneviewwidget.h index 0250882e..8affa5bd 100644 --- a/cockatrice/src/zoneviewwidget.h +++ b/cockatrice/src/zoneviewwidget.h @@ -26,6 +26,7 @@ signals: void sizeChanged(); private slots: void resizeToZoneContents(); + void zoneDeleted(); public: ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0, QGraphicsItem *parent = 0); ZoneViewZone *getZone() const { return zone; } diff --git a/cockatrice/src/zoneviewzone.cpp b/cockatrice/src/zoneviewzone.cpp index 0c868d54..73b5bd12 100644 --- a/cockatrice/src/zoneviewzone.cpp +++ b/cockatrice/src/zoneviewzone.cpp @@ -12,6 +12,7 @@ ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QG ZoneViewZone::~ZoneViewZone() { + emit beingDeleted(); qDebug("ZoneViewZone destructor"); origZone->setView(NULL); } diff --git a/cockatrice/src/zoneviewzone.h b/cockatrice/src/zoneviewzone.h index 69c57fc5..9e9eee73 100644 --- a/cockatrice/src/zoneviewzone.h +++ b/cockatrice/src/zoneviewzone.h @@ -30,6 +30,8 @@ public slots: void setSortingEnabled(int _sortingEnabled); private slots: void zoneDumpReceived(ProtocolResponse *r); +signals: + void beingDeleted(); protected: void addCardImpl(CardItem *card, int x, int y); QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; diff --git a/common/protocol_items.cpp b/common/protocol_items.cpp index 7c4d727d..7343a655 100644 --- a/common/protocol_items.cpp +++ b/common/protocol_items.cpp @@ -234,7 +234,7 @@ Event_RollDie::Event_RollDie(int _gameId, int _playerId, int _sides, int _value) insertItem(new SerializableItem_Int("sides", _sides)); insertItem(new SerializableItem_Int("value", _value)); } -Event_MoveCard::Event_MoveCard(int _gameId, int _playerId, int _cardId, const QString &_cardName, const QString &_startZone, int _position, const QString &_targetZone, int _x, int _y, bool _faceDown) +Event_MoveCard::Event_MoveCard(int _gameId, int _playerId, int _cardId, const QString &_cardName, const QString &_startZone, int _position, const QString &_targetZone, int _x, int _y, int _newCardId, bool _faceDown) : GameEvent("move_card", _gameId, _playerId) { insertItem(new SerializableItem_Int("card_id", _cardId)); @@ -244,6 +244,7 @@ Event_MoveCard::Event_MoveCard(int _gameId, int _playerId, int _cardId, const QS insertItem(new SerializableItem_String("target_zone", _targetZone)); insertItem(new SerializableItem_Int("x", _x)); insertItem(new SerializableItem_Int("y", _y)); + insertItem(new SerializableItem_Int("new_card_id", _newCardId)); insertItem(new SerializableItem_Bool("face_down", _faceDown)); } Event_CreateToken::Event_CreateToken(int _gameId, int _playerId, const QString &_zone, int _cardId, const QString &_cardName, const QString &_pt, int _x, int _y) diff --git a/common/protocol_items.dat b/common/protocol_items.dat index 34ca634c..0e41958e 100644 --- a/common/protocol_items.dat +++ b/common/protocol_items.dat @@ -41,7 +41,7 @@ 3:concede 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 +3:move_card:i,card_id:s,card_name:s,start_zone:i,position:s,target_zone:i,x:i,y:i,new_card_id:b,face_down 3:create_token:s,zone:i,card_id:s,card_name:s,pt:i,x:i,y 3:delete_arrow:i,arrow_id 3:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value diff --git a/common/protocol_items.h b/common/protocol_items.h index 991b28b7..1ffbfa85 100644 --- a/common/protocol_items.h +++ b/common/protocol_items.h @@ -368,7 +368,7 @@ public: class Event_MoveCard : public GameEvent { Q_OBJECT public: - Event_MoveCard(int _gameId = -1, int _playerId = -1, int _cardId = -1, const QString &_cardName = QString(), const QString &_startZone = QString(), int _position = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, bool _faceDown = false); + Event_MoveCard(int _gameId = -1, int _playerId = -1, int _cardId = -1, const QString &_cardName = QString(), const QString &_startZone = QString(), int _position = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, int _newCardId = -1, bool _faceDown = false); int getCardId() const { return static_cast(itemMap.value("card_id"))->getData(); }; QString getCardName() const { return static_cast(itemMap.value("card_name"))->getData(); }; QString getStartZone() const { return static_cast(itemMap.value("start_zone"))->getData(); }; @@ -376,6 +376,7 @@ public: QString getTargetZone() const { return static_cast(itemMap.value("target_zone"))->getData(); }; int getX() const { return static_cast(itemMap.value("x"))->getData(); }; int getY() const { return static_cast(itemMap.value("y"))->getData(); }; + int getNewCardId() const { return static_cast(itemMap.value("new_card_id"))->getData(); }; bool getFaceDown() const { return static_cast(itemMap.value("face_down"))->getData(); }; static SerializableItem *newItem() { return new Event_MoveCard; } int getItemId() const { return ItemId_Event_MoveCard; } diff --git a/common/server_player.cpp b/common/server_player.cpp index a4598bbd..fda88403 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -10,7 +10,7 @@ #include "decklist.h" Server_Player::Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler) - : game(_game), handler(_handler), deck(0), playerId(_playerId), playerName(_playerName), spectator(_spectator), nextCardId(0) + : game(_game), handler(_handler), deck(0), playerId(_playerId), playerName(_playerName), spectator(_spectator), nextCardId(0), readyStart(false), conceded(false) { } diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index c24ae36a..a1c5e439 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -430,34 +430,40 @@ ResponseCode Server_ProtocolHandler::moveCard(Server_Game *game, Server_Player * if (!(sourceHiddenToOthers && targetHiddenToOthers)) publicCardName = card->getName(); + int oldCardId = card->getId(); if (faceDown) card->setId(player->newCardId()); card->setFaceDown(faceDown); // The player does not get to see which card he moved if it moves between two parts of hidden zones which // are not being looked at. - int privateCardId = card->getId(); + int privateNewCardId = card->getId(); + int privateOldCardId = oldCardId; if (!targetBeingLookedAt && !sourceBeingLookedAt) { - privateCardId = -1; + privateOldCardId = -1; + privateNewCardId = -1; privateCardName = QString(); } int privatePosition = -1; if (startzone->getType() == HiddenZone) privatePosition = position; - player->sendProtocolItem(new Event_MoveCard(game->getGameId(), player->getPlayerId(), privateCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getName(), x, y, faceDown)); + player->sendProtocolItem(new Event_MoveCard(game->getGameId(), player->getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getName(), x, y, privateNewCardId, faceDown)); // Other players do not get to see the start and/or target position of the card if the respective // part of the zone is being looked at. The information is not needed anyway because in hidden zones, // all cards are equal. - if ((startzone->getType() == HiddenZone) && ((startzone->getCardsBeingLookedAt() > position) || (startzone->getCardsBeingLookedAt() == -1))) + if ( + ((startzone->getType() == HiddenZone) && ((startzone->getCardsBeingLookedAt() > position) || (startzone->getCardsBeingLookedAt() == -1))) + || (startzone->getType() == PublicZone) + ) position = -1; if ((targetzone->getType() == HiddenZone) && ((targetzone->getCardsBeingLookedAt() > x) || (targetzone->getCardsBeingLookedAt() == -1))) x = -1; if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone)) - game->sendGameEvent(new Event_MoveCard(-1, player->getPlayerId(), card->getId(), publicCardName, startzone->getName(), position, targetzone->getName(), x, y, faceDown), player); + game->sendGameEvent(new Event_MoveCard(-1, player->getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getName(), x, y, card->getId(), faceDown), player); else - game->sendGameEvent(new Event_MoveCard(-1, player->getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getName(), x, y, false), player); + game->sendGameEvent(new Event_MoveCard(-1, player->getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getName(), x, y, -1, false), player); // If the card was moved to another zone, delete all arrows from and to the card if (startzone != targetzone) {