zoneview improvement

This commit is contained in:
Max-Wilhelm Bruker 2009-08-19 18:55:21 +02:00
parent ff4b451e55
commit cc8de80db8
14 changed files with 277 additions and 176 deletions

View file

@ -93,6 +93,8 @@ void CardItem::setAttacking(bool _attacking)
void CardItem::setFaceDown(bool _facedown)
{
facedown = _facedown;
if (facedown)
setName(QString());
update();
}

View file

@ -47,7 +47,8 @@ void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
{
if (view)
view->addCard(new CardItem(player->getDb(), card->getName(), card->getId()), reorganize, x, y);
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1))
view->addCard(new CardItem(player->getDb(), card->getName(), card->getId()), reorganize, x, y);
addCardImpl(card, x, y);

View file

@ -2,6 +2,7 @@
#include <QMenu>
#include <QMessageBox>
#include <QSettings>
#include <stdlib.h>
#include "serverplayer.h"
#include "game.h"
#include "servereventdata.h"
@ -80,19 +81,17 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a
initSayMenu();
aTap = new QAction(tr("&Tap"), this);
connect(aTap, SIGNAL(triggered()), this, SLOT(actTap()));
aUntap = new QAction(tr("&Untap"), this);
connect(aUntap, SIGNAL(triggered()), this, SLOT(actUntap()));
aDoesntUntap = new QAction(tr("Toggle &normal untapping"), this);
connect(aDoesntUntap, SIGNAL(triggered()), this, SLOT(actDoesntUntap()));
aFlip = new QAction(tr("&Flip"), this);
connect(aFlip, SIGNAL(triggered()), this, SLOT(actFlip()));
aAddCounter = new QAction(tr("&Add counter"), this);
connect(aAddCounter, SIGNAL(triggered()), this, SLOT(actAddCounter()));
aRemoveCounter = new QAction(tr("&Remove counter"), this);
connect(aRemoveCounter, SIGNAL(triggered()), this, SLOT(actRemoveCounter()));
aSetCounters = new QAction(tr("&Set counters..."), this);
connect(aSetCounters, SIGNAL(triggered()), this, SLOT(actSetCounters()));
aMoveToTopLibrary = new QAction(tr("&top of library"), this);
aMoveToBottomLibrary = new QAction(tr("&bottom of library"), this);
aMoveToGraveyard = new QAction(tr("&graveyard"), this);
aMoveToExile = new QAction(tr("&exile"), this);
cardMenu->addAction(aTap);
cardMenu->addAction(aUntap);
@ -103,6 +102,30 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a
cardMenu->addAction(aAddCounter);
cardMenu->addAction(aRemoveCounter);
cardMenu->addAction(aSetCounters);
cardMenu->addSeparator();
moveMenu = cardMenu->addMenu(tr("&Move to"));
moveMenu->addAction(aMoveToTopLibrary);
moveMenu->addAction(aMoveToBottomLibrary);
moveMenu->addAction(aMoveToGraveyard);
moveMenu->addAction(aMoveToExile);
cardMenuHandlers.insert(aTap, &Game::actTap);
cardMenuHandlers.insert(aUntap, &Game::actUntap);
cardMenuHandlers.insert(aDoesntUntap, &Game::actDoesntUntap);
cardMenuHandlers.insert(aFlip, &Game::actFlip);
cardMenuHandlers.insert(aAddCounter, &Game::actAddCounter);
cardMenuHandlers.insert(aRemoveCounter, &Game::actRemoveCounter);
cardMenuHandlers.insert(aMoveToTopLibrary, &Game::actMoveToTopLibrary);
cardMenuHandlers.insert(aMoveToBottomLibrary, &Game::actMoveToBottomLibrary);
cardMenuHandlers.insert(aMoveToGraveyard, &Game::actMoveToGraveyard);
cardMenuHandlers.insert(aMoveToExile, &Game::actMoveToExile);
QHashIterator<QAction *, CardMenuHandler> i(cardMenuHandlers);
while (i.hasNext()) {
i.next();
connect(i.key(), SIGNAL(triggered()), this, SLOT(cardMenuAction()));
}
dlgStartGame = new DlgStartGame(db);
connect(dlgStartGame, SIGNAL(newDeckLoaded(const QStringList &)), client, SLOT(submitDeck(const QStringList &)));
@ -367,63 +390,55 @@ void Game::showCardMenu(QPoint p)
cardMenu->exec(p);
}
void Game::actTap()
void Game::cardMenuAction()
{
QListIterator<QGraphicsItem *> i(scene->selectedItems());
while (i.hasNext()) {
CardItem *temp = (CardItem *) i.next();
if (!temp->getTapped())
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "tapped", "1");
// Determine the appropriate handler function.
CardMenuHandler handler = cardMenuHandlers.value(static_cast<QAction *>(sender()));
// The list of selected items is randomly shuffled.
QList<QGraphicsItem *> sel = scene->selectedItems();
while (!sel.isEmpty()) {
unsigned int i = (unsigned int) (((double) sel.size()) * qrand() / (RAND_MAX + 1.0));
qDebug(QString("%1 items left, i=%2").arg(sel.size()).arg(i).toLatin1());
CardItem *card = qgraphicsitem_cast<CardItem *>(sel.takeAt(i));
// For each item, the handler function is called.
(this->*handler)(card);
}
}
void Game::actUntap()
void Game::actTap(CardItem *card)
{
QListIterator<QGraphicsItem *> i(scene->selectedItems());
while (i.hasNext()) {
CardItem *temp = (CardItem *) i.next();
if (temp->getTapped())
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "tapped", "0");
}
if (!card->getTapped())
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "1");
}
void Game::actDoesntUntap()
void Game::actUntap(CardItem *card)
{
QListIterator<QGraphicsItem *> i(scene->selectedItems());
while (i.hasNext()) {
CardItem *temp = (CardItem *) i.next();
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "doesnt_untap", QString::number(!temp->getDoesntUntap()));
}
if (card->getTapped())
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "0");
}
void Game::actFlip()
void Game::actDoesntUntap(CardItem *card)
{
QListIterator<QGraphicsItem *> i(scene->selectedItems());
while (i.hasNext()) {
CardItem *temp = (CardItem *) i.next();
QString zone = qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName();
client->moveCard(temp->getId(), zone, zone, temp->getGridPoint().x(), temp->getGridPoint().y(), !temp->getFaceDown());
}
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "doesnt_untap", QString::number(!card->getDoesntUntap()));
}
void Game::actAddCounter()
void Game::actFlip(CardItem *card)
{
QListIterator<QGraphicsItem *> i(scene->selectedItems());
while (i.hasNext()) {
CardItem *temp = (CardItem *) i.next();
if (temp->getCounters() < MAX_COUNTERS_ON_CARD)
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "counters", QString::number(temp->getCounters() + 1));
}
QString zone = qgraphicsitem_cast<CardZone *>(card->parentItem())->getName();
client->moveCard(card->getId(), zone, zone, card->getGridPoint().x(), card->getGridPoint().y(), !card->getFaceDown());
}
void Game::actRemoveCounter()
void Game::actAddCounter(CardItem *card)
{
QListIterator<QGraphicsItem *> i(scene->selectedItems());
while (i.hasNext()) {
CardItem *temp = (CardItem *) i.next();
if (temp->getCounters())
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "counters", QString::number(temp->getCounters() - 1));
}
if (card->getCounters() < MAX_COUNTERS_ON_CARD)
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "counters", QString::number(card->getCounters() + 1));
}
void Game::actRemoveCounter(CardItem *card)
{
if (card->getCounters())
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "counters", QString::number(card->getCounters() - 1));
}
void Game::actSetCounters()
@ -440,6 +455,30 @@ void Game::actSetCounters()
}
}
void Game::actMoveToTopLibrary(CardItem *card)
{
CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
client->moveCard(card->getId(), startZone->getName(), "deck", 0, 0, false);
}
void Game::actMoveToBottomLibrary(CardItem *card)
{
CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
client->moveCard(card->getId(), startZone->getName(), "deck", -1, 0, false);
}
void Game::actMoveToGraveyard(CardItem *card)
{
CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
client->moveCard(card->getId(), startZone->getName(), "grave", 0, 0, false);
}
void Game::actMoveToExile(CardItem *card)
{
CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
client->moveCard(card->getId(), startZone->getName(), "rfg", 0, 0, false);
}
void Game::actSayMessage()
{
QAction *a = qobject_cast<QAction *>(sender());

View file

@ -17,8 +17,12 @@ class Game : public QObject {
private:
static const int phaseCount = 11;
QMenu *actionsMenu, *sayMenu, *cardMenu;
typedef void (Game::*CardMenuHandler)(CardItem *card);
QHash<QAction *, CardMenuHandler> cardMenuHandlers;
QMenu *actionsMenu, *sayMenu, *cardMenu, *moveMenu;
QAction *aTap, *aUntap, *aDoesntUntap, *aFlip, *aAddCounter, *aRemoveCounter, *aSetCounters,
*aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToGraveyard, *aMoveToExile,
*aNextPhase, *aNextTurn, *aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aShuffle, *aDraw, *aDrawCards, *aRollDice, *aCreateToken;
DlgStartGame *dlgStartGame;
@ -32,6 +36,8 @@ private:
Player *addPlayer(int playerId, const QString &playerName, QPointF base, bool local);
void initSayMenu();
private slots:
void cardMenuAction();
void actNextPhase();
void actNextTurn();
void actUntapAll();
@ -45,20 +51,23 @@ private slots:
void actCreateToken();
void showCardMenu(QPoint p);
void actDoesntUntap();
void actFlip();
void actAddCounter();
void actRemoveCounter();
void actTap(CardItem *card);
void actUntap(CardItem *card);
void actDoesntUntap(CardItem *card);
void actFlip(CardItem *card);
void actAddCounter(CardItem *card);
void actRemoveCounter(CardItem *card);
void actSetCounters();
void actMoveToTopLibrary(CardItem *card);
void actMoveToBottomLibrary(CardItem *card);
void actMoveToGraveyard(CardItem *card);
void actMoveToExile(CardItem *card);
void actSayMessage();
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

@ -24,6 +24,7 @@
#include <QtPlugin>
#include <QTranslator>
#include <QLibraryInfo>
#include <QDateTime>
#include <QSettings>
#include <stdio.h>
@ -66,7 +67,7 @@ int main(int argc, char *argv[])
translator.load(lang);
app.installTranslator(&translator);
qsrand(QDateTime::currentDateTime().toTime_t());
MainWindow ui(&translator);
qDebug("main(): MainWindow constructor finished");

View file

@ -186,7 +186,7 @@ void MessageLogWidget::logSetDoesntUntap(Player *player, QString cardName, bool
void MessageLogWidget::logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards)
{
if (numberCards)
if (numberCards != -1)
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
append(tr("%1 is looking at %2's %3").arg(sanitizeHtml(player->getName())).arg(zoneOwner).arg(zoneName));

View file

@ -86,7 +86,7 @@ void Player::actMoveHandToBottomLibrary()
void Player::actViewLibrary()
{
emit toggleZoneView(this, "deck", 0);
emit toggleZoneView(this, "deck", -1);
}
void Player::actViewTopCards()
@ -101,17 +101,17 @@ void Player::actViewTopCards()
void Player::actViewGraveyard()
{
emit toggleZoneView(this, "grave", 0);
emit toggleZoneView(this, "grave", -1);
}
void Player::actViewRfg()
{
emit toggleZoneView(this, "rfg", 0);
emit toggleZoneView(this, "rfg", -1);
}
void Player::actViewSideboard()
{
emit toggleZoneView(this, "sb", 0);
emit toggleZoneView(this, "sb", -1);
}
void Player::addZone(CardZone *z)

View file

@ -14,7 +14,6 @@ ZoneViewWidget::ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_or
qreal y = 10;
if (_origZone->getIsShufflable() && (numberCards == 0)) {
qDebug(QString("ZoneViewWidget: bla!").toLatin1());
shuffleCheckBox = new QCheckBox("shuffle when closing");
shuffleCheckBox->setChecked(true);
QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget(this);

View file

@ -30,7 +30,7 @@ bool ZoneViewZone::initializeCards()
return false;
const CardList &c = origZone->getCards();
int number = numberCards == 0 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
for (int i = 0; i < number; i++) {
CardItem *card = c.at(i);
addCard(new CardItem(player->getDb(), card->getName(), card->getId(), this), false, i);

View file

@ -15,7 +15,7 @@ private:
signals:
void removeZoneViewWidget(ZoneViewWidget *zv);
public:
ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards = 0, QGraphicsItem *parent = 0);
ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards = -1, QGraphicsItem *parent = 0);
~ZoneViewZone();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);