merged with master

This commit is contained in:
Fabio Bas 2015-08-31 22:48:14 +02:00
commit 5cfb034452
416 changed files with 65983 additions and 19400 deletions

View file

@ -96,6 +96,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
shortcutsActive(false),
defaultNumberTopCards(1),
lastTokenDestroy(true),
lastTokenTableRow(0),
id(_id),
active(false),
local(_local),
@ -408,11 +409,14 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
aMoveToBottomLibrary = new QAction(this);
aMoveToBottomLibrary->setData(cmMoveToBottomLibrary);
aMoveToGraveyard = new QAction(this);
aMoveToHand = new QAction(this);
aMoveToHand->setData(cmMoveToHand);
aMoveToGraveyard->setData(cmMoveToGraveyard);
aMoveToExile = new QAction(this);
aMoveToExile->setData(cmMoveToExile);
connect(aMoveToTopLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToBottomLibrary, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToHand, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToGraveyard, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
connect(aMoveToExile, SIGNAL(triggered()), this, SLOT(cardMenuAction()));
@ -444,6 +448,8 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
rearrangeZones();
retranslateUi();
connect(&settingsCache->shortcuts(), SIGNAL(shortCutchanged()),this,SLOT(refreshShortcuts()));
refreshShortcuts();
}
Player::~Player()
@ -606,6 +612,7 @@ void Player::retranslateUi()
{
aViewGraveyard->setText(tr("&View graveyard"));
aViewRfg->setText(tr("&View exile"));
playerMenu->setTitle(tr("Player \"%1\"").arg(QString::fromStdString(userInfo->name())));
graveMenu->setTitle(tr("&Graveyard"));
rfgMenu->setTitle(tr("&Exile"));
@ -670,53 +677,49 @@ void Player::retranslateUi()
for (int i = 0; i < allPlayersActions.size(); ++i)
allPlayersActions[i]->setText(tr("&All players"));
}
aPlay->setText(tr("&Play"));
aHide->setText(tr("&Hide"));
aPlayFacedown->setText(tr("Play &Face Down"));
aTap->setText(tr("&Tap"));
aUntap->setText(tr("&Untap"));
aDoesntUntap->setText(tr("Toggle &normal untapping"));
aFlip->setText(tr("&Flip"));
aPeek->setText(tr("&Peek at card face"));
aClone->setText(tr("&Clone"));
aClone->setShortcut(QKeySequence("Ctrl+J"));
aAttach->setText(tr("Attac&h to card..."));
aAttach->setShortcut(QKeySequence("Ctrl+A"));
aUnattach->setText(tr("Unattac&h"));
aDrawArrow->setText(tr("&Draw arrow..."));
aIncP->setText(tr("&Increase power"));
aIncP->setShortcut(QKeySequence("Ctrl++"));
aDecP->setText(tr("&Decrease power"));
aDecP->setShortcut(QKeySequence("Ctrl+-"));
aIncT->setText(tr("I&ncrease toughness"));
aIncT->setShortcut(QKeySequence("Alt++"));
aDecT->setText(tr("D&ecrease toughness"));
aDecT->setShortcut(QKeySequence("Alt+-"));
aIncPT->setText(tr("In&crease power and toughness"));
aIncPT->setShortcut(QKeySequence("Ctrl+Alt++"));
aDecPT->setText(tr("Dec&rease power and toughness"));
aDecPT->setShortcut(QKeySequence("Ctrl+Alt+-"));
aSetPT->setText(tr("Set &power and toughness..."));
aSetPT->setShortcut(QKeySequence("Ctrl+P"));
aSetAnnotation->setText(tr("&Set annotation..."));
QStringList counterColors;
counterColors.append(tr("Red"));
counterColors.append(tr("Yellow"));
counterColors.append(tr("Green"));
for (int i = 0; i < aAddCounter.size(); ++i)
for (int i = 0; i < aAddCounter.size(); ++i){
aAddCounter[i]->setText(tr("&Add counter (%1)").arg(counterColors[i]));
for (int i = 0; i < aRemoveCounter.size(); ++i)
}
for (int i = 0; i < aRemoveCounter.size(); ++i){
aRemoveCounter[i]->setText(tr("&Remove counter (%1)").arg(counterColors[i]));
for (int i = 0; i < aSetCounter.size(); ++i)
}
for (int i = 0; i < aSetCounter.size(); ++i){
aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(counterColors[i]));
}
aMoveToTopLibrary->setText(tr("&Top of library"));
aMoveToBottomLibrary->setText(tr("&Bottom of library"));
aMoveToHand->setText(tr("&Hand"));
aMoveToGraveyard->setText(tr("&Graveyard"));
aMoveToGraveyard->setShortcut(QKeySequence("Ctrl+Del"));
aMoveToExile->setText(tr("&Exile"));
QMapIterator<QString, CardZone *> zoneIterator(zones);
while (zoneIterator.hasNext())
zoneIterator.next().value()->retranslateUi();
@ -726,24 +729,73 @@ void Player::setShortcutsActive()
{
shortcutsActive = true;
aViewSideboard->setShortcut(QKeySequence("Ctrl+F3"));
aViewLibrary->setShortcut(QKeySequence("F3"));
aViewTopCards->setShortcut(QKeySequence("Ctrl+W"));
aViewGraveyard->setShortcut(QKeySequence("F4"));
aDrawCard->setShortcut(QKeySequence("Ctrl+D"));
aDrawCards->setShortcut(QKeySequence("Ctrl+E"));
aUndoDraw->setShortcut(QKeySequence("Ctrl+Shift+D"));
aMulligan->setShortcut(QKeySequence("Ctrl+M"));
aShuffle->setShortcut(QKeySequence("Ctrl+S"));
aUntapAll->setShortcut(QKeySequence("Ctrl+U"));
aRollDie->setShortcut(QKeySequence("Ctrl+I"));
aCreateToken->setShortcut(QKeySequence("Ctrl+T"));
aCreateAnotherToken->setShortcut(QKeySequence("Ctrl+G"));
aAlwaysRevealTopCard->setShortcut(QKeySequence("Ctrl+N"));
aPlay->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aPlay"));
aTap->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aTap"));
aUntap->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aUntap"));
aDoesntUntap->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aDoesntUntap"));
aFlip->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aFlip"));
aPeek->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aPeek"));
aClone->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aClone"));
aAttach->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aAttach"));
aUnattach->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aUnattach"));
aDrawArrow->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aDrawArrow"));
aIncP->setShortcuts(settingsCache->shortcuts().getShortcut("Player/IncP"));
aDecP->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aDecP"));
aIncT->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aIncT"));
aDecT->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aDecT"));
aIncPT->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aIncPT"));
aDecPT->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aDecPT"));
aSetPT->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aSetPT"));
aSetAnnotation->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aSetAnnotation"));
aMoveToTopLibrary->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aMoveToTopLibrary"));
aMoveToBottomLibrary->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aMoveToBottomLibrary"));
aMoveToHand->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aMoveToHand"));
aMoveToGraveyard->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aMoveToGraveyard"));
aMoveToExile->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aMoveToExile"));
QList<QKeySequence> addCCShortCuts;
addCCShortCuts.append(settingsCache->shortcuts().getSingleShortcut("Player/aCCRed"));
addCCShortCuts.append(settingsCache->shortcuts().getSingleShortcut("Player/aCCYellow"));
addCCShortCuts.append(settingsCache->shortcuts().getSingleShortcut("Player/aCCGreen"));
QList<QKeySequence> removeCCShortCuts;
removeCCShortCuts.append(settingsCache->shortcuts().getSingleShortcut("Player/aRCRed"));
removeCCShortCuts.append(settingsCache->shortcuts().getSingleShortcut("Player/aRCYellow"));
removeCCShortCuts.append(settingsCache->shortcuts().getSingleShortcut("Player/aRCGreen"));
QList<QKeySequence> setCCShortCuts;
setCCShortCuts.append(settingsCache->shortcuts().getSingleShortcut("Player/aSCRed"));
setCCShortCuts.append(settingsCache->shortcuts().getSingleShortcut("Player/aSCYellow"));
setCCShortCuts.append(settingsCache->shortcuts().getSingleShortcut("Player/aSCGreen"));
for (int i = 0; i < aAddCounter.size(); ++i){
aAddCounter[i]->setShortcut(addCCShortCuts.at(i));
}
for (int i = 0; i < aRemoveCounter.size(); ++i){
aRemoveCounter[i]->setShortcut(removeCCShortCuts.at(i));
}
for (int i = 0; i < aSetCounter.size(); ++i){
aSetCounter[i]->setShortcut(setCCShortCuts.at(i));
}
QMapIterator<int, AbstractCounter *> counterIterator(counters);
while (counterIterator.hasNext())
counterIterator.next().value()->setShortcutsActive();
aViewSideboard->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aViewSideboard"));
aViewLibrary->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aViewLibrary"));
aViewTopCards->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aViewTopCards"));
aViewGraveyard->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aViewGraveyard"));
aDrawCard->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aDrawCard"));
aDrawCards->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aDrawCards"));
aUndoDraw->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aUndoDraw"));
aMulligan->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aMulligan"));
aShuffle->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aShuffle"));
aUntapAll->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aUntapAll"));
aRollDie->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aRollDie"));
aCreateToken->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aCreateToken"));
aCreateAnotherToken->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aCreateAnotherToken"));
aAlwaysRevealTopCard->setShortcut(settingsCache->shortcuts().getSingleShortcut("Player/aAlwaysRevealTopCard"));
}
void Player::setShortcutsInactive()
@ -777,10 +829,12 @@ void Player::initSayMenu()
QSettings settings;
settings.beginGroup("messages");
int count = settings.value("count", 0).toInt();
for (int i = 0; i < count; i++) {
QAction *newAction = new QAction(settings.value(QString("msg%1").arg(i)).toString(), this);
if (i <= 10)
newAction->setShortcut(QKeySequence(QString("Ctrl+%1").arg((i + 1) % 10)));
if (i <= 10){
newAction->setShortcut(QKeySequence("Ctrl+" + QString::number((i + 1) % 10)));
}
connect(newAction, SIGNAL(triggered()), this, SLOT(actSayMessage()));
sayMenu->addAction(newAction);
}
@ -794,13 +848,16 @@ void Player::setDeck(const DeckLoader &_deck)
createPredefinedTokenMenu->clear();
predefinedTokens.clear();
InnerDecklistNode *tokenZone = dynamic_cast<InnerDecklistNode *>(deck->getRoot()->findChild("tokens"));
if (tokenZone)
for (int i = 0; i < tokenZone->size(); ++i) {
const QString tokenName = tokenZone->at(i)->getName();
predefinedTokens.append(tokenName);
QAction *a = createPredefinedTokenMenu->addAction(tokenName);
if (i < 10)
{
a->setShortcut(QKeySequence("Alt+" + QString::number((i + 1) % 10)));
}
connect(a, SIGNAL(triggered()), this, SLOT(actCreatePredefinedToken()));
}
}
@ -1029,6 +1086,7 @@ void Player::actCreateToken()
lastTokenPT = dlg.getPT();
if (CardInfo *correctedCard = db->getCardBySimpleName(lastTokenName, false)) {
lastTokenName = correctedCard->getName();
lastTokenTableRow = table->clampValidTableRow(2 - correctedCard->getTableRow());
if (lastTokenPT.isEmpty())
lastTokenPT = correctedCard->getPowTough();
}
@ -1050,7 +1108,7 @@ void Player::actCreateAnotherToken()
cmd.set_annotation(lastTokenAnnotation.toStdString());
cmd.set_destroy_on_zone_change(lastTokenDestroy);
cmd.set_x(-1);
cmd.set_y(0);
cmd.set_y(lastTokenTableRow);
sendGameCommand(cmd);
}
@ -1063,13 +1121,39 @@ void Player::actCreatePredefinedToken()
lastTokenName = cardInfo->getName();
lastTokenColor = cardInfo->getColors().isEmpty() ? QString() : cardInfo->getColors().first().toLower();
lastTokenPT = cardInfo->getPowTough();
lastTokenAnnotation = cardInfo->getText();
lastTokenAnnotation = settingsCache->getAnnotateTokens() ? cardInfo->getText() : "";
lastTokenTableRow = table->clampValidTableRow(2 - cardInfo->getTableRow());
lastTokenDestroy = true;
aCreateAnotherToken->setEnabled(true);
actCreateAnotherToken();
}
void Player::actCreateRelatedCard()
{
// get the clicked card
CardItem * sourceCard = game->getActiveCard();
if(!sourceCard)
return;
// get the target card name
QAction *action = static_cast<QAction *>(sender());
CardInfo *cardInfo = db->getCard(action->text());
// create the token for the related card
Command_CreateToken cmd;
cmd.set_zone("table");
cmd.set_card_name(cardInfo->getName().toStdString());
cmd.set_color(cardInfo->getColors().isEmpty() ? QString().toStdString() : cardInfo->getColors().first().toLower().toStdString());
cmd.set_pt(cardInfo->getPowTough().toStdString());
cmd.set_annotation(settingsCache->getAnnotateTokens() ? cardInfo->getText().toStdString() : QString().toStdString());
cmd.set_destroy_on_zone_change(true);
cmd.set_target_zone(sourceCard->getZone()->getName().toStdString());
cmd.set_target_card_id(sourceCard->getId());
sendGameCommand(cmd);
}
void Player::actSayMessage()
{
QAction *a = qobject_cast<QAction *>(sender());
@ -1627,7 +1711,7 @@ void Player::playCard(CardItem *c, bool faceDown, bool tapped)
cmd.set_y(0);
} else {
int tableRow = faceDown ? 2 : ci->getTableRow();
QPoint gridPoint = QPoint(-1, 2 - tableRow);
QPoint gridPoint = QPoint(-1, table->clampValidTableRow(2 - tableRow));
cardToMove->set_face_down(faceDown);
cardToMove->set_pt(ci->getPowTough().toStdString());
cardToMove->set_tapped(faceDown ? false : tapped);
@ -1926,6 +2010,18 @@ void Player::cardMenuAction()
commandList.append(cmd);
break;
}
case cmMoveToHand: {
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("hand");
cmd->set_x(0);
cmd->set_y(0);
commandList.append(cmd);
break;
}
case cmMoveToGraveyard: {
Command_MoveCard *cmd = new Command_MoveCard;
cmd->set_start_player_id(startPlayerId);
@ -2188,6 +2284,12 @@ void Player::actPlayFacedown()
playCard(game->getActiveCard(), true, false);
}
void Player::refreshShortcuts()
{
if(shortcutsActive)
setShortcutsActive();
}
void Player::updateCardMenu(CardItem *card)
{
QMenu *cardMenu = card->getCardMenu();
@ -2215,6 +2317,8 @@ void Player::updateCardMenu(CardItem *card)
moveMenu->addAction(aMoveToTopLibrary);
moveMenu->addAction(aMoveToBottomLibrary);
moveMenu->addSeparator();
moveMenu->addAction(aMoveToHand);
moveMenu->addSeparator();
moveMenu->addAction(aMoveToGraveyard);
moveMenu->addSeparator();
moveMenu->addAction(aMoveToExile);
@ -2241,6 +2345,17 @@ void Player::updateCardMenu(CardItem *card)
cardMenu->addAction(aFlip);
if (card->getFaceDown())
cardMenu->addAction(aPeek);
QStringList relatedCards = card->getInfo()->getRelatedCards();
if(relatedCards.size())
{
QMenu * createRelatedCardMenu = cardMenu->addMenu(tr("Cr&eate related card"));
for (int i = 0; i < relatedCards.size(); ++i) {
QAction *a = createRelatedCardMenu->addAction(relatedCards.at(i));
connect(a, SIGNAL(triggered()), this, SLOT(actCreateRelatedCard()));
}
}
cardMenu->addSeparator();
cardMenu->addAction(aAttach);
if (card->getAttachedTo())
@ -2326,6 +2441,7 @@ void Player::setMirrored(bool _mirrored)
void Player::processSceneSizeChange(int newPlayerWidth)
{
// Extend table (and hand, if horizontal) to accomodate the new player width.
qreal tableWidth = newPlayerWidth - CARD_HEIGHT - 15 - counterAreaWidth - stack->boundingRect().width();
if (!settingsCache->getHorizontalHand())
tableWidth -= hand->boundingRect().width();