minor cleanups and log improvements
This commit is contained in:
parent
52b8a5b0e7
commit
2148005bd1
18 changed files with 215 additions and 306 deletions
|
@ -16,8 +16,8 @@ QT += network svg
|
|||
#QTPLUGIN += qjpeg
|
||||
|
||||
# Input
|
||||
HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h setsmodel.h src/window_sets.h src/abstractgraphicsitem.h src/dlg_settings.h
|
||||
SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp src/setsmodel.cpp src/window_sets.cpp src/abstractgraphicsitem.cpp src/dlg_settings.cpp
|
||||
HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h setsmodel.h src/window_sets.h src/abstractgraphicsitem.h src/dlg_settings.h
|
||||
SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp src/setsmodel.cpp src/window_sets.cpp src/abstractgraphicsitem.cpp src/dlg_settings.cpp
|
||||
TRANSLATIONS += \
|
||||
translations/cockatrice_de.ts \
|
||||
translations/cockatrice_en.ts
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "cardzone.h"
|
||||
#include "tablezone.h"
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
|
||||
CardItem::CardItem(CardDatabase *_db, const QString &_name, int _cardid, QGraphicsItem *parent)
|
||||
: AbstractGraphicsItem(parent), db(_db), info(db->getCard(_name)), name(_name), id(_cardid), tapped(false), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL)
|
||||
|
@ -200,7 +201,7 @@ void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|||
|
||||
void CardItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
((CardZone *) parentItem())->hoverCardEvent(this);
|
||||
((Game *) ((CardZone *) parentItem())->getPlayer()->parent())->hoverCardEvent(this);
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include "client.h"
|
||||
#include "zoneviewzone.h"
|
||||
|
||||
CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, QGraphicsItem *parent, bool isView)
|
||||
: AbstractGraphicsItem(parent), player(_p), name(_name), cards(NULL), view(NULL), menu(NULL), doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable)
|
||||
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)
|
||||
{
|
||||
if (!isView)
|
||||
player->addZone(this);
|
||||
|
@ -17,14 +17,13 @@ CardZone::~CardZone()
|
|||
qDebug(QString("CardZone destructor: %1").arg(name).toLatin1());
|
||||
delete view;
|
||||
clearContents();
|
||||
delete cards;
|
||||
}
|
||||
|
||||
void CardZone::clearContents()
|
||||
{
|
||||
for (int i = 0; i < cards->size(); i++)
|
||||
delete cards->at(i);
|
||||
cards->clear();
|
||||
for (int i = 0; i < cards.size(); i++)
|
||||
delete cards.at(i);
|
||||
cards.clear();
|
||||
}
|
||||
|
||||
void CardZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent */*event*/)
|
||||
|
@ -58,7 +57,7 @@ void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
|||
|
||||
CardItem *CardZone::getCard(int cardId, const QString &cardName)
|
||||
{
|
||||
CardItem *c = cards->findCard(cardId, false);
|
||||
CardItem *c = cards.findCard(cardId, false);
|
||||
// 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.
|
||||
// It can be assumed that in an invisible zone, all cards are equal.
|
||||
|
@ -71,9 +70,9 @@ CardItem *CardZone::getCard(int cardId, const QString &cardName)
|
|||
|
||||
CardItem *CardZone::takeCard(int position, int cardId, const QString &cardName)
|
||||
{
|
||||
Q_ASSERT(position < cards->size());
|
||||
Q_ASSERT(position < cards.size());
|
||||
|
||||
CardItem *c = cards->takeAt(position);
|
||||
CardItem *c = cards.takeAt(position);
|
||||
|
||||
if (view)
|
||||
view->removeCard(position);
|
||||
|
@ -91,11 +90,6 @@ void CardZone::setCardAttr(int cardId, const QString &aname, const QString &aval
|
|||
player->client->setCardAttr(name, cardId, aname, avalue);
|
||||
}
|
||||
|
||||
void CardZone::hoverCardEvent(CardItem *card)
|
||||
{
|
||||
player->hoverCardEvent(card);
|
||||
}
|
||||
|
||||
void CardZone::setView(ZoneViewZone *_view)
|
||||
{
|
||||
view = _view;
|
||||
|
@ -105,6 +99,6 @@ void CardZone::moveAllToZone(const QString &targetZone, int targetX)
|
|||
{
|
||||
// Cards need to be moved in reverse order so that the other
|
||||
// cards' list index doesn't change
|
||||
for (int i = cards->size() - 1; i >= 0; i--)
|
||||
player->client->moveCard(cards->at(i)->getId(), getName(), targetZone, targetX);
|
||||
for (int i = cards.size() - 1; i >= 0; i--)
|
||||
player->client->moveCard(cards.at(i)->getId(), getName(), targetZone, targetX);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class CardZone : public AbstractGraphicsItem {
|
|||
protected:
|
||||
Player *player;
|
||||
QString name;
|
||||
CardList *cards;
|
||||
CardList cards;
|
||||
ZoneViewZone *view;
|
||||
QMenu *menu;
|
||||
QAction *doubleClickAction;
|
||||
|
@ -29,7 +29,7 @@ public:
|
|||
enum { Type = typeZone };
|
||||
int type() const { return Type; }
|
||||
virtual void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown) = 0;
|
||||
CardZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, QGraphicsItem *parent = 0, bool isView = false);
|
||||
CardZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0, bool isView = false);
|
||||
~CardZone();
|
||||
void clearContents();
|
||||
bool getHasCardAttr() const { return hasCardAttr; }
|
||||
|
@ -38,15 +38,14 @@ public:
|
|||
void setMenu(QMenu *_menu, QAction *_doubleClickAction = 0) { menu = _menu; doubleClickAction = _doubleClickAction; }
|
||||
QString getName() const { return name; }
|
||||
Player *getPlayer() const { return player; }
|
||||
bool contentsKnown() const { return cards->getContentsKnown(); }
|
||||
CardList *getCards() const { return cards; }
|
||||
bool contentsKnown() const { return cards.getContentsKnown(); }
|
||||
const CardList &getCards() const { return cards; }
|
||||
void addCard(CardItem *card, bool reorganize, int x, int y = -1);
|
||||
// getCard() finds a card by id.
|
||||
CardItem *getCard(int cardId, const QString &cardName);
|
||||
// takeCard() finds a card by position and removes it from the zone and from all of its views.
|
||||
CardItem *takeCard(int position, int cardId, const QString &cardName);
|
||||
void setCardAttr(int cardId, const QString &aname, const QString &avalue);
|
||||
void hoverCardEvent(CardItem *card);
|
||||
ZoneViewZone *getView() const { return view; }
|
||||
void setView(ZoneViewZone *_view);
|
||||
virtual void reorganizeCards() = 0;
|
||||
|
|
|
@ -136,14 +136,13 @@ Player *Game::addPlayer(int playerId, const QString &playerName, QPointF base, b
|
|||
{
|
||||
Player *newPlayer = new Player(playerName, playerId, base, local, db, client, scene, this);
|
||||
|
||||
connect(newPlayer, SIGNAL(hoverCard(QString)), this, SIGNAL(hoverCard(QString)));
|
||||
connect(newPlayer, SIGNAL(sigShowCardMenu(QPoint)), this, SLOT(showCardMenu(QPoint)));
|
||||
connect(newPlayer, SIGNAL(logMoveCard(QString, QString, QString, QString)), this, SIGNAL(logMoveCard(QString, QString, QString, QString)));
|
||||
connect(newPlayer, SIGNAL(logCreateToken(QString, QString)), this, SIGNAL(logCreateToken(QString, QString)));
|
||||
connect(newPlayer, SIGNAL(logSetCardCounters(QString, QString, int, int)), this, SIGNAL(logSetCardCounters(QString, QString, int, int)));
|
||||
connect(newPlayer, SIGNAL(logSetTapped(QString, QString, bool)), this, SIGNAL(logSetTapped(QString, QString, bool)));
|
||||
connect(newPlayer, SIGNAL(logSetCounter(QString, QString, int, int)), this, SIGNAL(logSetCounter(QString, QString, int, int)));
|
||||
connect(newPlayer, SIGNAL(logSetDoesntUntap(QString, QString, bool)), this, SIGNAL(logSetDoesntUntap(QString, QString, bool)));
|
||||
connect(newPlayer, SIGNAL(logMoveCard(Player *, QString, QString, QString)), this, SIGNAL(logMoveCard(Player *, QString, QString, QString)));
|
||||
connect(newPlayer, SIGNAL(logCreateToken(Player *, QString)), this, SIGNAL(logCreateToken(Player *, QString)));
|
||||
connect(newPlayer, SIGNAL(logSetCardCounters(Player *, QString, int, int)), this, SIGNAL(logSetCardCounters(Player *, QString, int, int)));
|
||||
connect(newPlayer, SIGNAL(logSetTapped(Player *, QString, bool)), this, SIGNAL(logSetTapped(Player *, QString, bool)));
|
||||
connect(newPlayer, SIGNAL(logSetCounter(Player *, QString, int, int)), this, SIGNAL(logSetCounter(Player *, QString, int, int)));
|
||||
connect(newPlayer, SIGNAL(logSetDoesntUntap(Player *, QString, bool)), this, SIGNAL(logSetDoesntUntap(Player *, QString, bool)));
|
||||
|
||||
players << newPlayer;
|
||||
emit playerAdded(newPlayer);
|
||||
|
@ -192,21 +191,21 @@ void Game::gameEvent(const ServerEventData &msg)
|
|||
|
||||
switch(msg.getEventType()) {
|
||||
case eventSay:
|
||||
emit logSay(p->getName(), msg.getEventData()[0]);
|
||||
emit logSay(p, msg.getEventData()[0]);
|
||||
break;
|
||||
case eventJoin: {
|
||||
emit logJoin(msg.getPlayerName());
|
||||
emit logJoin(p);
|
||||
addPlayer(msg.getPlayerId(), msg.getPlayerName(), QPointF(0, 0), false);
|
||||
break;
|
||||
}
|
||||
case eventLeave:
|
||||
emit logLeave(msg.getPlayerName());
|
||||
emit logLeave(p);
|
||||
// XXX Spieler natürlich noch rauswerfen
|
||||
break;
|
||||
case eventReadyStart:
|
||||
if (started) {
|
||||
started = false;
|
||||
emit logReadyStart(p->getName());
|
||||
emit logReadyStart(p);
|
||||
if (!p->getLocal())
|
||||
restartGameDialog();
|
||||
}
|
||||
|
@ -216,13 +215,13 @@ void Game::gameEvent(const ServerEventData &msg)
|
|||
emit logGameStart();
|
||||
break;
|
||||
case eventShuffle:
|
||||
emit logShuffle(p->getName());
|
||||
emit logShuffle(p);
|
||||
break;
|
||||
case eventRollDice: {
|
||||
QStringList data = msg.getEventData();
|
||||
int sides = data[0].toInt();
|
||||
int roll = data[1].toInt();
|
||||
emit logRollDice(p->getName(), sides, roll);
|
||||
emit logRollDice(p, sides, roll);
|
||||
break;
|
||||
}
|
||||
case eventSetActivePlayer:
|
||||
|
@ -243,7 +242,7 @@ void Game::gameEvent(const ServerEventData &msg)
|
|||
}
|
||||
case eventDumpZone: {
|
||||
QStringList data = msg.getEventData();
|
||||
emit logDumpZone(p->getName(), data[1], players.findPlayer(data[0].toInt())->getName(), data[2].toInt());
|
||||
emit logDumpZone(p, data[1], players.findPlayer(data[0].toInt())->getName(), data[2].toInt());
|
||||
break;
|
||||
}
|
||||
case eventMoveCard: {
|
||||
|
@ -253,7 +252,7 @@ void Game::gameEvent(const ServerEventData &msg)
|
|||
break;
|
||||
}
|
||||
case eventDraw: {
|
||||
emit logDraw(p->getName(), msg.getEventData()[0].toInt());
|
||||
emit logDraw(p, msg.getEventData()[0].toInt());
|
||||
if (msg.getPlayerId() == localPlayer->getId())
|
||||
break;
|
||||
p->gameEvent(msg);
|
||||
|
@ -402,3 +401,8 @@ void Game::actSayMessage()
|
|||
QAction *a = qobject_cast<QAction *>(sender());
|
||||
client->say(a->text());
|
||||
}
|
||||
|
||||
void Game::hoverCardEvent(CardItem *card)
|
||||
{
|
||||
emit hoverCard(card->getName());
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ class Client;
|
|||
class ServerEventData;
|
||||
class CardDatabase;
|
||||
class DlgStartGame;
|
||||
class CardItem;
|
||||
|
||||
class Game : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -61,26 +62,27 @@ signals:
|
|||
|
||||
// Log events
|
||||
void logPlayerListReceived(QStringList players);
|
||||
void logJoin(QString playerName);
|
||||
void logLeave(QString playerName);
|
||||
void logReadyStart(QString playerName);
|
||||
void logJoin(Player *player);
|
||||
void logLeave(Player *player);
|
||||
void logReadyStart(Player *player);
|
||||
void logGameStart();
|
||||
void logSay(QString playerName, QString text);
|
||||
void logShuffle(QString playerName);
|
||||
void logRollDice(QString playerName, int sides, int roll);
|
||||
void logDraw(QString playerName, int number);
|
||||
void logMoveCard(QString playerName, QString cardName, QString startZone, QString targetZone);
|
||||
void logCreateToken(QString playerName, QString cardName);
|
||||
void logSetCardCounters(QString playerName, QString cardName, int value, int oldValue);
|
||||
void logSetTapped(QString playerName, QString cardName, bool tapped);
|
||||
void logSetCounter(QString playerName, QString counterName, int value, int oldValue);
|
||||
void logSetDoesntUntap(QString playerName, QString cardName, bool doesntUntap);
|
||||
void logDumpZone(QString playerName, QString zoneName, QString zoneOwner, int numberCards);
|
||||
void logSay(Player *player, QString text);
|
||||
void logShuffle(Player *player);
|
||||
void logRollDice(Player *player, int sides, int roll);
|
||||
void logDraw(Player *player, int number);
|
||||
void logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone);
|
||||
void logCreateToken(Player *player, QString cardName);
|
||||
void logSetCardCounters(Player *player, QString cardName, int value, int oldValue);
|
||||
void logSetTapped(Player *player, QString cardName, bool tapped);
|
||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
||||
void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards);
|
||||
public:
|
||||
Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent = 0);
|
||||
~Game();
|
||||
Player *getLocalPlayer() const { return localPlayer; }
|
||||
void restartGameDialog();
|
||||
void hoverCardEvent(CardItem *card);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
#include "client.h"
|
||||
|
||||
HandZone::HandZone(Player *_p, QGraphicsItem *parent)
|
||||
: CardZone(_p, "hand", false, false, parent)
|
||||
: CardZone(_p, "hand", false, false, _p->getLocal(), parent)
|
||||
{
|
||||
cards = new CardList(player->getLocal());
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
setAcceptsHoverEvents(true); // Awkwardly, this is needed to repaint the cached item after it has been corrupted by buggy rubberband drag.
|
||||
}
|
||||
|
||||
QRectF HandZone::boundingRect() const
|
||||
|
@ -21,20 +22,20 @@ void HandZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option
|
|||
|
||||
void HandZone::reorganizeCards()
|
||||
{
|
||||
if (cards->isEmpty())
|
||||
if (cards.isEmpty())
|
||||
return;
|
||||
|
||||
int cardCount = cards->size();
|
||||
const int cardCount = cards.size();
|
||||
qreal totalWidth = boundingRect().width();
|
||||
qreal totalHeight = boundingRect().height();
|
||||
qreal cardWidth = cards->at(0)->boundingRect().width();
|
||||
qreal cardHeight = cards->at(0)->boundingRect().height();
|
||||
qreal cardWidth = cards.at(0)->boundingRect().width();
|
||||
qreal cardHeight = cards.at(0)->boundingRect().height();
|
||||
qreal xspace = 5;
|
||||
qreal x1 = xspace;
|
||||
qreal x2 = totalWidth - xspace - cardWidth;
|
||||
|
||||
for (int i = 0; i < cardCount; i++) {
|
||||
CardItem *c = cards->at(i);
|
||||
CardItem *c = cards.at(i);
|
||||
qreal x = i % 2 ? x2 : x1;
|
||||
// If the total height of the cards is smaller than the available height,
|
||||
// the cards do not need to overlap and are displayed in the center of the area.
|
||||
|
@ -49,10 +50,10 @@ void HandZone::reorganizeCards()
|
|||
void HandZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||
{
|
||||
if (x == -1)
|
||||
x = cards->size();
|
||||
cards->insert(x, card);
|
||||
x = cards.size();
|
||||
cards.insert(x, card);
|
||||
|
||||
if (!cards->getContentsKnown()) {
|
||||
if (!cards.getContentsKnown()) {
|
||||
card->setId(-1);
|
||||
card->setName();
|
||||
}
|
||||
|
@ -64,5 +65,5 @@ void HandZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
|||
|
||||
void HandZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||
{
|
||||
player->client->moveCard(cardId, startZone->getName(), getName(), cards->size(), 0);
|
||||
player->client->moveCard(cardId, startZone->getName(), getName(), cards.size(), 0);
|
||||
}
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
#include <QtGui>
|
||||
#include "libraryzone.h"
|
||||
#include "player.h"
|
||||
#include "client.h"
|
||||
#include "carddatabase.h"
|
||||
#include "carddragitem.h"
|
||||
#include "zoneviewzone.h"
|
||||
|
||||
LibraryZone::LibraryZone(Player *_p, QGraphicsItem *parent)
|
||||
: CardZone(_p, "deck", false, true, parent)
|
||||
{
|
||||
cards = new CardList(false);
|
||||
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
||||
QRectF LibraryZone::boundingRect() const
|
||||
{
|
||||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||
}
|
||||
|
||||
void LibraryZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/)
|
||||
{
|
||||
QSizeF translatedSize = option->matrix.mapRect(boundingRect()).size();
|
||||
QPixmap *translatedPixmap = player->getDb()->getCard()->getPixmap(translatedSize.toSize());
|
||||
|
||||
painter->save();
|
||||
painter->resetTransform();
|
||||
painter->drawPixmap(translatedPixmap->rect(), *translatedPixmap, translatedPixmap->rect());
|
||||
painter->restore();
|
||||
|
||||
paintNumberEllipse(cards->size(), painter);
|
||||
}
|
||||
|
||||
void LibraryZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||
{
|
||||
cards->insert(x, card);
|
||||
card->setId(-1);
|
||||
card->setName(QString());
|
||||
card->setPos(0, 0);
|
||||
card->setVisible(false);
|
||||
card->resetState();
|
||||
card->setParentItem(this);
|
||||
}
|
||||
|
||||
void LibraryZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||
{
|
||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
||||
}
|
||||
|
||||
void LibraryZone::reorganizeCards()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void LibraryZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
CardZone::mousePressEvent(event);
|
||||
if (event->isAccepted())
|
||||
return;
|
||||
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
event->accept();
|
||||
} else
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void LibraryZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < QApplication::startDragDistance())
|
||||
return;
|
||||
|
||||
if (cards->empty())
|
||||
return;
|
||||
|
||||
bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
||||
CardItem *card = cards->at(0);
|
||||
CardDragItem *drag = card->createDragItem(0, event->pos(), event->scenePos(), faceDown);
|
||||
drag->grabMouse();
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
||||
void LibraryZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
|
||||
{
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef LIBRARYZONE_H
|
||||
#define LIBRARYZONE_H
|
||||
|
||||
#include "cardzone.h"
|
||||
|
||||
class LibraryZone : public CardZone {
|
||||
private:
|
||||
public:
|
||||
LibraryZone(Player *_p, QGraphicsItem *parent = 0);
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
void reorganizeCards();
|
||||
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void addCardImpl(CardItem *card, int x, int y);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,160 +1,168 @@
|
|||
#include "messagelogwidget.h"
|
||||
#include "game.h"
|
||||
#include <QScrollBar>
|
||||
#include "player.h"
|
||||
|
||||
QString MessageLogWidget::sanitizeHtml(QString dirty)
|
||||
{
|
||||
return dirty
|
||||
.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">");
|
||||
}
|
||||
|
||||
void MessageLogWidget::logConnecting(QString hostname)
|
||||
{
|
||||
appendPlainText(tr("Connecting to %1...").arg(hostname));
|
||||
append(tr("Connecting to %1...").arg(sanitizeHtml(hostname)));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logConnected(const QStringList WelcomeMsg)
|
||||
{
|
||||
appendPlainText(tr("Connected."));
|
||||
append(tr("Connected."));
|
||||
|
||||
QStringListIterator i(WelcomeMsg);
|
||||
while (i.hasNext())
|
||||
appendPlainText(i.next());
|
||||
append(i.next());
|
||||
}
|
||||
|
||||
void MessageLogWidget::logDisconnected()
|
||||
{
|
||||
appendPlainText(tr("Disconnected from server."));
|
||||
append(tr("Disconnected from server."));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSocketError(const QString &errorString)
|
||||
{
|
||||
appendPlainText(errorString);
|
||||
append(sanitizeHtml(errorString));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logServerError(ServerResponse response)
|
||||
{
|
||||
switch (response) {
|
||||
case RespPassword: appendPlainText(tr("Invalid password.")); break;
|
||||
case RespPassword: append(tr("Invalid password.")); break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
void MessageLogWidget::logPlayerListReceived(QStringList players)
|
||||
{
|
||||
appendPlainText("---");
|
||||
appendPlainText(tr("You have joined the game. Player list:"));
|
||||
append("---");
|
||||
append(tr("You have joined the game. Player list:"));
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
appendPlainText(players.at(i));
|
||||
appendPlainText("---");
|
||||
append(sanitizeHtml(players.at(i)));
|
||||
append("---");
|
||||
}
|
||||
|
||||
void MessageLogWidget::logJoin(QString playerName)
|
||||
void MessageLogWidget::logJoin(Player *player)
|
||||
{
|
||||
appendPlainText(tr("%1 has joined the game").arg(playerName));
|
||||
append(tr("%1 has joined the game").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logLeave(QString playerName)
|
||||
void MessageLogWidget::logLeave(Player *player)
|
||||
{
|
||||
appendPlainText(tr("%1 has left the game").arg(playerName));
|
||||
append(tr("%1 has left the game").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logReadyStart(QString playerName)
|
||||
void MessageLogWidget::logReadyStart(Player *player)
|
||||
{
|
||||
appendPlainText(tr("%1 is ready to start a new game.").arg(playerName));
|
||||
append(tr("%1 is ready to start a new game.").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logGameStart()
|
||||
{
|
||||
appendPlainText(tr("Game has started."));
|
||||
append(tr("Game has started."));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSay(QString playerName, QString message)
|
||||
void MessageLogWidget::logSay(Player *player, QString message)
|
||||
{
|
||||
appendHtml(QString("<font color=\"red\">%1:</font> %2").arg(playerName).arg(message));
|
||||
append(QString("<font color=\"red\">%1:</font> %2").arg(sanitizeHtml(player->getName())).arg(sanitizeHtml(message)));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logShuffle(QString playerName)
|
||||
void MessageLogWidget::logShuffle(Player *player)
|
||||
{
|
||||
appendPlainText(tr("%1 shuffles his/her library").arg(playerName));
|
||||
append(tr("%1 shuffles his/her library").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logRollDice(QString playerName, int sides, int roll)
|
||||
void MessageLogWidget::logRollDice(Player *player, int sides, int roll)
|
||||
{
|
||||
appendPlainText(tr("%1 rolled a %2 with a %3-sided dice").arg(playerName).arg(roll).arg(sides));
|
||||
append(tr("%1 rolled a %2 with a %3-sided dice").arg(sanitizeHtml(player->getName())).arg(roll).arg(sides));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logDraw(QString playerName, int number)
|
||||
void MessageLogWidget::logDraw(Player *player, int number)
|
||||
{
|
||||
if (number == 1)
|
||||
appendPlainText(tr("%1 draws a card").arg(playerName));
|
||||
append(tr("%1 draws a card").arg(sanitizeHtml(player->getName())));
|
||||
else
|
||||
appendPlainText(tr("%1 draws %2 cards").arg(playerName).arg(number));
|
||||
append(tr("%1 draws %2 cards").arg(sanitizeHtml(player->getName())).arg(number));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logMoveCard(QString playerName, QString cardName, QString startZone, QString targetZone)
|
||||
void MessageLogWidget::logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone)
|
||||
{
|
||||
appendPlainText(tr("%1 moves %2 from %3 to %4").arg(playerName).arg(cardName).arg(startZone).arg(targetZone));
|
||||
append(tr("%1 moves <font color=\"blue\">%2</font> from %3 to %4").arg(sanitizeHtml(player->getName())).arg(cardName).arg(startZone).arg(targetZone));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logCreateToken(QString playerName, QString cardName)
|
||||
void MessageLogWidget::logCreateToken(Player *player, QString cardName)
|
||||
{
|
||||
appendPlainText(tr("%1 creates token: %2").arg(playerName).arg(cardName));
|
||||
append(tr("%1 creates token: <font color=\"blue\">%2</font>").arg(sanitizeHtml(player->getName())).arg(cardName));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetCardCounters(QString playerName, QString cardName, int value, int oldValue)
|
||||
void MessageLogWidget::logSetCardCounters(Player *player, QString cardName, int value, int oldValue)
|
||||
{
|
||||
if (value > oldValue)
|
||||
appendPlainText(tr("%1 places %2 counters on %3 (now %4)").arg(playerName).arg(value - oldValue).arg(cardName).arg(value));
|
||||
append(tr("%1 places %2 counters on <font color=\"blue\">%3</font> (now %4)").arg(sanitizeHtml(player->getName())).arg(value - oldValue).arg(cardName).arg(value));
|
||||
else
|
||||
appendPlainText(tr("%1 removes %2 counters from %3 (now %4)").arg(playerName).arg(oldValue - value).arg(cardName).arg(value));
|
||||
append(tr("%1 removes %2 counters from <font color=\"blue\">%3</font> (now %4)").arg(sanitizeHtml(player->getName())).arg(oldValue - value).arg(cardName).arg(value));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetTapped(QString playerName, QString cardName, bool tapped)
|
||||
void MessageLogWidget::logSetTapped(Player *player, QString cardName, bool tapped)
|
||||
{
|
||||
if (cardName == "-1")
|
||||
cardName = tr("his permanents");
|
||||
appendPlainText(tr("%1 %2 %3").arg(playerName).arg(tapped ? "taps" : "untaps").arg(cardName));
|
||||
append(tr("%1 %2 <font color=\"blue\">%3</blue>").arg(sanitizeHtml(player->getName())).arg(tapped ? "taps" : "untaps").arg(cardName));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetCounter(QString playerName, QString counterName, int value, int oldValue)
|
||||
void MessageLogWidget::logSetCounter(Player *player, QString counterName, int value, int oldValue)
|
||||
{
|
||||
appendPlainText(tr("%1 sets counter \"%2\" to %3 (%4%5)").arg(playerName).arg(counterName).arg(value).arg(value > oldValue ? "+" : "").arg(value - oldValue));
|
||||
append(tr("%1 sets counter \"%2\" to %3 (%4%5)").arg(sanitizeHtml(player->getName())).arg(counterName).arg(value).arg(value > oldValue ? "+" : "").arg(value - oldValue));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetDoesntUntap(QString playerName, QString cardName, bool doesntUntap)
|
||||
void MessageLogWidget::logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap)
|
||||
{
|
||||
if (doesntUntap)
|
||||
appendPlainText(tr("%1 sets %2 to not untap normally.").arg(playerName).arg(cardName));
|
||||
append(tr("%1 sets <font color=\"blue\">%2</font> to not untap normally.").arg(sanitizeHtml(player->getName())).arg(cardName));
|
||||
else
|
||||
appendPlainText(tr("%1 sets %2 to untap normally.").arg(playerName).arg(cardName));
|
||||
append(tr("%1 sets <font color=\"blue\">%2</font> to untap normally.").arg(sanitizeHtml(player->getName())).arg(cardName));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logDumpZone(QString playerName, QString zoneName, QString zoneOwner, int numberCards)
|
||||
void MessageLogWidget::logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards)
|
||||
{
|
||||
if (numberCards)
|
||||
appendPlainText(tr("%1 is looking at the top %2 cards of %3's %4").arg(playerName).arg(numberCards).arg(zoneOwner).arg(zoneName));
|
||||
append(tr("%1 is looking at the top %2 cards of %3's %4").arg(sanitizeHtml(player->getName())).arg(numberCards).arg(zoneOwner).arg(zoneName));
|
||||
else
|
||||
appendPlainText(tr("%1 is looking at %2's %3").arg(playerName).arg(zoneOwner).arg(zoneName));
|
||||
append(tr("%1 is looking at %2's %3").arg(sanitizeHtml(player->getName())).arg(zoneOwner).arg(zoneName));
|
||||
}
|
||||
|
||||
|
||||
void MessageLogWidget::connectToGame(Game *game)
|
||||
{
|
||||
connect(game, SIGNAL(logPlayerListReceived(QStringList)), this, SLOT(logPlayerListReceived(QStringList)));
|
||||
connect(game, SIGNAL(logJoin(QString)), this, SLOT(logJoin(QString)));
|
||||
connect(game, SIGNAL(logLeave(QString)), this, SLOT(logLeave(QString)));
|
||||
connect(game, SIGNAL(logReadyStart(QString)), this, SLOT(logReadyStart(QString)));
|
||||
connect(game, SIGNAL(logJoin(Player *)), this, SLOT(logJoin(Player *)));
|
||||
connect(game, SIGNAL(logLeave(Player *)), this, SLOT(logLeave(Player *)));
|
||||
connect(game, SIGNAL(logReadyStart(Player *)), this, SLOT(logReadyStart(Player *)));
|
||||
connect(game, SIGNAL(logGameStart()), this, SLOT(logGameStart()));
|
||||
connect(game, SIGNAL(logSay(QString, QString)), this, SLOT(logSay(QString, QString)));
|
||||
connect(game, SIGNAL(logShuffle(QString)), this, SLOT(logShuffle(QString)));
|
||||
connect(game, SIGNAL(logRollDice(QString, int, int)), this, SLOT(logRollDice(QString, int, int)));
|
||||
connect(game, SIGNAL(logDraw(QString, int)), this, SLOT(logDraw(QString, int)));
|
||||
connect(game, SIGNAL(logMoveCard(QString, QString, QString, QString)), this, SLOT(logMoveCard(QString, QString, QString, QString)));
|
||||
connect(game, SIGNAL(logCreateToken(QString, QString)), this, SLOT(logCreateToken(QString, QString)));
|
||||
connect(game, SIGNAL(logSetCardCounters(QString, QString, int, int)), this, SLOT(logSetCardCounters(QString, QString, int, int)));
|
||||
connect(game, SIGNAL(logSetTapped(QString, QString, bool)), this, SLOT(logSetTapped(QString, QString, bool)));
|
||||
connect(game, SIGNAL(logSetCounter(QString, QString, int, int)), this, SLOT(logSetCounter(QString, QString, int, int)));
|
||||
connect(game, SIGNAL(logSetDoesntUntap(QString, QString, bool)), this, SLOT(logSetDoesntUntap(QString, QString, bool)));
|
||||
connect(game, SIGNAL(logDumpZone(QString, QString, QString, int)), this, SLOT(logDumpZone(QString, QString, QString, int)));
|
||||
connect(game, SIGNAL(logSay(Player *, QString)), this, SLOT(logSay(Player *, QString)));
|
||||
connect(game, SIGNAL(logShuffle(Player *)), this, SLOT(logShuffle(Player *)));
|
||||
connect(game, SIGNAL(logRollDice(Player *, int, int)), this, SLOT(logRollDice(Player *, int, int)));
|
||||
connect(game, SIGNAL(logDraw(Player *, int)), this, SLOT(logDraw(Player *, int)));
|
||||
connect(game, SIGNAL(logMoveCard(Player *, QString, QString, QString)), this, SLOT(logMoveCard(Player *, QString, QString, QString)));
|
||||
connect(game, SIGNAL(logCreateToken(Player *, QString)), this, SLOT(logCreateToken(Player *, QString)));
|
||||
connect(game, SIGNAL(logSetCardCounters(Player *, QString, int, int)), this, SLOT(logSetCardCounters(Player *, QString, int, int)));
|
||||
connect(game, SIGNAL(logSetTapped(Player *, QString, bool)), this, SLOT(logSetTapped(Player *, QString, bool)));
|
||||
connect(game, SIGNAL(logSetCounter(Player *, QString, int, int)), this, SLOT(logSetCounter(Player *, QString, int, int)));
|
||||
connect(game, SIGNAL(logSetDoesntUntap(Player *, QString, bool)), this, SLOT(logSetDoesntUntap(Player *, QString, bool)));
|
||||
connect(game, SIGNAL(logDumpZone(Player *, QString, QString, int)), this, SLOT(logDumpZone(Player *, QString, QString, int)));
|
||||
}
|
||||
|
||||
MessageLogWidget::MessageLogWidget(QWidget *parent)
|
||||
: QPlainTextEdit(parent)
|
||||
: QTextEdit(parent)
|
||||
{
|
||||
setReadOnly(true);
|
||||
QFont f;
|
||||
|
|
|
@ -6,9 +6,12 @@
|
|||
#include "client.h"
|
||||
|
||||
class Game;
|
||||
class Player;
|
||||
|
||||
class MessageLogWidget : public QPlainTextEdit {
|
||||
class MessageLogWidget : public QTextEdit {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString sanitizeHtml(QString dirty);
|
||||
public slots:
|
||||
void logConnecting(QString hostname);
|
||||
void logConnected(const QStringList WelcomeMsg);
|
||||
|
@ -17,21 +20,21 @@ public slots:
|
|||
void logServerError(ServerResponse response);
|
||||
private slots:
|
||||
void logPlayerListReceived(QStringList players);
|
||||
void logJoin(QString playerName);
|
||||
void logLeave(QString playerName);
|
||||
void logReadyStart(QString playerName);
|
||||
void logJoin(Player *player);
|
||||
void logLeave(Player *player);
|
||||
void logReadyStart(Player *player);
|
||||
void logGameStart();
|
||||
void logSay(QString playerName, QString message);
|
||||
void logShuffle(QString playerName);
|
||||
void logRollDice(QString playerName, int sides, int roll);
|
||||
void logDraw(QString playerName, int number);
|
||||
void logMoveCard(QString playerName, QString cardName, QString startZone, QString targetZone);
|
||||
void logCreateToken(QString playerName, QString cardName);
|
||||
void logSetCardCounters(QString playerName, QString cardName, int value, int oldValue);
|
||||
void logSetTapped(QString playerName, QString cardName, bool tapped);
|
||||
void logSetCounter(QString playerName, QString counterName, int value, int oldValue);
|
||||
void logSetDoesntUntap(QString playerName, QString cardName, bool doesntUntap);
|
||||
void logDumpZone(QString playerName, QString zoneName, QString zoneOwner, int numberCards);
|
||||
void logSay(Player *player, QString message);
|
||||
void logShuffle(Player *player);
|
||||
void logRollDice(Player *player, int sides, int roll);
|
||||
void logDraw(Player *player, int number);
|
||||
void logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone);
|
||||
void logCreateToken(Player *player, QString cardName);
|
||||
void logSetCardCounters(Player *player, QString cardName, int value, int oldValue);
|
||||
void logSetTapped(Player *player, QString cardName, bool tapped);
|
||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
||||
void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards);
|
||||
public:
|
||||
void connectToGame(Game *game);
|
||||
MessageLogWidget(QWidget *parent = 0);
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
#include <QtGui>
|
||||
#include "pilezone.h"
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
#include "client.h"
|
||||
#include "carddragitem.h"
|
||||
#include "zoneviewzone.h"
|
||||
|
||||
PileZone::PileZone(Player *_p, const QString &_name, QGraphicsItem *parent)
|
||||
: CardZone(_p, _name, false, false, parent)
|
||||
PileZone::PileZone(Player *_p, const QString &_name, bool _contentsKnown, QGraphicsItem *parent)
|
||||
: CardZone(_p, _name, false, false, _contentsKnown, parent)
|
||||
{
|
||||
cards = new CardList(true);
|
||||
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
||||
setAcceptsHoverEvents(true);
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
||||
|
@ -21,20 +22,24 @@ QRectF PileZone::boundingRect() const
|
|||
void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
qDebug("PileZone::paint");
|
||||
if (!cards->isEmpty()) {
|
||||
if (!cards.isEmpty()) {
|
||||
painter->save();
|
||||
cards->at(0)->paint(painter, option, widget);
|
||||
cards.at(0)->paint(painter, option, widget);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
paintNumberEllipse(cards->size(), painter);
|
||||
paintNumberEllipse(cards.size(), painter);
|
||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||
}
|
||||
|
||||
void PileZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||
{
|
||||
cards->insert(x, card);
|
||||
cards.insert(x, card);
|
||||
card->setPos(0, 0);
|
||||
if (!contentsKnown()) {
|
||||
card->setName(QString());
|
||||
card->setId(-1);
|
||||
}
|
||||
card->setVisible(false);
|
||||
card->resetState();
|
||||
card->setParentItem(this);
|
||||
|
@ -69,12 +74,13 @@ void PileZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|||
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < QApplication::startDragDistance())
|
||||
return;
|
||||
|
||||
if (cards->empty())
|
||||
if (cards.isEmpty())
|
||||
return;
|
||||
|
||||
bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier);
|
||||
CardItem *card = cards->at(0);
|
||||
CardDragItem *drag = card->createDragItem(card->getId(), event->pos(), event->scenePos(), faceDown);
|
||||
CardItem *card = cards.at(0);
|
||||
const int cardid = contentsKnown() ? card->getId() : 0;
|
||||
CardDragItem *drag = card->createDragItem(cardid, event->pos(), event->scenePos(), faceDown);
|
||||
drag->grabMouse();
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
@ -83,3 +89,10 @@ void PileZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
|
|||
{
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
}
|
||||
|
||||
void PileZone::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (!cards.isEmpty())
|
||||
((Game *) player->parent())->hoverCardEvent(cards.at(0));
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
#include "cardzone.h"
|
||||
|
||||
class PileZone : public CardZone {
|
||||
private:
|
||||
public:
|
||||
PileZone(Player *_p, const QString &_name, QGraphicsItem *parent = 0);
|
||||
PileZone(Player *_p, const QString &_name, bool _contentsKnown, QGraphicsItem *parent = 0);
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
void reorganizeCards();
|
||||
|
@ -15,6 +14,7 @@ protected:
|
|||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void addCardImpl(CardItem *card, int x, int y);
|
||||
};
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ void Player::setCardAttrHelper(CardItem *card, const QString &aname, const QStri
|
|||
bool tapped = avalue == "1";
|
||||
if (!(!tapped && card->getDoesntUntap() && allCards)) {
|
||||
if (!allCards)
|
||||
emit logSetTapped(name, card->getName(), tapped);
|
||||
emit logSetTapped(this, card->getName(), tapped);
|
||||
card->setTapped(tapped);
|
||||
}
|
||||
} else if (aname == "attacking")
|
||||
|
@ -134,13 +134,13 @@ void Player::setCardAttrHelper(CardItem *card, const QString &aname, const QStri
|
|||
card->setFaceDown(avalue == "1");
|
||||
else if (aname == "counters") {
|
||||
int value = avalue.toInt();
|
||||
emit logSetCardCounters(name, card->getName(), value, card->getCounters());
|
||||
emit logSetCardCounters(this, card->getName(), value, card->getCounters());
|
||||
card->setCounters(value);
|
||||
} else if (aname == "annotation")
|
||||
card->setAnnotation(avalue);
|
||||
else if (aname == "doesnt_untap") {
|
||||
bool value = (avalue == "1");
|
||||
emit logSetDoesntUntap(name, card->getName(), value);
|
||||
emit logSetDoesntUntap(this, card->getName(), value);
|
||||
card->setDoesntUntap(value);
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ void Player::gameEvent(const ServerEventData &event)
|
|||
|
||||
// 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.
|
||||
emit logMoveCard(name, card->getName(), startZone->getName(), targetZone->getName());
|
||||
emit logMoveCard(this, card->getName(), startZone->getName(), targetZone->getName());
|
||||
|
||||
targetZone->addCard(card, true, x, y);
|
||||
|
||||
|
@ -250,7 +250,7 @@ void Player::gameEvent(const ServerEventData &event)
|
|||
|
||||
CardItem *card = new CardItem(db, cardname, cardid);
|
||||
|
||||
emit logCreateToken(name, card->getName());
|
||||
emit logCreateToken(this, card->getName());
|
||||
zone->addCard(card, true, x, y);
|
||||
|
||||
break;
|
||||
|
@ -266,11 +266,11 @@ void Player::gameEvent(const ServerEventData &event)
|
|||
// XXX Fehlerbehandlung
|
||||
|
||||
if (cardId == -1) {
|
||||
CardList *const cards = zone->getCards();
|
||||
for (int i = 0; i < cards->size(); i++)
|
||||
setCardAttrHelper(cards->at(i), aname, avalue, true);
|
||||
const CardList &cards = zone->getCards();
|
||||
for (int i = 0; i < cards.size(); i++)
|
||||
setCardAttrHelper(cards.at(i), aname, avalue, true);
|
||||
if (aname == "tapped")
|
||||
emit logSetTapped(name, QString("-1"), avalue == "1");
|
||||
emit logSetTapped(this, QString("-1"), avalue == "1");
|
||||
} else {
|
||||
CardItem *card = zone->getCard(cardId, "");
|
||||
setCardAttrHelper(card, aname, avalue, false);
|
||||
|
@ -297,7 +297,7 @@ void Player::gameEvent(const ServerEventData &event)
|
|||
Counter *c = area->getCounter(counterName);
|
||||
int oldValue = c->getValue();
|
||||
c->setValue(value);
|
||||
emit logSetCounter(name, c->getName(), value, oldValue);
|
||||
emit logSetCounter(this, c->getName(), value, oldValue);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -305,11 +305,6 @@ void Player::gameEvent(const ServerEventData &event)
|
|||
}
|
||||
}
|
||||
|
||||
void Player::hoverCardEvent(CardItem *card)
|
||||
{
|
||||
emit hoverCard(card->getName());
|
||||
}
|
||||
|
||||
void Player::showCardMenu(const QPoint &p)
|
||||
{
|
||||
emit sigShowCardMenu(p);
|
||||
|
|
|
@ -23,12 +23,12 @@ signals:
|
|||
void toggleZoneView(Player *player, QString zoneName, int number);
|
||||
void sigShowCardMenu(QPoint p);
|
||||
// Log events
|
||||
void logMoveCard(QString playerName, QString cardName, QString startZone, QString targetZone);
|
||||
void logCreateToken(QString playerName, QString cardName);
|
||||
void logSetCardCounters(QString playerName, QString cardName, int value, int oldValue);
|
||||
void logSetTapped(QString playerName, QString cardName, bool tapped);
|
||||
void logSetCounter(QString playerName, QString counterName, int value, int oldValue);
|
||||
void logSetDoesntUntap(QString playerName, QString cardName, bool doesntUntap);
|
||||
void logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone);
|
||||
void logCreateToken(Player *player, QString cardName);
|
||||
void logSetCardCounters(Player *player, QString cardName, int value, int oldValue);
|
||||
void logSetTapped(Player *player, QString cardName, bool tapped);
|
||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
||||
private slots:
|
||||
void actMoveHandToTopLibrary();
|
||||
void actMoveHandToBottomLibrary();
|
||||
|
@ -66,7 +66,6 @@ public:
|
|||
bool getLocal() const { return local; }
|
||||
const ZoneList *getZones() const { return &zones; }
|
||||
void gameEvent(const ServerEventData &event);
|
||||
void hoverCardEvent(CardItem *card);
|
||||
CardDatabase *getDb() const { return db; }
|
||||
void showCardMenu(const QPoint &p);
|
||||
};
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "player.h"
|
||||
#include "tablezone.h"
|
||||
#include "handzone.h"
|
||||
#include "libraryzone.h"
|
||||
#include "pilezone.h"
|
||||
#include "counter.h"
|
||||
#include <QPainter>
|
||||
|
@ -10,20 +9,22 @@
|
|||
PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), player(_player)
|
||||
{
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
|
||||
QPointF base = QPointF(55, 50);
|
||||
|
||||
LibraryZone *deck = new LibraryZone(_player, this);
|
||||
PileZone *deck = new PileZone(_player, "deck", false, this);
|
||||
deck->setPos(base);
|
||||
|
||||
qreal h = deck->boundingRect().height() + 20;
|
||||
|
||||
PileZone *grave = new PileZone(_player, "grave", this);
|
||||
PileZone *grave = new PileZone(_player, "grave", true, this);
|
||||
grave->setPos(base + QPointF(0, h));
|
||||
|
||||
PileZone *rfg = new PileZone(_player, "rfg", this);
|
||||
PileZone *rfg = new PileZone(_player, "rfg", true, this);
|
||||
rfg->setPos(base + QPointF(0, 2 * h));
|
||||
|
||||
PileZone *sb = new PileZone(_player, "sb", this);
|
||||
PileZone *sb = new PileZone(_player, "sb", true, this);
|
||||
sb->setVisible(false);
|
||||
|
||||
base = QPointF(deck->boundingRect().width() + 60, 0);
|
||||
|
|
|
@ -4,10 +4,8 @@
|
|||
#include "client.h"
|
||||
|
||||
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
||||
: CardZone(_p, "table", true, false, parent), width(864), height(578)
|
||||
: CardZone(_p, "table", true, false, true, parent), width(864), height(578)
|
||||
{
|
||||
cards = new CardList(true);
|
||||
|
||||
gridPoints << (QList<QPoint>() << QPoint(8, 12)
|
||||
<< QPoint(9, 13)
|
||||
<< QPoint(10, 14)
|
||||
|
@ -68,7 +66,7 @@ void TableZone::addCardImpl(CardItem *card, int _x, int _y)
|
|||
qreal x = mapPoint.x();
|
||||
qreal y = mapPoint.y();
|
||||
|
||||
cards->append(card);
|
||||
cards.append(card);
|
||||
// if ((x != -1) && (y != -1)) {
|
||||
if (!player->getLocal())
|
||||
y = height - CARD_HEIGHT - y;
|
||||
|
@ -108,9 +106,9 @@ void TableZone::toggleTapped()
|
|||
|
||||
CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
|
||||
{
|
||||
for (int i = 0; i < cards->size(); i++)
|
||||
if (cards->at(i)->getGridPoint() == gridPoint)
|
||||
return cards->at(i);
|
||||
for (int i = 0; i < cards.size(); i++)
|
||||
if (cards.at(i)->getGridPoint() == gridPoint)
|
||||
return cards.at(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
#include "client.h"
|
||||
|
||||
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent)
|
||||
: CardZone(_p, _origZone->getName(), false, false, parent, true), height(0), numberCards(_numberCards), origZone(_origZone)
|
||||
: CardZone(_p, _origZone->getName(), false, false, true, parent, true), height(0), numberCards(_numberCards), origZone(_origZone)
|
||||
{
|
||||
cards = new CardList(true);
|
||||
origZone->setView(this);
|
||||
}
|
||||
|
||||
|
@ -30,10 +29,10 @@ bool ZoneViewZone::initializeCards()
|
|||
if (!origZone->contentsKnown())
|
||||
return false;
|
||||
|
||||
CardList *const c = origZone->getCards();
|
||||
int number = numberCards == 0 ? c->size() : (numberCards < c->size() ? numberCards : c->size());
|
||||
const CardList &c = origZone->getCards();
|
||||
int number = numberCards == 0 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
|
||||
for (int i = 0; i < number; i++) {
|
||||
CardItem *card = c->at(i);
|
||||
CardItem *card = c.at(i);
|
||||
addCard(new CardItem(player->getDb(), card->getName(), card->getId(), this), false, i);
|
||||
}
|
||||
reorganizeCards();
|
||||
|
@ -45,19 +44,19 @@ void ZoneViewZone::reorganizeCards()
|
|||
{
|
||||
qDebug("reorganizeCards");
|
||||
|
||||
if (cards->isEmpty())
|
||||
if (cards.isEmpty())
|
||||
return;
|
||||
|
||||
int cardCount = cards->size();
|
||||
int cardCount = cards.size();
|
||||
qreal totalWidth = boundingRect().width();
|
||||
qreal totalHeight = boundingRect().height();
|
||||
qreal cardWidth = cards->at(0)->boundingRect().width();
|
||||
qreal cardHeight = cards->at(0)->boundingRect().height();
|
||||
qreal cardWidth = cards.at(0)->boundingRect().width();
|
||||
qreal cardHeight = cards.at(0)->boundingRect().height();
|
||||
qreal x1 = 0;
|
||||
qreal x2 = (totalWidth - cardWidth);
|
||||
|
||||
for (int i = 0; i < cardCount; i++) {
|
||||
CardItem *c = cards->at(i);
|
||||
CardItem *c = cards.at(i);
|
||||
qreal x = i % 2 ? x2 : x1;
|
||||
// If the total height of the cards is smaller than the available height,
|
||||
// the cards do not need to overlap and are displayed in the center of the area.
|
||||
|
@ -73,7 +72,7 @@ void ZoneViewZone::reorganizeCards()
|
|||
|
||||
void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||
{
|
||||
cards->insert(x, card);
|
||||
cards.insert(x, card);
|
||||
card->setParentItem(this);
|
||||
card->update();
|
||||
}
|
||||
|
@ -86,10 +85,10 @@ void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint
|
|||
|
||||
void ZoneViewZone::removeCard(int position)
|
||||
{
|
||||
if (position >= cards->size())
|
||||
if (position >= cards.size())
|
||||
return;
|
||||
|
||||
CardItem *card = cards->takeAt(position);
|
||||
CardItem *card = cards.takeAt(position);
|
||||
delete card;
|
||||
reorganizeCards();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue