Merge ssh://cockatrice.git.sourceforge.net/gitroot/cockatrice

This commit is contained in:
Max-Wilhelm Bruker 2009-07-01 16:27:40 +02:00
commit 7023b95db0
19 changed files with 157 additions and 36 deletions

View file

@ -70,7 +70,7 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
void CardItem::setName(const QString &_name)
{
name = _name;
update(boundingRect());
update();
}
void CardItem::setTapped(bool _tapped)
@ -80,31 +80,31 @@ void CardItem::setTapped(bool _tapped)
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
else
setTransform(QTransform());
update(boundingRect());
update();
}
void CardItem::setAttacking(bool _attacking)
{
attacking = _attacking;
update(boundingRect());
update();
}
void CardItem::setFaceDown(bool _facedown)
{
facedown = _facedown;
update(boundingRect());
update();
}
void CardItem::setCounters(int _counters)
{
counters = _counters;
update(boundingRect());
update();
}
void CardItem::setAnnotation(const QString &_annotation)
{
annotation = _annotation;
update(boundingRect());
update();
}
void CardItem::setDoesntUntap(bool _doesntUntap)
@ -120,7 +120,7 @@ void CardItem::resetState()
annotation = QString();
setTapped(false);
setDoesntUntap(false);
update(boundingRect());
update();
}
CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown)
@ -215,7 +215,7 @@ QVariant CardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QV
return value;
} else if (change == ItemSelectedHasChanged) {
qDebug("selection changed");
update(boundingRect());
update();
return value;
} else
return QGraphicsItem::itemChange(change, value);

View file

@ -1,4 +1,5 @@
#include "cardlist.h"
#include "carditem.h"
CardList::CardList(bool _contentsKnown)
: QList<CardItem *>(), contentsKnown(_contentsKnown)

View file

@ -1,9 +1,10 @@
#ifndef CARDLIST_H
#define CARDLIST_H
#include "carditem.h"
#include <QList>
class CardItem;
class CardList : public QList<CardItem *> {
protected:
bool contentsKnown;

View file

@ -6,7 +6,7 @@
#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), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable)
: AbstractGraphicsItem(parent), player(_p), name(_name), cards(NULL), view(NULL), menu(NULL), doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable)
{
if (!isView)
player->addZone(this);
@ -27,7 +27,7 @@ void CardZone::clearContents()
cards->clear();
}
void CardZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
void CardZone::mouseDoubleClickEvent(QGraphicsSceneMouseEvent */*event*/)
{
if (doubleClickAction)
doubleClickAction->trigger();
@ -71,8 +71,7 @@ CardItem *CardZone::getCard(int cardId, const QString &cardName)
CardItem *CardZone::takeCard(int position, int cardId, const QString &cardName)
{
if (position >= cards->size())
return NULL;
Q_ASSERT(position < cards->size());
CardItem *c = cards->takeAt(position);

View file

@ -3,6 +3,7 @@
#include <QString>
#include "cardlist.h"
#include "carditem.h"
#include "abstractgraphicsitem.h"
class Player;

View file

@ -26,7 +26,7 @@ void Counter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*
void Counter::setValue(int _value)
{
value = _value;
update(boundingRect());
update();
}
void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event)

View file

@ -144,7 +144,7 @@ void Game::initSayMenu()
Player *Game::addPlayer(int playerId, const QString &playerName, QPointF base, bool local)
{
Player *newPlayer = new Player(playerName, playerId, base, local, db, client, scene);
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)));
@ -346,7 +346,8 @@ void Game::actTap()
QListIterator<QGraphicsItem *> i(scene->selectedItems());
while (i.hasNext()) {
CardItem *temp = (CardItem *) i.next();
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "tapped", "1");
if (!temp->getTapped())
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "tapped", "1");
}
}
@ -355,7 +356,8 @@ void Game::actUntap()
QListIterator<QGraphicsItem *> i(scene->selectedItems());
while (i.hasNext()) {
CardItem *temp = (CardItem *) i.next();
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "tapped", "0");
if (temp->getTapped())
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "tapped", "0");
}
}

View file

@ -40,8 +40,6 @@ private slots:
void actEditMessages();
void showCardMenu(QPoint p);
void actTap();
void actUntap();
void actDoesntUntap();
void actFlip();
void actAddCounter();
@ -54,6 +52,9 @@ private slots:
void gameEvent(const ServerEventData &msg);
void playerListReceived(QList<ServerPlayer *> playerList);
void readyStart();
public slots:
void actTap();
void actUntap();
signals:
void submitDecklist();
void hoverCard(QString name);

View file

@ -59,7 +59,7 @@ void HandZone::addCardImpl(CardItem *card, int x, int /*y*/)
card->setParentItem(this);
card->resetState();
card->setVisible(true);
card->update(card->boundingRect());
card->update();
}
void HandZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)

View file

@ -50,7 +50,7 @@ void LibraryZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint
void LibraryZone::reorganizeCards()
{
update(boundingRect());
update();
}
void LibraryZone::mousePressEvent(QGraphicsSceneMouseEvent *event)

View file

@ -20,6 +20,7 @@ QRectF PileZone::boundingRect() const
void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
qDebug("PileZone::paint");
if (!cards->isEmpty()) {
painter->save();
cards->at(0)->paint(painter, option, widget);
@ -47,7 +48,7 @@ void PileZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*
void PileZone::reorganizeCards()
{
qDebug(QString("PileZone: reorganize, x=%1, y=%2, w=%3, h=%4").arg(boundingRect().x()).arg(boundingRect().y()).arg(boundingRect().width()).arg(boundingRect().height()).toLatin1());
update(boundingRect());
update();
}
void PileZone::mousePressEvent(QGraphicsSceneMouseEvent *event)

View file

@ -4,11 +4,12 @@
#include "playerarea.h"
#include "counter.h"
#include "zoneviewzone.h"
#include "game.h"
#include <QGraphicsScene>
#include <QMenu>
Player::Player(const QString &_name, int _id, QPointF _base, bool _local, CardDatabase *_db, Client *_client, QGraphicsScene *_scene)
: QObject(), defaultNumberTopCards(3), name(_name), id(_id), base(_base), local(_local), db(_db), client(_client)
Player::Player(const QString &_name, int _id, QPointF _base, bool _local, CardDatabase *_db, Client *_client, QGraphicsScene *_scene, Game *_parent)
: QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), base(_base), local(_local), db(_db), client(_client)
{
area = new PlayerArea(this);
area->setPos(_base);

View file

@ -12,6 +12,7 @@ class QMenu;
class QAction;
class PlayerArea;
class ZoneViewZone;
class Game;
class Player : public QObject {
Q_OBJECT
@ -57,7 +58,7 @@ public:
PlayerArea *area;
Client *client;
void addZone(CardZone *z);
Player(const QString &_name, int _id, QPointF _base, bool _local, CardDatabase *_db, Client *_client, QGraphicsScene *_scene);
Player(const QString &_name, int _id, QPointF _base, bool _local, CardDatabase *_db, Client *_client, QGraphicsScene *_scene, Game *_parent);
~Player();
QMenu *getPlayerMenu() const { return playerMenu; }
int getId() const { return id; }

View file

@ -31,7 +31,7 @@ void TableZone::addCardImpl(CardItem *card, int x, int y)
qDebug(QString("table: appended %1 at pos %2: zValue = %3, x = %4, y = %5").arg(card->getName()).arg(cards->size() - 1).arg(card->zValue()).arg(x).arg(y).toLatin1());
card->setParentItem(this);
card->setVisible(true);
card->update(card->boundingRect());
card->update();
}
void TableZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
@ -55,9 +55,15 @@ void TableZone::reorganizeCards()
void TableZone::toggleTapped()
{
QListIterator<QGraphicsItem *> i(scene()->selectedItems());
while (i.hasNext()) {
CardItem *temp = (CardItem *) i.next();
setCardAttr(temp->getId(), "tapped", temp->getTapped() ? "0" : "1");
QList<QGraphicsItem *> selectedItems = scene()->selectedItems();
bool tapAll = false;
for (int i = 0; i < selectedItems.size(); i++)
if (!qgraphicsitem_cast<CardItem *>(selectedItems[i])->getTapped()) {
tapAll = true;
break;
}
for (int i = 0; i < selectedItems.size(); i++) {
CardItem *temp = qgraphicsitem_cast<CardItem *>(selectedItems[i]);
setCardAttr(temp->getId(), "tapped", (!temp->getTapped() || tapAll) ? "1" : "0");
}
}

View file

@ -52,7 +52,6 @@ void ZoneViewLayout::removeItem(ZoneViewWidget *item)
{
qDebug("ZoneViewLayout::removeItem");
views.removeAt(views.indexOf(item));
scene()->removeItem(item);
reorganize();
}

View file

@ -75,7 +75,7 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
{
cards->insert(x, card);
card->setParentItem(this);
card->update(card->boundingRect());
card->update();
}
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
@ -89,8 +89,7 @@ void ZoneViewZone::removeCard(int position)
if (position >= cards->size())
return;
CardItem *card = cards->at(position);
cards->removeAt(position);
CardItem *card = cards->takeAt(position);
delete card;
reorganizeCards();
}