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

minor changes, implemented 'doesn't untap' and facedown cards

parent e6d61624
......@@ -26,6 +26,7 @@ signals:
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);
private slots:
void actMoveHandToTopLibrary();
void actMoveHandToBottomLibrary();
......@@ -53,6 +54,7 @@ private:
ZoneList zones;
CounterList counters;
CardDatabase *db;
void setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards);
public:
Client *client;
void addZone(CardZone *z);
......
......@@ -48,7 +48,7 @@ void RfgZone::addCard(CardItem *card, bool reorganize, int x, int y)
reorganizeCards();
}
void RfgZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint)
void RfgZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
{
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
}
......@@ -79,8 +79,9 @@ void RfgZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (cards->empty())
return;
bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier);
CardItem *card = cards->at(0);
CardDragItem *drag = card->createDragItem(this, card->getId(), event->pos(), event->scenePos());
CardDragItem *drag = card->createDragItem(this, card->getId(), event->pos(), event->scenePos(), faceDown);
drag->grabMouse();
setCursor(Qt::OpenHandCursor);
}
......
......@@ -11,7 +11,7 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void addCard(CardItem *card, bool reorganize = true, int x = 0, int y = -1);
void reorganizeCards();
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint);
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
......
......@@ -42,7 +42,7 @@ void SideboardZone::addCard(CardItem *card, bool reorganize, int x, int y)
reorganizeCards();
}
void SideboardZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint)
void SideboardZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
{
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
}
......
......@@ -11,7 +11,7 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void addCard(CardItem *card, bool reorganize = true, int x = 0, int y = -1);
void reorganizeCards();
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint);
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
};
#endif
......@@ -31,17 +31,16 @@ void TableZone::addCard(CardItem *card, bool reorganize, int x, int y)
y = height - CARD_HEIGHT - y;
card->setPos(x, y);
}
qDebug(QString("zValue = %1, x = %2, y = %3").arg((y + CARD_HEIGHT) * width + x + 1000).arg(x).arg(y).toLatin1());
card->setZValue((y + CARD_HEIGHT) * width + x + 1000);
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());
}
void TableZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint)
void TableZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
{
player->client->moveCard(cardId, startZone->getName(), getName(), dropPoint.x(), dropPoint.y());
player->client->moveCard(cardId, startZone->getName(), getName(), dropPoint.x(), dropPoint.y(), faceDown);
}
void TableZone::reorganizeCards()
......
......@@ -16,7 +16,7 @@ public:
void addCard(CardItem *card, bool reorganize = true, int x = -1, int y = -1);
void reorganizeCards();
void toggleTapped();
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint);
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
};
#endif
......@@ -17,7 +17,6 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent)
deckModel = new DeckListModel(db, this);
deckView = new QTreeView();
deckView->setModel(deckModel);
// deckView->setSortingEnabled(true);
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
cardInfo = new CardInfoWidget(db);
......@@ -99,6 +98,8 @@ void WndDeckEditor::actSaveDeck()
void WndDeckEditor::actSaveDeckAs()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save deck as"), QString(), tr("Deck files (*.dec)"));
if (fileName.isEmpty())
return;
if (!fileName.endsWith(".dec"))
fileName.append(".dec");
if (deckModel->saveToFile(fileName))
......
......@@ -85,7 +85,7 @@ void ZoneViewZone::addCard(CardItem *card, bool reorganize, int x, int y)
reorganizeCards();
}
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint)
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
{
Q_UNUSED(dropPoint);
qDebug(QString("handleDropEvent id=%1").arg(cardId).toLatin1());
......
......@@ -9,7 +9,7 @@ class ZoneViewWidget;
class ZoneViewZone : public CardZone {
private:
int numberCards;
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint);
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
CardZone *origZone;
signals:
void removeZoneViewWidget(ZoneViewWidget *zv);
......
......@@ -19,8 +19,8 @@
***************************************************************************/
#include "playerzone.h"
PlayerZone::PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _id_access)
: name(_name), has_coords(_has_coords), is_public(_is_public), id_access(_id_access)
PlayerZone::PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _is_private, bool _id_access)
: name(_name), has_coords(_has_coords), is_public(_is_public), is_private(_is_private), id_access(_id_access)
{
}
......
......@@ -28,7 +28,8 @@ class PlayerZone {
private:
QString name;
bool has_coords;
bool is_public; // Contents of the zone are visible for anyone
bool is_public; // Contents of the zone are always visible to anyone
bool is_private; // Contents of the zone are always visible to the owner
bool id_access; // getCard() finds by id, not by list index
// Example: When moving a card from the library to the table,
// the card has to be found by list index because the client
......@@ -36,12 +37,13 @@ private:
// to the table, the card can be found by id because the client
// knows the id and the hand does not need to have a specific order.
public:
PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _id_access);
PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _is_private, bool _id_access);
~PlayerZone();
TestCard *getCard(int id, bool remove, int *position = NULL);
bool isPublic() { return is_public; }
bool isPrivate() { return is_private; }
bool hasCoords() { return has_coords; }
bool hasIdAccess() { return id_access; }
QString getName() { return name; }
......
......@@ -20,7 +20,7 @@
#include "testcard.h"
TestCard::TestCard(QString _name, int _id, int _coord_x, int _coord_y)
: id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), counters(0), tapped(false), attacking(false)
: id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), counters(0), tapped(false), attacking(false), facedown(false), annotation(QString()), doesntUntap(false)
{
}
......@@ -36,10 +36,11 @@ void TestCard::resetState()
setTapped(false);
setAttacking(false);
setFaceDown(false);
setAnnotation("");
setAnnotation(QString());
setDoesntUntap(false);
}
bool TestCard::setAttribute(const QString &aname, const QString &avalue)
bool TestCard::setAttribute(const QString &aname, const QString &avalue, bool allCards)
{
if (!aname.compare("counters")) {
bool ok;
......@@ -48,13 +49,17 @@ bool TestCard::setAttribute(const QString &aname, const QString &avalue)
return false;
setCounters(tmp_int);
} else if (!aname.compare("tapped")) {
setTapped(!avalue.compare("1"));
bool value = !avalue.compare("1");
if (!(!value && allCards && doesntUntap))
setTapped(value);
} else if (!aname.compare("attacking")) {
setAttacking(!avalue.compare("1"));
} else if (!aname.compare("facedown")) {
setFaceDown(!avalue.compare("1"));
} else if (!aname.compare("annotation")) {
setAnnotation(avalue);
} else if (!aname.compare("doesnt_untap")) {
setDoesntUntap(!avalue.compare("1"));
} else
return false;
......
......@@ -21,9 +21,7 @@
#define TESTCARD_H
#include <QString>
/**
@author Max-Wilhelm Bruker <brukie@laptop>
*/
class TestCard {
private:
int id;
......@@ -34,6 +32,7 @@ private:
bool attacking;
bool facedown;
QString annotation;
bool doesntUntap;
public:
TestCard(QString _name, int _id, int _coord_x, int _coord_y);
~TestCard();
......@@ -47,7 +46,9 @@ public:
bool getAttacking() { return attacking; }
bool getFaceDown() { return facedown; }
QString getAnnotation() { return annotation; }
bool getDoesntUntap() { return doesntUntap; }
void setId(int _id) { id = _id; }
void setCoords(int x, int y) { coord_x = x; coord_y = y; }
void setName(const QString &_name) { name = _name; }
void setCounters(int _counters) { counters = _counters; }
......@@ -55,9 +56,10 @@ public:
void setAttacking(bool _attacking) { attacking = _attacking; }
void setFaceDown(bool _facedown) { facedown = _facedown; }
void setAnnotation(const QString &_annotation) { annotation = _annotation; }
void setDoesntUntap(bool _doesntUntap) { doesntUntap = _doesntUntap; }
void resetState();
bool setAttribute(const QString &aname, const QString &avalue);
bool setAttribute(const QString &aname, const QString &avalue, bool allCards);
};
#endif
......@@ -42,6 +42,11 @@ TestServerSocket::~TestServerSocket()
game->removePlayer(this);
}
int TestServerSocket::newCardId()
{
return nextCardId++;
}
void TestServerSocket::setName(const QString &name)
{
emit broadcastEvent(QString("name|%1|%2").arg(PlayerName).arg(name), this);
......@@ -79,14 +84,14 @@ void TestServerSocket::setupZones()
// ------------------------------------------------------------------
// Create zones
PlayerZone *deck = new PlayerZone("deck", false, false, false);
PlayerZone *deck = new PlayerZone("deck", false, false, false, false);
zones << deck;
PlayerZone *sb = new PlayerZone("sb", false, false, false);
PlayerZone *sb = new PlayerZone("sb", false, false, false, false);
zones << sb;
zones << new PlayerZone("table", true, true, true);
zones << new PlayerZone("hand", false, false, true);
zones << new PlayerZone("grave", false, true, true);
zones << new PlayerZone("rfg", false, true, true);
zones << new PlayerZone("table", true, true, false, true);
zones << new PlayerZone("hand", false, false, true, true);
zones << new PlayerZone("grave", false, true, false, true);
zones << new PlayerZone("rfg", false, true, false, true);
// Create life counter
Counter *life = new Counter("life", 20);
......@@ -301,8 +306,8 @@ bool TestServerSocket::parseCommand(QString line)
emit broadcastEvent(QString("draw|%1").arg(number), this);
} else if (!cmd.compare("move_card", Qt::CaseInsensitive)) {
// ID Karte, Startzone, Zielzone, Koordinaten X, Y
if (params.size() != 5)
// ID Karte, Startzone, Zielzone, Koordinaten X, Y, Facedown
if (params.size() != 6)
return remsg->send("syntax", false);
bool ok;
int cardid = params[0].toInt(&ok);
......@@ -326,26 +331,43 @@ bool TestServerSocket::parseCommand(QString line)
if (!ok)
return remsg->send("syntax", false);
}
targetzone->insertCard(card, x, y);
bool facedown = params[5].toInt(&ok);
if (!ok)
return remsg->send("syntax", false);
remsg->send();
msg(QString("private|||move_card|%1|%2|%3|%4|%5|%6|%7").arg(card->getId())
.arg(card->getName())
targetzone->insertCard(card, x, y);
QString privateCardName, publicCardName;
if (facedown)
card->setId(newCardId());
if ((!facedown && !card->getFaceDown())
|| (card->getFaceDown() && !facedown && startzone->isPublic() && targetzone->isPublic()))
publicCardName = card->getName();
if ((!facedown && !card->getFaceDown())
|| (card->getFaceDown() && !facedown && startzone->isPublic() && targetzone->isPublic())
|| (!facedown && targetzone->isPrivate()))
privateCardName = card->getName();
card->setFaceDown(facedown);
msg(QString("private|||move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId())
.arg(privateCardName)
.arg(startzone->getName())
.arg(position)
.arg(targetzone->getName())
.arg(x)
.arg(y));
// Was ist mit Facedown-Karten?
.arg(y)
.arg(facedown ? 1 : 0));
if ((startzone->isPublic()) || (targetzone->isPublic()))
emit broadcastEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7").arg(card->getId())
.arg(card->getName())
emit broadcastEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId())
.arg(publicCardName)
.arg(startzone->getName())
.arg(position)
.arg(targetzone->getName())
.arg(x)
.arg(y), this);
.arg(y)
.arg(facedown ? 1 : 0), this);
else
emit broadcastEvent(QString("move_card|||%1|%2|%3|%4|%5").arg(startzone->getName())
emit broadcastEvent(QString("move_card|||%1|%2|%3|%4|%5|0").arg(startzone->getName())
.arg(position)
.arg(targetzone->getName())
.arg(x)
......@@ -361,7 +383,7 @@ bool TestServerSocket::parseCommand(QString line)
QString cardname = params[1];
int x = params[3].toInt();
int y = params[4].toInt();
int cardid = nextCardId++;
int cardid = newCardId();
QString powtough = params[2];
remsg->send();
......@@ -389,13 +411,13 @@ bool TestServerSocket::parseCommand(QString line)
if (cardid == -1) {
QListIterator<TestCard *> CardIterator(zone->cards);
while (CardIterator.hasNext())
if (!CardIterator.next()->setAttribute(params[2], params[3]))
if (!CardIterator.next()->setAttribute(params[2], params[3], true))
return remsg->send("syntax", false);
} else {
TestCard *card = zone->getCard(cardid, false);
if (!card)
return remsg->send("game_state", false);
if (!card->setAttribute(params[2], params[3]))
if (!card->setAttribute(params[2], params[3], false))
return remsg->send("syntax", false);
}
remsg->send();
......
......@@ -54,6 +54,7 @@ private:
QList<Counter *> counters;
int PlayerId;
int nextCardId;
int newCardId();
PlayerZone *getZone(const QString &name);
Counter *getCounter(const QString &name);
void setName(const QString &name);
......
......@@ -18,4 +18,4 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
const char *VERSION_STRING = "Testserver 0.20090304";
const char *VERSION_STRING = "Testserver 0.20090407";
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