Esempio n. 1
0
void CardContainer::fillCards(const QList<int> &card_ids, const QList<int> &disabled_ids) {
    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();
    }

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

    int card_width = G_COMMON_LAYOUT.m_cardNormalWidth;
    QPointF pos1(30 + card_width / 2, 40 + G_COMMON_LAYOUT.m_cardNormalHeight / 2);
    QPointF pos2(30 + card_width / 2, 184 + G_COMMON_LAYOUT.m_cardNormalHeight / 2);
    int skip = 102;
    qreal whole_width = skip * 4;
    items.append(card_items);
    int n = items.length();

    for (int i = 0; i < n; i++) {
        QPointF pos;
        if (n <= 10) {
            if (i < 5) {
                pos = pos1;
                pos.setX(pos.x() + i * skip);
            } else {
                pos = pos2;
                pos.setX(pos.x() + (i - 5) * skip);
            }            
        } else {
            int half = (n + 1) / 2;
            qreal real_skip = whole_width / (half - 1);

            if (i < half) {
                pos = pos1;
                pos.setX(pos.x() + i * real_skip);
            } else {
                pos = pos2;
                pos.setX(pos.x() + (i - half) * real_skip);
            }        
        }      
        CardItem *item = items[i];
        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->show();
    }    
}
void CardContainer::fillCards(const QList<int> &card_ids, const QList<int> &disabled_ids) {
    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();
    }

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

    items.append(card_items);
    _repaint();
    int n = items.length();

    const int blank = 3;
    int card_width = G_COMMON_LAYOUT.m_cardNormalWidth;
    int card_height = G_COMMON_LAYOUT.m_cardNormalHeight;
    bool one_row = true;
    int width = (card_width + blank) * items.length() - blank + 50;
    if (width * 1.5 > RoomSceneInstance->sceneRect().width()) {
        width = (card_width + blank) * ((items.length() + 1) / 2) - blank + 50;
        one_row = false;
    }
    int first_row = one_row ? items.length() : (items.length() + 1) / 2;

    for (int i = 0; i < n; i++) {
        QPointF pos;
        if (i < first_row) {
            pos.setX(25 + (card_width + blank) * i);
            pos.setY(45);
        } else {
            if (n % 2 == 1)
                pos.setX(25 + card_width / 2 + blank / 2
                    + (card_width + blank) * (i - first_row));
            else
                pos.setX(25 + (card_width + blank) * (i - first_row));
            pos.setY(45 + card_height + blank);
        }
        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->show();
    }
}
Esempio n. 3
0
void CardContainer::fillCards(const QList<int> &card_ids){
    if(card_ids.isEmpty()) return;
    else if(!items.isEmpty()){
        items_stack.push(items);
        items.clear();
    }
    QList<CardItem*> card_items = _createCards(card_ids);

    static const QPointF pos1(30, 40);
    static const QPointF pos2(30, 184);
    static const int card_width = 93;
    static const int skip = 102;
    static const qreal whole_width = skip * 4 + card_width;
    items.append(card_items);
    int n = items.length();

    for (int i = 0; i < n; i++) {
        QPointF pos;
        if(n <= 10){                    
            if(i < 5){
                pos = pos1;
                pos.setX(pos.x() + i * skip);
            }else{
                pos = pos2;
                pos.setX(pos.x() + (i - 5) * skip);
            }            
        }else{
            int half = n / 2 + 1;
            qreal real_skip = whole_width / half;
            
            if(i < half){
                pos = pos1;
                pos.setX(pos.x() + i * real_skip);
            }else{
                pos = pos2;
                pos.setX(pos.x() + (i-half) * real_skip);
            }        
        }      
        CardItem* item = items[i];
        item->setPos(pos);
        item->setHomePos(pos);
        item->setOpacity(1.0);
        item->setHomeOpacity(1.0);
        item->setFlag(QGraphicsItem::ItemIsFocusable);
    }    
}
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);
}
void PindianBox::doPindian(const QString &requestor, const QString &reason, const QStringList &targets)
{
    _m_mutex_pindian.lock();
    zhuge = requestor;
    this->targets = targets;
    this->reason = reason;
    upItems.clear();
    downItems.clear();
    scene_width = RoomSceneInstance->sceneRect().width();

    for (int i = 1; i <= targets.length(); i++) {
        card_ids << -1;
        CardItem *cardItem = new CardItem(Sanguosha->getCard(-1));
        cardItem->setFlag(QGraphicsItem::ItemIsFocusable);
        cardItem->setFlag(ItemIsMovable, false);
        cardItem->setAutoBack(false);
        upItems << cardItem;
        cardItem->setParentItem(this);
    }

    CardItem *card = new CardItem(Sanguosha->getCard(-1));
    card->setFlag(QGraphicsItem::ItemIsFocusable);
    card->setFlag(ItemIsMovable, false);
    card->setAutoBack(false);
    card->setParentItem(this);
    downItems << card;

    itemCount = upItems.length();

    int cardWidth = G_COMMON_LAYOUT.m_cardNormalWidth;
    int cardHeight = G_COMMON_LAYOUT.m_cardNormalHeight;
    int count = (itemCount >= 2) ? itemCount : 2;
    int width = (cardWidth + cardInterval + 20) * count - cardInterval + 50;
    this->width = width;
    int first = (width - targets.length() * cardWidth - (targets.length() - 1) * (cardInterval + 20)) / 2;

    for (int i = 0; i < upItems.length(); i++) {
        CardItem *cardItem = upItems.at(i);

        QPointF pos;
        int X, Y;

        X = first + (cardWidth + cardInterval + 20) * i;
        Y = 45;

        pos.setX(X);
        pos.setY(Y);
        cardItem->resetTransform();
        cardItem->setOuterGlowEffectEnabled(true);
        cardItem->setPos(pos);
        cardItem->setHomePos(pos);
        cardItem->goBack(true);
        cardItem->hide();
    }

    QPointF pos;
    pos.setX((width - cardWidth) / 2);
    pos.setY(45 + cardHeight + cardInterval);
    card->resetTransform();
    card->setOuterGlowEffectEnabled(true);
    card->setPos(pos);
    card->setHomePos(pos);
    card->goBack(true);
    card->hide();

    prepareGeometryChange();
    GraphicsBox::moveToCenter(this);
    show();
    _m_mutex_pindian.unlock();
}