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(); } }
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(); }