Commit a171df74 authored by Matt Kelly's avatar Matt Kelly
Browse files

Convert to 4-space indents

parent ac8c967d
...@@ -20,31 +20,31 @@ ...@@ -20,31 +20,31 @@
#include "client_metatypes.h" #include "client_metatypes.h"
AbstractClient::AbstractClient(QObject *parent) AbstractClient::AbstractClient(QObject *parent)
: QObject(parent), nextCmdId(0), status(StatusDisconnected) : QObject(parent), nextCmdId(0), status(StatusDisconnected)
{ {
qRegisterMetaType<QVariant>("QVariant"); qRegisterMetaType<QVariant>("QVariant");
qRegisterMetaType<CommandContainer>("CommandContainer"); qRegisterMetaType<CommandContainer>("CommandContainer");
qRegisterMetaType<Response>("Response"); qRegisterMetaType<Response>("Response");
qRegisterMetaType<Response::ResponseCode>("Response::ResponseCode"); qRegisterMetaType<Response::ResponseCode>("Response::ResponseCode");
qRegisterMetaType<ClientStatus>("ClientStatus"); qRegisterMetaType<ClientStatus>("ClientStatus");
qRegisterMetaType<RoomEvent>("RoomEvent"); qRegisterMetaType<RoomEvent>("RoomEvent");
qRegisterMetaType<GameEventContainer>("GameEventContainer"); qRegisterMetaType<GameEventContainer>("GameEventContainer");
qRegisterMetaType<Event_ServerIdentification>("Event_ServerIdentification"); qRegisterMetaType<Event_ServerIdentification>("Event_ServerIdentification");
qRegisterMetaType<Event_ConnectionClosed>("Event_ConnectionClosed"); qRegisterMetaType<Event_ConnectionClosed>("Event_ConnectionClosed");
qRegisterMetaType<Event_ServerShutdown>("Event_ServerShutdown"); qRegisterMetaType<Event_ServerShutdown>("Event_ServerShutdown");
qRegisterMetaType<Event_AddToList>("Event_AddToList"); qRegisterMetaType<Event_AddToList>("Event_AddToList");
qRegisterMetaType<Event_RemoveFromList>("Event_RemoveFromList"); qRegisterMetaType<Event_RemoveFromList>("Event_RemoveFromList");
qRegisterMetaType<Event_UserJoined>("Event_UserJoined"); qRegisterMetaType<Event_UserJoined>("Event_UserJoined");
qRegisterMetaType<Event_UserLeft>("Event_UserLeft"); qRegisterMetaType<Event_UserLeft>("Event_UserLeft");
qRegisterMetaType<Event_ServerMessage>("Event_ServerMessage"); qRegisterMetaType<Event_ServerMessage>("Event_ServerMessage");
qRegisterMetaType<Event_ListRooms>("Event_ListRooms"); qRegisterMetaType<Event_ListRooms>("Event_ListRooms");
qRegisterMetaType<Event_GameJoined>("Event_GameJoined"); qRegisterMetaType<Event_GameJoined>("Event_GameJoined");
qRegisterMetaType<Event_UserMessage>("Event_UserMessage"); qRegisterMetaType<Event_UserMessage>("Event_UserMessage");
qRegisterMetaType<ServerInfo_User>("ServerInfo_User"); qRegisterMetaType<ServerInfo_User>("ServerInfo_User");
qRegisterMetaType<QList<ServerInfo_User> >("QList<ServerInfo_User>"); qRegisterMetaType<QList<ServerInfo_User> >("QList<ServerInfo_User>");
qRegisterMetaType<Event_ReplayAdded>("Event_ReplayAdded"); qRegisterMetaType<Event_ReplayAdded>("Event_ReplayAdded");
connect(this, SIGNAL(sigQueuePendingCommand(PendingCommand *)), this, SLOT(queuePendingCommand(PendingCommand *))); connect(this, SIGNAL(sigQueuePendingCommand(PendingCommand *)), this, SLOT(queuePendingCommand(PendingCommand *)));
} }
AbstractClient::~AbstractClient() AbstractClient::~AbstractClient()
...@@ -53,110 +53,110 @@ AbstractClient::~AbstractClient() ...@@ -53,110 +53,110 @@ AbstractClient::~AbstractClient()
void AbstractClient::processProtocolItem(const ServerMessage &item) void AbstractClient::processProtocolItem(const ServerMessage &item)
{ {
switch (item.message_type()) { switch (item.message_type()) {
case ServerMessage::RESPONSE: { case ServerMessage::RESPONSE: {
const Response &response = item.response(); const Response &response = item.response();
const int cmdId = response.cmd_id(); const int cmdId = response.cmd_id();
PendingCommand *pend = pendingCommands.value(cmdId, 0); PendingCommand *pend = pendingCommands.value(cmdId, 0);
if (!pend) if (!pend)
return; return;
pendingCommands.remove(cmdId); pendingCommands.remove(cmdId);
pend->processResponse(response); pend->processResponse(response);
pend->deleteLater(); pend->deleteLater();
break; break;
} }
case ServerMessage::SESSION_EVENT: { case ServerMessage::SESSION_EVENT: {
const SessionEvent &event = item.session_event(); const SessionEvent &event = item.session_event();
switch ((SessionEvent::SessionEventType) getPbExtension(event)) { switch ((SessionEvent::SessionEventType) getPbExtension(event)) {
case SessionEvent::SERVER_IDENTIFICATION: emit serverIdentificationEventReceived(event.GetExtension(Event_ServerIdentification::ext)); break; case SessionEvent::SERVER_IDENTIFICATION: emit serverIdentificationEventReceived(event.GetExtension(Event_ServerIdentification::ext)); break;
case SessionEvent::SERVER_MESSAGE: emit serverMessageEventReceived(event.GetExtension(Event_ServerMessage::ext)); break; case SessionEvent::SERVER_MESSAGE: emit serverMessageEventReceived(event.GetExtension(Event_ServerMessage::ext)); break;
case SessionEvent::SERVER_SHUTDOWN: emit serverShutdownEventReceived(event.GetExtension(Event_ServerShutdown::ext)); break; case SessionEvent::SERVER_SHUTDOWN: emit serverShutdownEventReceived(event.GetExtension(Event_ServerShutdown::ext)); break;
case SessionEvent::CONNECTION_CLOSED: emit connectionClosedEventReceived(event.GetExtension(Event_ConnectionClosed::ext)); break; case SessionEvent::CONNECTION_CLOSED: emit connectionClosedEventReceived(event.GetExtension(Event_ConnectionClosed::ext)); break;
case SessionEvent::USER_MESSAGE: emit userMessageEventReceived(event.GetExtension(Event_UserMessage::ext)); break; case SessionEvent::USER_MESSAGE: emit userMessageEventReceived(event.GetExtension(Event_UserMessage::ext)); break;
case SessionEvent::LIST_ROOMS: emit listRoomsEventReceived(event.GetExtension(Event_ListRooms::ext)); break; case SessionEvent::LIST_ROOMS: emit listRoomsEventReceived(event.GetExtension(Event_ListRooms::ext)); break;
case SessionEvent::ADD_TO_LIST: emit addToListEventReceived(event.GetExtension(Event_AddToList::ext)); break; case SessionEvent::ADD_TO_LIST: emit addToListEventReceived(event.GetExtension(Event_AddToList::ext)); break;
case SessionEvent::REMOVE_FROM_LIST: emit removeFromListEventReceived(event.GetExtension(Event_RemoveFromList::ext)); break; case SessionEvent::REMOVE_FROM_LIST: emit removeFromListEventReceived(event.GetExtension(Event_RemoveFromList::ext)); break;
case SessionEvent::USER_JOINED: emit userJoinedEventReceived(event.GetExtension(Event_UserJoined::ext)); break; case SessionEvent::USER_JOINED: emit userJoinedEventReceived(event.GetExtension(Event_UserJoined::ext)); break;
case SessionEvent::USER_LEFT: emit userLeftEventReceived(event.GetExtension(Event_UserLeft::ext)); break; case SessionEvent::USER_LEFT: emit userLeftEventReceived(event.GetExtension(Event_UserLeft::ext)); break;
case SessionEvent::GAME_JOINED: emit gameJoinedEventReceived(event.GetExtension(Event_GameJoined::ext)); break; case SessionEvent::GAME_JOINED: emit gameJoinedEventReceived(event.GetExtension(Event_GameJoined::ext)); break;
case SessionEvent::REPLAY_ADDED: emit replayAddedEventReceived(event.GetExtension(Event_ReplayAdded::ext)); break; case SessionEvent::REPLAY_ADDED: emit replayAddedEventReceived(event.GetExtension(Event_ReplayAdded::ext)); break;
default: break; default: break;
} }
break; break;
} }
case ServerMessage::GAME_EVENT_CONTAINER: { case ServerMessage::GAME_EVENT_CONTAINER: {
emit gameEventContainerReceived(item.game_event_container()); emit gameEventContainerReceived(item.game_event_container());
break; break;
} }
case ServerMessage::ROOM_EVENT: { case ServerMessage::ROOM_EVENT: {
emit roomEventReceived(item.room_event()); emit roomEventReceived(item.room_event());
break; break;
} }
} }
} }
void AbstractClient::setStatus(const ClientStatus _status) void AbstractClient::setStatus(const ClientStatus _status)
{ {
QMutexLocker locker(&clientMutex); QMutexLocker locker(&clientMutex);
if (_status != status) { if (_status != status) {
status = _status; status = _status;
emit statusChanged(_status); emit statusChanged(_status);
} }
} }
void AbstractClient::sendCommand(const CommandContainer &cont) void AbstractClient::sendCommand(const CommandContainer &cont)
{ {
sendCommand(new PendingCommand(cont)); sendCommand(new PendingCommand(cont));
} }
void AbstractClient::sendCommand(PendingCommand *pend) void AbstractClient::sendCommand(PendingCommand *pend)
{ {
pend->moveToThread(thread()); pend->moveToThread(thread());
emit sigQueuePendingCommand(pend); emit sigQueuePendingCommand(pend);
} }
void AbstractClient::queuePendingCommand(PendingCommand *pend) void AbstractClient::queuePendingCommand(PendingCommand *pend)
{ {
// This function is always called from the client thread via signal/slot. // This function is always called from the client thread via signal/slot.
const int cmdId = getNewCmdId(); const int cmdId = getNewCmdId();
pend->getCommandContainer().set_cmd_id(cmdId); pend->getCommandContainer().set_cmd_id(cmdId);
pendingCommands.insert(cmdId, pend); pendingCommands.insert(cmdId, pend);
sendCommandContainer(pend->getCommandContainer()); sendCommandContainer(pend->getCommandContainer());
} }
PendingCommand *AbstractClient::prepareSessionCommand(const ::google::protobuf::Message &cmd) PendingCommand *AbstractClient::prepareSessionCommand(const ::google::protobuf::Message &cmd)
{ {
CommandContainer cont; CommandContainer cont;
SessionCommand *c = cont.add_session_command(); SessionCommand *c = cont.add_session_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont); return new PendingCommand(cont);
} }
PendingCommand *AbstractClient::prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId) PendingCommand *AbstractClient::prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId)
{ {
CommandContainer cont; CommandContainer cont;
RoomCommand *c = cont.add_room_command(); RoomCommand *c = cont.add_room_command();
cont.set_room_id(roomId); cont.set_room_id(roomId);
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont); return new PendingCommand(cont);
} }
PendingCommand *AbstractClient::prepareModeratorCommand(const ::google::protobuf::Message &cmd) PendingCommand *AbstractClient::prepareModeratorCommand(const ::google::protobuf::Message &cmd)
{ {
CommandContainer cont; CommandContainer cont;
ModeratorCommand *c = cont.add_moderator_command(); ModeratorCommand *c = cont.add_moderator_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont); return new PendingCommand(cont);
} }
PendingCommand *AbstractClient::prepareAdminCommand(const ::google::protobuf::Message &cmd) PendingCommand *AbstractClient::prepareAdminCommand(const ::google::protobuf::Message &cmd)
{ {
CommandContainer cont; CommandContainer cont;
AdminCommand *c = cont.add_admin_command(); AdminCommand *c = cont.add_admin_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont); return new PendingCommand(cont);
} }
...@@ -10,257 +10,257 @@ ...@@ -10,257 +10,257 @@
#include "pb/serverinfo_user.pb.h" #include "pb/serverinfo_user.pb.h"
CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool _isView) CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool _isView)
: AbstractGraphicsItem(parent), player(_p), name(_name), cards(_contentsKnown), view(NULL), menu(NULL), doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable), isView(_isView) : AbstractGraphicsItem(parent), player(_p), name(_name), cards(_contentsKnown), view(NULL), menu(NULL), doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable), isView(_isView)
{ {
if (!isView) if (!isView)
player->addZone(this); player->addZone(this);
} }
CardZone::~CardZone() CardZone::~CardZone()
{ {
qDebug() << "CardZone destructor: " << name; qDebug() << "CardZone destructor: " << name;
delete view; delete view;
clearContents(); clearContents();
} }
void CardZone::retranslateUi() void CardZone::retranslateUi()
{ {
for (int i = 0; i < cards.size(); ++i) for (int i = 0; i < cards.size(); ++i)
cards[i]->retranslateUi(); cards[i]->retranslateUi();
} }
void CardZone::clearContents() void CardZone::clearContents()
{ {
for (int i = 0; i < cards.size(); i++) { for (int i = 0; i < cards.size(); i++) {
// If an incorrectly implemented server doesn't return attached cards to whom they belong before dropping a player, // If an incorrectly implemented server doesn't return attached cards to whom they belong before dropping a player,
// we have to return them to avoid a crash. // we have to return them to avoid a crash.
const QList<CardItem *> &attachedCards = cards[i]->getAttachedCards(); const QList<CardItem *> &attachedCards = cards[i]->getAttachedCards();
for (int j = 0; j < attachedCards.size(); ++j) for (int j = 0; j < attachedCards.size(); ++j)
attachedCards[j]->setParentItem(attachedCards[j]->getZone()); attachedCards[j]->setParentItem(attachedCards[j]->getZone());
player->deleteCard(cards.at(i)); player->deleteCard(cards.at(i));
} }
cards.clear(); cards.clear();
emit cardCountChanged(); emit cardCountChanged();
} }
QString CardZone::getTranslatedName(bool hisOwn, GrammaticalCase gc) const QString CardZone::getTranslatedName(bool hisOwn, GrammaticalCase gc) const
{ {
QString ownerName = player->getName(); QString ownerName = player->getName();
bool female = player->getUserInfo()->gender() == ServerInfo_User::Female; bool female = player->getUserInfo()->gender() == ServerInfo_User::Female;
if (name == "hand") if (name == "hand")
return female return female
? (hisOwn ? (hisOwn
? tr("her hand", "nominative, female owner") ? tr("her hand", "nominative, female owner")
: tr("%1's hand", "nominative, female owner").arg(ownerName) : tr("%1's hand", "nominative, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("his hand", "nominative, male owner") ? tr("his hand", "nominative, male owner")
: tr("%1's hand", "nominative, male owner").arg(ownerName) : tr("%1's hand", "nominative, male owner").arg(ownerName)
); );
else if (name == "deck") else if (name == "deck")
switch (gc) { switch (gc) {
case CaseLookAtZone: case CaseLookAtZone:
return female return female
? (hisOwn ? (hisOwn
? tr("her library", "look at zone, female owner") ? tr("her library", "look at zone, female owner")
: tr("%1's library", "look at zone, female owner").arg(ownerName) : tr("%1's library", "look at zone, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("his library", "look at zone, male owner") ? tr("his library", "look at zone, male owner")
: tr("%1's library", "look at zone, male owner").arg(ownerName) : tr("%1's library", "look at zone, male owner").arg(ownerName)
); );
case CaseTopCardsOfZone: case CaseTopCardsOfZone:
return female return female
? (hisOwn ? (hisOwn
? tr("of her library", "top cards of zone, female owner") ? tr("of her library", "top cards of zone, female owner")
: tr("of %1's library", "top cards of zone, female owner").arg(ownerName) : tr("of %1's library", "top cards of zone, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("of his library", "top cards of zone, male owner") ? tr("of his library", "top cards of zone, male owner")
: tr("of %1's library", "top cards of zone, male owner").arg(ownerName) : tr("of %1's library", "top cards of zone, male owner").arg(ownerName)
); );
case CaseRevealZone: case CaseRevealZone:
return female return female
? (hisOwn ? (hisOwn
? tr("her library", "reveal zone, female owner") ? tr("her library", "reveal zone, female owner")
: tr("%1's library", "reveal zone, female owner").arg(ownerName) : tr("%1's library", "reveal zone, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("his library", "reveal zone, male owner") ? tr("his library", "reveal zone, male owner")
: tr("%1's library", "reveal zone, male owner").arg(ownerName) : tr("%1's library", "reveal zone, male owner").arg(ownerName)
); );
case CaseShuffleZone: case CaseShuffleZone:
return female return female
? (hisOwn ? (hisOwn
? tr("her library", "shuffle, female owner") ? tr("her library", "shuffle, female owner")
: tr("%1's library", "shuffle, female owner").arg(ownerName) : tr("%1's library", "shuffle, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("his library", "shuffle, male owner") ? tr("his library", "shuffle, male owner")
: tr("%1's library", "shuffle, male owner").arg(ownerName) : tr("%1's library", "shuffle, male owner").arg(ownerName)
); );
default: default:
return female return female
? (hisOwn ? (hisOwn
? tr("her library", "nominative, female owner") ? tr("her library", "nominative, female owner")
: tr("%1's library", "nominative, female owner").arg(ownerName) : tr("%1's library", "nominative, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("his library", "nominative, male owner") ? tr("his library", "nominative, male owner")
: tr("%1's library", "nominative, male owner").arg(ownerName) : tr("%1's library", "nominative, male owner").arg(ownerName)
); );
} }
else if (name == "grave") else if (name == "grave")
return female return female
? (hisOwn ? (hisOwn
? tr("her graveyard", "nominative, female owner") ? tr("her graveyard", "nominative, female owner")
: tr("%1's graveyard", "nominative, female owner").arg(ownerName) : tr("%1's graveyard", "nominative, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("his graveyard", "nominative, male owner") ? tr("his graveyard", "nominative, male owner")
: tr("%1's graveyard", "nominative, male owner").arg(ownerName) : tr("%1's graveyard", "nominative, male owner").arg(ownerName)
); );
else if (name == "rfg") else if (name == "rfg")
return female return female
? (hisOwn ? (hisOwn
? tr("her exile", "nominative, female owner") ? tr("her exile", "nominative, female owner")
: tr("%1's exile", "nominative, female owner").arg(ownerName) : tr("%1's exile", "nominative, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("his exile", "nominative, male owner") ? tr("his exile", "nominative, male owner")
: tr("%1's exile", "nominative, male owner").arg(ownerName) : tr("%1's exile", "nominative, male owner").arg(ownerName)
); );
else if (name == "sb") else if (name == "sb")
switch (gc) { switch (gc) {
case CaseLookAtZone: case CaseLookAtZone:
return female return female
? (hisOwn ? (hisOwn
? tr("her sideboard", "look at zone, female owner") ? tr("her sideboard", "look at zone, female owner")
: tr("%1's sideboard", "look at zone, female owner").arg(ownerName) : tr("%1's sideboard", "look at zone, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("his sideboard", "look at zone, male owner") ? tr("his sideboard", "look at zone, male owner")
: tr("%1's sideboard", "look at zone, male owner").arg(ownerName) : tr("%1's sideboard", "look at zone, male owner").arg(ownerName)
); );
case CaseNominative: case CaseNominative:
return female return female
? (hisOwn ? (hisOwn
? tr("her sideboard", "nominative, female owner") ? tr("her sideboard", "nominative, female owner")
: tr("%1's sideboard", "nominative, female owner").arg(ownerName) : tr("%1's sideboard", "nominative, female owner").arg(ownerName)
) : (hisOwn ) : (hisOwn
? tr("his sideboard", "nominative, male owner") ? tr("his sideboard", "nominative, male owner")
: tr("%1's sideboard", "nominative, male owner").arg(ownerName) : tr("%1's sideboard", "nominative, male owner").arg(ownerName)
); );
default: break; default: break;
} }
return QString(); return QString();
} }
void CardZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent */*event*/) void CardZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent */*event*/)
{ {
if (doubleClickAction) if (doubleClickAction)
doubleClickAction->trigger(); doubleClickAction->trigger();
} }
bool CardZone::showContextMenu(const QPoint &screenPos) bool CardZone::showContextMenu(const QPoint &screenPos)
{ {
if (menu) { if (menu) {
menu->exec(screenPos); menu->exec(screenPos);
return true; return true;
} }
return false; return false;
} }
void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event) void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::RightButton) { if (event->button() == Qt::RightButton) {
if (showContextMenu(event->screenPos())) if (showContextMenu(event->screenPos()))
event->accept(); event->accept();
else else
event->ignore(); event->ignore();
} else } else
event->ignore(); event->ignore();
} }
void CardZone::addCard(CardItem *card, bool reorganize, int x, int y) void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
{ {
if (view) if (view)
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) if ((x <= view->getCards().size()) || (view->getNumberCards() == -1))
view->addCard(new CardItem(player, card->getName(), card->getId()), reorganize, x, y); view->addCard(new CardItem(player, card->getName(), card->getId()), reorganize, x, y);
card->setZone(this); card->setZone(this);
addCardImpl(card, x, y); addCardImpl(card, x, y);
if (reorganize) if (reorganize)
reorganizeCards(); reorganizeCards();
emit cardCountChanged(); emit cardCountChanged();
} }
CardItem *CardZone::getCard(int cardId, const QString &cardName) CardItem *CardZone::getCard(int cardId, const QString &cardName)
{ {
CardItem *c = cards.findCard(cardId, false); CardItem *c = cards.findCard(cardId, false);
if (!c) { if (!c) {
qDebug() << "CardZone::getCard: card id=" << cardId << "not found"; qDebug() << "CardZone::getCard: card id=" << cardId << "not found";
return 0; return 0;
} }
// If the card's id is -1, this zone is invisible, // If the card's id is -1, this zone is invisible,
// so we need to give the card an id and a name as it comes out. // so we need to give the card an id and a name as it comes out.
// It can be assumed that in an invisible zone, all cards are equal. // It can be assumed that in an invisible zone, all cards are equal.
if ((c->getId() == -1) || (c->getName().isEmpty())) { if ((c->getId() == -1) || (c->getName().isEmpty())) {
c->setId(cardId); c->setId(cardId);
c->setName(cardName); c->setName(cardName);
} }
return c; return c;
} }
CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/) CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/)
{ {
if (position == -1) { if (position == -1) {
// position == -1 means either that the zone is indexed by card id // position == -1 means either that the zone is indexed by card id
// or that it doesn't matter which card you take. // or that it doesn't matter which card you take.
for (int i = 0; i < cards.size(); ++i) for (int i = 0; i < cards.size(); ++i)
if (cards[i]->getId() == cardId) { if (cards[i]->getId() == cardId) {
position = i; position = i;
break; break;
} }
if (position == -1) if (position == -1)
position = 0; position = 0;
} }
if (position >= cards.size()) if (position >= cards.size())
return 0; return 0;
CardItem *c = cards.takeAt(position); CardItem *c = cards.takeAt(position);
if (view) if (view)
view->removeCard(position); view->removeCard(position);
c->setId(cardId); c->setId(cardId);
reorganizeCards(); reorganizeCards();
emit cardCountChanged(); emit cardCountChanged();
return c; return c;
} }
void CardZone::removeCard(CardItem *card) void CardZone::removeCard(CardItem *card)
{ {
cards.removeAt(cards.indexOf(card)); cards.removeAt(cards.indexOf(card));
reorganizeCards(); reorganizeCards();
emit cardCountChanged(); emit cardCountChanged();
player->deleteCard(card); player->deleteCard(card);
} }
void CardZone::moveAllToZone() void CardZone::moveAllToZone()
{ {
QList<QVariant> data = static_cast<QAction *>(sender())->data().toList(); QList<QVariant> data = static_cast<QAction *>(sender())->data().toList();
QString targetZone = data[0].toString(); QString targetZone = data[0].toString();
int targetX = data[1].toInt(); int targetX = data[1].toInt();
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_zone(getName().toStdString()); cmd.set_start_zone(getName().toStdString());
cmd.set_target_player_id(player->getId()); cmd.set_target_player_id(player->getId());
cmd.set_target_zone(targetZone.toStdString()); cmd.set_target_zone(targetZone.toStdString());
cmd.set_x(targetX); cmd.set_x(targetX);
for (int i = 0; i < cards.size(); ++i) for (int i = 0; i < cards.size(); ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(cards[i]->getId()); cmd.mutable_cards_to_move()->add_card()->set_card_id(cards[i]->getId());
player->sendGameCommand(cmd); player->sendGameCommand(cmd);
} }
QPointF CardZone::closestGridPoint(const QPointF &point) QPointF CardZone::closestGridPoint(const QPointF &point)
{ {
return point; return point;
} }
...@@ -66,1368 +66,1368 @@ ...@@ -66,1368 +66,1368 @@
#include "pb/event_change_zone_properties.pb.h" #include "pb/event_change_zone_properties.pb.h"
PlayerArea::PlayerArea(QGraphicsItem *parentItem) PlayerArea::PlayerArea(QGraphicsItem *parentItem)
: QObject(), QGraphicsItem(parentItem) : QObject(), QGraphicsItem(parentItem)
{ {
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap())); connect(settingsCache, SIGNAL(playerBgPathChanged()), this, SLOT(updateBgPixmap()));
updateBgPixmap(); updateBgPixmap();
} }
void PlayerArea::updateBgPixmap() void PlayerArea::updateBgPixmap()
{ {
QString bgPath = settingsCache->getPlayerBgPath(); QString bgPath = settingsCache->getPlayerBgPath();
if (bgPath.isEmpty()) if (bgPath.isEmpty())
bgPixmapBrush = QBrush(QColor(200, 200, 200)); bgPixmapBrush = QBrush(QColor(200, 200, 200));
else { else {
qDebug() << "loading" << bgPath; qDebug() << "loading" << bgPath;
bgPixmapBrush = QBrush(QPixmap(bgPath)); bgPixmapBrush = QBrush(QPixmap(bgPath));
} }
update(); update();
} }
void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{ {
painter->fillRect(bRect, bgPixmapBrush); painter->fillRect(bRect, bgPixmapBrush);
} }
void PlayerArea::setSize(qreal width, qreal height) void PlayerArea::setSize(qreal width, qreal height)
{ {
prepareGeometryChange(); prepareGeometryChange();
bRect = QRectF(0, 0, width, height); bRect = QRectF(0, 0, width, height);
} }
Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_parent) Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_parent)
: QObject(_parent), : QObject(_parent),
game(_parent), game(_parent),
shortcutsActive(false), shortcutsActive(false),
defaultNumberTopCards(3), defaultNumberTopCards(3),
lastTokenDestroy(true), lastTokenDestroy(true),
id(_id), id(_id),
active(false), active(false),
local(_local), local(_local),
mirrored(false), mirrored(false),
handVisible(false), handVisible(false),
conceded(false), conceded(false),
dialogSemaphore(false), dialogSemaphore(false),
deck(0) deck(0)
{ {
userInfo = new ServerInfo_User; userInfo = new ServerInfo_User;
userInfo->CopyFrom(info); userInfo->CopyFrom(info);
connect(settingsCache, SIGNAL(horizontalHandChanged()), this, SLOT(rearrangeZones())); connect(settingsCache, SIGNAL(horizontalHandChanged()), this, SLOT(rearrangeZones()));
playerArea = new PlayerArea(this); playerArea = new PlayerArea(this);
playerTarget = new PlayerTarget(this, playerArea); playerTarget = new PlayerTarget(this, 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));
PileZone *deck = new PileZone(this, "deck", true, false, playerArea); PileZone *deck = new PileZone(this, "deck", true, false, playerArea);
QPointF base = QPointF(counterAreaWidth + (CARD_HEIGHT - CARD_WIDTH + 15) / 2.0, 10 + playerTarget->boundingRect().height() + 5 - (CARD_HEIGHT - CARD_WIDTH) / 2.0); QPointF base = QPointF(counterAreaWidth + (CARD_HEIGHT - CARD_WIDTH + 15) / 2.0, 10 + playerTarget->boundingRect().height() + 5 - (CARD_HEIGHT - CARD_WIDTH) / 2.0);
deck->setPos(base); deck->setPos(base);
qreal h = deck->boundingRect().width() + 5; qreal h = deck->boundingRect().width() + 5;
HandCounter *handCounter = new HandCounter(playerArea); HandCounter *handCounter = new HandCounter(playerArea);
handCounter->setPos(base + QPointF(0, h + 10)); handCounter->setPos(base + QPointF(0, h + 10));
qreal h2 = handCounter->boundingRect().height(); qreal h2 = handCounter->boundingRect().height();
PileZone *grave = new PileZone(this, "grave", false, true, playerArea); PileZone *grave = new PileZone(this, "grave", false, true, playerArea);
grave->setPos(base + QPointF(0, h + h2 + 10)); grave->setPos(base + QPointF(0, h + h2 + 10));
PileZone *rfg = new PileZone(this, "rfg", false, true, playerArea); PileZone *rfg = new PileZone(this, "rfg", false, true, playerArea);
rfg->setPos(base + QPointF(0, 2 * h + h2 + 10)); rfg->setPos(base + QPointF(0, 2 * h + h2 + 10));
PileZone *sb = new PileZone(this, "sb", false, false, playerArea); PileZone *sb = new PileZone(this, "sb", false, false, playerArea);
sb->setVisible(false); sb->setVisible(false);
table = new TableZone(this, this); table = new TableZone(this, this);
connect(table, SIGNAL(sizeChanged()), this, SLOT(updateBoundingRect())); connect(table, SIGNAL(sizeChanged()), this, SLOT(updateBoundingRect()));
stack = new StackZone(this, (int) table->boundingRect().height(), this); stack = new StackZone(this, (int) table->boundingRect().height(), this);
hand = new HandZone(this, _local || (_parent->getSpectator() && _parent->getSpectatorsSeeEverything()), (int) table->boundingRect().height(), this); hand = new HandZone(this, _local || (_parent->getSpectator() && _parent->getSpectatorsSeeEverything()), (int) table->boundingRect().height(), this);
connect(hand, SIGNAL(cardCountChanged()), handCounter, SLOT(updateNumber())); connect(hand, SIGNAL(cardCountChanged()), handCounter, SLOT(updateNumber()));
connect(handCounter, SIGNAL(showContextMenu(const QPoint &)), hand, SLOT(showContextMenu(const QPoint &))); connect(handCounter, SIGNAL(showContextMenu(const QPoint &)), hand, SLOT(showContextMenu(const QPoint &)));
updateBoundingRect(); updateBoundingRect();
if (local) { if (local) {
connect(_parent, SIGNAL(playerAdded(Player *)), this, SLOT(addPlayer(Player *))); connect(_parent, SIGNAL(playerAdded(Player *)), this, SLOT(addPlayer(Player *)));
connect(_parent, SIGNAL(playerRemoved(Player *)), this, SLOT(removePlayer(Player *))); connect(_parent, SIGNAL(playerRemoved(Player *)), this, SLOT(removePlayer(Player *)));
aMoveHandToTopLibrary = new QAction(this); aMoveHandToTopLibrary = new QAction(this);
aMoveHandToTopLibrary->setData(QList<QVariant>() << "deck" << 0); aMoveHandToTopLibrary->setData(QList<QVariant>() << "deck" << 0);
aMoveHandToBottomLibrary = new QAction(this); aMoveHandToBottomLibrary = new QAction(this);
aMoveHandToBottomLibrary->setData(QList<QVariant>() << "deck" << -1); aMoveHandToBottomLibrary->setData(QList<QVariant>() << "deck" << -1);
aMoveHandToGrave = new QAction(this); aMoveHandToGrave = new QAction(this);
aMoveHandToGrave->setData(QList<QVariant>() << "grave" << 0); aMoveHandToGrave->setData(QList<QVariant>() << "grave" << 0);
aMoveHandToRfg = new QAction(this); aMoveHandToRfg = new QAction(this);
aMoveHandToRfg->setData(QList<QVariant>() << "rfg" << 0); aMoveHandToRfg->setData(QList<QVariant>() << "rfg" << 0);
connect(aMoveHandToTopLibrary, SIGNAL(triggered()), hand, SLOT(moveAllToZone())); connect(aMoveHandToTopLibrary, SIGNAL(triggered()), hand, SLOT(moveAllToZone()));
connect(aMoveHandToBottomLibrary, SIGNAL(triggered()), hand, SLOT(moveAllToZone())); connect(aMoveHandToBottomLibrary, SIGNAL(triggered()), hand, SLOT(moveAllToZone()));
connect(aMoveHandToGrave, SIGNAL(triggered()), hand, SLOT(moveAllToZone())); connect(aMoveHandToGrave, SIGNAL(triggered()), hand, SLOT(moveAllToZone()));
connect(aMoveHandToRfg, SIGNAL(triggered()), hand, SLOT(moveAllToZone())); connect(aMoveHandToRfg, SIGNAL(triggered()), hand, SLOT(moveAllToZone()));
aMoveGraveToTopLibrary = new QAction(this); aMoveGraveToTopLibrary = new QAction(this);
aMoveGraveToTopLibrary->setData(QList<QVariant>() << "deck" << 0); aMoveGraveToTopLibrary->setData(QList<QVariant>() << "deck" << 0);
aMoveGraveToBottomLibrary = new QAction(this); aMoveGraveToBottomLibrary = new QAction(this);
aMoveGraveToBottomLibrary->setData(QList<QVariant>() << "deck" << -1); aMoveGraveToBottomLibrary->setData(QList<QVariant>() << "deck" << -1);
aMoveGraveToHand = new QAction(this); aMoveGraveToHand = new QAction(this);
aMoveGraveToHand->setData(QList<QVariant>() << "hand" << 0); aMoveGraveToHand->setData(QList<QVariant>() << "hand" << 0);
aMoveGraveToRfg = new QAction(this); aMoveGraveToRfg = new QAction(this);
aMoveGraveToRfg->setData(QList<QVariant>() << "rfg" << 0); aMoveGraveToRfg->setData(QList<QVariant>() << "rfg" << 0);
connect(aMoveGraveToTopLibrary, SIGNAL(triggered()), grave, SLOT(moveAllToZone())); connect(aMoveGraveToTopLibrary, SIGNAL(triggered()), grave, SLOT(moveAllToZone()));
connect(aMoveGraveToBottomLibrary, SIGNAL(triggered()), grave, SLOT(moveAllToZone())); connect(aMoveGraveToBottomLibrary, SIGNAL(triggered()), grave, SLOT(moveAllToZone()));
connect(aMoveGraveToHand, SIGNAL(triggered()), grave, SLOT(moveAllToZone())); connect(aMoveGraveToHand, SIGNAL(triggered()), grave, SLOT(moveAllToZone()));
connect(aMoveGraveToRfg, SIGNAL(triggered()), grave, SLOT(moveAllToZone())); connect(aMoveGraveToRfg, SIGNAL(triggered()), grave, SLOT(moveAllToZone()));
aMoveRfgToTopLibrary = new QAction(this); aMoveRfgToTopLibrary = new QAction(this);
aMoveRfgToTopLibrary->setData(QList<QVariant>() << "deck" << 0); aMoveRfgToTopLibrary->setData(QList<QVariant>() << "deck" << 0);
aMoveRfgToBottomLibrary = new QAction(this); aMoveRfgToBottomLibrary = new QAction(this);
aMoveRfgToBottomLibrary->setData(QList<QVariant>() << "deck" << -1); aMoveRfgToBottomLibrary->setData(QList<QVariant>() << "deck" << -1);
aMoveRfgToHand = new QAction(this); aMoveRfgToHand = new QAction(this);
aMoveRfgToHand->setData(QList<QVariant>() << "hand" << 0); aMoveRfgToHand->setData(QList<QVariant>() << "hand" << 0);
aMoveRfgToGrave = new QAction(this); aMoveRfgToGrave = new QAction(this);
aMoveRfgToGrave->setData(QList<QVariant>() << "grave" << 0); aMoveRfgToGrave->setData(QList<QVariant>() << "grave" << 0);
connect(aMoveRfgToTopLibrary, SIGNAL(triggered()), rfg, SLOT(moveAllToZone())); connect(aMoveRfgToTopLibrary, SIGNAL(triggered()), rfg, SLOT(moveAllToZone()));
connect(aMoveRfgToBottomLibrary, SIGNAL(triggered()), rfg, SLOT(moveAllToZone())); connect(aMoveRfgToBottomLibrary, SIGNAL(triggered()), rfg, SLOT(moveAllToZone()));
connect(aMoveRfgToHand, SIGNAL(triggered()), rfg, SLOT(moveAllToZone())); connect(aMoveRfgToHand, SIGNAL(triggered()), rfg, SLOT(moveAllToZone()));
connect(aMoveRfgToGrave, SIGNAL(triggered()), rfg, SLOT(moveAllToZone())); connect(aMoveRfgToGrave, SIGNAL(triggered()), rfg, SLOT(moveAllToZone()));
aViewLibrary = new QAction(this); aViewLibrary = new QAction(this);
connect(aViewLibrary, SIGNAL(triggered()), this, SLOT(actViewLibrary())); connect(aViewLibrary, SIGNAL(triggered()), this, SLOT(actViewLibrary()));
aViewTopCards = new QAction(this); aViewTopCards = new QAction(this);
connect(aViewTopCards, SIGNAL(triggered()), this, SLOT(actViewTopCards())); connect(aViewTopCards, SIGNAL(triggered()), this, SLOT(actViewTopCards()));
aAlwaysRevealTopCard = new QAction(this); aAlwaysRevealTopCard = new QAction(this);
aAlwaysRevealTopCard->setCheckable(true); aAlwaysRevealTopCard->setCheckable(true);
connect(aAlwaysRevealTopCard, SIGNAL(triggered()), this, SLOT(actAlwaysRevealTopCard())); connect(aAlwaysRevealTopCard, SIGNAL(triggered()), this, SLOT(actAlwaysRevealTopCard()));
aOpenDeckInDeckEditor = new QAction(this); aOpenDeckInDeckEditor = new QAction(this);
aOpenDeckInDeckEditor->setEnabled(false); aOpenDeckInDeckEditor->setEnabled(false);
connect(aOpenDeckInDeckEditor, SIGNAL(triggered()), this, SLOT(actOpenDeckInDeckEditor())); connect(aOpenDeckInDeckEditor, SIGNAL(triggered()), this, SLOT(actOpenDeckInDeckEditor()));
} }
aViewGraveyard = new QAction(this); aViewGraveyard = new QAction(this);
connect(aViewGraveyard, SIGNAL(triggered()), this, SLOT(actViewGraveyard())); connect(aViewGraveyard, SIGNAL(triggered()), this, SLOT(actViewGraveyard()));
aViewRfg = new QAction(this); aViewRfg = new QAction(this);
connect(aViewRfg, SIGNAL(triggered()), this, SLOT(actViewRfg())); connect(aViewRfg, SIGNAL(triggered()), this, SLOT(actViewRfg()));
if (local) { if (local) {
aViewSideboard = new QAction(this); aViewSideboard = new QAction(this);
connect(aViewSideboard, SIGNAL(triggered()), this, SLOT(actViewSideboard())); connect(aViewSideboard, SIGNAL(triggered()), this, SLOT(actViewSideboard()));
aDrawCard = new QAction(this); aDrawCard = new QAction(this);
connect(aDrawCard, SIGNAL(triggered()), this, SLOT(actDrawCard())); connect(aDrawCard, SIGNAL(triggered()), this, SLOT(actDrawCard()));
aDrawCards = new QAction(this); aDrawCards = new QAction(this);
connect(aDrawCards, SIGNAL(triggered()), this, SLOT(actDrawCards())); connect(aDrawCards, SIGNAL(triggered()), this, SLOT(actDrawCards()));
aUndoDraw = new QAction(this); aUndoDraw = new QAction(this);
connect(aUndoDraw, SIGNAL(triggered()), this, SLOT(actUndoDraw())); connect(aUndoDraw, SIGNAL(triggered()), this, SLOT(actUndoDraw()));
aShuffle = new QAction(this); aShuffle = new QAction(this);
connect(aShuffle, SIGNAL(triggered()), this, SLOT(actShuffle())); connect(aShuffle, SIGNAL(triggered()), this, SLOT(actShuffle()));
aMulligan = new QAction(this); aMulligan = new QAction(this);
connect(aMulligan, SIGNAL(triggered()), this, SLOT(actMulligan())); connect(aMulligan, SIGNAL(triggered()), this, SLOT(actMulligan()));
aMoveTopCardsToGrave = new QAction(this); aMoveTopCardsToGrave = new QAction(this);
connect(aMoveTopCardsToGrave, SIGNAL(triggered()), this, SLOT(actMoveTopCardsToGrave())); connect(aMoveTopCardsToGrave, SIGNAL(triggered()), this, SLOT(actMoveTopCardsToGrave()));
aMoveTopCardsToExile = new QAction(this); aMoveTopCardsToExile = new QAction(this);
connect(aMoveTopCardsToExile, SIGNAL(triggered()), this, SLOT(actMoveTopCardsToExile())); connect(aMoveTopCardsToExile, SIGNAL(triggered()), this, SLOT(actMoveTopCardsToExile()));
aMoveTopCardToBottom = new QAction(this); aMoveTopCardToBottom = new QAction(this);
connect(aMoveTopCardToBottom, SIGNAL(triggered()), this, SLOT(actMoveTopCardToBottom())); connect(aMoveTopCardToBottom, SIGNAL(triggered()), this, SLOT(actMoveTopCardToBottom()));
} }
playerMenu = new QMenu(QString()); playerMenu = new QMenu(QString());
table->setMenu(playerMenu); table->setMenu(playerMenu);
if (local) { if (local) {
handMenu = playerMenu->addMenu(QString()); handMenu = playerMenu->addMenu(QString());
handMenu->addAction(aMulligan); handMenu->addAction(aMulligan);
handMenu->addAction(aMoveHandToTopLibrary); handMenu->addAction(aMoveHandToTopLibrary);
handMenu->addAction(aMoveHandToBottomLibrary); handMenu->addAction(aMoveHandToBottomLibrary);
handMenu->addAction(aMoveHandToGrave); handMenu->addAction(aMoveHandToGrave);
handMenu->addAction(aMoveHandToRfg); handMenu->addAction(aMoveHandToRfg);
handMenu->addSeparator(); handMenu->addSeparator();
playerLists.append(mRevealHand = handMenu->addMenu(QString())); playerLists.append(mRevealHand = handMenu->addMenu(QString()));
playerLists.append(mRevealRandomHandCard = handMenu->addMenu(QString())); playerLists.append(mRevealRandomHandCard = handMenu->addMenu(QString()));
hand->setMenu(handMenu); hand->setMenu(handMenu);
libraryMenu = playerMenu->addMenu(QString()); libraryMenu = playerMenu->addMenu(QString());
libraryMenu->addAction(aDrawCard); libraryMenu->addAction(aDrawCard);
libraryMenu->addAction(aDrawCards); libraryMenu->addAction(aDrawCards);
libraryMenu->addAction(aUndoDraw); libraryMenu->addAction(aUndoDraw);
libraryMenu->addSeparator(); libraryMenu->addSeparator();
libraryMenu->addAction(aShuffle); libraryMenu->addAction(aShuffle);
libraryMenu->addSeparator(); libraryMenu->addSeparator();
libraryMenu->addAction(aViewLibrary); libraryMenu->addAction(aViewLibrary);
libraryMenu->addAction(aViewTopCards); libraryMenu->addAction(aViewTopCards);
libraryMenu->addSeparator(); libraryMenu->addSeparator();
playerLists.append(mRevealLibrary = libraryMenu->addMenu(QString())); playerLists.append(mRevealLibrary = libraryMenu->addMenu(QString()));
playerLists.append(mRevealTopCard = libraryMenu->addMenu(QString())); playerLists.append(mRevealTopCard = libraryMenu->addMenu(QString()));
libraryMenu->addAction(aAlwaysRevealTopCard); libraryMenu->addAction(aAlwaysRevealTopCard);
libraryMenu->addAction(aOpenDeckInDeckEditor); libraryMenu->addAction(aOpenDeckInDeckEditor);
libraryMenu->addSeparator(); libraryMenu->addSeparator();
libraryMenu->addAction(aMoveTopCardsToGrave); libraryMenu->addAction(aMoveTopCardsToGrave);
libraryMenu->addAction(aMoveTopCardsToExile); libraryMenu->addAction(aMoveTopCardsToExile);
libraryMenu->addAction(aMoveTopCardToBottom); libraryMenu->addAction(aMoveTopCardToBottom);
deck->setMenu(libraryMenu, aDrawCard); deck->setMenu(libraryMenu, aDrawCard);
} else { } else {
handMenu = 0; handMenu = 0;
libraryMenu = 0; libraryMenu = 0;
} }
graveMenu = playerMenu->addMenu(QString()); graveMenu = playerMenu->addMenu(QString());
graveMenu->addAction(aViewGraveyard); graveMenu->addAction(aViewGraveyard);
grave->setMenu(graveMenu, aViewGraveyard); grave->setMenu(graveMenu, aViewGraveyard);
rfgMenu = playerMenu->addMenu(QString()); rfgMenu = playerMenu->addMenu(QString());
rfgMenu->addAction(aViewRfg); rfgMenu->addAction(aViewRfg);
rfg->setMenu(rfgMenu, aViewRfg); rfg->setMenu(rfgMenu, aViewRfg);
if (local) { if (local) {
graveMenu->addSeparator(); graveMenu->addSeparator();
graveMenu->addAction(aMoveGraveToTopLibrary); graveMenu->addAction(aMoveGraveToTopLibrary);
graveMenu->addAction(aMoveGraveToBottomLibrary); graveMenu->addAction(aMoveGraveToBottomLibrary);
graveMenu->addAction(aMoveGraveToHand); graveMenu->addAction(aMoveGraveToHand);
graveMenu->addAction(aMoveGraveToRfg); graveMenu->addAction(aMoveGraveToRfg);
rfgMenu->addSeparator(); rfgMenu->addSeparator();
rfgMenu->addAction(aMoveRfgToTopLibrary); rfgMenu->addAction(aMoveRfgToTopLibrary);
rfgMenu->addAction(aMoveRfgToBottomLibrary); rfgMenu->addAction(aMoveRfgToBottomLibrary);
rfgMenu->addAction(aMoveRfgToHand); rfgMenu->addAction(aMoveRfgToHand);
rfgMenu->addAction(aMoveRfgToGrave); rfgMenu->addAction(aMoveRfgToGrave);
sbMenu = playerMenu->addMenu(QString()); sbMenu = playerMenu->addMenu(QString());
sbMenu->addAction(aViewSideboard); sbMenu->addAction(aViewSideboard);
sb->setMenu(sbMenu, aViewSideboard); sb->setMenu(sbMenu, aViewSideboard);
aUntapAll = new QAction(this); aUntapAll = new QAction(this);
connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll())); connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll()));
aRollDie = new QAction(this); aRollDie = new QAction(this);
connect(aRollDie, SIGNAL(triggered()), this, SLOT(actRollDie())); connect(aRollDie, SIGNAL(triggered()), this, SLOT(actRollDie()));
aCreateToken = new QAction(this); aCreateToken = new QAction(this);
connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken())); connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken()));
aCreateAnotherToken = new QAction(this); aCreateAnotherToken = new QAction(this);
connect(aCreateAnotherToken, SIGNAL(triggered()), this, SLOT(actCreateAnotherToken())); connect(aCreateAnotherToken, SIGNAL(triggered()), this, SLOT(actCreateAnotherToken()));
aCreateAnotherToken->setEnabled(false); aCreateAnotherToken->setEnabled(false);
createPredefinedTokenMenu = new QMenu(QString()); createPredefinedTokenMenu = new QMenu(QString());
playerMenu->addSeparator(); playerMenu->addSeparator();
countersMenu = playerMenu->addMenu(QString()); countersMenu = playerMenu->addMenu(QString());
playerMenu->addSeparator(); playerMenu->addSeparator();
playerMenu->addAction(aUntapAll); playerMenu->addAction(aUntapAll);
playerMenu->addSeparator(); playerMenu->addSeparator();
playerMenu->addAction(aRollDie); playerMenu->addAction(aRollDie);
playerMenu->addSeparator(); playerMenu->addSeparator();
playerMenu->addAction(aCreateToken); playerMenu->addAction(aCreateToken);
playerMenu->addAction(aCreateAnotherToken); playerMenu->addAction(aCreateAnotherToken);
playerMenu->addMenu(createPredefinedTokenMenu); playerMenu->addMenu(createPredefinedTokenMenu);
playerMenu->addSeparator(); playerMenu->addSeparator();
sayMenu = playerMenu->addMenu(QString()); sayMenu = playerMenu->addMenu(QString());
initSayMenu(); initSayMenu();
aCardMenu = new QAction(this); aCardMenu = new QAction(this);
playerMenu->addSeparator(); playerMenu->addSeparator();
playerMenu->addAction(aCardMenu); playerMenu->addAction(aCardMenu);
for (int i = 0; i < playerLists.size(); ++i) { for (int i = 0; i < playerLists.size(); ++i) {
QAction *newAction = playerLists[i]->addAction(QString()); QAction *newAction = playerLists[i]->addAction(QString());
newAction->setData(-1); newAction->setData(-1);
connect(newAction, SIGNAL(triggered()), this, SLOT(playerListActionTriggered())); connect(newAction, SIGNAL(triggered()), this, SLOT(playerListActionTriggered()));
allPlayersActions.append(newAction); allPlayersActions.append(newAction);
playerLists[i]->addSeparator(); playerLists[i]->addSeparator();
} }
} else { } else {
countersMenu = 0; countersMenu = 0;
sbMenu = 0; sbMenu = 0;
aCreateAnotherToken = 0; aCreateAnotherToken = 0;
createPredefinedTokenMenu = 0; createPredefinedTokenMenu = 0;
aCardMenu = 0; aCardMenu = 0;
} }
aTap = new QAction(this); aTap = new QAction(this);
aTap->setData(cmTap); aTap->setData(cmTap);
connect(aTap, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aTap, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
aUntap = new QAction(this); aUntap = new QAction(this);
aUntap->setData(cmUntap); aUntap->setData(cmUntap);
connect(aUntap, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aUntap, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
aDoesntUntap = new QAction(this); aDoesntUntap = new QAction(this);
aDoesntUntap->setData(cmDoesntUntap); aDoesntUntap->setData(cmDoesntUntap);
connect(aDoesntUntap, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aDoesntUntap, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
aAttach = new QAction(this); aAttach = new QAction(this);
connect(aAttach, SIGNAL(triggered()), this, SLOT(actAttach())); connect(aAttach, SIGNAL(triggered()), this, SLOT(actAttach()));
aUnattach = new QAction(this); aUnattach = new QAction(this);
connect(aUnattach, SIGNAL(triggered()), this, SLOT(actUnattach())); connect(aUnattach, SIGNAL(triggered()), this, SLOT(actUnattach()));
aDrawArrow = new QAction(this); aDrawArrow = new QAction(this);
connect(aDrawArrow, SIGNAL(triggered()), this, SLOT(actDrawArrow())); connect(aDrawArrow, SIGNAL(triggered()), this, SLOT(actDrawArrow()));
aIncP = new QAction(this); aIncP = new QAction(this);
connect(aIncP, SIGNAL(triggered()), this, SLOT(actIncP())); connect(aIncP, SIGNAL(triggered()), this, SLOT(actIncP()));
aDecP = new QAction(this); aDecP = new QAction(this);
connect(aDecP, SIGNAL(triggered()), this, SLOT(actDecP())); connect(aDecP, SIGNAL(triggered()), this, SLOT(actDecP()));
aIncT = new QAction(this); aIncT = new QAction(this);
connect(aIncT, SIGNAL(triggered()), this, SLOT(actIncT())); connect(aIncT, SIGNAL(triggered()), this, SLOT(actIncT()));
aDecT = new QAction(this); aDecT = new QAction(this);
connect(aDecT, SIGNAL(triggered()), this, SLOT(actDecT())); connect(aDecT, SIGNAL(triggered()), this, SLOT(actDecT()));
aIncPT = new QAction(this); aIncPT = new QAction(this);
connect(aIncPT, SIGNAL(triggered()), this, SLOT(actIncPT())); connect(aIncPT, SIGNAL(triggered()), this, SLOT(actIncPT()));
aDecPT = new QAction(this); aDecPT = new QAction(this);
connect(aDecPT, SIGNAL(triggered()), this, SLOT(actDecPT())); connect(aDecPT, SIGNAL(triggered()), this, SLOT(actDecPT()));
aSetPT = new QAction(this); aSetPT = new QAction(this);
connect(aSetPT, SIGNAL(triggered()), this, SLOT(actSetPT())); connect(aSetPT, SIGNAL(triggered()), this, SLOT(actSetPT()));
aSetAnnotation = new QAction(this); aSetAnnotation = new QAction(this);
connect(aSetAnnotation, SIGNAL(triggered()), this, SLOT(actSetAnnotation())); connect(aSetAnnotation, SIGNAL(triggered()), this, SLOT(actSetAnnotation()));
aFlip = new QAction(this); aFlip = new QAction(this);
aFlip->setData(cmFlip); aFlip->setData(cmFlip);
connect(aFlip, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aFlip, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
aPeek = new QAction(this); aPeek = new QAction(this);
aPeek->setData(cmPeek); aPeek->setData(cmPeek);
connect(aPeek, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aPeek, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
aClone = new QAction(this); aClone = new QAction(this);
aClone->setData(cmClone); aClone->setData(cmClone);
connect(aClone, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aClone, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
aMoveToTopLibrary = new QAction(this); aMoveToTopLibrary = new QAction(this);
aMoveToTopLibrary->setData(cmMoveToTopLibrary); aMoveToTopLibrary->setData(cmMoveToTopLibrary);
aMoveToBottomLibrary = new QAction(this); aMoveToBottomLibrary = new QAction(this);
aMoveToBottomLibrary->setData(cmMoveToBottomLibrary); aMoveToBottomLibrary->setData(cmMoveToBottomLibrary);
aMoveToGraveyard = new QAction(this); aMoveToGraveyard = new QAction(this);
aMoveToGraveyard->setData(cmMoveToGraveyard); aMoveToGraveyard->setData(cmMoveToGraveyard);
aMoveToExile = new QAction(this); aMoveToExile = new QAction(this);
aMoveToExile->setData(cmMoveToExile); aMoveToExile->setData(cmMoveToExile);
connect(aMoveToTopLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aMoveToTopLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToBottomLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aMoveToBottomLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToGraveyard, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aMoveToGraveyard, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToExile, SIGNAL(triggered()), this, SLOT(cardMenuAction())); connect(aMoveToExile, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
aPlay = new QAction(this); aPlay = new QAction(this);
connect(aPlay, SIGNAL(triggered()), this, SLOT(actPlay())); connect(aPlay, SIGNAL(triggered()), this, SLOT(actPlay()));
aHide = new QAction(this); aHide = new QAction(this);
connect(aHide, SIGNAL(triggered()), this, SLOT(actHide())); connect(aHide, SIGNAL(triggered()), this, SLOT(actHide()));
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
QAction *tempAddCounter = new QAction(this); QAction *tempAddCounter = new QAction(this);
tempAddCounter->setData(9 + i * 1000); tempAddCounter->setData(9 + i * 1000);
QAction *tempRemoveCounter = new QAction(this); QAction *tempRemoveCounter = new QAction(this);
tempRemoveCounter->setData(10 + i * 1000); tempRemoveCounter->setData(10 + i * 1000);
QAction *tempSetCounter = new QAction(this); QAction *tempSetCounter = new QAction(this);
tempSetCounter->setData(11 + i * 1000); tempSetCounter->setData(11 + i * 1000);
aAddCounter.append(tempAddCounter); aAddCounter.append(tempAddCounter);
aRemoveCounter.append(tempRemoveCounter); aRemoveCounter.append(tempRemoveCounter);
aSetCounter.append(tempSetCounter); aSetCounter.append(tempSetCounter);
connect(tempAddCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger())); connect(tempAddCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
connect(tempRemoveCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger())); connect(tempRemoveCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
connect(tempSetCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger())); connect(tempSetCounter, SIGNAL(triggered()), this, SLOT(actCardCounterTrigger()));
} }
const QList<Player *> &players = game->getPlayers().values(); const QList<Player *> &players = game->getPlayers().values();
for (int i = 0; i < players.size(); ++i) for (int i = 0; i < players.size(); ++i)
addPlayer(players[i]); addPlayer(players[i]);
rearrangeZones(); rearrangeZones();
retranslateUi(); retranslateUi();
} }
Player::~Player() Player::~Player()
{ {
qDebug() << "Player destructor:" << getName(); qDebug() << "Player destructor:" << getName();
static_cast<GameScene *>(scene())->removePlayer(this); static_cast<GameScene *>(scene())->removePlayer(this);
clear(); clear();
QMapIterator<QString, CardZone *> i(zones); QMapIterator<QString, CardZone *> i(zones);
while (i.hasNext()) while (i.hasNext())
delete i.next().value(); delete i.next().value();
zones.clear(); zones.clear();
delete playerMenu; delete playerMenu;
delete userInfo; delete userInfo;
} }
void Player::clear() void Player::clear()
{ {
clearArrows(); clearArrows();
QMapIterator<QString, CardZone *> i(zones); QMapIterator<QString, CardZone *> i(zones);
while (i.hasNext()) while (i.hasNext())
i.next().value()->clearContents(); i.next().value()->clearContents();
clearCounters(); clearCounters();
} }
void Player::addPlayer(Player *player) void Player::addPlayer(Player *player)
{ {
if (player == this) if (player == this)
return; return;
for (int i = 0; i < playerLists.size(); ++i) { for (int i = 0; i < playerLists.size(); ++i) {
QAction *newAction = playerLists[i]->addAction(player->getName()); QAction *newAction = playerLists[i]->addAction(player->getName());
newAction->setData(player->getId()); newAction->setData(player->getId());
connect(newAction, SIGNAL(triggered()), this, SLOT(playerListActionTriggered())); connect(newAction, SIGNAL(triggered()), this, SLOT(playerListActionTriggered()));
} }
} }
void Player::removePlayer(Player *player) void Player::removePlayer(Player *player)
{ {
for (int i = 0; i < playerLists.size(); ++i) { for (int i = 0; i < playerLists.size(); ++i) {
QList<QAction *> actionList = playerLists[i]->actions(); QList<QAction *> actionList = playerLists[i]->actions();
for (int j = 0; j < actionList.size(); ++j) for (int j = 0; j < actionList.size(); ++j)
if (actionList[j]->data().toInt() == player->getId()) { if (actionList[j]->data().toInt() == player->getId()) {
playerLists[i]->removeAction(actionList[j]); playerLists[i]->removeAction(actionList[j]);
actionList[j]->deleteLater(); actionList[j]->deleteLater();
} }
} }
} }
void Player::playerListActionTriggered() void Player::playerListActionTriggered()
{ {
QAction *action = static_cast<QAction *>(sender()); QAction *action = static_cast<QAction *>(sender());
QMenu *menu = static_cast<QMenu *>(action->parentWidget()); QMenu *menu = static_cast<QMenu *>(action->parentWidget());
Command_RevealCards cmd; Command_RevealCards cmd;
const int otherPlayerId = action->data().toInt(); const int otherPlayerId = action->data().toInt();
if (otherPlayerId != -1) if (otherPlayerId != -1)
cmd.set_player_id(otherPlayerId); cmd.set_player_id(otherPlayerId);
if (menu == mRevealLibrary) { if (menu == mRevealLibrary) {
cmd.set_zone_name("deck"); cmd.set_zone_name("deck");
cmd.set_grant_write_access(true); cmd.set_grant_write_access(true);
} else if (menu == mRevealTopCard) { } else if (menu == mRevealTopCard) {
cmd.set_zone_name("deck"); cmd.set_zone_name("deck");
cmd.set_card_id(0); cmd.set_card_id(0);
} else if (menu == mRevealHand) } else if (menu == mRevealHand)
cmd.set_zone_name("hand"); cmd.set_zone_name("hand");
else if (menu == mRevealRandomHandCard) { else if (menu == mRevealRandomHandCard) {
cmd.set_zone_name("hand"); cmd.set_zone_name("hand");
cmd.set_card_id(-2); cmd.set_card_id(-2);
} else } else
return; return;
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::rearrangeZones() void Player::rearrangeZones()
{ {
QPointF base = QPointF(CARD_HEIGHT + counterAreaWidth + 15, 0); QPointF base = QPointF(CARD_HEIGHT + counterAreaWidth + 15, 0);
if (settingsCache->getHorizontalHand()) { if (settingsCache->getHorizontalHand()) {
if (mirrored) { if (mirrored) {
if (hand->contentsKnown()) { if (hand->contentsKnown()) {
handVisible = true; handVisible = true;
hand->setPos(base); hand->setPos(base);
base += QPointF(0, hand->boundingRect().height()); base += QPointF(0, hand->boundingRect().height());
} else } else
handVisible = false; handVisible = false;
stack->setPos(base); stack->setPos(base);
base += QPointF(stack->boundingRect().width(), 0); base += QPointF(stack->boundingRect().width(), 0);
table->setPos(base); table->setPos(base);
} else { } else {
stack->setPos(base); stack->setPos(base);
table->setPos(base.x() + stack->boundingRect().width(), 0); table->setPos(base.x() + stack->boundingRect().width(), 0);
base += QPointF(0, table->boundingRect().height()); base += QPointF(0, table->boundingRect().height());
if (hand->contentsKnown()) { if (hand->contentsKnown()) {
handVisible = true; handVisible = true;
hand->setPos(base); hand->setPos(base);
} else } else
handVisible = false; handVisible = false;
} }
hand->setWidth(table->getWidth() + stack->boundingRect().width()); hand->setWidth(table->getWidth() + stack->boundingRect().width());
} else { } else {
handVisible = true; handVisible = true;
hand->setPos(base); hand->setPos(base);
base += QPointF(hand->boundingRect().width(), 0); base += QPointF(hand->boundingRect().width(), 0);
stack->setPos(base); stack->setPos(base);
base += QPointF(stack->boundingRect().width(), 0); base += QPointF(stack->boundingRect().width(), 0);
table->setPos(base); table->setPos(base);
} }
hand->setVisible(handVisible); hand->setVisible(handVisible);
hand->updateOrientation(); hand->updateOrientation();
table->reorganizeCards(); table->reorganizeCards();
updateBoundingRect(); updateBoundingRect();
rearrangeCounters(); rearrangeCounters();
} }
void Player::updateZones() void Player::updateZones()
{ {
table->reorganizeCards(); table->reorganizeCards();
} }
void Player::updateBoundingRect() void Player::updateBoundingRect()
{ {
prepareGeometryChange(); prepareGeometryChange();
qreal width = CARD_HEIGHT + 15 + counterAreaWidth + stack->boundingRect().width(); qreal width = CARD_HEIGHT + 15 + counterAreaWidth + stack->boundingRect().width();
if (settingsCache->getHorizontalHand()) { if (settingsCache->getHorizontalHand()) {
qreal handHeight = handVisible ? hand->boundingRect().height() : 0; qreal handHeight = handVisible ? hand->boundingRect().height() : 0;
bRect = QRectF(0, 0, width + table->boundingRect().width(), table->boundingRect().height() + handHeight); bRect = QRectF(0, 0, width + table->boundingRect().width(), table->boundingRect().height() + handHeight);
} else } else
bRect = QRectF(0, 0, width + hand->boundingRect().width() + table->boundingRect().width(), table->boundingRect().height()); bRect = QRectF(0, 0, width + hand->boundingRect().width() + table->boundingRect().width(), table->boundingRect().height());
playerArea->setSize(CARD_HEIGHT + counterAreaWidth + 15, bRect.height()); playerArea->setSize(CARD_HEIGHT + counterAreaWidth + 15, bRect.height());
emit sizeChanged(); emit sizeChanged();
} }
void Player::retranslateUi() void Player::retranslateUi()
{ {
aViewGraveyard->setText(tr("&View graveyard")); aViewGraveyard->setText(tr("&View graveyard"));
aViewRfg->setText(tr("&View exile")); aViewRfg->setText(tr("&View exile"));
playerMenu->setTitle(tr("Player \"%1\"").arg(QString::fromStdString(userInfo->name()))); playerMenu->setTitle(tr("Player \"%1\"").arg(QString::fromStdString(userInfo->name())));
graveMenu->setTitle(tr("&Graveyard")); graveMenu->setTitle(tr("&Graveyard"));
rfgMenu->setTitle(tr("&Exile")); rfgMenu->setTitle(tr("&Exile"));
if (local) { if (local) {
aMoveHandToTopLibrary->setText(tr("Move to &top of library")); aMoveHandToTopLibrary->setText(tr("Move to &top of library"));
aMoveHandToBottomLibrary->setText(tr("Move to &bottom of library")); aMoveHandToBottomLibrary->setText(tr("Move to &bottom of library"));
aMoveHandToGrave->setText(tr("Move to &graveyard")); aMoveHandToGrave->setText(tr("Move to &graveyard"));
aMoveHandToRfg->setText(tr("Move to &exile")); aMoveHandToRfg->setText(tr("Move to &exile"));
aMoveGraveToTopLibrary->setText(tr("Move to &top of library")); aMoveGraveToTopLibrary->setText(tr("Move to &top of library"));
aMoveGraveToBottomLibrary->setText(tr("Move to &bottom of library")); aMoveGraveToBottomLibrary->setText(tr("Move to &bottom of library"));
aMoveGraveToHand->setText(tr("Move to &hand")); aMoveGraveToHand->setText(tr("Move to &hand"));
aMoveGraveToRfg->setText(tr("Move to &exile")); aMoveGraveToRfg->setText(tr("Move to &exile"));
aMoveRfgToTopLibrary->setText(tr("Move to &top of library")); aMoveRfgToTopLibrary->setText(tr("Move to &top of library"));
aMoveRfgToBottomLibrary->setText(tr("Move to &bottom of library")); aMoveRfgToBottomLibrary->setText(tr("Move to &bottom of library"));
aMoveRfgToHand->setText(tr("Move to &hand")); aMoveRfgToHand->setText(tr("Move to &hand"));
aMoveRfgToGrave->setText(tr("Move to &graveyard")); aMoveRfgToGrave->setText(tr("Move to &graveyard"));
aViewLibrary->setText(tr("&View library")); aViewLibrary->setText(tr("&View library"));
aViewTopCards->setText(tr("View &top cards of library...")); aViewTopCards->setText(tr("View &top cards of library..."));
mRevealLibrary->setTitle(tr("Reveal &library to")); mRevealLibrary->setTitle(tr("Reveal &library to"));
mRevealTopCard->setTitle(tr("Reveal t&op card to")); mRevealTopCard->setTitle(tr("Reveal t&op card to"));
aAlwaysRevealTopCard->setText(tr("&Always reveal top card")); aAlwaysRevealTopCard->setText(tr("&Always reveal top card"));
aOpenDeckInDeckEditor->setText(tr("O&pen deck in deck editor")); aOpenDeckInDeckEditor->setText(tr("O&pen deck in deck editor"));
aViewSideboard->setText(tr("&View sideboard")); aViewSideboard->setText(tr("&View sideboard"));
aDrawCard->setText(tr("&Draw card")); aDrawCard->setText(tr("&Draw card"));
aDrawCards->setText(tr("D&raw cards...")); aDrawCards->setText(tr("D&raw cards..."));
aUndoDraw->setText(tr("&Undo last draw")); aUndoDraw->setText(tr("&Undo last draw"));
aMulligan->setText(tr("Take &mulligan")); aMulligan->setText(tr("Take &mulligan"));
aShuffle->setText(tr("&Shuffle")); aShuffle->setText(tr("&Shuffle"));
aMoveTopCardsToGrave->setText(tr("Move top cards to &graveyard...")); aMoveTopCardsToGrave->setText(tr("Move top cards to &graveyard..."));
aMoveTopCardsToExile->setText(tr("Move top cards to &exile...")); aMoveTopCardsToExile->setText(tr("Move top cards to &exile..."));
aMoveTopCardToBottom->setText(tr("Put top card on &bottom")); aMoveTopCardToBottom->setText(tr("Put top card on &bottom"));
handMenu->setTitle(tr("&Hand")); handMenu->setTitle(tr("&Hand"));
mRevealHand->setTitle(tr("&Reveal to")); mRevealHand->setTitle(tr("&Reveal to"));
mRevealRandomHandCard->setTitle(tr("Reveal r&andom card to")); mRevealRandomHandCard->setTitle(tr("Reveal r&andom card to"));
sbMenu->setTitle(tr("&Sideboard")); sbMenu->setTitle(tr("&Sideboard"));
libraryMenu->setTitle(tr("&Library")); libraryMenu->setTitle(tr("&Library"));
countersMenu->setTitle(tr("&Counters")); countersMenu->setTitle(tr("&Counters"));
aUntapAll->setText(tr("&Untap all permanents")); aUntapAll->setText(tr("&Untap all permanents"));
aRollDie->setText(tr("R&oll die...")); aRollDie->setText(tr("R&oll die..."));
aCreateToken->setText(tr("&Create token...")); aCreateToken->setText(tr("&Create token..."));
aCreateAnotherToken->setText(tr("C&reate another token")); aCreateAnotherToken->setText(tr("C&reate another token"));
createPredefinedTokenMenu->setTitle(tr("Cr&eate predefined token")); createPredefinedTokenMenu->setTitle(tr("Cr&eate predefined token"));
sayMenu->setTitle(tr("S&ay")); sayMenu->setTitle(tr("S&ay"));
QMapIterator<int, AbstractCounter *> counterIterator(counters); QMapIterator<int, AbstractCounter *> counterIterator(counters);
while (counterIterator.hasNext()) while (counterIterator.hasNext())
counterIterator.next().value()->retranslateUi(); counterIterator.next().value()->retranslateUi();
aCardMenu->setText(tr("C&ard")); aCardMenu->setText(tr("C&ard"));
for (int i = 0; i < allPlayersActions.size(); ++i) for (int i = 0; i < allPlayersActions.size(); ++i)
allPlayersActions[i]->setText(tr("&All players")); allPlayersActions[i]->setText(tr("&All players"));
} }
aPlay->setText(tr("&Play")); aPlay->setText(tr("&Play"));
aHide->setText(tr("&Hide")); aHide->setText(tr("&Hide"));
aTap->setText(tr("&Tap")); aTap->setText(tr("&Tap"));
aUntap->setText(tr("&Untap")); aUntap->setText(tr("&Untap"));
aDoesntUntap->setText(tr("Toggle &normal untapping")); aDoesntUntap->setText(tr("Toggle &normal untapping"));
aFlip->setText(tr("&Flip")); aFlip->setText(tr("&Flip"));
aPeek->setText(tr("&Peek at card face")); aPeek->setText(tr("&Peek at card face"));
aClone->setText(tr("&Clone")); aClone->setText(tr("&Clone"));
aClone->setShortcut(tr("Ctrl+J")); aClone->setShortcut(tr("Ctrl+J"));
aAttach->setText(tr("Attac&h to card...")); aAttach->setText(tr("Attac&h to card..."));
aAttach->setShortcut(tr("Ctrl+A")); aAttach->setShortcut(tr("Ctrl+A"));
aUnattach->setText(tr("Unattac&h")); aUnattach->setText(tr("Unattac&h"));
aDrawArrow->setText(tr("&Draw arrow...")); aDrawArrow->setText(tr("&Draw arrow..."));
aIncP->setText(tr("&Increase power")); aIncP->setText(tr("&Increase power"));
aIncP->setShortcut(tr("Ctrl++")); aIncP->setShortcut(tr("Ctrl++"));
aDecP->setText(tr("&Decrease power")); aDecP->setText(tr("&Decrease power"));
aDecP->setShortcut(tr("Ctrl+-")); aDecP->setShortcut(tr("Ctrl+-"));
aIncT->setText(tr("I&ncrease toughness")); aIncT->setText(tr("I&ncrease toughness"));
aIncT->setShortcut(tr("Alt++")); aIncT->setShortcut(tr("Alt++"));
aDecT->setText(tr("D&ecrease toughness")); aDecT->setText(tr("D&ecrease toughness"));
aDecT->setShortcut(tr("Alt+-")); aDecT->setShortcut(tr("Alt+-"));
aIncPT->setText(tr("In&crease power and toughness")); aIncPT->setText(tr("In&crease power and toughness"));
aIncPT->setShortcut(tr("Ctrl+Alt++")); aIncPT->setShortcut(tr("Ctrl+Alt++"));
aDecPT->setText(tr("Dec&rease power and toughness")); aDecPT->setText(tr("Dec&rease power and toughness"));
aDecPT->setShortcut(tr("Ctrl+Alt+-")); aDecPT->setShortcut(tr("Ctrl+Alt+-"));
aSetPT->setText(tr("Set &power and toughness...")); aSetPT->setText(tr("Set &power and toughness..."));
aSetPT->setShortcut(tr("Ctrl+P")); aSetPT->setShortcut(tr("Ctrl+P"));
aSetAnnotation->setText(tr("&Set annotation...")); aSetAnnotation->setText(tr("&Set annotation..."));
QStringList counterColors; QStringList counterColors;
counterColors.append(tr("red")); counterColors.append(tr("red"));
counterColors.append(tr("yellow")); counterColors.append(tr("yellow"));
counterColors.append(tr("green")); counterColors.append(tr("green"));
for (int i = 0; i < aAddCounter.size(); ++i) for (int i = 0; i < aAddCounter.size(); ++i)
aAddCounter[i]->setText(tr("&Add counter (%1)").arg(counterColors[i])); aAddCounter[i]->setText(tr("&Add counter (%1)").arg(counterColors[i]));
for (int i = 0; i < aRemoveCounter.size(); ++i) for (int i = 0; i < aRemoveCounter.size(); ++i)
aRemoveCounter[i]->setText(tr("&Remove counter (%1)").arg(counterColors[i])); aRemoveCounter[i]->setText(tr("&Remove counter (%1)").arg(counterColors[i]));
for (int i = 0; i < aSetCounter.size(); ++i) for (int i = 0; i < aSetCounter.size(); ++i)
aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(counterColors[i])); aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(counterColors[i]));
aMoveToTopLibrary->setText(tr("&top of library")); aMoveToTopLibrary->setText(tr("&top of library"));
aMoveToBottomLibrary->setText(tr("&bottom of library")); aMoveToBottomLibrary->setText(tr("&bottom of library"));
aMoveToGraveyard->setText(tr("&graveyard")); aMoveToGraveyard->setText(tr("&graveyard"));
aMoveToGraveyard->setShortcut(tr("Ctrl+Del")); aMoveToGraveyard->setShortcut(tr("Ctrl+Del"));
aMoveToExile->setText(tr("&exile")); aMoveToExile->setText(tr("&exile"));
QMapIterator<QString, CardZone *> zoneIterator(zones); QMapIterator<QString, CardZone *> zoneIterator(zones);
while (zoneIterator.hasNext()) while (zoneIterator.hasNext())
zoneIterator.next().value()->retranslateUi(); zoneIterator.next().value()->retranslateUi();
} }
void Player::setShortcutsActive() void Player::setShortcutsActive()
{ {
shortcutsActive = true; shortcutsActive = true;
aViewSideboard->setShortcut(tr("Ctrl+F3")); aViewSideboard->setShortcut(tr("Ctrl+F3"));
aViewLibrary->setShortcut(tr("F3")); aViewLibrary->setShortcut(tr("F3"));
aViewTopCards->setShortcut(tr("Ctrl+W")); aViewTopCards->setShortcut(tr("Ctrl+W"));
aViewGraveyard->setShortcut(tr("F4")); aViewGraveyard->setShortcut(tr("F4"));
aDrawCard->setShortcut(tr("Ctrl+D")); aDrawCard->setShortcut(tr("Ctrl+D"));
aDrawCards->setShortcut(tr("Ctrl+E")); aDrawCards->setShortcut(tr("Ctrl+E"));
aUndoDraw->setShortcut(tr("Ctrl+Shift+D")); aUndoDraw->setShortcut(tr("Ctrl+Shift+D"));
aMulligan->setShortcut(tr("Ctrl+M")); aMulligan->setShortcut(tr("Ctrl+M"));
aShuffle->setShortcut(tr("Ctrl+S")); aShuffle->setShortcut(tr("Ctrl+S"));
aUntapAll->setShortcut(tr("Ctrl+U")); aUntapAll->setShortcut(tr("Ctrl+U"));
aRollDie->setShortcut(tr("Ctrl+I")); aRollDie->setShortcut(tr("Ctrl+I"));
aCreateToken->setShortcut(tr("Ctrl+T")); aCreateToken->setShortcut(tr("Ctrl+T"));
aCreateAnotherToken->setShortcut(tr("Ctrl+G")); aCreateAnotherToken->setShortcut(tr("Ctrl+G"));
QMapIterator<int, AbstractCounter *> counterIterator(counters); QMapIterator<int, AbstractCounter *> counterIterator(counters);
while (counterIterator.hasNext()) while (counterIterator.hasNext())
counterIterator.next().value()->setShortcutsActive(); counterIterator.next().value()->setShortcutsActive();
} }
void Player::setShortcutsInactive() void Player::setShortcutsInactive()
{ {
shortcutsActive = false; shortcutsActive = false;
aViewSideboard->setShortcut(QKeySequence()); aViewSideboard->setShortcut(QKeySequence());
aViewLibrary->setShortcut(QKeySequence()); aViewLibrary->setShortcut(QKeySequence());
aViewTopCards->setShortcut(QKeySequence()); aViewTopCards->setShortcut(QKeySequence());
aViewGraveyard->setShortcut(QKeySequence()); aViewGraveyard->setShortcut(QKeySequence());
aDrawCard->setShortcut(QKeySequence()); aDrawCard->setShortcut(QKeySequence());
aDrawCards->setShortcut(QKeySequence()); aDrawCards->setShortcut(QKeySequence());
aUndoDraw->setShortcut(QKeySequence()); aUndoDraw->setShortcut(QKeySequence());
aMulligan->setShortcut(QKeySequence()); aMulligan->setShortcut(QKeySequence());
aShuffle->setShortcut(QKeySequence()); aShuffle->setShortcut(QKeySequence());
aUntapAll->setShortcut(QKeySequence()); aUntapAll->setShortcut(QKeySequence());
aRollDie->setShortcut(QKeySequence()); aRollDie->setShortcut(QKeySequence());
aCreateToken->setShortcut(QKeySequence()); aCreateToken->setShortcut(QKeySequence());
aCreateAnotherToken->setShortcut(QKeySequence()); aCreateAnotherToken->setShortcut(QKeySequence());
QMapIterator<int, AbstractCounter *> counterIterator(counters); QMapIterator<int, AbstractCounter *> counterIterator(counters);
while (counterIterator.hasNext()) while (counterIterator.hasNext())
counterIterator.next().value()->setShortcutsInactive(); counterIterator.next().value()->setShortcutsInactive();
} }
void Player::initSayMenu() void Player::initSayMenu()
{ {
sayMenu->clear(); sayMenu->clear();
QSettings settings; QSettings settings;
settings.beginGroup("messages"); settings.beginGroup("messages");
int count = settings.value("count", 0).toInt(); int count = settings.value("count", 0).toInt();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
QAction *newAction = new QAction(settings.value(QString("msg%1").arg(i)).toString(), this); QAction *newAction = new QAction(settings.value(QString("msg%1").arg(i)).toString(), this);
if (i <= 10) if (i <= 10)
newAction->setShortcut(QString("Ctrl+%1").arg((i + 1) % 10)); newAction->setShortcut(QString("Ctrl+%1").arg((i + 1) % 10));
connect(newAction, SIGNAL(triggered()), this, SLOT(actSayMessage())); connect(newAction, SIGNAL(triggered()), this, SLOT(actSayMessage()));
sayMenu->addAction(newAction); sayMenu->addAction(newAction);
} }
} }
void Player::setDeck(const DeckLoader &_deck) void Player::setDeck(const DeckLoader &_deck)
{ {
deck = new DeckLoader(_deck); deck = new DeckLoader(_deck);
aOpenDeckInDeckEditor->setEnabled(deck); aOpenDeckInDeckEditor->setEnabled(deck);
createPredefinedTokenMenu->clear(); createPredefinedTokenMenu->clear();
predefinedTokens.clear(); predefinedTokens.clear();
InnerDecklistNode *tokenZone = dynamic_cast<InnerDecklistNode *>(deck->getRoot()->findChild("tokens")); InnerDecklistNode *tokenZone = dynamic_cast<InnerDecklistNode *>(deck->getRoot()->findChild("tokens"));
if (tokenZone) if (tokenZone)
for (int i = 0; i < tokenZone->size(); ++i) { for (int i = 0; i < tokenZone->size(); ++i) {
const QString tokenName = tokenZone->at(i)->getName(); const QString tokenName = tokenZone->at(i)->getName();
predefinedTokens.append(tokenName); predefinedTokens.append(tokenName);
QAction *a = createPredefinedTokenMenu->addAction(tokenName); QAction *a = createPredefinedTokenMenu->addAction(tokenName);
if (i < 10) if (i < 10)
a->setShortcut("Alt+" + QString::number((i + 1) % 10)); a->setShortcut("Alt+" + QString::number((i + 1) % 10));
connect(a, SIGNAL(triggered()), this, SLOT(actCreatePredefinedToken())); connect(a, SIGNAL(triggered()), this, SLOT(actCreatePredefinedToken()));
} }
} }
void Player::actViewLibrary() void Player::actViewLibrary()
{ {
static_cast<GameScene *>(scene())->toggleZoneView(this, "deck", -1); static_cast<GameScene *>(scene())->toggleZoneView(this, "deck", -1);
} }
void Player::actViewTopCards() void Player::actViewTopCards()
{ {
bool ok; bool ok;
int number = QInputDialog::getInteger(0, tr("View top cards of library"), tr("Number of cards:"), defaultNumberTopCards, 1, 2000000000, 1, &ok); int number = QInputDialog::getInteger(0, tr("View top cards of library"), tr("Number of cards:"), defaultNumberTopCards, 1, 2000000000, 1, &ok);
if (ok) { if (ok) {
defaultNumberTopCards = number; defaultNumberTopCards = number;
static_cast<GameScene *>(scene())->toggleZoneView(this, "deck", number); static_cast<GameScene *>(scene())->toggleZoneView(this, "deck", number);
} }
} }
void Player::actAlwaysRevealTopCard() void Player::actAlwaysRevealTopCard()
{ {
Command_ChangeZoneProperties cmd; Command_ChangeZoneProperties cmd;
cmd.set_zone_name("deck"); cmd.set_zone_name("deck");
cmd.set_always_reveal_top_card(aAlwaysRevealTopCard->isChecked()); cmd.set_always_reveal_top_card(aAlwaysRevealTopCard->isChecked());
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::actOpenDeckInDeckEditor() void Player::actOpenDeckInDeckEditor()
{ {
emit openDeckEditor(deck); emit openDeckEditor(deck);
} }
void Player::actViewGraveyard() void Player::actViewGraveyard()
{ {
static_cast<GameScene *>(scene())->toggleZoneView(this, "grave", -1); static_cast<GameScene *>(scene())->toggleZoneView(this, "grave", -1);
} }
void Player::actViewRfg() void Player::actViewRfg()
{ {
static_cast<GameScene *>(scene())->toggleZoneView(this, "rfg", -1); static_cast<GameScene *>(scene())->toggleZoneView(this, "rfg", -1);
} }
void Player::actViewSideboard() void Player::actViewSideboard()
{ {
static_cast<GameScene *>(scene())->toggleZoneView(this, "sb", -1); static_cast<GameScene *>(scene())->toggleZoneView(this, "sb", -1);
} }
void Player::actShuffle() void Player::actShuffle()
{ {
sendGameCommand(Command_Shuffle()); sendGameCommand(Command_Shuffle());
} }
void Player::actDrawCard() void Player::actDrawCard()
{ {
Command_DrawCards cmd; Command_DrawCards cmd;
cmd.set_number(1); cmd.set_number(1);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::actMulligan() void Player::actMulligan()
{ {
sendGameCommand(Command_Mulligan()); sendGameCommand(Command_Mulligan());
} }
void Player::actDrawCards() void Player::actDrawCards()
{ {
int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:")); int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:"));
if (number) { if (number) {
Command_DrawCards cmd; Command_DrawCards cmd;
cmd.set_number(number); cmd.set_number(number);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
} }
void Player::actUndoDraw() void Player::actUndoDraw()
{ {
sendGameCommand(Command_UndoDraw()); sendGameCommand(Command_UndoDraw());
} }
void Player::actMoveTopCardsToGrave() void Player::actMoveTopCardsToGrave()
{ {
int number = QInputDialog::getInteger(0, tr("Move top cards to grave"), tr("Number:")); int number = QInputDialog::getInteger(0, tr("Move top cards to grave"), tr("Number:"));
if (!number) if (!number)
return; return;
const int maxCards = zones.value("deck")->getCards().size(); const int maxCards = zones.value("deck")->getCards().size();
if (number > maxCards) if (number > maxCards)
number = maxCards; number = maxCards;
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_zone("deck"); cmd.set_start_zone("deck");
cmd.set_target_player_id(getId()); cmd.set_target_player_id(getId());
cmd.set_target_zone("grave"); cmd.set_target_zone("grave");
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
for (int i = 0; i < number; ++i) for (int i = 0; i < number; ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(i); cmd.mutable_cards_to_move()->add_card()->set_card_id(i);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::actMoveTopCardsToExile() void Player::actMoveTopCardsToExile()
{ {
int number = QInputDialog::getInteger(0, tr("Move top cards to exile"), tr("Number:")); int number = QInputDialog::getInteger(0, tr("Move top cards to exile"), tr("Number:"));
if (!number) if (!number)
return; return;
const int maxCards = zones.value("deck")->getCards().size(); const int maxCards = zones.value("deck")->getCards().size();
if (number > maxCards) if (number > maxCards)
number = maxCards; number = maxCards;
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_zone("deck"); cmd.set_start_zone("deck");
cmd.set_target_player_id(getId()); cmd.set_target_player_id(getId());
cmd.set_target_zone("rfg"); cmd.set_target_zone("rfg");
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
for (int i = 0; i < number; ++i) for (int i = 0; i < number; ++i)
cmd.mutable_cards_to_move()->add_card()->set_card_id(i); cmd.mutable_cards_to_move()->add_card()->set_card_id(i);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::actMoveTopCardToBottom() void Player::actMoveTopCardToBottom()
{ {
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_zone("deck"); cmd.set_start_zone("deck");
cmd.mutable_cards_to_move()->add_card()->set_card_id(0); cmd.mutable_cards_to_move()->add_card()->set_card_id(0);
cmd.set_target_player_id(getId()); cmd.set_target_player_id(getId());
cmd.set_target_zone("deck"); cmd.set_target_zone("deck");
cmd.set_x(-1); cmd.set_x(-1);
cmd.set_y(0); cmd.set_y(0);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::actUntapAll() void Player::actUntapAll()
{ {
Command_SetCardAttr cmd; Command_SetCardAttr cmd;
cmd.set_zone("table"); cmd.set_zone("table");
cmd.set_attribute(AttrTapped); cmd.set_attribute(AttrTapped);
cmd.set_attr_value("0"); cmd.set_attr_value("0");
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::actRollDie() void Player::actRollDie()
{ {
bool ok; bool ok;
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok); int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
if (ok) { if (ok) {
Command_RollDie cmd; Command_RollDie cmd;
cmd.set_sides(sides); cmd.set_sides(sides);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
} }
void Player::actCreateToken() void Player::actCreateToken()
{ {
DlgCreateToken dlg(predefinedTokens); DlgCreateToken dlg(predefinedTokens);
if (!dlg.exec()) if (!dlg.exec())
return; return;
lastTokenName = dlg.getName(); lastTokenName = dlg.getName();
lastTokenColor = dlg.getColor(); lastTokenColor = dlg.getColor();
lastTokenPT = dlg.getPT(); lastTokenPT = dlg.getPT();
lastTokenAnnotation = dlg.getAnnotation(); lastTokenAnnotation = dlg.getAnnotation();
lastTokenDestroy = dlg.getDestroy(); lastTokenDestroy = dlg.getDestroy();
aCreateAnotherToken->setEnabled(true); aCreateAnotherToken->setEnabled(true);
actCreateAnotherToken(); actCreateAnotherToken();
} }
void Player::actCreateAnotherToken() void Player::actCreateAnotherToken()
{ {
Command_CreateToken cmd; Command_CreateToken cmd;
cmd.set_zone("table"); cmd.set_zone("table");
cmd.set_card_name(lastTokenName.toStdString()); cmd.set_card_name(lastTokenName.toStdString());
cmd.set_color(lastTokenColor.toStdString()); cmd.set_color(lastTokenColor.toStdString());
cmd.set_pt(lastTokenPT.toStdString()); cmd.set_pt(lastTokenPT.toStdString());
cmd.set_annotation(lastTokenAnnotation.toStdString()); cmd.set_annotation(lastTokenAnnotation.toStdString());
cmd.set_destroy_on_zone_change(lastTokenDestroy); cmd.set_destroy_on_zone_change(lastTokenDestroy);
cmd.set_x(-1); cmd.set_x(-1);
cmd.set_y(0); cmd.set_y(0);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::actCreatePredefinedToken() void Player::actCreatePredefinedToken()
{ {
QAction *action = static_cast<QAction *>(sender()); QAction *action = static_cast<QAction *>(sender());
CardInfo *cardInfo = db->getCard(action->text()); CardInfo *cardInfo = db->getCard(action->text());
lastTokenName = cardInfo->getName(); lastTokenName = cardInfo->getName();
lastTokenColor = cardInfo->getColors().isEmpty() ? QString() : cardInfo->getColors().first().toLower(); lastTokenColor = cardInfo->getColors().isEmpty() ? QString() : cardInfo->getColors().first().toLower();
lastTokenPT = cardInfo->getPowTough(); lastTokenPT = cardInfo->getPowTough();
lastTokenAnnotation = cardInfo->getText(); lastTokenAnnotation = cardInfo->getText();
lastTokenDestroy = true; lastTokenDestroy = true;
aCreateAnotherToken->setEnabled(true); aCreateAnotherToken->setEnabled(true);
actCreateAnotherToken(); actCreateAnotherToken();
} }
void Player::actSayMessage() void Player::actSayMessage()
{ {
QAction *a = qobject_cast<QAction *>(sender()); QAction *a = qobject_cast<QAction *>(sender());
Command_GameSay cmd; Command_GameSay cmd;
cmd.set_message(a->text().toStdString()); cmd.set_message(a->text().toStdString());
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::setCardAttrHelper(const GameEventContext &context, CardItem *card, CardAttribute attribute, const QString &avalue, bool allCards) void Player::setCardAttrHelper(const GameEventContext &context, CardItem *card, CardAttribute attribute, const QString &avalue, bool allCards)
{ {
bool moveCardContext = context.HasExtension(Context_MoveCard::ext); bool moveCardContext = context.HasExtension(Context_MoveCard::ext);
switch (attribute) { switch (attribute) {
case AttrTapped: { case AttrTapped: {
bool tapped = avalue == "1"; bool tapped = avalue == "1";
if (!(!tapped && card->getDoesntUntap() && allCards)) { if (!(!tapped && card->getDoesntUntap() && allCards)) {
if (!allCards) if (!allCards)
emit logSetTapped(this, card, tapped); emit logSetTapped(this, card, tapped);
card->setTapped(tapped, !moveCardContext); card->setTapped(tapped, !moveCardContext);
} }
break; break;
} }
case AttrAttacking: card->setAttacking(avalue == "1"); break; case AttrAttacking: card->setAttacking(avalue == "1"); break;
case AttrFaceDown: card->setFaceDown(avalue == "1"); break; case AttrFaceDown: card->setFaceDown(avalue == "1"); break;
case AttrColor: card->setColor(avalue); break; case AttrColor: card->setColor(avalue); break;
case AttrAnnotation: { case AttrAnnotation: {
emit logSetAnnotation(this, card, avalue); emit logSetAnnotation(this, card, avalue);
card->setAnnotation(avalue); card->setAnnotation(avalue);
break; break;
} }
case AttrDoesntUntap: { case AttrDoesntUntap: {
bool value = (avalue == "1"); bool value = (avalue == "1");
emit logSetDoesntUntap(this, card, value); emit logSetDoesntUntap(this, card, value);
card->setDoesntUntap(value); card->setDoesntUntap(value);
break; break;
} }
case AttrPT: { case AttrPT: {
emit logSetPT(this, card, avalue); emit logSetPT(this, card, avalue);
card->setPT(avalue); card->setPT(avalue);
break; break;
} }
} }
} }
void Player::eventGameSay(const Event_GameSay &event) void Player::eventGameSay(const Event_GameSay &event)
{ {
emit logSay(this, QString::fromStdString(event.message())); emit logSay(this, QString::fromStdString(event.message()));
} }
void Player::eventShuffle(const Event_Shuffle &event) void Player::eventShuffle(const Event_Shuffle &event)
{ {
CardZone *zone = zones.value(QString::fromStdString(event.zone_name())); CardZone *zone = zones.value(QString::fromStdString(event.zone_name()));
if (!zone) if (!zone)
return; return;
if (zone->getView()) if (zone->getView())
if (zone->getView()->getRevealZone()) if (zone->getView()->getRevealZone())
zone->getView()->setWriteableRevealZone(false); zone->getView()->setWriteableRevealZone(false);
emit logShuffle(this, zone); emit logShuffle(this, zone);
} }
void Player::eventRollDie(const Event_RollDie &event) void Player::eventRollDie(const Event_RollDie &event)
{ {
emit logRollDie(this, event.sides(), event.value()); emit logRollDie(this, event.sides(), event.value());
} }
void Player::eventCreateArrow(const Event_CreateArrow &event) void Player::eventCreateArrow(const Event_CreateArrow &event)
{ {
ArrowItem *arrow = addArrow(event.arrow_info()); ArrowItem *arrow = addArrow(event.arrow_info());
if (!arrow) if (!arrow)
return; return;
CardItem *startCard = static_cast<CardItem *>(arrow->getStartItem()); CardItem *startCard = static_cast<CardItem *>(arrow->getStartItem());
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(arrow->getTargetItem()); CardItem *targetCard = qgraphicsitem_cast<CardItem *>(arrow->getTargetItem());
if (targetCard) if (targetCard)
emit logCreateArrow(this, startCard->getOwner(), startCard->getName(), targetCard->getOwner(), targetCard->getName(), false); emit logCreateArrow(this, startCard->getOwner(), startCard->getName(), targetCard->getOwner(), targetCard->getName(), false);
else else
emit logCreateArrow(this, startCard->getOwner(), startCard->getName(), arrow->getTargetItem()->getOwner(), QString(), true); emit logCreateArrow(this, startCard->getOwner(), startCard->getName(), arrow->getTargetItem()->getOwner(), QString(), true);
} }
void Player::eventDeleteArrow(const Event_DeleteArrow &event) void Player::eventDeleteArrow(const Event_DeleteArrow &event)
{ {
delArrow(event.arrow_id()); delArrow(event.arrow_id());
} }
void Player::eventCreateToken(const Event_CreateToken &event) void Player::eventCreateToken(const Event_CreateToken &event)
{ {
CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0); CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0);
if (!zone) if (!zone)
return; return;
CardItem *card = new CardItem(this, QString::fromStdString(event.card_name()), event.card_id()); CardItem *card = new CardItem(this, QString::fromStdString(event.card_name()), event.card_id());
card->setColor(QString::fromStdString(event.color())); card->setColor(QString::fromStdString(event.color()));
card->setPT(QString::fromStdString(event.pt())); card->setPT(QString::fromStdString(event.pt()));
card->setAnnotation(QString::fromStdString(event.annotation())); card->setAnnotation(QString::fromStdString(event.annotation()));
card->setDestroyOnZoneChange(event.destroy_on_zone_change()); card->setDestroyOnZoneChange(event.destroy_on_zone_change());
emit logCreateToken(this, card->getName(), card->getPT()); emit logCreateToken(this, card->getName(), card->getPT());
zone->addCard(card, true, event.x(), event.y()); zone->addCard(card, true, event.x(), event.y());
} }
void Player::eventSetCardAttr(const Event_SetCardAttr &event, const GameEventContext &context) void Player::eventSetCardAttr(const Event_SetCardAttr &event, const GameEventContext &context)
{ {
CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0); CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0);
if (!zone) if (!zone)
return; return;
if (!event.has_card_id()) { if (!event.has_card_id()) {
const CardList &cards = zone->getCards(); const CardList &cards = zone->getCards();
for (int i = 0; i < cards.size(); i++) for (int i = 0; i < cards.size(); i++)
setCardAttrHelper(context, cards.at(i), event.attribute(), QString::fromStdString(event.attr_value()), true); setCardAttrHelper(context, cards.at(i), event.attribute(), QString::fromStdString(event.attr_value()), true);
if (event.attribute() == AttrTapped) if (event.attribute() == AttrTapped)
emit logSetTapped(this, 0, event.attr_value() == "1"); emit logSetTapped(this, 0, event.attr_value() == "1");
} else { } else {
CardItem *card = zone->getCard(event.card_id(), QString()); CardItem *card = zone->getCard(event.card_id(), QString());
if (!card) { if (!card) {
qDebug() << "Player::eventSetCardAttr: card id=" << event.card_id() << "not found"; qDebug() << "Player::eventSetCardAttr: card id=" << event.card_id() << "not found";
return; return;
} }
setCardAttrHelper(context, card, event.attribute(), QString::fromStdString(event.attr_value()), false); setCardAttrHelper(context, card, event.attribute(), QString::fromStdString(event.attr_value()), false);
} }
} }
void Player::eventSetCardCounter(const Event_SetCardCounter &event) void Player::eventSetCardCounter(const Event_SetCardCounter &event)
{ {
CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0); CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0);
if (!zone) if (!zone)
return; return;
CardItem *card = zone->getCard(event.card_id(), QString()); CardItem *card = zone->getCard(event.card_id(), QString());
if (!card) if (!card)
return; return;
int oldValue = card->getCounters().value(event.counter_id(), 0); int oldValue = card->getCounters().value(event.counter_id(), 0);
card->setCounter(event.counter_id(), event.counter_value()); card->setCounter(event.counter_id(), event.counter_value());
emit logSetCardCounter(this, card->getName(), event.counter_id(), event.counter_value(), oldValue); emit logSetCardCounter(this, card->getName(), event.counter_id(), event.counter_value(), oldValue);
} }
void Player::eventCreateCounter(const Event_CreateCounter &event) void Player::eventCreateCounter(const Event_CreateCounter &event)
{ {
addCounter(event.counter_info()); addCounter(event.counter_info());
} }
void Player::eventSetCounter(const Event_SetCounter &event) void Player::eventSetCounter(const Event_SetCounter &event)
{ {
AbstractCounter *c = counters.value(event.counter_id(), 0); AbstractCounter *c = counters.value(event.counter_id(), 0);
if (!c) if (!c)
return; return;
int oldValue = c->getValue(); int oldValue = c->getValue();
c->setValue(event.value()); c->setValue(event.value());
emit logSetCounter(this, c->getName(), event.value(), oldValue); emit logSetCounter(this, c->getName(), event.value(), oldValue);
} }
void Player::eventDelCounter(const Event_DelCounter &event) void Player::eventDelCounter(const Event_DelCounter &event)
{ {
delCounter(event.counter_id()); delCounter(event.counter_id());
} }
void Player::eventDumpZone(const Event_DumpZone &event) void Player::eventDumpZone(const Event_DumpZone &event)
{ {
Player *zoneOwner = game->getPlayers().value(event.zone_owner_id(), 0); Player *zoneOwner = game->getPlayers().value(event.zone_owner_id(), 0);
if (!zoneOwner) if (!zoneOwner)
return; return;
CardZone *zone = zoneOwner->getZones().value(QString::fromStdString(event.zone_name()), 0); CardZone *zone = zoneOwner->getZones().value(QString::fromStdString(event.zone_name()), 0);
if (!zone) if (!zone)
return; return;
emit logDumpZone(this, zone, event.number_cards()); emit logDumpZone(this, zone, event.number_cards());
} }
void Player::eventStopDumpZone(const Event_StopDumpZone &event) void Player::eventStopDumpZone(const Event_StopDumpZone &event)
{ {
Player *zoneOwner = game->getPlayers().value(event.zone_owner_id(), 0); Player *zoneOwner = game->getPlayers().value(event.zone_owner_id(), 0);
if (!zoneOwner) if (!zoneOwner)
return; return;
CardZone *zone = zoneOwner->getZones().value(QString::fromStdString(event.zone_name()), 0); CardZone *zone = zoneOwner->getZones().value(QString::fromStdString(event.zone_name()), 0);
if (!zone) if (!zone)
return; return;
emit logStopDumpZone(this, zone); emit logStopDumpZone(this, zone);
} }
void Player::eventMoveCard(const Event_MoveCard &event, const GameEventContext &context) void Player::eventMoveCard(const Event_MoveCard &event, const GameEventContext &context)
{ {
Player *startPlayer = game->getPlayers().value(event.start_player_id()); Player *startPlayer = game->getPlayers().value(event.start_player_id());
if (!startPlayer) if (!startPlayer)
return; return;
CardZone *startZone = startPlayer->getZones().value(QString::fromStdString(event.start_zone()), 0); CardZone *startZone = startPlayer->getZones().value(QString::fromStdString(event.start_zone()), 0);
Player *targetPlayer = game->getPlayers().value(event.target_player_id()); Player *targetPlayer = game->getPlayers().value(event.target_player_id());
if (!targetPlayer) if (!targetPlayer)
return; return;
CardZone *targetZone; CardZone *targetZone;
if (event.has_target_zone()) if (event.has_target_zone())
targetZone = targetPlayer->getZones().value(QString::fromStdString(event.target_zone()), 0); targetZone = targetPlayer->getZones().value(QString::fromStdString(event.target_zone()), 0);
else else
targetZone = startZone; targetZone = startZone;
if (!startZone || !targetZone) if (!startZone || !targetZone)
return; return;
int position = event.position(); int position = event.position();
int x = event.x(); int x = event.x();
int y = event.y(); int y = event.y();
int logPosition = position; int logPosition = position;
int logX = x; int logX = x;
if (x == -1) if (x == -1)
x = 0; x = 0;
CardItem *card = startZone->takeCard(position, event.card_id(), startZone != targetZone); CardItem *card = startZone->takeCard(position, event.card_id(), startZone != targetZone);
if (!card) if (!card)
return; return;
if (startZone != targetZone) if (startZone != targetZone)
card->deleteCardInfoPopup(); card->deleteCardInfoPopup();
if (event.has_card_name()) if (event.has_card_name())
card->setName(QString::fromStdString(event.card_name())); card->setName(QString::fromStdString(event.card_name()));
if (card->getAttachedTo() && (startZone != targetZone)) { if (card->getAttachedTo() && (startZone != targetZone)) {
CardItem *parentCard = card->getAttachedTo(); CardItem *parentCard = card->getAttachedTo();
card->setAttachedTo(0); card->setAttachedTo(0);
parentCard->getZone()->reorganizeCards(); parentCard->getZone()->reorganizeCards();
} }
card->deleteDragItem(); card->deleteDragItem();
card->setId(event.new_card_id()); card->setId(event.new_card_id());
card->setFaceDown(event.face_down()); card->setFaceDown(event.face_down());
if (startZone != targetZone) { if (startZone != targetZone) {
card->setBeingPointedAt(false); card->setBeingPointedAt(false);
card->setHovered(false); card->setHovered(false);
const QList<CardItem *> &attachedCards = card->getAttachedCards(); const QList<CardItem *> &attachedCards = card->getAttachedCards();
for (int i = 0; i < attachedCards.size(); ++i) for (int i = 0; i < attachedCards.size(); ++i)
attachedCards[i]->setParentItem(targetZone); attachedCards[i]->setParentItem(targetZone);
if (startZone->getPlayer() != targetZone->getPlayer()) if (startZone->getPlayer() != targetZone->getPlayer())
card->setOwner(targetZone->getPlayer()); card->setOwner(targetZone->getPlayer());
} }
// 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
// because the addCard function can modify the card object. // because the addCard function can modify the card object.
if (context.HasExtension(Context_UndoDraw::ext)) if (context.HasExtension(Context_UndoDraw::ext))
emit logUndoDraw(this, card->getName()); emit logUndoDraw(this, card->getName());
else else
emit logMoveCard(this, card, startZone, logPosition, targetZone, logX); emit logMoveCard(this, card, startZone, logPosition, targetZone, logX);
targetZone->addCard(card, true, x, y); targetZone->addCard(card, true, x, y);
// Look at all arrows from and to the card. // Look at all arrows from and to the card.
// If the card was moved to another zone, delete the arrows, otherwise update them. // If the card was moved to another zone, delete the arrows, otherwise update them.
QMapIterator<int, Player *> playerIterator(game->getPlayers()); QMapIterator<int, Player *> playerIterator(game->getPlayers());
while (playerIterator.hasNext()) { while (playerIterator.hasNext()) {
Player *p = playerIterator.next().value(); Player *p = playerIterator.next().value();
QList<ArrowItem *> arrowsToDelete; QList<ArrowItem *> arrowsToDelete;
QMapIterator<int, ArrowItem *> arrowIterator(p->getArrows()); QMapIterator<int, ArrowItem *> arrowIterator(p->getArrows());
while (arrowIterator.hasNext()) { while (arrowIterator.hasNext()) {
ArrowItem *arrow = arrowIterator.next().value(); ArrowItem *arrow = arrowIterator.next().value();
if ((arrow->getStartItem() == card) || (arrow->getTargetItem() == card)) { if ((arrow->getStartItem() == card) || (arrow->getTargetItem() == card)) {
if (startZone == targetZone) if (startZone == targetZone)
arrow->updatePath(); arrow->updatePath();
else else
arrowsToDelete.append(arrow); arrowsToDelete.append(arrow);
} }
} }
for (int i = 0; i < arrowsToDelete.size(); ++i) for (int i = 0; i < arrowsToDelete.size(); ++i)
arrowsToDelete[i]->delArrow(); arrowsToDelete[i]->delArrow();
} }
} }
void Player::eventFlipCard(const Event_FlipCard &event) void Player::eventFlipCard(const Event_FlipCard &event)
{ {
CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0); CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0);
if (!zone) if (!zone)
return; return;
CardItem *card = zone->getCard(event.card_id(), QString::fromStdString(event.card_name())); CardItem *card = zone->getCard(event.card_id(), QString::fromStdString(event.card_name()));
if (!card) if (!card)
return; return;
emit logFlipCard(this, card->getName(), event.face_down()); emit logFlipCard(this, card->getName(), event.face_down());
card->setFaceDown(event.face_down()); card->setFaceDown(event.face_down());
} }
void Player::eventDestroyCard(const Event_DestroyCard &event) void Player::eventDestroyCard(const Event_DestroyCard &event)
{ {
CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0); CardZone *zone = zones.value(QString::fromStdString(event.zone_name()), 0);
if (!zone) if (!zone)
return; return;
CardItem *card = zone->getCard(event.card_id(), QString()); CardItem *card = zone->getCard(event.card_id(), QString());
if (!card) if (!card)
return; return;
QList<CardItem *> attachedCards = card->getAttachedCards(); QList<CardItem *> attachedCards = card->getAttachedCards();
// This list is always empty except for buggy server implementations. // This list is always empty except for buggy server implementations.
for (int i = 0; i < attachedCards.size(); ++i) for (int i = 0; i < attachedCards.size(); ++i)
attachedCards[i]->setAttachedTo(0); attachedCards[i]->setAttachedTo(0);
emit logDestroyCard(this, card->getName()); emit logDestroyCard(this, card->getName());
zone->takeCard(-1, event.card_id(), true); zone->takeCard(-1, event.card_id(), true);
card->deleteLater(); card->deleteLater();
} }
void Player::eventAttachCard(const Event_AttachCard &event) void Player::eventAttachCard(const Event_AttachCard &event)
{ {
const QMap<int, Player *> &playerList = game->getPlayers(); const QMap<int, Player *> &playerList = game->getPlayers();
Player *targetPlayer = 0; Player *targetPlayer = 0;
CardZone *targetZone = 0; CardZone *targetZone = 0;
CardItem *targetCard = 0; CardItem *targetCard = 0;
if (event.has_target_player_id()) { if (event.has_target_player_id()) {
targetPlayer = playerList.value(event.target_player_id(), 0); targetPlayer = playerList.value(event.target_player_id(), 0);
if (targetPlayer) { if (targetPlayer) {
targetZone = targetPlayer->getZones().value(QString::fromStdString(event.target_zone()), 0); targetZone = targetPlayer->getZones().value(QString::fromStdString(event.target_zone()), 0);
if (targetZone) if (targetZone)
targetCard = targetZone->getCard(event.target_card_id(), QString()); targetCard = targetZone->getCard(event.target_card_id(), QString());
} }
} }
CardZone *startZone = getZones().value(QString::fromStdString(event.start_zone()), 0); CardZone *startZone = getZones().value(QString::fromStdString(event.start_zone()), 0);
if (!startZone) if (!startZone)
return; return;
CardItem *startCard = startZone->getCard(event.card_id(), QString()); CardItem *startCard = startZone->getCard(event.card_id(), QString());
if (!startCard) if (!startCard)
return; return;
CardItem *oldParent = startCard->getAttachedTo(); CardItem *oldParent = startCard->getAttachedTo();
startCard->setAttachedTo(targetCard); startCard->setAttachedTo(targetCard);
startZone->reorganizeCards(); startZone->reorganizeCards();
if ((startZone != targetZone) && targetZone) if ((startZone != targetZone) && targetZone)
targetZone->reorganizeCards(); targetZone->reorganizeCards();
if (oldParent) if (oldParent)
oldParent->getZone()->reorganizeCards(); oldParent->getZone()->reorganizeCards();
if (targetCard) if (targetCard)
emit logAttachCard(this, startCard->getName(), targetPlayer, targetCard->getName()); emit logAttachCard(this, startCard->getName(), targetPlayer, targetCard->getName());
else else
emit logUnattachCard(this, startCard->getName()); emit logUnattachCard(this, startCard->getName());
} }
void Player::eventDrawCards(const Event_DrawCards &event) void Player::eventDrawCards(const Event_DrawCards &event)
{ {
CardZone *deck = zones.value("deck"); CardZone *deck = zones.value("deck");
CardZone *hand = zones.value("hand"); CardZone *hand = zones.value("hand");
const int listSize = event.cards_size(); const int listSize = event.cards_size();
if (listSize) { if (listSize) {
for (int i = 0; i < listSize; ++i) { for (int i = 0; i < listSize; ++i) {
const ServerInfo_Card &cardInfo = event.cards(i); const ServerInfo_Card &cardInfo = event.cards(i);
CardItem *card = deck->takeCard(0, cardInfo.id()); CardItem *card = deck->takeCard(0, cardInfo.id());
card->setName(QString::fromStdString(cardInfo.name())); card->setName(QString::fromStdString(cardInfo.name()));
hand->addCard(card, false, -1); hand->addCard(card, false, -1);
} }
} else { } else {
const int number = event.number(); const int number = event.number();
for (int i = 0; i < number; ++i) for (int i = 0; i < number; ++i)
hand->addCard(deck->takeCard(0, -1), false, -1); hand->addCard(deck->takeCard(0, -1), false, -1);
} }
hand->reorganizeCards(); hand->reorganizeCards();
deck->reorganizeCards(); deck->reorganizeCards();
emit logDrawCards(this, event.number()); emit logDrawCards(this, event.number());
} }
void Player::eventRevealCards(const Event_RevealCards &event) void Player::eventRevealCards(const Event_RevealCards &event)
{ {
CardZone *zone = zones.value(QString::fromStdString(event.zone_name())); CardZone *zone = zones.value(QString::fromStdString(event.zone_name()));
if (!zone) if (!zone)
return; return;
Player *otherPlayer = 0; Player *otherPlayer = 0;
if (event.has_other_player_id()) { if (event.has_other_player_id()) {
otherPlayer = game->getPlayers().value(event.other_player_id()); otherPlayer = game->getPlayers().value(event.other_player_id());
if (!otherPlayer) if (!otherPlayer)
return; return;
} }
bool peeking = false; bool peeking = false;
QList<const ServerInfo_Card *> cardList; QList<const ServerInfo_Card *> cardList;
const int cardListSize = event.cards_size(); const int cardListSize = event.cards_size();
for (int i = 0; i < cardListSize; ++i) { for (int i = 0; i < cardListSize; ++i) {
const ServerInfo_Card *temp = &event.cards(i); const ServerInfo_Card *temp = &event.cards(i);
if (temp->face_down()) if (temp->face_down())
peeking = true; peeking = true;
cardList.append(temp); cardList.append(temp);
} }
if (peeking) { if (peeking) {
for (int i = 0; i < cardList.size(); ++i) { for (int i = 0; i < cardList.size(); ++i) {
QString cardName = QString::fromStdString(cardList.at(i)->name()); QString cardName = QString::fromStdString(cardList.at(i)->name());
CardItem *card = zone->getCard(cardList.at(i)->id(), QString()); CardItem *card = zone->getCard(cardList.at(i)->id(), QString());
if (!card) if (!card)
continue; continue;
card->setName(cardName); card->setName(cardName);
emit logRevealCards(this, zone, cardList.at(i)->id(), cardName, this, true); emit logRevealCards(this, zone, cardList.at(i)->id(), cardName, this, true);
} }
} else { } else {
bool showZoneView = true; bool showZoneView = true;
QString cardName; QString cardName;
if (cardList.size() == 1) { if (cardList.size() == 1) {
cardName = QString::fromStdString(cardList.first()->name()); cardName = QString::fromStdString(cardList.first()->name());
if ((event.card_id() == 0) && dynamic_cast<PileZone *>(zone)) { if ((event.card_id() == 0) && dynamic_cast<PileZone *>(zone)) {
zone->getCards().first()->setName(cardName); zone->getCards().first()->setName(cardName);
zone->update(); zone->update();
showZoneView = false; showZoneView = false;
} }
} }
if (showZoneView && !cardList.isEmpty()) if (showZoneView && !cardList.isEmpty())
static_cast<GameScene *>(scene())->addRevealedZoneView(this, zone, cardList, event.grant_write_access()); static_cast<GameScene *>(scene())->addRevealedZoneView(this, zone, cardList, event.grant_write_access());
emit logRevealCards(this, zone, event.card_id(), cardName, otherPlayer, false); emit logRevealCards(this, zone, event.card_id(), cardName, otherPlayer, false);
} }
} }
void Player::eventChangeZoneProperties(const Event_ChangeZoneProperties &event) void Player::eventChangeZoneProperties(const Event_ChangeZoneProperties &event)
{ {
CardZone *zone = zones.value(QString::fromStdString(event.zone_name())); CardZone *zone = zones.value(QString::fromStdString(event.zone_name()));
if (!zone) if (!zone)
return; return;
if (event.has_always_reveal_top_card()) { if (event.has_always_reveal_top_card()) {
zone->setAlwaysRevealTopCard(event.always_reveal_top_card()); zone->setAlwaysRevealTopCard(event.always_reveal_top_card());
emit logAlwaysRevealTopCard(this, zone, event.always_reveal_top_card()); emit logAlwaysRevealTopCard(this, zone, event.always_reveal_top_card());
} }
} }
void Player::processGameEvent(GameEvent::GameEventType type, const GameEvent &event, const GameEventContext &context) void Player::processGameEvent(GameEvent::GameEventType type, const GameEvent &event, const GameEventContext &context)
{ {
switch (type) { switch (type) {
case GameEvent::GAME_SAY: eventGameSay(event.GetExtension(Event_GameSay::ext)); break; case GameEvent::GAME_SAY: eventGameSay(event.GetExtension(Event_GameSay::ext)); break;
case GameEvent::SHUFFLE: eventShuffle(event.GetExtension(Event_Shuffle::ext)); break; case GameEvent::SHUFFLE: eventShuffle(event.GetExtension(Event_Shuffle::ext)); break;
case GameEvent::ROLL_DIE: eventRollDie(event.GetExtension(Event_RollDie::ext)); break; case GameEvent::ROLL_DIE: eventRollDie(event.GetExtension(Event_RollDie::ext)); break;
case GameEvent::CREATE_ARROW: eventCreateArrow(event.GetExtension(Event_CreateArrow::ext)); break; case GameEvent::CREATE_ARROW: eventCreateArrow(event.GetExtension(Event_CreateArrow::ext)); break;
case GameEvent::DELETE_ARROW: eventDeleteArrow(event.GetExtension(Event_DeleteArrow::ext)); break; case GameEvent::DELETE_ARROW: eventDeleteArrow(event.GetExtension(Event_DeleteArrow::ext)); break;
case GameEvent::CREATE_TOKEN: eventCreateToken(event.GetExtension(Event_CreateToken::ext)); break; case GameEvent::CREATE_TOKEN: eventCreateToken(event.GetExtension(Event_CreateToken::ext)); break;
case GameEvent::SET_CARD_ATTR: eventSetCardAttr(event.GetExtension(Event_SetCardAttr::ext), context); break; case GameEvent::SET_CARD_ATTR: eventSetCardAttr(event.GetExtension(Event_SetCardAttr::ext), context); break;
case GameEvent::SET_CARD_COUNTER: eventSetCardCounter(event.GetExtension(Event_SetCardCounter::ext)); break; case GameEvent::SET_CARD_COUNTER: eventSetCardCounter(event.GetExtension(Event_SetCardCounter::ext)); break;
case GameEvent::CREATE_COUNTER: eventCreateCounter(event.GetExtension(Event_CreateCounter::ext)); break; case GameEvent::CREATE_COUNTER: eventCreateCounter(event.GetExtension(Event_CreateCounter::ext)); break;
case GameEvent::SET_COUNTER: eventSetCounter(event.GetExtension(Event_SetCounter::ext)); break; case GameEvent::SET_COUNTER: eventSetCounter(event.GetExtension(Event_SetCounter::ext)); break;
case GameEvent::DEL_COUNTER: eventDelCounter(event.GetExtension(Event_DelCounter::ext)); break; case GameEvent::DEL_COUNTER: eventDelCounter(event.GetExtension(Event_DelCounter::ext)); break;
case GameEvent::DUMP_ZONE: eventDumpZone(event.GetExtension(Event_DumpZone::ext)); break; case GameEvent::DUMP_ZONE: eventDumpZone(event.GetExtension(Event_DumpZone::ext)); break;
case GameEvent::STOP_DUMP_ZONE: eventStopDumpZone(event.GetExtension(Event_StopDumpZone::ext)); break; case GameEvent::STOP_DUMP_ZONE: eventStopDumpZone(event.GetExtension(Event_StopDumpZone::ext)); break;
case GameEvent::MOVE_CARD: eventMoveCard(event.GetExtension(Event_MoveCard::ext), context); break; case GameEvent::MOVE_CARD: eventMoveCard(event.GetExtension(Event_MoveCard::ext), context); break;
case GameEvent::FLIP_CARD: eventFlipCard(event.GetExtension(Event_FlipCard::ext)); break; case GameEvent::FLIP_CARD: eventFlipCard(event.GetExtension(Event_FlipCard::ext)); break;
case GameEvent::DESTROY_CARD: eventDestroyCard(event.GetExtension(Event_DestroyCard::ext)); break; case GameEvent::DESTROY_CARD: eventDestroyCard(event.GetExtension(Event_DestroyCard::ext)); break;
case GameEvent::ATTACH_CARD: eventAttachCard(event.GetExtension(Event_AttachCard::ext)); break; case GameEvent::ATTACH_CARD: eventAttachCard(event.GetExtension(Event_AttachCard::ext)); break;
case GameEvent::DRAW_CARDS: eventDrawCards(event.GetExtension(Event_DrawCards::ext)); break; case GameEvent::DRAW_CARDS: eventDrawCards(event.GetExtension(Event_DrawCards::ext)); break;
case GameEvent::REVEAL_CARDS: eventRevealCards(event.GetExtension(Event_RevealCards::ext)); break; case GameEvent::REVEAL_CARDS: eventRevealCards(event.GetExtension(Event_RevealCards::ext)); break;
case GameEvent::CHANGE_ZONE_PROPERTIES: eventChangeZoneProperties(event.GetExtension(Event_ChangeZoneProperties::ext)); break; case GameEvent::CHANGE_ZONE_PROPERTIES: eventChangeZoneProperties(event.GetExtension(Event_ChangeZoneProperties::ext)); break;
default: { default: {
qDebug() << "unhandled game event"; qDebug() << "unhandled game event";
} }
} }
} }
void Player::setActive(bool _active) void Player::setActive(bool _active)
{ {
active = _active; active = _active;
table->setActive(active); table->setActive(active);
update(); update();
} }
QRectF Player::boundingRect() const QRectF Player::boundingRect() const
{ {
return bRect; return bRect;
} }
void Player::paint(QPainter * /*painter*/, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) void Player::paint(QPainter * /*painter*/, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
...@@ -1436,759 +1436,759 @@ void Player::paint(QPainter * /*painter*/, const QStyleOptionGraphicsItem */*opt ...@@ -1436,759 +1436,759 @@ void Player::paint(QPainter * /*painter*/, const QStyleOptionGraphicsItem */*opt
void Player::processPlayerInfo(const ServerInfo_Player &info) void Player::processPlayerInfo(const ServerInfo_Player &info)
{ {
clearCounters(); clearCounters();
clearArrows(); clearArrows();
QMapIterator<QString, CardZone *> zoneIt(zones); QMapIterator<QString, CardZone *> zoneIt(zones);
while (zoneIt.hasNext()) while (zoneIt.hasNext())
zoneIt.next().value()->clearContents(); zoneIt.next().value()->clearContents();
const int zoneListSize = info.zone_list_size(); const int zoneListSize = info.zone_list_size();
for (int i = 0; i < zoneListSize; ++i) { for (int i = 0; i < zoneListSize; ++i) {
const ServerInfo_Zone &zoneInfo = info.zone_list(i); const ServerInfo_Zone &zoneInfo = info.zone_list(i);
CardZone *zone = zones.value(QString::fromStdString(zoneInfo.name()), 0); CardZone *zone = zones.value(QString::fromStdString(zoneInfo.name()), 0);
if (!zone) if (!zone)
continue; continue;
const int cardListSize = zoneInfo.card_list_size(); const int cardListSize = zoneInfo.card_list_size();
if (!cardListSize) { if (!cardListSize) {
for (int j = 0; j < zoneInfo.card_count(); ++j) for (int j = 0; j < zoneInfo.card_count(); ++j)
zone->addCard(new CardItem(this), false, -1); zone->addCard(new CardItem(this), false, -1);
} else { } else {
for (int j = 0; j < cardListSize; ++j) { for (int j = 0; j < cardListSize; ++j) {
const ServerInfo_Card &cardInfo = zoneInfo.card_list(j); const ServerInfo_Card &cardInfo = zoneInfo.card_list(j);
CardItem *card = new CardItem(this); CardItem *card = new CardItem(this);
card->processCardInfo(cardInfo); card->processCardInfo(cardInfo);
zone->addCard(card, false, cardInfo.x(), cardInfo.y()); zone->addCard(card, false, cardInfo.x(), cardInfo.y());
} }
} }
if (zoneInfo.has_always_reveal_top_card()) if (zoneInfo.has_always_reveal_top_card())
zone->setAlwaysRevealTopCard(zoneInfo.always_reveal_top_card()); zone->setAlwaysRevealTopCard(zoneInfo.always_reveal_top_card());
zone->reorganizeCards(); zone->reorganizeCards();
} }
const int counterListSize = info.counter_list_size(); const int counterListSize = info.counter_list_size();
for (int i = 0; i < counterListSize; ++i) for (int i = 0; i < counterListSize; ++i)
addCounter(info.counter_list(i)); addCounter(info.counter_list(i));
setConceded(info.properties().conceded()); setConceded(info.properties().conceded());
} }
void Player::processCardAttachment(const ServerInfo_Player &info) void Player::processCardAttachment(const ServerInfo_Player &info)
{ {
const int zoneListSize = info.zone_list_size(); const int zoneListSize = info.zone_list_size();
for (int i = 0; i < zoneListSize; ++i) { for (int i = 0; i < zoneListSize; ++i) {
const ServerInfo_Zone &zoneInfo = info.zone_list(i); const ServerInfo_Zone &zoneInfo = info.zone_list(i);
CardZone *zone = zones.value(QString::fromStdString(zoneInfo.name()), 0); CardZone *zone = zones.value(QString::fromStdString(zoneInfo.name()), 0);
if (!zone) if (!zone)
continue; continue;
const int cardListSize = zoneInfo.card_list_size(); const int cardListSize = zoneInfo.card_list_size();
for (int j = 0; j < cardListSize; ++j) { for (int j = 0; j < cardListSize; ++j) {
const ServerInfo_Card &cardInfo = zoneInfo.card_list(j); const ServerInfo_Card &cardInfo = zoneInfo.card_list(j);
if (cardInfo.has_attach_player_id()) { if (cardInfo.has_attach_player_id()) {
CardItem *startCard = zone->getCard(cardInfo.id(), QString()); CardItem *startCard = zone->getCard(cardInfo.id(), QString());
CardItem *targetCard = game->getCard(cardInfo.attach_player_id(), QString::fromStdString(cardInfo.attach_zone()), cardInfo.attach_card_id()); CardItem *targetCard = game->getCard(cardInfo.attach_player_id(), QString::fromStdString(cardInfo.attach_zone()), cardInfo.attach_card_id());
if (!targetCard) if (!targetCard)
continue; continue;
startCard->setAttachedTo(targetCard); startCard->setAttachedTo(targetCard);
} }
} }
} }
const int arrowListSize = info.arrow_list_size(); const int arrowListSize = info.arrow_list_size();
for (int i = 0; i < arrowListSize; ++i) for (int i = 0; i < arrowListSize; ++i)
addArrow(info.arrow_list(i)); addArrow(info.arrow_list(i));
} }
void Player::playCard(CardItem *c, bool faceDown, bool tapped) void Player::playCard(CardItem *c, bool faceDown, bool tapped)
{ {
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_player_id(c->getZone()->getPlayer()->getId()); cmd.set_start_player_id(c->getZone()->getPlayer()->getId());
cmd.set_start_zone(c->getZone()->getName().toStdString()); cmd.set_start_zone(c->getZone()->getName().toStdString());
cmd.set_target_player_id(getId()); cmd.set_target_player_id(getId());
CardToMove *cardToMove = cmd.mutable_cards_to_move()->add_card(); CardToMove *cardToMove = cmd.mutable_cards_to_move()->add_card();
cardToMove->set_card_id(c->getId()); cardToMove->set_card_id(c->getId());
CardInfo *ci = c->getInfo(); CardInfo *ci = c->getInfo();
if ((!settingsCache->getPlayToStack() && ci->getTableRow() == 3) || if ((!settingsCache->getPlayToStack() && ci->getTableRow() == 3) ||
((settingsCache->getPlayToStack() && ci->getTableRow() != 0) && ((settingsCache->getPlayToStack() && ci->getTableRow() != 0) &&
c->getZone()->getName().toStdString() != "stack")) { c->getZone()->getName().toStdString() != "stack")) {
cmd.set_target_zone("stack"); cmd.set_target_zone("stack");
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
} else { } else {
QPoint gridPoint = QPoint(-1, 2 - ci->getTableRow()); QPoint gridPoint = QPoint(-1, 2 - ci->getTableRow());
cardToMove->set_face_down(faceDown); cardToMove->set_face_down(faceDown);
cardToMove->set_pt(ci->getPowTough().toStdString()); cardToMove->set_pt(ci->getPowTough().toStdString());
cardToMove->set_tapped(tapped); cardToMove->set_tapped(tapped);
if(ci->getTableRow() != 3) if(ci->getTableRow() != 3)
cmd.set_target_zone("table"); cmd.set_target_zone("table");
cmd.set_x(gridPoint.x()); cmd.set_x(gridPoint.x());
cmd.set_y(gridPoint.y()); cmd.set_y(gridPoint.y());
} }
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::addCard(CardItem *c) void Player::addCard(CardItem *c)
{ {
emit newCardAdded(c); emit newCardAdded(c);
} }
void Player::deleteCard(CardItem *c) void Player::deleteCard(CardItem *c)
{ {
if (dialogSemaphore) if (dialogSemaphore)
cardsToDelete.append(c); cardsToDelete.append(c);
else else
c->deleteLater(); c->deleteLater();
} }
void Player::addZone(CardZone *z) void Player::addZone(CardZone *z)
{ {
zones.insert(z->getName(), z); zones.insert(z->getName(), z);
} }
AbstractCounter *Player::addCounter(const ServerInfo_Counter &counter) AbstractCounter *Player::addCounter(const ServerInfo_Counter &counter)
{ {
return addCounter(counter.id(), QString::fromStdString(counter.name()), convertColorToQColor(counter.counter_color()), counter.radius(), counter.count()); return addCounter(counter.id(), QString::fromStdString(counter.name()), convertColorToQColor(counter.counter_color()), counter.radius(), counter.count());
} }
AbstractCounter *Player::addCounter(int counterId, const QString &name, QColor color, int radius, int value) AbstractCounter *Player::addCounter(int counterId, const QString &name, QColor color, int radius, int value)
{ {
qDebug() << "addCounter:" << getName() << counterId << name; qDebug() << "addCounter:" << getName() << counterId << name;
if (counters.contains(counterId)) if (counters.contains(counterId))
return 0; return 0;
AbstractCounter *c; AbstractCounter *c;
if (name == "life") if (name == "life")
c = playerTarget->addCounter(counterId, name, value); c = playerTarget->addCounter(counterId, name, value);
else else
c = new GeneralCounter(this, counterId, name, color, radius, value, this); c = new GeneralCounter(this, counterId, name, color, radius, value, this);
counters.insert(counterId, c); counters.insert(counterId, c);
if (countersMenu) if (countersMenu)
countersMenu->addMenu(c->getMenu()); countersMenu->addMenu(c->getMenu());
if (shortcutsActive) if (shortcutsActive)
c->setShortcutsActive(); c->setShortcutsActive();
rearrangeCounters(); rearrangeCounters();
return c; return c;
} }
void Player::delCounter(int counterId) void Player::delCounter(int counterId)
{ {
AbstractCounter *c = counters.value(counterId, 0); AbstractCounter *c = counters.value(counterId, 0);
if (!c) if (!c)
return; return;
c->delCounter(); c->delCounter();
counters.remove(counterId); counters.remove(counterId);
rearrangeCounters(); rearrangeCounters();
} }
void Player::clearCounters() void Player::clearCounters()
{ {
QMapIterator<int, AbstractCounter *> counterIterator(counters); QMapIterator<int, AbstractCounter *> counterIterator(counters);
while (counterIterator.hasNext()) while (counterIterator.hasNext())
counterIterator.next().value()->delCounter(); counterIterator.next().value()->delCounter();
counters.clear(); counters.clear();
} }
ArrowItem *Player::addArrow(const ServerInfo_Arrow &arrow) ArrowItem *Player::addArrow(const ServerInfo_Arrow &arrow)
{ {
const QMap<int, Player *> &playerList = game->getPlayers(); const QMap<int, Player *> &playerList = game->getPlayers();
Player *startPlayer = playerList.value(arrow.start_player_id(), 0); Player *startPlayer = playerList.value(arrow.start_player_id(), 0);
Player *targetPlayer = playerList.value(arrow.target_player_id(), 0); Player *targetPlayer = playerList.value(arrow.target_player_id(), 0);
if (!startPlayer || !targetPlayer) if (!startPlayer || !targetPlayer)
return 0; return 0;
CardZone *startZone = startPlayer->getZones().value(QString::fromStdString(arrow.start_zone()), 0); CardZone *startZone = startPlayer->getZones().value(QString::fromStdString(arrow.start_zone()), 0);
CardZone *targetZone = 0; CardZone *targetZone = 0;
if (arrow.has_target_zone()) if (arrow.has_target_zone())
targetZone = targetPlayer->getZones().value(QString::fromStdString(arrow.target_zone()), 0); targetZone = targetPlayer->getZones().value(QString::fromStdString(arrow.target_zone()), 0);
if (!startZone || (!targetZone && arrow.has_target_zone())) if (!startZone || (!targetZone && arrow.has_target_zone()))
return 0; return 0;
CardItem *startCard = startZone->getCard(arrow.start_card_id(), QString()); CardItem *startCard = startZone->getCard(arrow.start_card_id(), QString());
CardItem *targetCard = 0; CardItem *targetCard = 0;
if (targetZone) if (targetZone)
targetCard = targetZone->getCard(arrow.target_card_id(), QString()); targetCard = targetZone->getCard(arrow.target_card_id(), QString());
if (!startCard || (!targetCard && arrow.has_target_card_id())) if (!startCard || (!targetCard && arrow.has_target_card_id()))
return 0; return 0;
if (targetCard) if (targetCard)
return addArrow(arrow.id(), startCard, targetCard, convertColorToQColor(arrow.arrow_color())); return addArrow(arrow.id(), startCard, targetCard, convertColorToQColor(arrow.arrow_color()));
else else
return addArrow(arrow.id(), startCard, targetPlayer->getPlayerTarget(), convertColorToQColor(arrow.arrow_color())); return addArrow(arrow.id(), startCard, targetPlayer->getPlayerTarget(), convertColorToQColor(arrow.arrow_color()));
} }
ArrowItem *Player::addArrow(int arrowId, CardItem *startCard, ArrowTarget *targetItem, const QColor &color) ArrowItem *Player::addArrow(int arrowId, CardItem *startCard, ArrowTarget *targetItem, const QColor &color)
{ {
ArrowItem *arrow = new ArrowItem(this, arrowId, startCard, targetItem, color); ArrowItem *arrow = new ArrowItem(this, arrowId, startCard, targetItem, color);
arrows.insert(arrowId, arrow); arrows.insert(arrowId, arrow);
scene()->addItem(arrow); scene()->addItem(arrow);
return arrow; return arrow;
} }
void Player::delArrow(int arrowId) void Player::delArrow(int arrowId)
{ {
ArrowItem *a = arrows.value(arrowId, 0); ArrowItem *a = arrows.value(arrowId, 0);
if (!a) if (!a)
return; return;
a->delArrow(); a->delArrow();
} }
void Player::removeArrow(ArrowItem *arrow) void Player::removeArrow(ArrowItem *arrow)
{ {
if (arrow->getId() != -1) if (arrow->getId() != -1)
arrows.remove(arrow->getId()); arrows.remove(arrow->getId());
} }
void Player::clearArrows() void Player::clearArrows()
{ {
QMapIterator<int, ArrowItem *> arrowIterator(arrows); QMapIterator<int, ArrowItem *> arrowIterator(arrows);
while (arrowIterator.hasNext()) while (arrowIterator.hasNext())
arrowIterator.next().value()->delArrow(); arrowIterator.next().value()->delArrow();
arrows.clear(); arrows.clear();
} }
void Player::rearrangeCounters() void Player::rearrangeCounters()
{ {
qreal marginTop = 80; qreal marginTop = 80;
// Determine total height of bounding rectangles // Determine total height of bounding rectangles
qreal totalHeight = 0; qreal totalHeight = 0;
QMapIterator<int, AbstractCounter *> counterIterator(counters); QMapIterator<int, AbstractCounter *> counterIterator(counters);
while (counterIterator.hasNext()) { while (counterIterator.hasNext()) {
counterIterator.next(); counterIterator.next();
if (counterIterator.value()->getShownInCounterArea()) if (counterIterator.value()->getShownInCounterArea())
totalHeight += counterIterator.value()->boundingRect().height(); totalHeight += counterIterator.value()->boundingRect().height();
} }
const qreal padding = 5; const qreal padding = 5;
qreal y = boundingRect().y() + marginTop; qreal y = boundingRect().y() + marginTop;
// Place objects // Place objects
for (counterIterator.toFront(); counterIterator.hasNext(); ) { for (counterIterator.toFront(); counterIterator.hasNext(); ) {
AbstractCounter *c = counterIterator.next().value(); AbstractCounter *c = counterIterator.next().value();
if (!c->getShownInCounterArea()) if (!c->getShownInCounterArea())
continue; continue;
QRectF br = c->boundingRect(); QRectF br = c->boundingRect();
c->setPos((counterAreaWidth - br.width()) / 2, y); c->setPos((counterAreaWidth - br.width()) / 2, y);
y += br.height() + padding; y += br.height() + padding;
} }
} }
PendingCommand * Player::prepareGameCommand(const google::protobuf::Message &cmd) PendingCommand * Player::prepareGameCommand(const google::protobuf::Message &cmd)
{ {
return game->prepareGameCommand(cmd); return game->prepareGameCommand(cmd);
} }
PendingCommand * Player::prepareGameCommand(const QList<const::google::protobuf::Message *> &cmdList) PendingCommand * Player::prepareGameCommand(const QList<const::google::protobuf::Message *> &cmdList)
{ {
return game->prepareGameCommand(cmdList); return game->prepareGameCommand(cmdList);
} }
void Player::sendGameCommand(const google::protobuf::Message &command) void Player::sendGameCommand(const google::protobuf::Message &command)
{ {
game->sendGameCommand(command, id); game->sendGameCommand(command, id);
} }
void Player::sendGameCommand(PendingCommand *pend) void Player::sendGameCommand(PendingCommand *pend)
{ {
game->sendGameCommand(pend, id); game->sendGameCommand(pend, id);
} }
bool Player::clearCardsToDelete() bool Player::clearCardsToDelete()
{ {
if (cardsToDelete.isEmpty()) if (cardsToDelete.isEmpty())
return false; return false;
for (int i = 0; i < cardsToDelete.size(); ++i) for (int i = 0; i < cardsToDelete.size(); ++i)
cardsToDelete[i]->deleteLater(); cardsToDelete[i]->deleteLater();
cardsToDelete.clear(); cardsToDelete.clear();
return true; return true;
} }
void Player::cardMenuAction() void Player::cardMenuAction()
{ {
QAction *a = static_cast<QAction *>(sender()); QAction *a = static_cast<QAction *>(sender());
QList<QGraphicsItem *> sel = scene()->selectedItems(); QList<QGraphicsItem *> sel = scene()->selectedItems();
QList<CardItem *> cardList; QList<CardItem *> cardList;
while (!sel.isEmpty()) while (!sel.isEmpty())
cardList.append(qgraphicsitem_cast<CardItem *>(sel.takeFirst())); cardList.append(qgraphicsitem_cast<CardItem *>(sel.takeFirst()));
QList< const ::google::protobuf::Message * > commandList; QList< const ::google::protobuf::Message * > commandList;
if (a->data().toInt() <= (int) cmClone) if (a->data().toInt() <= (int) cmClone)
for (int i = 0; i < cardList.size(); ++i) { for (int i = 0; i < cardList.size(); ++i) {
CardItem *card = cardList[i]; CardItem *card = cardList[i];
switch (static_cast<CardMenuActionType>(a->data().toInt())) { switch (static_cast<CardMenuActionType>(a->data().toInt())) {
case cmTap: case cmTap:
if (!card->getTapped()) { if (!card->getTapped()) {
Command_SetCardAttr *cmd = new Command_SetCardAttr; Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_attribute(AttrTapped); cmd->set_attribute(AttrTapped);
cmd->set_attr_value("1"); cmd->set_attr_value("1");
commandList.append(cmd); commandList.append(cmd);
} }
break; break;
case cmUntap: case cmUntap:
if (card->getTapped()) { if (card->getTapped()) {
Command_SetCardAttr *cmd = new Command_SetCardAttr; Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_attribute(AttrTapped); cmd->set_attribute(AttrTapped);
cmd->set_attr_value("0"); cmd->set_attr_value("0");
commandList.append(cmd); commandList.append(cmd);
} }
break; break;
case cmDoesntUntap: { case cmDoesntUntap: {
Command_SetCardAttr *cmd = new Command_SetCardAttr; Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_attribute(AttrDoesntUntap); cmd->set_attribute(AttrDoesntUntap);
cmd->set_attr_value(card->getDoesntUntap() ? "0" : "1"); cmd->set_attr_value(card->getDoesntUntap() ? "0" : "1");
commandList.append(cmd); commandList.append(cmd);
break; break;
} }
case cmFlip: { case cmFlip: {
Command_FlipCard *cmd = new Command_FlipCard; Command_FlipCard *cmd = new Command_FlipCard;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_face_down(!card->getFaceDown()); cmd->set_face_down(!card->getFaceDown());
commandList.append(cmd); commandList.append(cmd);
break; break;
} }
case cmPeek: { case cmPeek: {
Command_RevealCards *cmd = new Command_RevealCards; Command_RevealCards *cmd = new Command_RevealCards;
cmd->set_zone_name(card->getZone()->getName().toStdString()); cmd->set_zone_name(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_player_id(id); cmd->set_player_id(id);
commandList.append(cmd); commandList.append(cmd);
break; break;
} }
case cmClone: { case cmClone: {
Command_CreateToken *cmd = new Command_CreateToken; Command_CreateToken *cmd = new Command_CreateToken;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_name(card->getName().toStdString()); cmd->set_card_name(card->getName().toStdString());
cmd->set_color(card->getColor().toStdString()); cmd->set_color(card->getColor().toStdString());
cmd->set_pt(card->getPT().toStdString()); cmd->set_pt(card->getPT().toStdString());
cmd->set_annotation(card->getAnnotation().toStdString()); cmd->set_annotation(card->getAnnotation().toStdString());
cmd->set_destroy_on_zone_change(true); cmd->set_destroy_on_zone_change(true);
cmd->set_x(-1); cmd->set_x(-1);
cmd->set_y(card->getGridPoint().y()); cmd->set_y(card->getGridPoint().y());
commandList.append(cmd); commandList.append(cmd);
break; break;
} }
default: break; default: break;
} }
} }
else { else {
ListOfCardsToMove idList; ListOfCardsToMove idList;
for (int i = 0; i < cardList.size(); ++i) for (int i = 0; i < cardList.size(); ++i)
idList.add_card()->set_card_id(cardList[i]->getId()); idList.add_card()->set_card_id(cardList[i]->getId());
int startPlayerId = cardList[0]->getZone()->getPlayer()->getId(); int startPlayerId = cardList[0]->getZone()->getPlayer()->getId();
QString startZone = cardList[0]->getZone()->getName(); QString startZone = cardList[0]->getZone()->getName();
switch (static_cast<CardMenuActionType>(a->data().toInt())) { switch (static_cast<CardMenuActionType>(a->data().toInt())) {
case cmMoveToTopLibrary: { case cmMoveToTopLibrary: {
Command_MoveCard *cmd = new Command_MoveCard; Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_player_id(startPlayerId); cmd->set_start_player_id(startPlayerId);
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(getId()); cmd->set_target_player_id(getId());
cmd->set_target_zone("deck"); cmd->set_target_zone("deck");
cmd->set_x(0); cmd->set_x(0);
cmd->set_y(0); cmd->set_y(0);
commandList.append(cmd); commandList.append(cmd);
break; break;
} }
case cmMoveToBottomLibrary: { case cmMoveToBottomLibrary: {
Command_MoveCard *cmd = new Command_MoveCard; Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_player_id(startPlayerId); cmd->set_start_player_id(startPlayerId);
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(getId()); cmd->set_target_player_id(getId());
cmd->set_target_zone("deck"); cmd->set_target_zone("deck");
cmd->set_x(-1); cmd->set_x(-1);
cmd->set_y(0); cmd->set_y(0);
commandList.append(cmd); commandList.append(cmd);
break; break;
} }
case cmMoveToGraveyard: { case cmMoveToGraveyard: {
Command_MoveCard *cmd = new Command_MoveCard; Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_player_id(startPlayerId); cmd->set_start_player_id(startPlayerId);
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(getId()); cmd->set_target_player_id(getId());
cmd->set_target_zone("grave"); cmd->set_target_zone("grave");
cmd->set_x(0); cmd->set_x(0);
cmd->set_y(0); cmd->set_y(0);
commandList.append(cmd); commandList.append(cmd);
break; break;
} }
case cmMoveToExile: { case cmMoveToExile: {
Command_MoveCard *cmd = new Command_MoveCard; Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_player_id(startPlayerId); cmd->set_start_player_id(startPlayerId);
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(getId()); cmd->set_target_player_id(getId());
cmd->set_target_zone("rfg"); cmd->set_target_zone("rfg");
cmd->set_x(0); cmd->set_x(0);
cmd->set_y(0); cmd->set_y(0);
commandList.append(cmd); commandList.append(cmd);
break; break;
} }
default: ; default: ;
} }
} }
game->sendGameCommand(prepareGameCommand(commandList)); game->sendGameCommand(prepareGameCommand(commandList));
} }
void Player::actIncPT(int deltaP, int deltaT) void Player::actIncPT(int deltaP, int deltaT)
{ {
QString ptString = "+" + QString::number(deltaP) + "/+" + QString::number(deltaT); QString ptString = "+" + QString::number(deltaP) + "/+" + QString::number(deltaT);
QList< const ::google::protobuf::Message * > commandList; QList< const ::google::protobuf::Message * > commandList;
QListIterator<QGraphicsItem *> j(scene()->selectedItems()); QListIterator<QGraphicsItem *> j(scene()->selectedItems());
while (j.hasNext()) { while (j.hasNext()) {
CardItem *card = static_cast<CardItem *>(j.next()); CardItem *card = static_cast<CardItem *>(j.next());
Command_SetCardAttr *cmd = new Command_SetCardAttr; Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_attribute(AttrPT); cmd->set_attribute(AttrPT);
cmd->set_attr_value(ptString.toStdString()); cmd->set_attr_value(ptString.toStdString());
commandList.append(cmd); commandList.append(cmd);
} }
sendGameCommand(prepareGameCommand(commandList)); sendGameCommand(prepareGameCommand(commandList));
} }
void Player::actSetPT() void Player::actSetPT()
{ {
QString oldPT; QString oldPT;
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
if (!card->getPT().isEmpty()) if (!card->getPT().isEmpty())
oldPT = card->getPT(); oldPT = card->getPT();
} }
bool ok; bool ok;
dialogSemaphore = true; dialogSemaphore = true;
QString pt = QInputDialog::getText(0, tr("Set power/toughness"), tr("Please enter the new PT:"), QLineEdit::Normal, oldPT, &ok); QString pt = QInputDialog::getText(0, tr("Set power/toughness"), tr("Please enter the new PT:"), QLineEdit::Normal, oldPT, &ok);
dialogSemaphore = false; dialogSemaphore = false;
if (clearCardsToDelete()) if (clearCardsToDelete())
return; return;
if (!ok) if (!ok)
return; return;
QList< const ::google::protobuf::Message * > commandList; QList< const ::google::protobuf::Message * > commandList;
QListIterator<QGraphicsItem *> j(scene()->selectedItems()); QListIterator<QGraphicsItem *> j(scene()->selectedItems());
while (j.hasNext()) { while (j.hasNext()) {
CardItem *card = static_cast<CardItem *>(j.next()); CardItem *card = static_cast<CardItem *>(j.next());
Command_SetCardAttr *cmd = new Command_SetCardAttr; Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_attribute(AttrPT); cmd->set_attribute(AttrPT);
cmd->set_attr_value(pt.toStdString()); cmd->set_attr_value(pt.toStdString());
commandList.append(cmd); commandList.append(cmd);
} }
sendGameCommand(prepareGameCommand(commandList)); sendGameCommand(prepareGameCommand(commandList));
} }
void Player::actDrawArrow() void Player::actDrawArrow()
{ {
game->getActiveCard()->drawArrow(Qt::red); game->getActiveCard()->drawArrow(Qt::red);
} }
void Player::actIncP() void Player::actIncP()
{ {
actIncPT(1, 0); actIncPT(1, 0);
} }
void Player::actDecP() void Player::actDecP()
{ {
actIncPT(-1, 0); actIncPT(-1, 0);
} }
void Player::actIncT() void Player::actIncT()
{ {
actIncPT(0, 1); actIncPT(0, 1);
} }
void Player::actDecT() void Player::actDecT()
{ {
actIncPT(0, -1); actIncPT(0, -1);
} }
void Player::actIncPT() void Player::actIncPT()
{ {
actIncPT(1, 1); actIncPT(1, 1);
} }
void Player::actDecPT() void Player::actDecPT()
{ {
actIncPT(-1, -1); actIncPT(-1, -1);
} }
void Player::actSetAnnotation() void Player::actSetAnnotation()
{ {
QString oldAnnotation; QString oldAnnotation;
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
if (!card->getAnnotation().isEmpty()) if (!card->getAnnotation().isEmpty())
oldAnnotation = card->getAnnotation(); oldAnnotation = card->getAnnotation();
} }
bool ok; bool ok;
dialogSemaphore = true; dialogSemaphore = true;
QString annotation = QInputDialog::getText(0, tr("Set annotation"), tr("Please enter the new annotation:"), QLineEdit::Normal, oldAnnotation, &ok); QString annotation = QInputDialog::getText(0, tr("Set annotation"), tr("Please enter the new annotation:"), QLineEdit::Normal, oldAnnotation, &ok);
dialogSemaphore = false; dialogSemaphore = false;
if (clearCardsToDelete()) if (clearCardsToDelete())
return; return;
if (!ok) if (!ok)
return; return;
QList< const ::google::protobuf::Message * > commandList; QList< const ::google::protobuf::Message * > commandList;
i.toFront(); i.toFront();
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
Command_SetCardAttr *cmd = new Command_SetCardAttr; Command_SetCardAttr *cmd = new Command_SetCardAttr;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_attribute(AttrAnnotation); cmd->set_attribute(AttrAnnotation);
cmd->set_attr_value(annotation.toStdString()); cmd->set_attr_value(annotation.toStdString());
commandList.append(cmd); commandList.append(cmd);
} }
sendGameCommand(prepareGameCommand(commandList)); sendGameCommand(prepareGameCommand(commandList));
} }
void Player::actAttach() void Player::actAttach()
{ {
ArrowAttachItem *arrow = new ArrowAttachItem(game->getActiveCard()); ArrowAttachItem *arrow = new ArrowAttachItem(game->getActiveCard());
scene()->addItem(arrow); scene()->addItem(arrow);
arrow->grabMouse(); arrow->grabMouse();
} }
void Player::actUnattach() void Player::actUnattach()
{ {
Command_AttachCard cmd; Command_AttachCard cmd;
cmd.set_start_zone(game->getActiveCard()->getZone()->getName().toStdString()); cmd.set_start_zone(game->getActiveCard()->getZone()->getName().toStdString());
cmd.set_card_id(game->getActiveCard()->getId()); cmd.set_card_id(game->getActiveCard()->getId());
sendGameCommand(cmd); sendGameCommand(cmd);
} }
void Player::actCardCounterTrigger() void Player::actCardCounterTrigger()
{ {
QAction *a = static_cast<QAction *>(sender()); QAction *a = static_cast<QAction *>(sender());
int counterId = a->data().toInt() / 1000; int counterId = a->data().toInt() / 1000;
int action = a->data().toInt() % 1000; int action = a->data().toInt() % 1000;
QList< const ::google::protobuf::Message * > commandList; QList< const ::google::protobuf::Message * > commandList;
switch (action) { switch (action) {
case 9: { case 9: {
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
if (card->getCounters().value(counterId, 0) < MAX_COUNTERS_ON_CARD) { if (card->getCounters().value(counterId, 0) < MAX_COUNTERS_ON_CARD) {
Command_SetCardCounter *cmd = new Command_SetCardCounter; Command_SetCardCounter *cmd = new Command_SetCardCounter;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_counter_id(counterId); cmd->set_counter_id(counterId);
cmd->set_counter_value(card->getCounters().value(counterId, 0) + 1); cmd->set_counter_value(card->getCounters().value(counterId, 0) + 1);
commandList.append(cmd); commandList.append(cmd);
} }
} }
break; break;
} }
case 10: { case 10: {
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
if (card->getCounters().value(counterId, 0)) { if (card->getCounters().value(counterId, 0)) {
Command_SetCardCounter *cmd = new Command_SetCardCounter; Command_SetCardCounter *cmd = new Command_SetCardCounter;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_counter_id(counterId); cmd->set_counter_id(counterId);
cmd->set_counter_value(card->getCounters().value(counterId, 0) - 1); cmd->set_counter_value(card->getCounters().value(counterId, 0) - 1);
commandList.append(cmd); commandList.append(cmd);
} }
} }
break; break;
} }
case 11: { case 11: {
bool ok; bool ok;
dialogSemaphore = true; dialogSemaphore = true;
int number = QInputDialog::getInteger(0, tr("Set counters"), tr("Number:"), 0, 0, MAX_COUNTERS_ON_CARD, 1, &ok); int number = QInputDialog::getInteger(0, tr("Set counters"), tr("Number:"), 0, 0, MAX_COUNTERS_ON_CARD, 1, &ok);
dialogSemaphore = false; dialogSemaphore = false;
if (clearCardsToDelete()) if (clearCardsToDelete())
return; return;
if (!ok) if (!ok)
return; return;
QListIterator<QGraphicsItem *> i(scene()->selectedItems()); QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) { while (i.hasNext()) {
CardItem *card = static_cast<CardItem *>(i.next()); CardItem *card = static_cast<CardItem *>(i.next());
Command_SetCardCounter *cmd = new Command_SetCardCounter; Command_SetCardCounter *cmd = new Command_SetCardCounter;
cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_zone(card->getZone()->getName().toStdString());
cmd->set_card_id(card->getId()); cmd->set_card_id(card->getId());
cmd->set_counter_id(counterId); cmd->set_counter_id(counterId);
cmd->set_counter_value(number); cmd->set_counter_value(number);
commandList.append(cmd); commandList.append(cmd);
} }
break; break;
} }
default: ; default: ;
} }
sendGameCommand(prepareGameCommand(commandList)); sendGameCommand(prepareGameCommand(commandList));
} }
void Player::actPlay() void Player::actPlay()
{ {
playCard(game->getActiveCard(), false, game->getActiveCard()->getInfo()->getCipt()); playCard(game->getActiveCard(), false, game->getActiveCard()->getInfo()->getCipt());
} }
void Player::actHide() void Player::actHide()
{ {
game->getActiveCard()->getZone()->removeCard(game->getActiveCard()); game->getActiveCard()->getZone()->removeCard(game->getActiveCard());
} }
void Player::updateCardMenu(CardItem *card) void Player::updateCardMenu(CardItem *card)
{ {
QMenu *cardMenu = card->getCardMenu(); QMenu *cardMenu = card->getCardMenu();
QMenu *ptMenu = card->getPTMenu(); QMenu *ptMenu = card->getPTMenu();
QMenu *moveMenu = card->getMoveMenu(); QMenu *moveMenu = card->getMoveMenu();
cardMenu->clear(); cardMenu->clear();
bool revealedCard = false; bool revealedCard = false;
bool writeableCard = getLocal(); bool writeableCard = getLocal();
if (card->getZone()) if (card->getZone())
if (card->getZone()->getIsView()) { if (card->getZone()->getIsView()) {
ZoneViewZone *view = static_cast<ZoneViewZone *>(card->getZone()); ZoneViewZone *view = static_cast<ZoneViewZone *>(card->getZone());
if (view->getRevealZone()) { if (view->getRevealZone()) {
if (view->getWriteableRevealZone()) if (view->getWriteableRevealZone())
writeableCard = true; writeableCard = true;
else else
revealedCard = true; revealedCard = true;
} }
} }
if (revealedCard) if (revealedCard)
cardMenu->addAction(aHide); cardMenu->addAction(aHide);
else if (writeableCard) { else if (writeableCard) {
if (moveMenu->isEmpty()) { if (moveMenu->isEmpty()) {
moveMenu->addAction(aMoveToTopLibrary); moveMenu->addAction(aMoveToTopLibrary);
moveMenu->addAction(aMoveToBottomLibrary); moveMenu->addAction(aMoveToBottomLibrary);
moveMenu->addAction(aMoveToGraveyard); moveMenu->addAction(aMoveToGraveyard);
moveMenu->addAction(aMoveToExile); moveMenu->addAction(aMoveToExile);
} }
if (card->getZone()) { if (card->getZone()) {
if (card->getZone()->getName() == "table") { if (card->getZone()->getName() == "table") {
if (ptMenu->isEmpty()) { if (ptMenu->isEmpty()) {
ptMenu->addAction(aIncP); ptMenu->addAction(aIncP);
ptMenu->addAction(aDecP); ptMenu->addAction(aDecP);
ptMenu->addSeparator(); ptMenu->addSeparator();
ptMenu->addAction(aIncT); ptMenu->addAction(aIncT);
ptMenu->addAction(aDecT); ptMenu->addAction(aDecT);
ptMenu->addSeparator(); ptMenu->addSeparator();
ptMenu->addAction(aIncPT); ptMenu->addAction(aIncPT);
ptMenu->addAction(aDecPT); ptMenu->addAction(aDecPT);
ptMenu->addSeparator(); ptMenu->addSeparator();
ptMenu->addAction(aSetPT); ptMenu->addAction(aSetPT);
} }
cardMenu->addAction(aTap); cardMenu->addAction(aTap);
cardMenu->addAction(aUntap); cardMenu->addAction(aUntap);
cardMenu->addAction(aDoesntUntap); cardMenu->addAction(aDoesntUntap);
cardMenu->addAction(aFlip); cardMenu->addAction(aFlip);
if (card->getFaceDown()) if (card->getFaceDown())
cardMenu->addAction(aPeek); cardMenu->addAction(aPeek);
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addAction(aAttach); cardMenu->addAction(aAttach);
if (card->getAttachedTo()) if (card->getAttachedTo())
cardMenu->addAction(aUnattach); cardMenu->addAction(aUnattach);
cardMenu->addAction(aDrawArrow); cardMenu->addAction(aDrawArrow);
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addMenu(ptMenu); cardMenu->addMenu(ptMenu);
cardMenu->addAction(aSetAnnotation); cardMenu->addAction(aSetAnnotation);
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addAction(aClone); cardMenu->addAction(aClone);
cardMenu->addMenu(moveMenu); cardMenu->addMenu(moveMenu);
for (int i = 0; i < aAddCounter.size(); ++i) { for (int i = 0; i < aAddCounter.size(); ++i) {
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addAction(aAddCounter[i]); cardMenu->addAction(aAddCounter[i]);
cardMenu->addAction(aRemoveCounter[i]); cardMenu->addAction(aRemoveCounter[i]);
cardMenu->addAction(aSetCounter[i]); cardMenu->addAction(aSetCounter[i]);
} }
cardMenu->addSeparator(); cardMenu->addSeparator();
} else if (card->getZone()->getName() == "stack") { } else if (card->getZone()->getName() == "stack") {
cardMenu->addAction(aDrawArrow); cardMenu->addAction(aDrawArrow);
cardMenu->addMenu(moveMenu); cardMenu->addMenu(moveMenu);
} else { } else {
cardMenu->addAction(aPlay); cardMenu->addAction(aPlay);
cardMenu->addMenu(moveMenu); cardMenu->addMenu(moveMenu);
} }
} else } else
cardMenu->addMenu(moveMenu); cardMenu->addMenu(moveMenu);
} }
} }
void Player::setCardMenu(QMenu *menu) void Player::setCardMenu(QMenu *menu)
{ {
if (aCardMenu) if (aCardMenu)
aCardMenu->setMenu(menu); aCardMenu->setMenu(menu);
} }
QMenu *Player::getCardMenu() const QMenu *Player::getCardMenu() const
{ {
if (aCardMenu) if (aCardMenu)
return aCardMenu->menu(); return aCardMenu->menu();
return 0; return 0;
} }
QString Player::getName() const QString Player::getName() const
{ {
return QString::fromStdString(userInfo->name()); return QString::fromStdString(userInfo->name());
} }
qreal Player::getMinimumWidth() const qreal Player::getMinimumWidth() const
{ {
qreal result = table->getMinimumWidth() + CARD_HEIGHT + 15 + counterAreaWidth + stack->boundingRect().width(); qreal result = table->getMinimumWidth() + CARD_HEIGHT + 15 + counterAreaWidth + stack->boundingRect().width();
if (!settingsCache->getHorizontalHand()) if (!settingsCache->getHorizontalHand())
result += hand->boundingRect().width(); result += hand->boundingRect().width();
return result; return result;
} }
void Player::setConceded(bool _conceded) void Player::setConceded(bool _conceded)
{ {
conceded = _conceded; conceded = _conceded;
setVisible(!conceded); setVisible(!conceded);
if (conceded) { if (conceded) {
clear(); clear();
emit gameConceded(); emit gameConceded();
} }
} }
void Player::setMirrored(bool _mirrored) void Player::setMirrored(bool _mirrored)
{ {
if (mirrored != _mirrored) { if (mirrored != _mirrored) {
mirrored = _mirrored; mirrored = _mirrored;
rearrangeZones(); rearrangeZones();
} }
} }
void Player::processSceneSizeChange(int newPlayerWidth) void Player::processSceneSizeChange(int newPlayerWidth)
{ {
qreal tableWidth = newPlayerWidth - CARD_HEIGHT - 15 - counterAreaWidth - stack->boundingRect().width(); qreal tableWidth = newPlayerWidth - CARD_HEIGHT - 15 - counterAreaWidth - stack->boundingRect().width();
if (!settingsCache->getHorizontalHand()) if (!settingsCache->getHorizontalHand())
tableWidth -= hand->boundingRect().width(); tableWidth -= hand->boundingRect().width();
table->setWidth(tableWidth); table->setWidth(tableWidth);
hand->setWidth(tableWidth + stack->boundingRect().width()); hand->setWidth(tableWidth + stack->boundingRect().width());
} }
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