allow placement below top X cards (#2666)

Close #2666
This commit is contained in:
Zach H 2017-04-27 20:32:24 -04:00 committed by Gavin Bisesi
parent 7c1a18da5e
commit 12c9e4b81a
4 changed files with 56 additions and 4 deletions

View file

@ -95,6 +95,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
game(_parent),
shortcutsActive(false),
defaultNumberTopCards(1),
defaultNumberTopCardsToPlaceBelow(1),
lastTokenDestroy(true),
lastTokenTableRow(0),
id(_id),
@ -417,6 +418,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
aMoveToTopLibrary->setData(cmMoveToTopLibrary);
aMoveToBottomLibrary = new QAction(this);
aMoveToBottomLibrary->setData(cmMoveToBottomLibrary);
aMoveToXfromTopOfLibrary = new QAction(this);
aMoveToGraveyard = new QAction(this);
aMoveToHand = new QAction(this);
aMoveToHand->setData(cmMoveToHand);
@ -425,6 +427,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
aMoveToExile->setData(cmMoveToExile);
connect(aMoveToTopLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToBottomLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToXfromTopOfLibrary, SIGNAL(triggered()), this, SLOT(actMoveCardXCardsFromTop()));
connect(aMoveToHand, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToGraveyard, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToExile, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
@ -723,6 +726,7 @@ void Player::retranslateUi()
}
aMoveToTopLibrary->setText(tr("&Top of library"));
aMoveToXfromTopOfLibrary->setText(tr("X cards from the top..."));
aMoveToBottomLibrary->setText(tr("&Bottom of library"));
aMoveToHand->setText(tr("&Hand"));
aMoveToGraveyard->setText(tr("&Graveyard"));
@ -1972,6 +1976,49 @@ bool Player::clearCardsToDelete()
return true;
}
void Player::actMoveCardXCardsFromTop()
{
bool ok;
int number = QInputDialog::getInt(0, tr("Place card X cards from top library"), tr("How many cards from the top of the deck should this card be placed:"), defaultNumberTopCardsToPlaceBelow, 1, 2000000000, 1, &ok);
number--;
if (!ok)
return;
defaultNumberTopCardsToPlaceBelow = number;
QList<QGraphicsItem *> sel = scene()->selectedItems();
QList<CardItem *> cardList;
while (!sel.isEmpty())
cardList.append(qgraphicsitem_cast<CardItem *>(sel.takeFirst()));
QList< const ::google::protobuf::Message * > commandList;
ListOfCardsToMove idList;
for (int i = 0; i < cardList.size(); ++i)
idList.add_card()->set_card_id(cardList[i]->getId());
if (cardList.isEmpty())
return;
int startPlayerId = cardList[0]->getZone()->getPlayer()->getId();
QString startZone = cardList[0]->getZone()->getName();
Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_player_id(startPlayerId);
cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(getId());
cmd->set_target_zone("deck");
cmd->set_x(number);
cmd->set_y(0);
commandList.append(cmd);
if (local)
sendGameCommand(prepareGameCommand(commandList));
else
game->sendGameCommand(prepareGameCommand(commandList));
}
void Player::cardMenuAction()
{
QAction *a = static_cast<QAction *>(sender());
@ -2406,6 +2453,7 @@ void Player::updateCardMenu(const CardItem *card)
else if (writeableCard) {
if (moveMenu->isEmpty()) {
moveMenu->addAction(aMoveToTopLibrary);
moveMenu->addAction(aMoveToXfromTopOfLibrary);
moveMenu->addAction(aMoveToBottomLibrary);
moveMenu->addSeparator();
moveMenu->addAction(aMoveToHand);