mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
game is almost playable again
This commit is contained in:
parent
0d4717f40b
commit
e796af2b89
34 changed files with 309 additions and 320 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include "cardzone.h"
|
||||
#include "player.h"
|
||||
#include "math.h"
|
||||
#include "protocol_items.h"
|
||||
#include <QPainter>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsScene>
|
||||
|
|
@ -76,7 +77,7 @@ void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
|
||||
event->accept();
|
||||
if (event->button() == Qt::RightButton)
|
||||
player->client->deleteArrow(id);
|
||||
player->sendGameCommand(new Command_DeleteArrow(-1, id));
|
||||
}
|
||||
|
||||
ArrowDragItem::ArrowDragItem(CardItem *_startItem, const QColor &_color)
|
||||
|
|
@ -110,7 +111,8 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
|||
if (targetItem && (targetItem != startItem)) {
|
||||
CardZone *startZone = static_cast<CardZone *>(startItem->parentItem());
|
||||
CardZone *targetZone = static_cast<CardZone *>(targetItem->parentItem());
|
||||
player->client->createArrow(
|
||||
player->sendGameCommand(new Command_CreateArrow(
|
||||
-1,
|
||||
startZone->getPlayer()->getId(),
|
||||
startZone->getName(),
|
||||
startItem->getId(),
|
||||
|
|
@ -118,7 +120,7 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
|||
targetZone->getName(),
|
||||
targetItem->getId(),
|
||||
color
|
||||
);
|
||||
));
|
||||
}
|
||||
deleteLater();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,18 @@ void CardItem::resetState()
|
|||
update();
|
||||
}
|
||||
|
||||
void CardItem::processCardInfo(ServerInfo_Card *info)
|
||||
{
|
||||
id = info->getId();
|
||||
name = info->getName();
|
||||
attacking = info->getAttacking();
|
||||
counters = info->getCounters();
|
||||
annotation = info->getAnnotation();
|
||||
tapped = info->getTapped();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown)
|
||||
{
|
||||
deleteDragItem();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
class CardDatabase;
|
||||
class CardDragItem;
|
||||
class CardZone;
|
||||
class ServerInfo_Card;
|
||||
|
||||
const int MAX_COUNTERS_ON_CARD = 999;
|
||||
|
||||
|
|
@ -41,6 +42,7 @@ public:
|
|||
bool getDoesntUntap() const { return doesntUntap; }
|
||||
void setDoesntUntap(bool _doesntUntap);
|
||||
void resetState();
|
||||
void processCardInfo(ServerInfo_Card *info);
|
||||
|
||||
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
|
||||
void deleteDragItem();
|
||||
|
|
|
|||
|
|
@ -128,9 +128,9 @@ CardItem *CardZone::takeCard(int position, int cardId, const QString &cardName,
|
|||
|
||||
void CardZone::setCardAttr(int cardId, const QString &aname, const QString &avalue)
|
||||
{
|
||||
if (hasCardAttr)
|
||||
/* if (hasCardAttr)
|
||||
player->client->setCardAttr(name, cardId, aname, avalue);
|
||||
}
|
||||
*/}
|
||||
|
||||
void CardZone::moveAllToZone()
|
||||
{
|
||||
|
|
@ -140,8 +140,8 @@ void CardZone::moveAllToZone()
|
|||
|
||||
// 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);
|
||||
}
|
||||
|
||||
QPointF CardZone::closestGridPoint(const QPointF &point)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ class Client : public QObject {
|
|||
Q_OBJECT
|
||||
signals:
|
||||
void statusChanged(ClientStatus _status);
|
||||
// void playerIdReceived(int id, QString name);
|
||||
void maxPingTime(int seconds, int maxSeconds);
|
||||
void serverTimeout();
|
||||
void logSocketError(const QString &errorString);
|
||||
|
|
@ -79,40 +78,6 @@ public:
|
|||
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||
void disconnectFromServer();
|
||||
void sendCommand(Command *cmd);
|
||||
public slots:
|
||||
|
||||
void chatListChannels() { }
|
||||
void chatJoinChannel(const QString &name) { }
|
||||
void chatLeaveChannel(const QString &name) { }
|
||||
void chatSay(const QString &name, const QString &s) { }
|
||||
void listGames() { }
|
||||
void listPlayers() { }
|
||||
void createGame(const QString &description, const QString &password, unsigned int maxPlayers, bool spectatorsAllowed) { }
|
||||
void joinGame(int gameId, const QString &password, bool spectator) { }
|
||||
void leaveGame() { }
|
||||
void login(const QString &name, const QString &pass) { }
|
||||
void say(const QString &s) { }
|
||||
void shuffle() { }
|
||||
void rollDie(unsigned int sides) { }
|
||||
void drawCard() { return drawCards(1); }
|
||||
void drawCards(unsigned int number) { }
|
||||
void moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false) { }
|
||||
void createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y) { }
|
||||
void createArrow(int startPlayerId, const QString &startZone, int startCardId, int targetPlayerId, const QString &targetPlayerZone, int targetCardId, const QColor &color) { }
|
||||
void deleteArrow(int arrowId) { }
|
||||
void setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue) { }
|
||||
void readyStart() { }
|
||||
void incCounter(int counterId, int delta) { }
|
||||
void addCounter(const QString &counterName, QColor color, int radius, int value) { }
|
||||
void setCounter(int counterId, int value) { }
|
||||
void delCounter(int counterId) { }
|
||||
void nextTurn() { }
|
||||
void setActivePhase(int phase) { }
|
||||
void dumpZone(int player, const QString &zone, int numberCards) { }
|
||||
void stopDumpZone(int player, const QString &zone) { }
|
||||
void dumpAll() { }
|
||||
void submitDeck(const QStringList &deck) { }
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "counter.h"
|
||||
#include "player.h"
|
||||
#include "client.h"
|
||||
#include "protocol_items.h"
|
||||
#include <QtGui>
|
||||
|
||||
Counter::Counter(Player *_player, int _id, const QString &_name, QColor _color, int _radius, int _value, QGraphicsItem *parent)
|
||||
|
|
@ -77,10 +78,10 @@ void Counter::setValue(int _value)
|
|||
void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
player->client->incCounter(id, 1);
|
||||
player->sendGameCommand(new Command_IncCounter(-1, id, 1));
|
||||
event->accept();
|
||||
} else if (event->button() == Qt::RightButton) {
|
||||
player->client->incCounter(id, -1);
|
||||
player->sendGameCommand(new Command_IncCounter(-1, id, -1));
|
||||
event->accept();
|
||||
} else if (event->button() == Qt::MidButton) {
|
||||
if (menu)
|
||||
|
|
@ -93,7 +94,7 @@ void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
void Counter::incrementCounter()
|
||||
{
|
||||
int delta = static_cast<QAction *>(sender())->data().toInt();
|
||||
player->client->incCounter(id, delta);
|
||||
player->sendGameCommand(new Command_IncCounter(-1, id, delta));
|
||||
}
|
||||
|
||||
void Counter::setCounter()
|
||||
|
|
@ -101,5 +102,5 @@ void Counter::setCounter()
|
|||
bool ok;
|
||||
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, 0, 2000000000, 1, &ok);
|
||||
if (ok)
|
||||
player->client->setCounter(id, newValue);
|
||||
player->sendGameCommand(new Command_SetCounter(-1, id, newValue));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,49 +129,6 @@ void Game::retranslateUi()
|
|||
}
|
||||
|
||||
/*
|
||||
void Game::cardListReceived(QList<ServerZoneCard> list)
|
||||
{
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
Player *p = players.value(list[i].getPlayerId(), 0);
|
||||
if (!p)
|
||||
continue;
|
||||
|
||||
CardZone *zone = p->getZones().value(list[i].getZoneName(), 0);
|
||||
if (!zone)
|
||||
continue;
|
||||
|
||||
CardItem *card = new CardItem(db, list[i].getName(), list[i].getId());
|
||||
zone->addCard(card, false, list[i].getX(), list[i].getY());
|
||||
|
||||
card->setCounters(list[i].getCounters());
|
||||
card->setTapped(list[i].getTapped());
|
||||
card->setAttacking(list[i].getAttacking());
|
||||
card->setAnnotation(list[i].getAnnotation());
|
||||
}
|
||||
}
|
||||
|
||||
void Game::zoneListReceived(QList<ServerZone> list)
|
||||
{
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
Player *p = players.value(list[i].getPlayerId(), 0);
|
||||
if (!p)
|
||||
continue;
|
||||
|
||||
CardZone *zone = p->getZones().value(list[i].getName(), 0);
|
||||
if (!zone)
|
||||
continue;
|
||||
|
||||
zone->clearContents();
|
||||
if (
|
||||
(list[i].getType() != ServerZone::PublicZone)
|
||||
&& !((list[i].getType() == ServerZone::PrivateZone) && p->getLocal())
|
||||
) {
|
||||
for (int j = 0; j < list[i].getCardCount(); ++j)
|
||||
zone->addCard(new CardItem(db), false, -1);
|
||||
zone->reorganizeCards();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::counterListReceived(QList<ServerCounter> list)
|
||||
{
|
||||
|
|
@ -228,11 +185,6 @@ void Game::playerListReceived(QList<ServerPlayer> playerList)
|
|||
restartGameDialog();
|
||||
}
|
||||
*/
|
||||
void Game::readyStart()
|
||||
{
|
||||
client->readyStart();
|
||||
}
|
||||
|
||||
void Game::restartGameDialog()
|
||||
{
|
||||
// dlgStartGame->show();
|
||||
|
|
@ -393,12 +345,12 @@ void Game::actNextPhase()
|
|||
int phase = currentPhase;
|
||||
if (++phase >= phaseCount)
|
||||
phase = 0;
|
||||
client->setActivePhase(phase);
|
||||
// client->setActivePhase(phase);
|
||||
}
|
||||
|
||||
void Game::actNextTurn()
|
||||
{
|
||||
client->nextTurn();
|
||||
// client->nextTurn();
|
||||
}
|
||||
|
||||
void Game::actRemoveLocalArrows()
|
||||
|
|
@ -409,7 +361,7 @@ void Game::actRemoveLocalArrows()
|
|||
QMapIterator<int, ArrowItem *> arrowIterator(players[i]->getArrows());
|
||||
while (arrowIterator.hasNext()) {
|
||||
ArrowItem *a = arrowIterator.next().value();
|
||||
players[i]->client->deleteArrow(a->getId());
|
||||
// players[i]->client->deleteArrow(a->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -436,37 +388,37 @@ void Game::cardMenuAction()
|
|||
|
||||
void Game::actTap(CardItem *card)
|
||||
{
|
||||
if (!card->getTapped())
|
||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "1");
|
||||
// if (!card->getTapped())
|
||||
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "1");
|
||||
}
|
||||
|
||||
void Game::actUntap(CardItem *card)
|
||||
{
|
||||
if (card->getTapped())
|
||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "0");
|
||||
// if (card->getTapped())
|
||||
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "0");
|
||||
}
|
||||
|
||||
void Game::actDoesntUntap(CardItem *card)
|
||||
{
|
||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "doesnt_untap", QString::number(!card->getDoesntUntap()));
|
||||
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "doesnt_untap", QString::number(!card->getDoesntUntap()));
|
||||
}
|
||||
|
||||
void Game::actFlip(CardItem *card)
|
||||
{
|
||||
QString zone = qgraphicsitem_cast<CardZone *>(card->parentItem())->getName();
|
||||
client->moveCard(card->getId(), zone, zone, card->getGridPoint().x(), card->getGridPoint().y(), !card->getFaceDown());
|
||||
// QString zone = qgraphicsitem_cast<CardZone *>(card->parentItem())->getName();
|
||||
// client->moveCard(card->getId(), zone, zone, card->getGridPoint().x(), card->getGridPoint().y(), !card->getFaceDown());
|
||||
}
|
||||
|
||||
void Game::actAddCounter(CardItem *card)
|
||||
{
|
||||
if (card->getCounters() < MAX_COUNTERS_ON_CARD)
|
||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "counters", QString::number(card->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));
|
||||
// if (card->getCounters())
|
||||
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "counters", QString::number(card->getCounters() - 1));
|
||||
}
|
||||
|
||||
void Game::actSetCounters()
|
||||
|
|
@ -479,32 +431,32 @@ void Game::actSetCounters()
|
|||
QListIterator<QGraphicsItem *> i(scene->selectedItems());
|
||||
while (i.hasNext()) {
|
||||
CardItem *temp = (CardItem *) i.next();
|
||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "counters", QString::number(number));
|
||||
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "counters", QString::number(number));
|
||||
}
|
||||
}
|
||||
|
||||
void Game::actMoveToTopLibrary(CardItem *card)
|
||||
{
|
||||
CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
||||
client->moveCard(card->getId(), startZone->getName(), "deck", 0, 0, false);
|
||||
// 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);
|
||||
// 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);
|
||||
// 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);
|
||||
// CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
||||
// client->moveCard(card->getId(), startZone->getName(), "rfg", 0, 0, false);
|
||||
}
|
||||
|
||||
void Game::hoverCardEvent(CardItem *card)
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ private slots:
|
|||
void counterListReceived(QList<ServerCounter> list);
|
||||
void arrowListReceived(QList<ServerArrow> list);
|
||||
*/
|
||||
void readyStart();
|
||||
signals:
|
||||
void submitDecklist();
|
||||
void hoverCard(QString name);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "handzone.h"
|
||||
#include "player.h"
|
||||
#include "client.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
HandZone::HandZone(Player *_p, int _zoneHeight, QGraphicsItem *parent)
|
||||
: CardZone(_p, "hand", false, false, _p->getLocal(), parent), zoneHeight(_zoneHeight)
|
||||
|
|
@ -73,5 +74,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->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), cards.size(), -1, false));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "client.h"
|
||||
#include "carddragitem.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent)
|
||||
: CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent)
|
||||
|
|
@ -47,7 +48,7 @@ void PileZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
|||
|
||||
void PileZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||
{
|
||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
||||
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), 0, 0, false));
|
||||
}
|
||||
|
||||
void PileZone::reorganizeCards()
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "handzone.h"
|
||||
#include "cardlist.h"
|
||||
#include "tab_game.h"
|
||||
#include "protocol_items.h"
|
||||
#include <QSettings>
|
||||
#include <QPainter>
|
||||
#include <QMenu>
|
||||
|
|
@ -327,12 +328,12 @@ void Player::actViewSideboard()
|
|||
|
||||
void Player::actShuffle()
|
||||
{
|
||||
client->shuffle();
|
||||
sendGameCommand(new Command_Shuffle);
|
||||
}
|
||||
|
||||
void Player::actDrawCard()
|
||||
{
|
||||
client->drawCards(1);
|
||||
sendGameCommand(new Command_DrawCards(-1, 1));
|
||||
}
|
||||
|
||||
void Player::actMulligan()
|
||||
|
|
@ -342,21 +343,21 @@ void Player::actMulligan()
|
|||
|
||||
const CardList &handCards = hand->getCards();
|
||||
for (int i = 0; i < handCards.size(); i++)
|
||||
client->moveCard(handCards.at(i)->getId(), "hand", "deck", 0);
|
||||
client->shuffle();
|
||||
client->drawCards(mulliganCards--);
|
||||
sendGameCommand(new Command_MoveCard(-1, "hand", handCards.at(i)->getId(), "deck", 0, -1, false));
|
||||
sendGameCommand(new Command_Shuffle);
|
||||
sendGameCommand(new Command_DrawCards(-1, mulliganCards--));
|
||||
}
|
||||
|
||||
void Player::actDrawCards()
|
||||
{
|
||||
int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:"));
|
||||
if (number)
|
||||
client->drawCards(number);
|
||||
sendGameCommand(new Command_DrawCards(-1, number));
|
||||
}
|
||||
|
||||
void Player::actUntapAll()
|
||||
{
|
||||
client->setCardAttr("table", -1, "tapped", "false");
|
||||
// client->setCardAttr("table", -1, "tapped", "false");
|
||||
}
|
||||
|
||||
void Player::actRollDie()
|
||||
|
|
@ -364,25 +365,20 @@ void Player::actRollDie()
|
|||
bool ok;
|
||||
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
|
||||
if (ok)
|
||||
client->rollDie(sides);
|
||||
sendGameCommand(new Command_RollDie(-1, sides));
|
||||
}
|
||||
|
||||
void Player::actCreateToken()
|
||||
{
|
||||
QString cardname = QInputDialog::getText(0, tr("Create token"), tr("Name:"));
|
||||
if (!cardname.isEmpty())
|
||||
client->createToken("table", cardname, QString(), 0, 0);
|
||||
sendGameCommand(new Command_CreateToken(-1, "table", cardname, QString(), 0, 0));
|
||||
}
|
||||
|
||||
void Player::actSayMessage()
|
||||
{
|
||||
QAction *a = qobject_cast<QAction *>(sender());
|
||||
client->say(a->text());
|
||||
}
|
||||
|
||||
void Player::addZone(CardZone *z)
|
||||
{
|
||||
zones.insert(z->getName(), z);
|
||||
sendGameCommand(new Command_Say(-1, a->text()));
|
||||
}
|
||||
|
||||
void Player::setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards)
|
||||
|
|
@ -699,6 +695,56 @@ void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/
|
|||
|
||||
void Player::processPlayerInfo(ServerInfo_Player *info)
|
||||
{
|
||||
for (int i = 0; i < info->getZoneList().size(); ++i) {
|
||||
ServerInfo_Zone *zoneInfo = info->getZoneList()[i];
|
||||
CardZone *zone = zones.value(zoneInfo->getName(), 0);
|
||||
if (!zone)
|
||||
continue;
|
||||
|
||||
zone->clearContents();
|
||||
const QList<ServerInfo_Card *> &cardList = zoneInfo->getCardList();
|
||||
if (cardList.isEmpty()) {
|
||||
for (int j = 0; j < zoneInfo->getCardCount(); ++j)
|
||||
zone->addCard(new CardItem, false, -1);
|
||||
} else {
|
||||
for (int j = 0; j < cardList.size(); ++j) {
|
||||
CardItem *card = new CardItem;
|
||||
card->processCardInfo(cardList[i]);
|
||||
zone->addCard(card, false, cardList[i]->getX(), cardList[i]->getY());
|
||||
}
|
||||
}
|
||||
zone->reorganizeCards();
|
||||
}
|
||||
|
||||
clearCounters();
|
||||
for (int i = 0; i < info->getCounterList().size(); ++i) {
|
||||
ServerInfo_Counter *counterInfo = info->getCounterList().at(i);
|
||||
addCounter(counterInfo->getId(), counterInfo->getName(), counterInfo->getColor(), counterInfo->getRadius(), counterInfo->getCount());
|
||||
}
|
||||
|
||||
clearArrows();
|
||||
for (int i = 0; i < info->getArrowList().size(); ++i) {
|
||||
ServerInfo_Arrow *arrowInfo = info->getArrowList().at(i);
|
||||
const QMap<int, Player *> &playerList = static_cast<TabGame *>(parent())->getPlayers();
|
||||
Player *startPlayer = playerList.value(arrowInfo->getStartPlayerId(), 0);
|
||||
Player *targetPlayer = playerList.value(arrowInfo->getTargetPlayerId(), 0);
|
||||
if (!startPlayer || !targetPlayer)
|
||||
continue;
|
||||
CardZone *startZone = startPlayer->getZones().value(arrowInfo->getStartZone(), 0);
|
||||
CardZone *targetZone = targetPlayer->getZones().value(arrowInfo->getTargetZone(), 0);
|
||||
if (!startZone || !targetZone)
|
||||
continue;
|
||||
CardItem *startCard = startZone->getCard(arrowInfo->getStartCardId(), QString());
|
||||
CardItem *targetCard = targetZone->getCard(arrowInfo->getTargetCardId(), QString());
|
||||
if (!startCard || !targetCard)
|
||||
continue;
|
||||
addArrow(arrowInfo->getId(), startCard, targetCard, arrowInfo->getColor());
|
||||
}
|
||||
}
|
||||
|
||||
void Player::addZone(CardZone *z)
|
||||
{
|
||||
zones.insert(z->getName(), z);
|
||||
}
|
||||
|
||||
void Player::addCounter(int counterId, const QString &name, QColor color, int radius, int value)
|
||||
|
|
@ -783,3 +829,8 @@ void Player::rearrangeCounters()
|
|||
y += br.height() + padding;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::sendGameCommand(GameCommand *command)
|
||||
{
|
||||
static_cast<TabGame *>(parent())->sendGameCommand(command);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class CardZone;
|
|||
class TableZone;
|
||||
class HandZone;
|
||||
class ServerInfo_Player;
|
||||
class GameCommand;
|
||||
|
||||
class Player : public QObject, public QGraphicsItem {
|
||||
Q_OBJECT
|
||||
|
|
@ -94,6 +95,8 @@ public:
|
|||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
|
||||
void addZone(CardZone *z);
|
||||
|
||||
void addCounter(int counterId, const QString &name, QColor color, int radius, int value);
|
||||
void delCounter(int counterId);
|
||||
void clearCounters();
|
||||
|
|
@ -103,7 +106,6 @@ public:
|
|||
void clearArrows();
|
||||
|
||||
Client *client;
|
||||
void addZone(CardZone *z);
|
||||
Player(const QString &_name, int _id, bool _local, Client *_client, TabGame *_parent);
|
||||
~Player();
|
||||
void retranslateUi();
|
||||
|
|
@ -120,6 +122,7 @@ public:
|
|||
void setActive(bool _active);
|
||||
|
||||
void processPlayerInfo(ServerInfo_Player *info);
|
||||
void sendGameCommand(GameCommand *command);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
#include "dlg_load_remote_deck.h"
|
||||
#include "main.h"
|
||||
|
||||
TabGame::TabGame(Client *_client, int _gameId)
|
||||
: client(_client), gameId(_gameId), localPlayerId(-1)
|
||||
TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator)
|
||||
: client(_client), gameId(_gameId), localPlayerId(_localPlayerId), spectator(_spectator)
|
||||
{
|
||||
zoneLayout = new ZoneViewLayout;
|
||||
scene = new GameScene(zoneLayout, this);
|
||||
|
|
@ -124,20 +124,26 @@ void TabGame::processGameEvent(GameEvent *event)
|
|||
{
|
||||
switch (event->getItemId()) {
|
||||
case ItemId_Event_GameStart: eventGameStart(qobject_cast<Event_GameStart *>(event)); break;
|
||||
case ItemId_Event_GameStateChanged: eventGameStateChanged(qobject_cast<Event_GameStateChanged *>(event)); break;
|
||||
default: qDebug() << "unhandled game event";
|
||||
}
|
||||
}
|
||||
|
||||
void TabGame::processGameJoinedEvent(Event_GameJoined *event)
|
||||
void TabGame::sendGameCommand(GameCommand *command)
|
||||
{
|
||||
localPlayerId = event->getPlayerId();
|
||||
spectator = event->getSpectator();
|
||||
command->setGameId(gameId);
|
||||
client->sendCommand(command);
|
||||
}
|
||||
|
||||
void TabGame::eventGameStateChanged(Event_GameStateChanged *event)
|
||||
{
|
||||
const QList<ServerInfo_Player *> &plList = event->getPlayerList();
|
||||
for (int i = 0; i < plList.size(); ++i) {
|
||||
ServerInfo_Player *pl = plList[i];
|
||||
Player *newPlayer = addPlayer(pl->getPlayerId(), pl->getName());
|
||||
newPlayer->processPlayerInfo(pl);
|
||||
Player *player = players.value(pl->getPlayerId(), 0);
|
||||
if (!player)
|
||||
player = addPlayer(pl->getPlayerId(), pl->getName());
|
||||
player->processPlayerInfo(pl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ class ZoneViewWidget;
|
|||
class PhasesToolbar;
|
||||
class ProtocolResponse;
|
||||
class GameEvent;
|
||||
class Event_GameJoined;
|
||||
class GameCommand;
|
||||
class Event_GameStateChanged;
|
||||
class Event_GameStart;
|
||||
class Player;
|
||||
class CardZone;
|
||||
|
|
@ -51,6 +52,7 @@ private:
|
|||
|
||||
Player *addPlayer(int playerId, const QString &playerName);
|
||||
|
||||
void eventGameStateChanged(Event_GameStateChanged *event);
|
||||
void eventGameStart(Event_GameStart *event);
|
||||
signals:
|
||||
void playerAdded(Player *player);
|
||||
|
|
@ -86,11 +88,12 @@ private slots:
|
|||
void readyStart();
|
||||
void deckSelectFinished(ProtocolResponse *r);
|
||||
public:
|
||||
TabGame(Client *_client, int _gameId);
|
||||
TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator);
|
||||
void retranslateUi();
|
||||
const QMap<int, Player *> &getPlayers() const { return players; }
|
||||
|
||||
void processGameEvent(GameEvent *event);
|
||||
void processGameJoinedEvent(Event_GameJoined *event);
|
||||
void sendGameCommand(GameCommand *command);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -101,10 +101,9 @@ void TabSupervisor::updatePingTime(int value, int max)
|
|||
|
||||
void TabSupervisor::gameJoined(Event_GameJoined *event)
|
||||
{
|
||||
TabGame *tab = new TabGame(client, event->getGameId());
|
||||
TabGame *tab = new TabGame(client, event->getGameId(), event->getPlayerId(), event->getSpectator());
|
||||
addTab(tab, tr("Game %1").arg(event->getGameId()));
|
||||
gameTabs.insert(event->getGameId(), tab);
|
||||
tab->processGameJoinedEvent(event);
|
||||
setCurrentWidget(tab);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "tablezone.h"
|
||||
#include "player.h"
|
||||
#include "client.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
||||
: CardZone(_p, "table", true, false, true, parent)
|
||||
|
|
@ -67,7 +68,7 @@ void TableZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &d
|
|||
|
||||
void TableZone::handleDropEventByGrid(int cardId, CardZone *startZone, const QPoint &gridPoint, bool faceDown)
|
||||
{
|
||||
player->client->moveCard(cardId, startZone->getName(), getName(), gridPoint.x(), gridPoint.y(), faceDown);
|
||||
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), gridPoint.x(), gridPoint.y(), faceDown));
|
||||
}
|
||||
|
||||
void TableZone::reorganizeCards()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
#include <QtGui>
|
||||
|
||||
#include "zoneviewwidget.h"
|
||||
#include "carditem.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include "player.h"
|
||||
#include "client.h"
|
||||
#include "gamescene.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards, QGraphicsItem *parent)
|
||||
: QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player)
|
||||
|
|
@ -91,10 +91,10 @@ void ZoneViewWidget::resizeToZoneContents()
|
|||
|
||||
void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
player->client->stopDumpZone(player->getId(), zone->getName());
|
||||
player->sendGameCommand(new Command_StopDumpZone(-1, player->getId(), zone->getName()));
|
||||
if (shuffleCheckBox)
|
||||
if (shuffleCheckBox->isChecked())
|
||||
player->client->shuffle();
|
||||
player->sendGameCommand(new Command_Shuffle);
|
||||
emit closePressed(this);
|
||||
deleteLater();
|
||||
event->accept();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "zoneviewzone.h"
|
||||
#include "player.h"
|
||||
#include "client.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent)
|
||||
: CardZone(_p, _origZone->getName(), false, false, true, parent, true), height(0), numberCards(_numberCards), origZone(_origZone), sortingEnabled(false)
|
||||
|
|
@ -105,7 +106,7 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
|||
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||
{
|
||||
qDebug(QString("handleDropEvent id=%1").arg(cardId).toLatin1());
|
||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
||||
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), 0, 0, false));
|
||||
}
|
||||
|
||||
void ZoneViewZone::removeCard(int position)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue