mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
[Game] Refactor move cards from library actions (#6658)
* refactor move top/bottom cards actions * minor cleanup * translate zone display names
This commit is contained in:
parent
b36ab66583
commit
e7a3ad86eb
2 changed files with 25 additions and 62 deletions
|
|
@ -424,37 +424,15 @@ void PlayerActions::actMoveTopCardToExile()
|
|||
|
||||
void PlayerActions::actMoveTopCardsToGrave()
|
||||
{
|
||||
const int maxCards = player->getDeckZone()->getCards().size();
|
||||
if (maxCards == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move top cards to grave"),
|
||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
||||
maxCards, 1, &ok);
|
||||
if (!ok) {
|
||||
return;
|
||||
} else if (number > maxCards) {
|
||||
number = maxCards;
|
||||
}
|
||||
defaultNumberTopCards = number;
|
||||
|
||||
Command_MoveCard cmd;
|
||||
cmd.set_start_zone("deck");
|
||||
cmd.set_target_player_id(player->getPlayerInfo()->getId());
|
||||
cmd.set_target_zone("grave");
|
||||
cmd.set_x(0);
|
||||
cmd.set_y(0);
|
||||
|
||||
for (int i = number - 1; i >= 0; --i) {
|
||||
cmd.mutable_cards_to_move()->add_card()->set_card_id(i);
|
||||
}
|
||||
|
||||
sendGameCommand(cmd);
|
||||
moveTopCardsTo("grave", tr("grave"));
|
||||
}
|
||||
|
||||
void PlayerActions::actMoveTopCardsToExile()
|
||||
{
|
||||
moveTopCardsTo("rfg", tr("exile"));
|
||||
}
|
||||
|
||||
void PlayerActions::moveTopCardsTo(const QString &targetZone, const QString &zoneDisplayName)
|
||||
{
|
||||
const int maxCards = player->getDeckZone()->getCards().size();
|
||||
if (maxCards == 0) {
|
||||
|
|
@ -462,12 +440,14 @@ void PlayerActions::actMoveTopCardsToExile()
|
|||
}
|
||||
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move top cards to exile"),
|
||||
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move top cards to %1").arg(zoneDisplayName),
|
||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
|
||||
maxCards, 1, &ok);
|
||||
if (!ok) {
|
||||
return;
|
||||
} else if (number > maxCards) {
|
||||
}
|
||||
|
||||
if (number > maxCards) {
|
||||
number = maxCards;
|
||||
}
|
||||
defaultNumberTopCards = number;
|
||||
|
|
@ -475,7 +455,7 @@ void PlayerActions::actMoveTopCardsToExile()
|
|||
Command_MoveCard cmd;
|
||||
cmd.set_start_zone("deck");
|
||||
cmd.set_target_player_id(player->getPlayerInfo()->getId());
|
||||
cmd.set_target_zone("rfg");
|
||||
cmd.set_target_zone(targetZone.toStdString());
|
||||
cmd.set_x(0);
|
||||
cmd.set_y(0);
|
||||
|
||||
|
|
@ -628,37 +608,15 @@ void PlayerActions::actMoveBottomCardToExile()
|
|||
|
||||
void PlayerActions::actMoveBottomCardsToGrave()
|
||||
{
|
||||
const int maxCards = player->getDeckZone()->getCards().size();
|
||||
if (maxCards == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move bottom cards to grave"),
|
||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
||||
maxCards, 1, &ok);
|
||||
if (!ok) {
|
||||
return;
|
||||
} else if (number > maxCards) {
|
||||
number = maxCards;
|
||||
}
|
||||
defaultNumberBottomCards = number;
|
||||
|
||||
Command_MoveCard cmd;
|
||||
cmd.set_start_zone("deck");
|
||||
cmd.set_target_player_id(player->getPlayerInfo()->getId());
|
||||
cmd.set_target_zone("grave");
|
||||
cmd.set_x(0);
|
||||
cmd.set_y(0);
|
||||
|
||||
for (int i = maxCards - number; i < maxCards; ++i) {
|
||||
cmd.mutable_cards_to_move()->add_card()->set_card_id(i);
|
||||
}
|
||||
|
||||
sendGameCommand(cmd);
|
||||
moveBottomCardsTo("grave", tr("grave"));
|
||||
}
|
||||
|
||||
void PlayerActions::actMoveBottomCardsToExile()
|
||||
{
|
||||
moveBottomCardsTo("rfg", tr("exile"));
|
||||
}
|
||||
|
||||
void PlayerActions::moveBottomCardsTo(const QString &targetZone, const QString &zoneDisplayName)
|
||||
{
|
||||
const int maxCards = player->getDeckZone()->getCards().size();
|
||||
if (maxCards == 0) {
|
||||
|
|
@ -666,12 +624,14 @@ void PlayerActions::actMoveBottomCardsToExile()
|
|||
}
|
||||
|
||||
bool ok;
|
||||
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move bottom cards to exile"),
|
||||
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move bottom cards to %1").arg(zoneDisplayName),
|
||||
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
|
||||
maxCards, 1, &ok);
|
||||
if (!ok) {
|
||||
return;
|
||||
} else if (number > maxCards) {
|
||||
}
|
||||
|
||||
if (number > maxCards) {
|
||||
number = maxCards;
|
||||
}
|
||||
defaultNumberBottomCards = number;
|
||||
|
|
@ -679,7 +639,7 @@ void PlayerActions::actMoveBottomCardsToExile()
|
|||
Command_MoveCard cmd;
|
||||
cmd.set_start_zone("deck");
|
||||
cmd.set_target_player_id(player->getPlayerInfo()->getId());
|
||||
cmd.set_target_zone("rfg");
|
||||
cmd.set_target_zone(targetZone.toStdString());
|
||||
cmd.set_x(0);
|
||||
cmd.set_y(0);
|
||||
|
||||
|
|
|
|||
|
|
@ -180,6 +180,9 @@ private:
|
|||
FilterString movingCardsUntilFilter;
|
||||
int movingCardsUntilCounter = 0;
|
||||
|
||||
void moveTopCardsTo(const QString &targetZone, const QString &zoneDisplayName);
|
||||
void moveBottomCardsTo(const QString &targetZone, const QString &zoneDisplayName);
|
||||
|
||||
void createCard(const CardItem *sourceCard,
|
||||
const QString &dbCardName,
|
||||
CardRelationType attach = CardRelationType::DoesNotAttach,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue