crash fixes; move_card fixes
This commit is contained in:
parent
2aa5c7eb3c
commit
d23ece59ea
12 changed files with 43 additions and 10 deletions
|
@ -11,6 +11,7 @@ GameScene::GameScene(ZoneViewLayout *_zvLayout, QObject *parent)
|
||||||
|
|
||||||
void GameScene::addPlayer(Player *player)
|
void GameScene::addPlayer(Player *player)
|
||||||
{
|
{
|
||||||
|
qDebug("GameScene::addPlayer");
|
||||||
players << player;
|
players << player;
|
||||||
addItem(player);
|
addItem(player);
|
||||||
rearrange();
|
rearrange();
|
||||||
|
@ -19,6 +20,7 @@ void GameScene::addPlayer(Player *player)
|
||||||
|
|
||||||
void GameScene::removePlayer(Player *player)
|
void GameScene::removePlayer(Player *player)
|
||||||
{
|
{
|
||||||
|
qDebug("GameScene::removePlayer");
|
||||||
players.removeAt(players.indexOf(player));
|
players.removeAt(players.indexOf(player));
|
||||||
removeItem(player);
|
removeItem(player);
|
||||||
rearrange();
|
rearrange();
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "cardlist.h"
|
#include "cardlist.h"
|
||||||
#include "tab_game.h"
|
#include "tab_game.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
#include "gamescene.h"
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
@ -252,6 +253,8 @@ Player::~Player()
|
||||||
{
|
{
|
||||||
qDebug("Player destructor");
|
qDebug("Player destructor");
|
||||||
|
|
||||||
|
static_cast<GameScene *>(scene())->removePlayer(this);
|
||||||
|
|
||||||
QMapIterator<QString, CardZone *> i(zones);
|
QMapIterator<QString, CardZone *> i(zones);
|
||||||
while (i.hasNext())
|
while (i.hasNext())
|
||||||
delete i.next().value();
|
delete i.next().value();
|
||||||
|
@ -619,6 +622,7 @@ void Player::eventMoveCard(Event_MoveCard *event)
|
||||||
|
|
||||||
card->deleteDragItem();
|
card->deleteDragItem();
|
||||||
|
|
||||||
|
card->setId(event->getNewCardId());
|
||||||
card->setFaceDown(event->getFaceDown());
|
card->setFaceDown(event->getFaceDown());
|
||||||
|
|
||||||
// The log event has to be sent before the card is added to the target zone
|
// The log event has to be sent before the card is added to the target zone
|
||||||
|
|
|
@ -120,6 +120,11 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
|
||||||
|
|
||||||
TabGame::~TabGame()
|
TabGame::~TabGame()
|
||||||
{
|
{
|
||||||
|
QMapIterator<int, Player *> i(players);
|
||||||
|
while (i.hasNext())
|
||||||
|
delete i.next().value();
|
||||||
|
players.clear();
|
||||||
|
|
||||||
emit gameClosing(this);
|
emit gameClosing(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,6 +292,7 @@ void TabGame::eventGameStateChanged(Event_GameStateChanged *event)
|
||||||
if (player->getLocal() && pl->getDeck()) {
|
if (player->getLocal() && pl->getDeck()) {
|
||||||
Deck_PictureCacher::cachePictures(pl->getDeck(), this);
|
Deck_PictureCacher::cachePictures(pl->getDeck(), this);
|
||||||
deckView->setDeck(new DeckList(pl->getDeck()));
|
deckView->setDeck(new DeckList(pl->getDeck()));
|
||||||
|
readyStartButton->setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC
|
||||||
|
|
||||||
zone = new ZoneViewZone(player, _origZone, numberCards, this);
|
zone = new ZoneViewZone(player, _origZone, numberCards, this);
|
||||||
connect(zone, SIGNAL(contentsChanged()), this, SLOT(resizeToZoneContents()));
|
connect(zone, SIGNAL(contentsChanged()), this, SLOT(resizeToZoneContents()));
|
||||||
|
connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted()));
|
||||||
zone->dumpObjectInfo();
|
zone->dumpObjectInfo();
|
||||||
vbox->addItem(zone);
|
vbox->addItem(zone);
|
||||||
zone->initializeCards();
|
zone->initializeCards();
|
||||||
|
@ -91,6 +92,7 @@ void ZoneViewWidget::resizeToZoneContents()
|
||||||
|
|
||||||
void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
|
disconnect(zone, SIGNAL(beingDeleted()), this, 0);
|
||||||
player->sendGameCommand(new Command_StopDumpZone(-1, player->getId(), zone->getName()));
|
player->sendGameCommand(new Command_StopDumpZone(-1, player->getId(), zone->getName()));
|
||||||
if (shuffleCheckBox)
|
if (shuffleCheckBox)
|
||||||
if (shuffleCheckBox->isChecked())
|
if (shuffleCheckBox->isChecked())
|
||||||
|
@ -99,3 +101,10 @@ void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
||||||
deleteLater();
|
deleteLater();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ZoneViewWidget::zoneDeleted()
|
||||||
|
{
|
||||||
|
emit closePressed(this);
|
||||||
|
qDebug("foo");
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ signals:
|
||||||
void sizeChanged();
|
void sizeChanged();
|
||||||
private slots:
|
private slots:
|
||||||
void resizeToZoneContents();
|
void resizeToZoneContents();
|
||||||
|
void zoneDeleted();
|
||||||
public:
|
public:
|
||||||
ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0, QGraphicsItem *parent = 0);
|
ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0, QGraphicsItem *parent = 0);
|
||||||
ZoneViewZone *getZone() const { return zone; }
|
ZoneViewZone *getZone() const { return zone; }
|
||||||
|
|
|
@ -12,6 +12,7 @@ ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QG
|
||||||
|
|
||||||
ZoneViewZone::~ZoneViewZone()
|
ZoneViewZone::~ZoneViewZone()
|
||||||
{
|
{
|
||||||
|
emit beingDeleted();
|
||||||
qDebug("ZoneViewZone destructor");
|
qDebug("ZoneViewZone destructor");
|
||||||
origZone->setView(NULL);
|
origZone->setView(NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ public slots:
|
||||||
void setSortingEnabled(int _sortingEnabled);
|
void setSortingEnabled(int _sortingEnabled);
|
||||||
private slots:
|
private slots:
|
||||||
void zoneDumpReceived(ProtocolResponse *r);
|
void zoneDumpReceived(ProtocolResponse *r);
|
||||||
|
signals:
|
||||||
|
void beingDeleted();
|
||||||
protected:
|
protected:
|
||||||
void addCardImpl(CardItem *card, int x, int y);
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
|
||||||
|
|
|
@ -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("sides", _sides));
|
||||||
insertItem(new SerializableItem_Int("value", _value));
|
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)
|
: GameEvent("move_card", _gameId, _playerId)
|
||||||
{
|
{
|
||||||
insertItem(new SerializableItem_Int("card_id", _cardId));
|
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_String("target_zone", _targetZone));
|
||||||
insertItem(new SerializableItem_Int("x", _x));
|
insertItem(new SerializableItem_Int("x", _x));
|
||||||
insertItem(new SerializableItem_Int("y", _y));
|
insertItem(new SerializableItem_Int("y", _y));
|
||||||
|
insertItem(new SerializableItem_Int("new_card_id", _newCardId));
|
||||||
insertItem(new SerializableItem_Bool("face_down", _faceDown));
|
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)
|
Event_CreateToken::Event_CreateToken(int _gameId, int _playerId, const QString &_zone, int _cardId, const QString &_cardName, const QString &_pt, int _x, int _y)
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
3:concede
|
3:concede
|
||||||
3:shuffle
|
3:shuffle
|
||||||
3:roll_die:i,sides:i,value
|
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:create_token:s,zone:i,card_id:s,card_name:s,pt:i,x:i,y
|
||||||
3:delete_arrow:i,arrow_id
|
3:delete_arrow:i,arrow_id
|
||||||
3:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
3:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
||||||
|
|
|
@ -368,7 +368,7 @@ public:
|
||||||
class Event_MoveCard : public GameEvent {
|
class Event_MoveCard : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); };
|
||||||
QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); };
|
QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); };
|
||||||
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
|
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); };
|
||||||
|
@ -376,6 +376,7 @@ public:
|
||||||
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
|
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); };
|
||||||
int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); };
|
int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); };
|
||||||
int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); };
|
int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); };
|
||||||
|
int getNewCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("new_card_id"))->getData(); };
|
||||||
bool getFaceDown() const { return static_cast<SerializableItem_Bool *>(itemMap.value("face_down"))->getData(); };
|
bool getFaceDown() const { return static_cast<SerializableItem_Bool *>(itemMap.value("face_down"))->getData(); };
|
||||||
static SerializableItem *newItem() { return new Event_MoveCard; }
|
static SerializableItem *newItem() { return new Event_MoveCard; }
|
||||||
int getItemId() const { return ItemId_Event_MoveCard; }
|
int getItemId() const { return ItemId_Event_MoveCard; }
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
Server_Player::Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler)
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -430,34 +430,40 @@ ResponseCode Server_ProtocolHandler::moveCard(Server_Game *game, Server_Player *
|
||||||
if (!(sourceHiddenToOthers && targetHiddenToOthers))
|
if (!(sourceHiddenToOthers && targetHiddenToOthers))
|
||||||
publicCardName = card->getName();
|
publicCardName = card->getName();
|
||||||
|
|
||||||
|
int oldCardId = card->getId();
|
||||||
if (faceDown)
|
if (faceDown)
|
||||||
card->setId(player->newCardId());
|
card->setId(player->newCardId());
|
||||||
card->setFaceDown(faceDown);
|
card->setFaceDown(faceDown);
|
||||||
|
|
||||||
// The player does not get to see which card he moved if it moves between two parts of hidden zones which
|
// 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.
|
// are not being looked at.
|
||||||
int privateCardId = card->getId();
|
int privateNewCardId = card->getId();
|
||||||
|
int privateOldCardId = oldCardId;
|
||||||
if (!targetBeingLookedAt && !sourceBeingLookedAt) {
|
if (!targetBeingLookedAt && !sourceBeingLookedAt) {
|
||||||
privateCardId = -1;
|
privateOldCardId = -1;
|
||||||
|
privateNewCardId = -1;
|
||||||
privateCardName = QString();
|
privateCardName = QString();
|
||||||
}
|
}
|
||||||
int privatePosition = -1;
|
int privatePosition = -1;
|
||||||
if (startzone->getType() == HiddenZone)
|
if (startzone->getType() == HiddenZone)
|
||||||
privatePosition = position;
|
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
|
// 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,
|
// part of the zone is being looked at. The information is not needed anyway because in hidden zones,
|
||||||
// all cards are equal.
|
// 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;
|
position = -1;
|
||||||
if ((targetzone->getType() == HiddenZone) && ((targetzone->getCardsBeingLookedAt() > x) || (targetzone->getCardsBeingLookedAt() == -1)))
|
if ((targetzone->getType() == HiddenZone) && ((targetzone->getCardsBeingLookedAt() > x) || (targetzone->getCardsBeingLookedAt() == -1)))
|
||||||
x = -1;
|
x = -1;
|
||||||
|
|
||||||
if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone))
|
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
|
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 the card was moved to another zone, delete all arrows from and to the card
|
||||||
if (startzone != targetzone) {
|
if (startzone != targetzone) {
|
||||||
|
|
Loading…
Reference in a new issue