Beispiel #1
0
void GameScene::updateHover(const QPointF &scenePos)
{
    QList<QGraphicsItem *> itemList = items(scenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, getViewTransform());
    
    // Search for the topmost zone and ignore all cards not belonging to that zone.
    CardZone *zone = 0;
    for (int i = 0; i < itemList.size(); ++i)
        if ((zone = qgraphicsitem_cast<CardZone *>(itemList[i])))
            break;
    
    CardItem *maxZCard = 0;
    if (zone) {
        qreal maxZ = -1;
        for (int i = 0; i < itemList.size(); ++i) {
            CardItem *card = qgraphicsitem_cast<CardItem *>(itemList[i]);
            if (!card)
                continue;
            if (card->getAttachedTo()) {
                if (card->getAttachedTo()->getZone() != zone)
                    continue;
            } else if (card->getZone() != zone)
                continue;
            
            if (card->getRealZValue() > maxZ) {
                maxZ = card->getRealZValue();
                maxZCard = card;
            }
        }
    }
    if (hoveredCard && (maxZCard != hoveredCard))
        hoveredCard->setHovered(false);
    if (maxZCard && (maxZCard != hoveredCard))
        maxZCard->setHovered(true);
    hoveredCard = maxZCard;
}
Beispiel #2
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);
}
Beispiel #3
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();
}
Beispiel #4
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);
}
Beispiel #5
0
void CardItem::drawArrow(const QColor &arrowColor)
{
    if (static_cast<TabGame *>(owner->parent())->getSpectator())
        return;
    
    Player *arrowOwner = static_cast<TabGame *>(owner->parent())->getActiveLocalPlayer();
    ArrowDragItem *arrow = new ArrowDragItem(arrowOwner, this, arrowColor);
    scene()->addItem(arrow);
    arrow->grabMouse();
    
    QListIterator<QGraphicsItem *> itemIterator(scene()->selectedItems());
    while (itemIterator.hasNext()) {
        CardItem *c = qgraphicsitem_cast<CardItem *>(itemIterator.next());
        if (!c || (c == this))
            continue;
        if (c->getZone() != zone)
            continue;
        
        ArrowDragItem *childArrow = new ArrowDragItem(arrowOwner, c, arrowColor);
        scene()->addItem(childArrow);
        arrow->addChildArrow(childArrow);
    }
}