zone view works

This commit is contained in:
Max-Wilhelm Bruker 2009-11-29 03:35:55 +01:00
parent 694070724c
commit 55482246dd
5 changed files with 48 additions and 12 deletions

View file

@ -28,8 +28,9 @@ void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem *
void ZoneViewZone::initializeCards() void ZoneViewZone::initializeCards()
{ {
if (!origZone->contentsKnown()) { if (!origZone->contentsKnown()) {
// PendingCommand_DumpZone *dumpZoneCommand = player->client->dumpZone(player->getId(), name, numberCards); Command_DumpZone *command = new Command_DumpZone(-1, player->getId(), name, numberCards);
// connect(dumpZoneCommand, SIGNAL(cardListReceived(QList<ServerZoneCard>)), this, SLOT(zoneDumpReceived(QList<ServerZoneCard>))); connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(zoneDumpReceived(ProtocolResponse *)));
player->sendGameCommand(command);
} else { } else {
const CardList &c = origZone->getCards(); const CardList &c = origZone->getCards();
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size()); int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
@ -42,17 +43,22 @@ void ZoneViewZone::initializeCards()
} }
} }
/*void ZoneViewZone::zoneDumpReceived(QList<ServerInfo_Card *> cards) void ZoneViewZone::zoneDumpReceived(ProtocolResponse *r)
{ {
for (int i = 0; i < cards.size(); i++) { Response_DumpZone *resp = qobject_cast<Response_DumpZone *>(r);
CardItem *card = new CardItem(player, cards[i].getName(), i, this); if (!resp)
return;
const QList<ServerInfo_Card *> &respCardList = resp->getZone()->getCardList();
for (int i = 0; i < respCardList.size(); i++) {
CardItem *card = new CardItem(player, respCardList[i]->getName(), respCardList[i]->getId(), this);
addCard(card, false, i); addCard(card, false, i);
} }
emit contentsChanged(); emit contentsChanged();
reorganizeCards(); reorganizeCards();
} }
*/
// Because of boundingRect(), this function must not be called before the zone was added to a scene. // Because of boundingRect(), this function must not be called before the zone was added to a scene.
void ZoneViewZone::reorganizeCards() void ZoneViewZone::reorganizeCards()
{ {

View file

@ -2,11 +2,11 @@
#define ZONEVIEWERZONE_H #define ZONEVIEWERZONE_H
#include "cardzone.h" #include "cardzone.h"
#include "protocol_datastructures.h"
#include <QGraphicsWidget> #include <QGraphicsWidget>
#include <QGraphicsLayoutItem> #include <QGraphicsLayoutItem>
class ZoneViewWidget; class ZoneViewWidget;
class ProtocolResponse;
class ZoneViewZone : public CardZone, public QGraphicsLayoutItem { class ZoneViewZone : public CardZone, public QGraphicsLayoutItem {
Q_OBJECT Q_OBJECT
@ -29,7 +29,7 @@ public:
public slots: public slots:
void setSortingEnabled(int _sortingEnabled); void setSortingEnabled(int _sortingEnabled);
private slots: private slots:
// void zoneDumpReceived(QList<ServerInfo_Card> cards); void zoneDumpReceived(ProtocolResponse *r);
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;

View file

@ -33,6 +33,7 @@ void ProtocolItem::initializeHash()
registerSerializableItem("respdeck_list", Response_DeckList::newItem); registerSerializableItem("respdeck_list", Response_DeckList::newItem);
registerSerializableItem("respdeck_download", Response_DeckDownload::newItem); registerSerializableItem("respdeck_download", Response_DeckDownload::newItem);
registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem); registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem);
registerSerializableItem("respdump_zone", Response_DumpZone::newItem);
registerSerializableItem("generic_eventlist_games", Event_ListGames::newItem); registerSerializableItem("generic_eventlist_games", Event_ListGames::newItem);
registerSerializableItem("generic_eventlist_chat_channels", Event_ListChatChannels::newItem); registerSerializableItem("generic_eventlist_chat_channels", Event_ListChatChannels::newItem);
@ -171,6 +172,14 @@ Response_DeckUpload::Response_DeckUpload(int _cmdId, ResponseCode _responseCode,
insertItem(_file); insertItem(_file);
} }
Response_DumpZone::Response_DumpZone(int _cmdId, ResponseCode _responseCode, ServerInfo_Zone *_zone)
: ProtocolResponse(_cmdId, _responseCode, "dump_zone")
{
if (!_zone)
_zone = new ServerInfo_Zone;
insertItem(_zone);
}
GameEvent::GameEvent(const QString &_eventName, int _gameId, int _playerId) GameEvent::GameEvent(const QString &_eventName, int _gameId, int _playerId)
: ProtocolItem("game_event", _eventName) : ProtocolItem("game_event", _eventName)
{ {

View file

@ -29,6 +29,7 @@ enum ItemId {
ItemId_Response_DeckList = ItemId_Other + 300, ItemId_Response_DeckList = ItemId_Other + 300,
ItemId_Response_DeckDownload = ItemId_Other + 301, ItemId_Response_DeckDownload = ItemId_Other + 301,
ItemId_Response_DeckUpload = ItemId_Other + 302, ItemId_Response_DeckUpload = ItemId_Other + 302,
ItemId_Response_DumpZone = ItemId_Other + 303,
ItemId_Invalid = ItemId_Other + 1000 ItemId_Invalid = ItemId_Other + 1000
}; };
@ -172,6 +173,15 @@ public:
DeckList_File *getFile() const { return static_cast<DeckList_File *>(itemMap.value("file")); } DeckList_File *getFile() const { return static_cast<DeckList_File *>(itemMap.value("file")); }
}; };
class Response_DumpZone : public ProtocolResponse {
Q_OBJECT
public:
Response_DumpZone(int _cmdId = -1, ResponseCode _responseCode = RespOk, ServerInfo_Zone *zone = 0);
int getItemId() const { return ItemId_Response_DumpZone; }
static SerializableItem *newItem() { return new Response_DumpZone; }
ServerInfo_Zone *getZone() const { return static_cast<ServerInfo_Zone *>(itemMap.value("zone")); }
};
// -------------- // --------------
// --- EVENTS --- // --- EVENTS ---
// -------------- // --------------

View file

@ -554,11 +554,22 @@ ResponseCode Server_ProtocolHandler::cmdDumpZone(Command_DumpZone *cmd, Server_G
if (!((zone->getType() == PublicZone) || (player == otherPlayer))) if (!((zone->getType() == PublicZone) || (player == otherPlayer)))
return RespContextError; return RespContextError;
if (zone->getType() == HiddenZone) { int numberCards = cmd->getNumberCards();
// game->broadcastEvent(QString("dump_zone|%1|%2|%3").arg(player_id).arg(zone->getName()).arg(number_cards), player); QList<ServerInfo_Card *> respCardList;
for (int i = 0; (i < zone->cards.size()) && (i < numberCards || numberCards == -1); ++i) {
Server_Card *card = zone->cards[i];
QString displayedName = card->getFaceDown() ? QString() : card->getName();
if (zone->getType() == HiddenZone)
respCardList.append(new ServerInfo_Card(i, displayedName));
else
respCardList.append(new ServerInfo_Card(card->getId(), displayedName, card->getX(), card->getY(), card->getCounters(), card->getTapped(), card->getAttacking(), card->getAnnotation()));
} }
// remsg->sendList(dumpZoneHelper(otherPlayer, zone, number_cards)); if (zone->getType() == HiddenZone) {
return RespOk; zone->setCardsBeingLookedAt(numberCards);
game->sendGameEvent(new Event_DumpZone(-1, player->getPlayerId(), otherPlayer->getPlayerId(), zone->getName(), numberCards));
}
sendProtocolItem(new Response_DumpZone(cmd->getCmdId(), RespOk, new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), numberCards < zone->cards.size() ? zone->cards.size() : numberCards, respCardList)));
return RespNothing;
} }
ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player) ResponseCode Server_ProtocolHandler::cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player)