Convert to 4-space indents
This commit is contained in:
parent
ac8c967d10
commit
a171df744d
3 changed files with 1925 additions and 1925 deletions
|
@ -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()
|
||||||
|
|
||||||
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 @@
|
||||||
#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;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue