Exemple #1
0
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    if (!startItem)
        return;

    if (targetItem && (targetItem != startItem)) {
        CardZone *startZone = static_cast<CardItem *>(startItem)->getZone();
        // For now, we can safely assume that the start item is always a card.
        // The target item can be a player as well.
        CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
        CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);

        Command_CreateArrow cmd;
        cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(color));
        cmd.set_start_player_id(startZone->getPlayer()->getId());
        cmd.set_start_zone(startZone->getName().toStdString());
        cmd.set_start_card_id(startCard->getId());

        if (targetCard) {
            CardZone *targetZone = targetCard->getZone();
            cmd.set_target_player_id(targetZone->getPlayer()->getId());
            cmd.set_target_zone(targetZone->getName().toStdString());
            cmd.set_target_card_id(targetCard->getId());
        } else {
            PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem);
            cmd.set_target_player_id(targetPlayer->getOwner()->getId());
        }
        if (startZone->getName().compare("hand") == 0)  {
            startCard->playCard(false);
            CardInfo *ci = startCard->getInfo();
            if (((!settingsCache->getPlayToStack() && ci->getTableRow() == 3) ||
                ((settingsCache->getPlayToStack() && ci->getTableRow() != 0) &&
                startCard->getZone()->getName().toStdString() != "stack")))
                cmd.set_start_zone("stack");
            else
                cmd.set_start_zone(settingsCache->getPlayToStack() ? "stack" :"table");
        }
        player->sendGameCommand(cmd);
    }
    delArrow();

    for (int i = 0; i < childArrows.size(); ++i)
        childArrows[i]->mouseReleaseEvent(event);
}
Exemple #2
0
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
{
    if (!startItem)
        return;

    if (targetItem && (targetItem != startItem)) {
        CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
        CardZone *startZone = startCard->getZone();
        CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
        CardZone *targetZone = targetCard->getZone();

        Command_AttachCard cmd;
        cmd.set_start_zone(startZone->getName().toStdString());
        cmd.set_card_id(startCard->getId());
        cmd.set_target_player_id(targetZone->getPlayer()->getId());
        cmd.set_target_zone(targetZone->getName().toStdString());
        cmd.set_target_card_id(targetCard->getId());

        player->sendGameCommand(cmd);
    }

    delArrow();
}
Exemple #3
0
void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (event->buttons().testFlag(Qt::RightButton)) {
        if ((event->screenPos() - event->buttonDownScreenPos(Qt::RightButton)).manhattanLength() < 2 * QApplication::startDragDistance())
            return;
        
        QColor arrowColor = Qt::red;
        if (event->modifiers().testFlag(Qt::ControlModifier))
            arrowColor = Qt::yellow;
        else if (event->modifiers().testFlag(Qt::AltModifier))
            arrowColor = Qt::blue;
        else if (event->modifiers().testFlag(Qt::ShiftModifier))
            arrowColor = Qt::green;
        
        drawArrow(arrowColor);
    } else if (event->buttons().testFlag(Qt::LeftButton)) {
        if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < 2 * QApplication::startDragDistance())
            return;
        if (zone->getIsView()) {
            const ZoneViewZone *const view = static_cast<const ZoneViewZone *const>(zone);
            if (view->getRevealZone() && !view->getWriteableRevealZone())
                return;
        } else if (!owner->getLocal())
            return;
        
        bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
    
        createDragItem(id, event->pos(), event->scenePos(), facedown || forceFaceDown);
        dragItem->grabMouse();
        
        QList<QGraphicsItem *> sel = scene()->selectedItems();
        int j = 0;
        for (int i = 0; i < sel.size(); i++) {
            CardItem *c = (CardItem *) sel.at(i);
            if ((c == this) || (c->getZone() != zone))
                continue;
            ++j;
            QPointF childPos;
            if (zone->getHasCardAttr())
                childPos = c->pos() - pos();
            else
                childPos = QPointF(j * CARD_WIDTH / 2, 0);
            CardDragItem *drag = new CardDragItem(c, c->getId(), childPos, c->getFaceDown() || forceFaceDown, dragItem);
            drag->setPos(dragItem->pos() + childPos);
            scene()->addItem(drag);
        }
    }
    setCursor(Qt::OpenHandCursor);
}
void PileZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < QApplication::startDragDistance())
        return;

    if (cards.isEmpty())
        return;

    bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier);
    bool bottomCard = event->modifiers().testFlag(Qt::ControlModifier);
    CardItem *card = bottomCard ? cards.last() : cards.first();
    const int cardid = contentsKnown() ? card->getId() : (bottomCard ? cards.size() - 1 : 0);
    CardDragItem *drag = card->createDragItem(cardid, event->pos(), event->scenePos(), faceDown);
    drag->grabMouse();
    setCursor(Qt::OpenHandCursor);
}
Exemple #5
0
CardItem *CardZone::getCard(int cardId, const QString &cardName)
{
    CardItem *c = cards.findCard(cardId, false);
    if (!c) {
        qDebug() << "CardZone::getCard: card id=" << cardId << "not found";
        return 0;
    }
    // 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.
    if ((c->getId() == -1) || (c->getName().isEmpty())) {
        c->setId(cardId);
        c->setName(cardName);
    }
    return c;
}
void TableZone::toggleTapped()
{
    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;
        }
    QList< const ::google::protobuf::Message * > cmdList;
    for (int i = 0; i < selectedItems.size(); i++) {
        CardItem *temp = qgraphicsitem_cast<CardItem *>(selectedItems[i]);
        if (temp->getTapped() != tapAll) {
            Command_SetCardAttr *cmd = new Command_SetCardAttr;
            cmd->set_zone(name.toStdString());
            cmd->set_card_id(temp->getId());
            cmd->set_attribute(AttrTapped);
            cmd->set_attr_value(tapAll ? "1" : "0");
            cmdList.append(cmd);
        }
    }
    player->sendGameCommand(player->prepareGameCommand(cmdList));
}
Exemple #7
0
QVariant CardModel::data(const QModelIndex &index, int role) const
{
	QVariant res;
	if (!index.isValid())
	{
		return res;
	}

	CardItem* item = (CardItem*)items.value(index.row());
	if (role == Qt::DisplayRole)
	{
		if (item != NULL)
		{
			res = item->getName() +
				  " (" + QString::number(item->getDiscont()) + ")";
		}
	}
	else if (role == Qt::EditRole
			|| role == SortRole
			|| role == SearchRole)
	{
		if (item != NULL)
		{
			res = item->getName();
		}
	}
	else if (role == KeyRole)
	{
		res = item->getId();
	}
	else if (role == DiscontRole)
	{
		res = item->getDiscont();
	}

	return res;
}
Exemple #8
0
CardItem *CardList::findCard(const int id, const bool remove, int *position)
{
	if (!contentsKnown) {
		if (empty())
			return 0;
		CardItem *temp = at(0);
		if (remove)
			removeAt(0);
		if (position)
			*position = id;
		return temp;
	} else
		for (int i = 0; i < size(); i++) {
			CardItem *temp = at(i);
			if (temp->getId() == id) {
				if (remove)
					removeAt(i);
				if (position)
					*position = i;
				return temp;
			}
		}
	return 0;
}
void CardContainer::fillCards(const QList<int> &card_ids, const QList<int> &disabled_ids)
{
    if (card_ids == ids)
        return;

    QList<CardItem *> card_items;
    if (card_ids.isEmpty() && items.isEmpty())
        return;
    else if (card_ids.isEmpty() && !items.isEmpty()) {
        card_items = items;
        items.clear();
    } else if (!items.isEmpty()) {
        retained_stack.push(retained());
        items_stack.push(items);
        foreach(CardItem *item, items)
            item->hide();
        items.clear();
    }

    scene_width = RoomSceneInstance->sceneRect().width();

    confirm_button->hide();
    if (card_items.isEmpty())
        card_items = _createCards(card_ids);

    items.append(card_items);
    itemCount = items.length();
    prepareGeometryChange();

    int card_width = G_COMMON_LAYOUT.m_cardNormalWidth;
    int card_height = G_COMMON_LAYOUT.m_cardNormalHeight;
    bool one_row = true;
    int width = (card_width + cardInterval) * itemCount - cardInterval + 50;
    if (width * 1.5 > scene_width) {
        width = (card_width + cardInterval) * ((itemCount + 1) / 2) - cardInterval + 50;
        one_row = false;
    }
    int first_row = one_row ? itemCount : (itemCount + 1) / 2;

    for (int i = 0; i < itemCount; i++) {
        QPointF pos;
        if (i < first_row) {
            pos.setX(25 + (card_width + cardInterval) * i);
            pos.setY(45);
        } else {
            if (itemCount % 2 == 1)
                pos.setX(25 + card_width / 2 + cardInterval / 2
                + (card_width + cardInterval) * (i - first_row));
            else
                pos.setX(25 + (card_width + cardInterval) * (i - first_row));
            pos.setY(45 + card_height + cardInterval);
        }
        CardItem *item = items[i];
        item->resetTransform();
        item->setPos(pos);
        item->setHomePos(pos);
        item->setOpacity(1.0);
        item->setHomeOpacity(1.0);
        item->setFlag(QGraphicsItem::ItemIsFocusable);
        if (disabled_ids.contains(item->getCard()->getEffectiveId()))
            item->setEnabled(false);
        item->setOuterGlowEffectEnabled(true);
        item->show();
        ids << item->getId();
    }
    confirm_button->setPos(boundingRect().center().x() - confirm_button->boundingRect().width() / 2, boundingRect().height() - 60);
}