Commit e1380f19 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

full reveal card support

parent 1cd76c26
...@@ -63,6 +63,7 @@ HEADERS += src/counter.h \ ...@@ -63,6 +63,7 @@ HEADERS += src/counter.h \
src/localserver.h \ src/localserver.h \
src/localserverinterface.h \ src/localserverinterface.h \
src/localclient.h \ src/localclient.h \
src/translation.h \
../common/color.h \ ../common/color.h \
../common/serializable_item.h \ ../common/serializable_item.h \
../common/decklist.h \ ../common/decklist.h \
......
...@@ -48,33 +48,33 @@ QString CardZone::getTranslatedName(bool hisOwn, GrammaticalCase gc) const ...@@ -48,33 +48,33 @@ QString CardZone::getTranslatedName(bool hisOwn, GrammaticalCase gc) const
QString ownerName = player->getName(); QString ownerName = player->getName();
if (name == "hand") if (name == "hand")
switch (gc) { switch (gc) {
case CaseNominative: return hisOwn ? tr("his hand") : tr("%1's hand").arg(ownerName); case CaseNominative: return hisOwn ? tr("his hand", "nominative") : tr("%1's hand", "nominative").arg(ownerName);
case CaseGenitive: return hisOwn ? tr("of his hand") : tr("of %1's hand").arg(ownerName); case CaseGenitive: return hisOwn ? tr("of his hand", "genitive") : tr("of %1's hand", "genitive").arg(ownerName);
case CaseAccusative: return hisOwn ? tr("his hand") : tr("%1's hand").arg(ownerName); case CaseAccusative: return hisOwn ? tr("his hand", "accusative") : tr("%1's hand", "accusative").arg(ownerName);
} }
else if (name == "deck") else if (name == "deck")
switch (gc) { switch (gc) {
case CaseNominative: return hisOwn ? tr("his library") : tr("%1's library").arg(ownerName); case CaseNominative: return hisOwn ? tr("his library", "nominative") : tr("%1's library", "nominative").arg(ownerName);
case CaseGenitive: return hisOwn ? tr("of his library") : tr("of %1's library").arg(ownerName); case CaseGenitive: return hisOwn ? tr("of his library", "genitive") : tr("of %1's library", "genitive").arg(ownerName);
case CaseAccusative: return hisOwn ? tr("his library") : tr("%1's library").arg(ownerName); case CaseAccusative: return hisOwn ? tr("his library", "accusative") : tr("%1's library", "accusative").arg(ownerName);
} }
else if (name == "grave") else if (name == "grave")
switch (gc) { switch (gc) {
case CaseNominative: return hisOwn ? tr("his graveyard") : tr("%1's graveyard").arg(ownerName); case CaseNominative: return hisOwn ? tr("his graveyard", "nominative") : tr("%1's graveyard", "nominative").arg(ownerName);
case CaseGenitive: return hisOwn ? tr("of his graveyard") : tr("of %1's graveyard").arg(ownerName); case CaseGenitive: return hisOwn ? tr("of his graveyard", "genitive") : tr("of %1's graveyard", "genitive").arg(ownerName);
case CaseAccusative: return hisOwn ? tr("his graveyard") : tr("%1's graveyard").arg(ownerName); case CaseAccusative: return hisOwn ? tr("his graveyard", "accusative") : tr("%1's graveyard", "accusative").arg(ownerName);
} }
else if (name == "rfg") else if (name == "rfg")
switch (gc) { switch (gc) {
case CaseNominative: return hisOwn ? tr("his exile") : tr("%1's exile").arg(ownerName); case CaseNominative: return hisOwn ? tr("his exile", "nominative") : tr("%1's exile", "nominative").arg(ownerName);
case CaseGenitive: return hisOwn ? tr("of his exile") : tr("of %1's exile").arg(ownerName); case CaseGenitive: return hisOwn ? tr("of his exile", "genitive") : tr("of %1's exile", "genitive").arg(ownerName);
case CaseAccusative: return hisOwn ? tr("his exile") : tr("%1's exile").arg(ownerName); case CaseAccusative: return hisOwn ? tr("his exile", "accusative") : tr("%1's exile", "accusative").arg(ownerName);
} }
else if (name == "sb") else if (name == "sb")
switch (gc) { switch (gc) {
case CaseNominative: return hisOwn ? tr("his sideboard") : tr("%1's sideboard").arg(ownerName); case CaseNominative: return hisOwn ? tr("his sideboard", "nominative") : tr("%1's sideboard", "nominative").arg(ownerName);
case CaseGenitive: return hisOwn ? tr("of his sideboard") : tr("of %1's sideboard").arg(ownerName); case CaseGenitive: return hisOwn ? tr("of his sideboard", "genitive") : tr("of %1's sideboard", "genitive").arg(ownerName);
case CaseAccusative: return hisOwn ? tr("his sideboard") : tr("%1's sideboard").arg(ownerName); case CaseAccusative: return hisOwn ? tr("his sideboard", "accusative") : tr("%1's sideboard", "accusative").arg(ownerName);
} }
return QString(); return QString();
} }
......
...@@ -89,6 +89,15 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb ...@@ -89,6 +89,15 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
item->setPos(100, 100); item->setPos(100, 100);
} }
void GameScene::addRevealedZoneView(Player *player, CardZone *zone, const QList<ServerInfo_Card *> &cardList)
{
ZoneViewWidget *item = new ZoneViewWidget(player, zone, -2, cardList);
views.append(item);
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeZoneView(ZoneViewWidget *)));
addItem(item);
item->setPos(100, 100);
}
void GameScene::removeZoneView(ZoneViewWidget *item) void GameScene::removeZoneView(ZoneViewWidget *item)
{ {
views.removeAt(views.indexOf(item)); views.removeAt(views.indexOf(item));
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
class Player; class Player;
class ZoneViewWidget; class ZoneViewWidget;
class CardZone;
class ServerInfo_Card;
class GameScene : public QGraphicsScene { class GameScene : public QGraphicsScene {
Q_OBJECT Q_OBJECT
...@@ -23,6 +25,7 @@ public: ...@@ -23,6 +25,7 @@ public:
void processViewSizeChange(const QSize &newSize); void processViewSizeChange(const QSize &newSize);
public slots: public slots:
void toggleZoneView(Player *player, const QString &zoneName, int numberCards); void toggleZoneView(Player *player, const QString &zoneName, int numberCards);
void addRevealedZoneView(Player *player, CardZone *zone, const QList<ServerInfo_Card *> &cardList);
void removeZoneView(ZoneViewWidget *item); void removeZoneView(ZoneViewWidget *item);
void addPlayer(Player *player); void addPlayer(Player *player);
void removePlayer(Player *player); void removePlayer(Player *player);
......
...@@ -138,14 +138,11 @@ void MessageLogWidget::logDrawCards(Player *player, int number) ...@@ -138,14 +138,11 @@ void MessageLogWidget::logDrawCards(Player *player, int number)
append(tr("%1 draws %2 cards.").arg(sanitizeHtml(player->getName())).arg(number)); append(tr("%1 draws %2 cards.").arg(sanitizeHtml(player->getName())).arg(number));
} }
void MessageLogWidget::logMoveCard(Player *player, QString cardName, CardZone *startZone, int oldX, CardZone *targetZone, int newX) QPair<QString, QString> MessageLogWidget::getFromStr(CardZone *zone, QString cardName, int position) const
{ {
QString startName = startZone->getName();
QString targetName = targetZone->getName();
if (((startName == "table") && (targetName == "table")) || ((startName == "hand") && (targetName == "hand")))
return;
QString fromStr;
bool cardNameContainsStartZone = false; bool cardNameContainsStartZone = false;
QString fromStr;
QString startName = zone->getName();
if (startName == "table") if (startName == "table")
fromStr = tr(" from table"); fromStr = tr(" from table");
...@@ -156,13 +153,13 @@ void MessageLogWidget::logMoveCard(Player *player, QString cardName, CardZone *s ...@@ -156,13 +153,13 @@ void MessageLogWidget::logMoveCard(Player *player, QString cardName, CardZone *s
else if (startName == "hand") else if (startName == "hand")
fromStr = tr(" from hand"); fromStr = tr(" from hand");
else if (startName == "deck") { else if (startName == "deck") {
if (oldX == startZone->getCards().size() - 1) { if (position == zone->getCards().size() - 1) {
if (cardName.isEmpty()) { if (cardName.isEmpty()) {
cardName = tr("the bottom card of his library"); cardName = tr("the bottom card of his library");
cardNameContainsStartZone = true; cardNameContainsStartZone = true;
} else } else
fromStr = tr(" from the bottom of his library"); fromStr = tr(" from the bottom of his library");
} else if (oldX == 0) { } else if (position == 0) {
if (cardName.isEmpty()) { if (cardName.isEmpty()) {
cardName = tr("the top card of his library"); cardName = tr("the top card of his library");
cardNameContainsStartZone = true; cardNameContainsStartZone = true;
...@@ -172,6 +169,25 @@ void MessageLogWidget::logMoveCard(Player *player, QString cardName, CardZone *s ...@@ -172,6 +169,25 @@ void MessageLogWidget::logMoveCard(Player *player, QString cardName, CardZone *s
fromStr = tr(" from library"); fromStr = tr(" from library");
} else if (startName == "sb") } else if (startName == "sb")
fromStr = tr(" from sideboard"); fromStr = tr(" from sideboard");
if (!cardNameContainsStartZone)
cardName.clear();
return QPair<QString, QString>(cardName, fromStr);
}
void MessageLogWidget::logMoveCard(Player *player, QString cardName, CardZone *startZone, int oldX, CardZone *targetZone, int newX)
{
QString startName = startZone->getName();
QString targetName = targetZone->getName();
if (((startName == "table") && (targetName == "table")) || ((startName == "hand") && (targetName == "hand")))
return;
QPair<QString, QString> temp = getFromStr(startZone, cardName, oldX);
bool cardNameContainsStartZone = false;
if (!temp.first.isEmpty()) {
cardNameContainsStartZone = true;
cardName = temp.first;
}
QString fromStr = temp.second;
QString finalStr; QString finalStr;
if (targetName == "table") if (targetName == "table")
...@@ -321,6 +337,42 @@ void MessageLogWidget::logStopDumpZone(Player *player, CardZone *zone) ...@@ -321,6 +337,42 @@ void MessageLogWidget::logStopDumpZone(Player *player, CardZone *zone)
append(tr("%1 stops looking at %2.").arg(sanitizeHtml(player->getName())).arg(zoneName)); append(tr("%1 stops looking at %2.").arg(sanitizeHtml(player->getName())).arg(zoneName));
} }
void MessageLogWidget::logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer)
{
QPair<QString, QString> temp = getFromStr(zone, cardName, cardId);
bool cardNameContainsStartZone = false;
if (!temp.first.isEmpty()) {
cardNameContainsStartZone = true;
cardName = temp.first;
}
QString fromStr = temp.second;
QString cardStr;
if (cardNameContainsStartZone)
cardStr = cardName;
else if (cardName.isEmpty())
cardStr = tr("a card");
else
cardStr = QString("<font color=\"blue\">%1</font>").arg(sanitizeHtml(cardName));
if (cardId == -1) {
if (otherPlayer)
append(tr("%1 reveals %2 to %3.").arg(sanitizeHtml(player->getName())).arg(zone->getTranslatedName(true, CaseAccusative)).arg(sanitizeHtml(otherPlayer->getName())));
else
append(tr("%1 reveals %2.").arg(sanitizeHtml(player->getName())).arg(zone->getTranslatedName(true, CaseAccusative)));
} else if (cardId == -2) {
if (otherPlayer)
append(tr("%1 randomly reveals %2%3 to %4.").arg(sanitizeHtml(player->getName())).arg(cardStr).arg(fromStr).arg(sanitizeHtml(otherPlayer->getName())));
else
append(tr("%1 randomly reveals %2%3.").arg(sanitizeHtml(player->getName())).arg(cardStr).arg(fromStr));
} else {
if (otherPlayer)
append(tr("%1 reveals %2%3 to %4.").arg(sanitizeHtml(player->getName())).arg(cardStr).arg(fromStr).arg(sanitizeHtml(otherPlayer->getName())));
else
append(tr("%1 reveals %2%3.").arg(sanitizeHtml(player->getName())).arg(cardStr).arg(fromStr));
}
}
void MessageLogWidget::logSetActivePlayer(Player *player) void MessageLogWidget::logSetActivePlayer(Player *player)
{ {
append("---"); append("---");
...@@ -368,6 +420,7 @@ void MessageLogWidget::connectToPlayer(Player *player) ...@@ -368,6 +420,7 @@ void MessageLogWidget::connectToPlayer(Player *player)
connect(player, SIGNAL(logDumpZone(Player *, CardZone *, int)), this, SLOT(logDumpZone(Player *, CardZone *, int))); connect(player, SIGNAL(logDumpZone(Player *, CardZone *, int)), this, SLOT(logDumpZone(Player *, CardZone *, int)));
connect(player, SIGNAL(logStopDumpZone(Player *, CardZone *)), this, SLOT(logStopDumpZone(Player *, CardZone *))); connect(player, SIGNAL(logStopDumpZone(Player *, CardZone *)), this, SLOT(logStopDumpZone(Player *, CardZone *)));
connect(player, SIGNAL(logDrawCards(Player *, int)), this, SLOT(logDrawCards(Player *, int))); connect(player, SIGNAL(logDrawCards(Player *, int)), this, SLOT(logDrawCards(Player *, int)));
connect(player, SIGNAL(logRevealCards(Player *, CardZone *, int, QString, Player *)), this, SLOT(logRevealCards(Player *, CardZone *, int, QString, Player *)));
} }
MessageLogWidget::MessageLogWidget(QWidget *parent) MessageLogWidget::MessageLogWidget(QWidget *parent)
...@@ -379,12 +432,12 @@ MessageLogWidget::MessageLogWidget(QWidget *parent) ...@@ -379,12 +432,12 @@ MessageLogWidget::MessageLogWidget(QWidget *parent)
setFont(f); setFont(f);
} }
void MessageLogWidget::enterEvent(QEvent *event) void MessageLogWidget::enterEvent(QEvent * /*event*/)
{ {
setMouseTracking(true); setMouseTracking(true);
} }
void MessageLogWidget::leaveEvent(QEvent *event) void MessageLogWidget::leaveEvent(QEvent * /*event*/)
{ {
setMouseTracking(false); setMouseTracking(false);
} }
......
...@@ -17,7 +17,7 @@ class MessageLogWidget : public QTextEdit { ...@@ -17,7 +17,7 @@ class MessageLogWidget : public QTextEdit {
private: private:
CardInfoWidget *infoWidget; CardInfoWidget *infoWidget;
QString sanitizeHtml(QString dirty) const; QString sanitizeHtml(QString dirty) const;
QString trZoneName(CardZone *zone, Player *player, bool hisOwn, GrammaticalCase gc) const; QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position) const;
QString getCardNameUnderMouse(const QPoint &pos) const; QString getCardNameUnderMouse(const QPoint &pos) const;
signals: signals:
void cardNameHovered(QString cardName); void cardNameHovered(QString cardName);
...@@ -62,6 +62,7 @@ public slots: ...@@ -62,6 +62,7 @@ public slots:
void logSetAnnotation(Player *player, QString cardName, QString newAnnotation); void logSetAnnotation(Player *player, QString cardName, QString newAnnotation);
void logDumpZone(Player *player, CardZone *zone, int numberCards); void logDumpZone(Player *player, CardZone *zone, int numberCards);
void logStopDumpZone(Player *player, CardZone *zone); void logStopDumpZone(Player *player, CardZone *zone);
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer);
void logSetActivePlayer(Player *player); void logSetActivePlayer(Player *player);
void logSetActivePhase(int phase); void logSetActivePhase(int phase);
public: public:
......
...@@ -223,6 +223,15 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent) ...@@ -223,6 +223,15 @@ Player::Player(ServerInfo_User *info, int _id, bool _local, TabGame *_parent)
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) {
QAction *newAction = playerLists[i]->addAction(QString());
newAction->setData(-1);
connect(newAction, SIGNAL(triggered()), this, SLOT(playerListActionTriggered()));
allPlayersActions.append(newAction);
playerLists[i]->addSeparator();
}
} else { } else {
countersMenu = 0; countersMenu = 0;
sbMenu = 0; sbMenu = 0;
...@@ -286,6 +295,12 @@ void Player::playerListActionTriggered() ...@@ -286,6 +295,12 @@ void Player::playerListActionTriggered()
if (menu == mRevealLibrary) { if (menu == mRevealLibrary) {
sendGameCommand(new Command_RevealCards(-1, "deck", -1, otherPlayerId)); sendGameCommand(new Command_RevealCards(-1, "deck", -1, otherPlayerId));
} else if (menu == mRevealTopCard) {
sendGameCommand(new Command_RevealCards(-1, "deck", 0, otherPlayerId));
} else if (menu == mRevealHand) {
sendGameCommand(new Command_RevealCards(-1, "hand", -1, otherPlayerId));
} else if (menu == mRevealRandomHandCard) {
sendGameCommand(new Command_RevealCards(-1, "hand", -2, otherPlayerId));
} }
} }
...@@ -384,6 +399,9 @@ void Player::retranslateUi() ...@@ -384,6 +399,9 @@ void Player::retranslateUi()
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)
allPlayersActions[i]->setText(tr("&All players"));
} }
QMapIterator<QString, CardZone *> zoneIterator(zones); QMapIterator<QString, CardZone *> zoneIterator(zones);
...@@ -880,6 +898,28 @@ void Player::eventDrawCards(Event_DrawCards *event) ...@@ -880,6 +898,28 @@ void Player::eventDrawCards(Event_DrawCards *event)
emit logDrawCards(this, event->getNumberCards()); emit logDrawCards(this, event->getNumberCards());
} }
void Player::eventRevealCards(Event_RevealCards *event)
{
CardZone *zone = zones.value(event->getZoneName());
if (!zone)
return;
Player *otherPlayer = 0;
if (event->getOtherPlayerId() != -1) {
otherPlayer = static_cast<TabGame *>(parent())->getPlayers().value(event->getOtherPlayerId());
if (!otherPlayer)
return;
}
QList<ServerInfo_Card *> cardList = event->getCardList();
if (!cardList.isEmpty())
static_cast<GameScene *>(scene())->addRevealedZoneView(this, zone, cardList);
QString cardName;
if (cardList.size() == 1)
cardName = cardList.first()->getName();
emit logRevealCards(this, zone, event->getCardId(), cardName, otherPlayer);
}
void Player::processGameEvent(GameEvent *event, GameEventContext *context) void Player::processGameEvent(GameEvent *event, GameEventContext *context)
{ {
qDebug() << "player event: id=" << event->getItemId(); qDebug() << "player event: id=" << event->getItemId();
...@@ -902,6 +942,7 @@ void Player::processGameEvent(GameEvent *event, GameEventContext *context) ...@@ -902,6 +942,7 @@ void Player::processGameEvent(GameEvent *event, GameEventContext *context)
case ItemId_Event_DestroyCard: eventDestroyCard(qobject_cast<Event_DestroyCard *>(event)); break; case ItemId_Event_DestroyCard: eventDestroyCard(qobject_cast<Event_DestroyCard *>(event)); break;
case ItemId_Event_AttachCard: eventAttachCard(qobject_cast<Event_AttachCard *>(event)); break; case ItemId_Event_AttachCard: eventAttachCard(qobject_cast<Event_AttachCard *>(event)); break;
case ItemId_Event_DrawCards: eventDrawCards(qobject_cast<Event_DrawCards *>(event)); break; case ItemId_Event_DrawCards: eventDrawCards(qobject_cast<Event_DrawCards *>(event)); break;
case ItemId_Event_RevealCards: eventRevealCards(qobject_cast<Event_RevealCards *>(event)); break;
default: { default: {
qDebug() << "unhandled game event"; qDebug() << "unhandled game event";
} }
......
...@@ -43,6 +43,7 @@ class Event_FlipCard; ...@@ -43,6 +43,7 @@ class Event_FlipCard;
class Event_DestroyCard; class Event_DestroyCard;
class Event_AttachCard; class Event_AttachCard;
class Event_DrawCards; class Event_DrawCards;
class Event_RevealCards;
class Player : public QObject, public QGraphicsItem { class Player : public QObject, public QGraphicsItem {
Q_OBJECT Q_OBJECT
...@@ -68,6 +69,7 @@ signals: ...@@ -68,6 +69,7 @@ signals:
void logSetAnnotation(Player *player, QString cardName, QString newAnnotation); void logSetAnnotation(Player *player, QString cardName, QString newAnnotation);
void logDumpZone(Player *player, CardZone *zone, int numberCards); void logDumpZone(Player *player, CardZone *zone, int numberCards);
void logStopDumpZone(Player *player, CardZone *zone); void logStopDumpZone(Player *player, CardZone *zone);
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer);
void sizeChanged(); void sizeChanged();
public slots: public slots:
...@@ -109,6 +111,7 @@ private: ...@@ -109,6 +111,7 @@ private:
QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *countersMenu, *sayMenu, QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *countersMenu, *sayMenu,
*mRevealLibrary, *mRevealTopCard, *mRevealHand, *mRevealRandomHandCard; *mRevealLibrary, *mRevealTopCard, *mRevealHand, *mRevealRandomHandCard;
QList<QMenu *> playerLists; QList<QMenu *> playerLists;
QList<QAction *> allPlayersActions;
QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg, QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg,
*aMoveGraveToTopLibrary, *aMoveGraveToBottomLibrary, *aMoveGraveToHand, *aMoveGraveToRfg, *aMoveGraveToTopLibrary, *aMoveGraveToBottomLibrary, *aMoveGraveToHand, *aMoveGraveToRfg,
*aMoveRfgToTopLibrary, *aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave, *aMoveRfgToTopLibrary, *aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave,
...@@ -166,6 +169,7 @@ private: ...@@ -166,6 +169,7 @@ private:
void eventDestroyCard(Event_DestroyCard *event); void eventDestroyCard(Event_DestroyCard *event);
void eventAttachCard(Event_AttachCard *event); void eventAttachCard(Event_AttachCard *event);
void eventDrawCards(Event_DrawCards *event); void eventDrawCards(Event_DrawCards *event);
void eventRevealCards(Event_RevealCards *event);
public: public:
static const int counterAreaWidth = 65; static const int counterAreaWidth = 65;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "protocol_items.h" #include "protocol_items.h"
#include "settingscache.h" #include "settingscache.h"
ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards) ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards, const QList<ServerInfo_Card *> &cardList)
: QGraphicsWidget(0, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player) : QGraphicsWidget(0, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player)
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
...@@ -21,7 +21,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC ...@@ -21,7 +21,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC
QGraphicsLinearLayout *vbox = new QGraphicsLinearLayout(Qt::Vertical); QGraphicsLinearLayout *vbox = new QGraphicsLinearLayout(Qt::Vertical);
if (numberCards == -1) { if (numberCards < 0) {
sortByNameCheckBox = new QCheckBox; sortByNameCheckBox = new QCheckBox;
QGraphicsProxyWidget *sortByNameProxy = new QGraphicsProxyWidget; QGraphicsProxyWidget *sortByNameProxy = new QGraphicsProxyWidget;
sortByNameProxy->setWidget(sortByNameCheckBox); sortByNameProxy->setWidget(sortByNameCheckBox);
...@@ -52,7 +52,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC ...@@ -52,7 +52,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberC
connect(zone, SIGNAL(optimumRectChanged()), this, SLOT(resizeToZoneContents())); connect(zone, SIGNAL(optimumRectChanged()), this, SLOT(resizeToZoneContents()));
connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted())); connect(zone, SIGNAL(beingDeleted()), this, SLOT(zoneDeleted()));
vbox->addItem(zone); vbox->addItem(zone);
zone->initializeCards(); zone->initializeCards(cardList);
if (sortByNameCheckBox) { if (sortByNameCheckBox) {
connect(sortByNameCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByName(int))); connect(sortByNameCheckBox, SIGNAL(stateChanged(int)), zone, SLOT(setSortByName(int)));
...@@ -89,7 +89,8 @@ void ZoneViewWidget::resizeToZoneContents() ...@@ -89,7 +89,8 @@ void ZoneViewWidget::resizeToZoneContents()
void ZoneViewWidget::closeEvent(QCloseEvent *event) void ZoneViewWidget::closeEvent(QCloseEvent *event)
{ {
disconnect(zone, SIGNAL(beingDeleted()), this, 0); disconnect(zone, SIGNAL(beingDeleted()), this, 0);
player->sendGameCommand(new Command_StopDumpZone(-1, player->getId(), zone->getName())); if (zone->getNumberCards() != -2)
player->sendGameCommand(new Command_StopDumpZone(-1, player->getId(), zone->getName()));
if (shuffleCheckBox) if (shuffleCheckBox)
if (shuffleCheckBox->isChecked()) if (shuffleCheckBox->isChecked())
player->sendGameCommand(new Command_Shuffle); player->sendGameCommand(new Command_Shuffle);
......
...@@ -12,6 +12,7 @@ class CardDatabase; ...@@ -12,6 +12,7 @@ class CardDatabase;
class QScrollBar; class QScrollBar;
class QCheckBox; class QCheckBox;
class GameScene; class GameScene;
class ServerInfo_Card;
class ZoneViewWidget : public QGraphicsWidget { class ZoneViewWidget : public QGraphicsWidget {
Q_OBJECT Q_OBJECT
...@@ -29,7 +30,7 @@ private slots: ...@@ -29,7 +30,7 @@ private slots:
void resizeToZoneContents(); void resizeToZoneContents();
void zoneDeleted(); void zoneDeleted();
public: public:
ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0); ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0, const QList<ServerInfo_Card *> &cardList = QList<ServerInfo_Card *>());
ZoneViewZone *getZone() const { return zone; } ZoneViewZone *getZone() const { return zone; }
void retranslateUi(); void retranslateUi();
protected: protected:
......
...@@ -26,9 +26,13 @@ void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem * ...@@ -26,9 +26,13 @@ void ZoneViewZone::paint(QPainter */*painter*/, const QStyleOptionGraphicsItem *
{ {
} }
void ZoneViewZone::initializeCards() void ZoneViewZone::initializeCards(const QList<ServerInfo_Card *> &cardList)
{ {
if (!origZone->contentsKnown()) { if (!cardList.isEmpty()) {
for (int i = 0; i < cardList.size(); ++i)
addCard(new CardItem(player, cardList[i]->getName(), cardList[i]->getId(), this), false, i);
reorganizeCards();
} else if (!origZone->contentsKnown()) {
Command_DumpZone *command = new Command_DumpZone(-1, player->getId(), name, numberCards); Command_DumpZone *command = new Command_DumpZone(-1, player->getId(), name, numberCards);
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(zoneDumpReceived(ProtocolResponse *))); connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(zoneDumpReceived(ProtocolResponse *)));
player->sendGameCommand(command); player->sendGameCommand(command);
...@@ -80,6 +84,7 @@ void ZoneViewZone::reorganizeCards() ...@@ -80,6 +84,7 @@ void ZoneViewZone::reorganizeCards()
cols = 2; cols = 2;
qDebug() << "reorganizeCards: rows=" << rows << "cols=" << cols; qDebug() << "reorganizeCards: rows=" << rows << "cols=" << cols;
qDebug() << "SORT BY NAME:" << sortByName << "SORT BY TYPE:" << sortByType;
CardList cardsToDisplay(cards); CardList cardsToDisplay(cards);
if (sortByName || sortByType) if (sortByName || sortByType)
...@@ -119,7 +124,6 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/) ...@@ -119,7 +124,6 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/) void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
{ {
qDebug(QString("handleDropEvent id=%1").arg(cardId).toLatin1());
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), 0, 0, false)); player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), 0, 0, false));
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
class ZoneViewWidget; class ZoneViewWidget;
class ProtocolResponse; class ProtocolResponse;
class ServerInfo_Card;
class ZoneViewZone : public CardZone, public QGraphicsLayoutItem { class ZoneViewZone : public CardZone, public QGraphicsLayoutItem {
Q_OBJECT Q_OBJECT
...@@ -21,7 +22,7 @@ public: ...@@ -21,7 +22,7 @@ public:
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards(); void reorganizeCards();
void initializeCards(); void initializeCards(const QList<ServerInfo_Card *> &cardList = QList<ServerInfo_Card *>());
void removeCard(int position); void removeCard(int position);
int getNumberCards() const { return numberCards; } int getNumberCards() const { return numberCards; }
void setGeometry(const QRectF &rect); void setGeometry(const QRectF &rect);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -1161,9 +1161,12 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co ...@@ -1161,9 +1161,12 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co
if (!game->getGameStarted()) if (!game->getGameStarted())
return RespGameNotStarted; return RespGameNotStarted;
Server_Player *otherPlayer = game->getPlayer(cmd->getPlayerId()); Server_Player *otherPlayer = 0;
if (!otherPlayer) if (cmd->getPlayerId() != -1) {
return RespNameNotFound; otherPlayer = game->getPlayer(cmd->getPlayerId());
if (!otherPlayer)
return RespNameNotFound;
}
Server_CardZone *zone = player->getZones().value(cmd->getZoneName()); Server_CardZone *zone = player->getZones().value(cmd->getZoneName());
if (!zone) if (!zone)
return RespNameNotFound; return RespNameNotFound;
...@@ -1171,7 +1174,11 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co ...@@ -1171,7 +1174,11 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co
QList<Server_Card *> cardsToReveal; QList<Server_Card *> cardsToReveal;
if (cmd->getCardId() == -1) if (cmd->getCardId() == -1)
cardsToReveal = zone->cards; cardsToReveal = zone->cards;
else { else if (cmd->getCardId() == -2) {
if (zone->cards.isEmpty())
return RespContextError;
cardsToReveal.append(zone->cards.at(rng->getNumber(0, zone->cards.size() - 1)));
} else {
Server_Card *card = zone->getCard(cmd->getCardId(), false); Server_Card *card = zone->getCard(cmd->getCardId(), false);
if (!card) if (!card)
return RespNameNotFound; return RespNameNotFound;
...@@ -1198,13 +1205,18 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co ...@@ -1198,13 +1205,18 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(Command_RevealCards *cmd, Co
attachCardId = card->getParentCard()->getId(); attachCardId = card->getParentCard()->getId();
} }
respCardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getTapped(), card->getAttacking(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), cardCounterList, attachPlayerId, attachZone, attachCardId)); if (cmd->getPlayerId() != -1)
respCardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getTapped(), card->getAttacking(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), cardCounterList, attachPlayerId, attachZone, attachCardId));
respCardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getTapped(), card->getAttacking(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), cardCounterList, attachPlayerId, attachZone, attachCardId)); respCardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getTapped(), card->getAttacking(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), cardCounterList, attachPlayerId, attachZone, attachCardId));
} }
cont->enqueueGameEventPublic(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), otherPlayer->getPlayerId()), game->getGameId()); if (cmd->getPlayerId() == -1)
cont->enqueueGameEventPrivate(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), otherPlayer->getPlayerId(), respCardListPrivate), game->getGameId(), otherPlayer->getPlayerId()); cont->enqueueGameEventPublic(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), -1, respCardListOmniscient), game->getGameId());
cont->enqueueGameEventOmniscient(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), otherPlayer->getPlayerId(), respCardListOmniscient), game->getGameId()); else {
cont->enqueueGameEventPublic(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), otherPlayer->getPlayerId()), game->getGameId());
cont->enqueueGameEventPrivate(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), otherPlayer->getPlayerId(), respCardListPrivate), game->getGameId(), otherPlayer->getPlayerId());
cont->enqueueGameEventOmniscient(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd->getCardId(), otherPlayer->getPlayerId(), respCardListOmniscient), game->getGameId());
}
return RespOk; return RespOk;
} }
\ No newline at end of file
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