improved token dialog w/ storage inside the deck list - now we need a reliable online source for token data (preferably with pictures)

This commit is contained in:
Max-Wilhelm Bruker 2012-04-06 15:16:52 +02:00
parent f553fd7456
commit 12b5e39440
7 changed files with 121 additions and 17 deletions

View file

@ -80,7 +80,7 @@ CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
{
CardInfo *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
if (((isToken == ShowTrue) && !info->getIsToken()) || (isToken == ShowFalse) && info->getIsToken())
return false;
@ -88,11 +88,15 @@ bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex
if (!cardNameBeginning.isEmpty())
if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive))
return false;
if (!cardName.isEmpty())
if (!info->getName().contains(cardName, Qt::CaseInsensitive))
return false;
if (!cardNameSet.isEmpty())
if (!cardNameSet.contains(info->getName()))
return false;
if (!cardText.isEmpty())
if (!info->getText().contains(cardText, Qt::CaseInsensitive))
return false;

View file

@ -16,7 +16,7 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
CardInfo *getCard(int index) const { return cardList[index]; }
CardInfo const *getCard(int index) const { return cardList[index]; }
private:
QList<CardInfo *> cardList;
CardDatabase *db;
@ -31,12 +31,13 @@ public:
private:
FilterBool isToken;
QString cardNameBeginning, cardName, cardText;
QSet<QString> cardTypes, cardColors;
QSet<QString> cardNameSet, cardTypes, cardColors;
public:
CardDatabaseDisplayModel(QObject *parent = 0);
void setIsToken(FilterBool _isToken) { isToken = _isToken; invalidate(); }
void setCardNameBeginning(const QString &_beginning) { cardNameBeginning = _beginning; invalidate(); }
void setCardName(const QString &_cardName) { cardName = _cardName; invalidate(); }
void setCardNameSet(const QSet<QString> &_cardNameSet) { cardNameSet = _cardNameSet; invalidate(); }
void setCardText(const QString &_cardText) { cardText = _cardText; invalidate(); }
void setCardTypes(const QSet<QString> &_cardTypes) { cardTypes = _cardTypes; invalidate(); }
void setCardColors(const QSet<QString> &_cardColors) { cardColors = _cardColors; invalidate(); }

View file

@ -9,13 +9,14 @@
#include <QGroupBox>
#include <QTreeView>
#include <QRadioButton>
#include <QHeaderView>
#include "decklist.h"
#include "dlg_create_token.h"
#include "carddatabasemodel.h"
#include "main.h"
DlgCreateToken::DlgCreateToken(DeckList *_deck, QWidget *parent)
: QDialog(parent)
DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent)
: QDialog(parent), predefinedTokens(_predefinedTokens)
{
nameLabel = new QLabel(tr("&Name:"));
nameEdit = new QLineEdit(tr("Token"));
@ -30,7 +31,7 @@ DlgCreateToken::DlgCreateToken(DeckList *_deck, QWidget *parent)
colorEdit->addItem(tr("red"), "r");
colorEdit->addItem(tr("green"), "g");
colorEdit->addItem(tr("multicolor"), "m");
colorEdit->addItem(tr("colorless"), "");
colorEdit->addItem(tr("colorless"), QString());
colorLabel->setBuddy(colorEdit);
ptLabel = new QLabel(tr("&P/T:"));
@ -63,10 +64,31 @@ DlgCreateToken::DlgCreateToken(DeckList *_deck, QWidget *parent)
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
QRadioButton *chooseTokenFromAllRadioButton = new QRadioButton(tr("Show &all tokens"));
QRadioButton *chooseTokenFromDeckRadioButton = new QRadioButton(tr("Show tokens from this &deck"));
chooseTokenFromAllRadioButton = new QRadioButton(tr("Show &all tokens"));
connect(chooseTokenFromAllRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromAll(bool)));
chooseTokenFromDeckRadioButton = new QRadioButton(tr("Show tokens from this &deck"));
connect(chooseTokenFromDeckRadioButton, SIGNAL(toggled(bool)), this, SLOT(actChooseTokenFromDeck(bool)));
QTreeView *chooseTokenView = new QTreeView;
chooseTokenView->setModel(cardDatabaseDisplayModel);
chooseTokenView->setUniformRowHeights(true);
chooseTokenView->setRootIsDecorated(false);
chooseTokenView->setAlternatingRowColors(true);
chooseTokenView->setSortingEnabled(true);
chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
chooseTokenView->resizeColumnToContents(0);
chooseTokenView->header()->setStretchLastSection(false);
chooseTokenView->header()->hideSection(1);
chooseTokenView->header()->hideSection(2);
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
if (predefinedTokens.isEmpty())
chooseTokenFromAllRadioButton->setChecked(true);
else {
chooseTokenFromDeckRadioButton->setChecked(true);
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
}
QVBoxLayout *tokenChooseLayout = new QVBoxLayout;
tokenChooseLayout->addWidget(chooseTokenFromAllRadioButton);
@ -76,8 +98,12 @@ DlgCreateToken::DlgCreateToken(DeckList *_deck, QWidget *parent)
QGroupBox *tokenChooseGroupBox = new QGroupBox(tr("Choose token from list"));
tokenChooseGroupBox->setLayout(tokenChooseLayout);
QVBoxLayout *leftVBox = new QVBoxLayout;
leftVBox->addWidget(tokenDataGroupBox);
leftVBox->addStretch();
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(tokenDataGroupBox);
hbox->addLayout(leftVBox);
hbox->addWidget(tokenChooseGroupBox);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
@ -94,6 +120,30 @@ DlgCreateToken::DlgCreateToken(DeckList *_deck, QWidget *parent)
setMinimumWidth(300);
}
void DlgCreateToken::tokenSelectionChanged(const QModelIndex &current, const QModelIndex & /*previous*/)
{
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
const CardInfo *cardInfo = cardDatabaseModel->getCard(realIndex.row());
nameEdit->setText(cardInfo->getName());
const QString cardColor = cardInfo->getColors().isEmpty() ? QString() : (cardInfo->getColors().size() > 1 ? QString("m") : cardInfo->getColors().first());
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
ptEdit->setText(cardInfo->getPowTough());
annotationEdit->setText(cardInfo->getText());
}
void DlgCreateToken::actChooseTokenFromAll(bool checked)
{
if (checked)
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>());
}
void DlgCreateToken::actChooseTokenFromDeck(bool checked)
{
if (checked)
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
}
void DlgCreateToken::actOk()
{
accept();

View file

@ -2,12 +2,14 @@
#define DLG_CREATETOKEN_H
#include <QDialog>
#include <QLineEdit>
#include <QModelIndex>
class QLabel;
class QLineEdit;
class QComboBox;
class QCheckBox;
class QPushButton;
class QRadioButton;
class DeckList;
class CardDatabaseModel;
class CardDatabaseDisplayModel;
@ -15,21 +17,26 @@ class CardDatabaseDisplayModel;
class DlgCreateToken : public QDialog {
Q_OBJECT
public:
DlgCreateToken(DeckList *_deck, QWidget *parent = 0);
DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent = 0);
QString getName() const;
QString getColor() const;
QString getPT() const;
QString getAnnotation() const;
bool getDestroy() const;
private slots:
void tokenSelectionChanged(const QModelIndex &current, const QModelIndex &previous);
void actChooseTokenFromAll(bool checked);
void actChooseTokenFromDeck(bool checked);
void actOk();
private:
CardDatabaseModel *cardDatabaseModel;
CardDatabaseDisplayModel *cardDatabaseDisplayModel;
QStringList predefinedTokens;
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
QComboBox *colorEdit;
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
QCheckBox *destroyCheckBox;
QRadioButton *chooseTokenFromAllRadioButton, *chooseTokenFromDeckRadioButton;
};
#endif

View file

@ -18,6 +18,8 @@
#include "dlg_create_token.h"
#include "carddatabase.h"
#include "color.h"
#include "decklist.h"
#include "main.h"
#include <QSettings>
#include <QPainter>
#include <QMenu>
@ -307,6 +309,8 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
aCreateAnotherToken = new QAction(this);
connect(aCreateAnotherToken, SIGNAL(triggered()), this, SLOT(actCreateAnotherToken()));
aCreateAnotherToken->setEnabled(false);
createPredefinedTokenMenu = new QMenu(QString());
playerMenu->addSeparator();
countersMenu = playerMenu->addMenu(QString());
@ -317,6 +321,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
playerMenu->addSeparator();
playerMenu->addAction(aCreateToken);
playerMenu->addAction(aCreateAnotherToken);
playerMenu->addMenu(createPredefinedTokenMenu);
playerMenu->addSeparator();
sayMenu = playerMenu->addMenu(QString());
initSayMenu();
@ -332,11 +337,11 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
allPlayersActions.append(newAction);
playerLists[i]->addSeparator();
}
} else {
countersMenu = 0;
sbMenu = 0;
aCreateAnotherToken = 0;
createPredefinedTokenMenu = 0;
aCardMenu = 0;
}
@ -611,6 +616,7 @@ void Player::retranslateUi()
aRollDie->setText(tr("R&oll die..."));
aCreateToken->setText(tr("&Create token..."));
aCreateAnotherToken->setText(tr("C&reate another token"));
createPredefinedTokenMenu->setTitle(tr("Cr&eate predefined token"));
sayMenu->setTitle(tr("S&ay"));
QMapIterator<int, AbstractCounter *> counterIterator(counters);
@ -735,6 +741,24 @@ void Player::initSayMenu()
}
}
void Player::setDeck(DeckList *_deck)
{
deck = _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("Alt+" + QString::number((i + 1) % 10));
connect(a, SIGNAL(triggered()), this, SLOT(actCreatePredefinedToken()));
}
}
void Player::actViewLibrary()
{
static_cast<GameScene *>(scene())->toggleZoneView(this, "deck", -1);
@ -888,7 +912,7 @@ void Player::actRollDie()
void Player::actCreateToken()
{
DlgCreateToken dlg(deck);
DlgCreateToken dlg(predefinedTokens);
if (!dlg.exec())
return;
@ -917,6 +941,21 @@ void Player::actCreateAnotherToken()
sendGameCommand(cmd);
}
void Player::actCreatePredefinedToken()
{
QAction *action = static_cast<QAction *>(sender());
CardInfo *cardInfo = db->getCard(action->text());
lastTokenName = cardInfo->getName();
lastTokenColor = cardInfo->getColors().isEmpty() ? QString() : cardInfo->getColors().first();
lastTokenPT = cardInfo->getPowTough();
lastTokenAnnotation = cardInfo->getText();
lastTokenDestroy = true;
aCreateAnotherToken->setEnabled(true);
actCreateAnotherToken();
}
void Player::actSayMessage()
{
QAction *a = qobject_cast<QAction *>(sender());

View file

@ -134,6 +134,7 @@ private slots:
void updateBoundingRect();
void rearrangeZones();
void actCreatePredefinedToken();
void cardMenuAction();
void actCardCounterTrigger();
void actAttach();
@ -153,7 +154,7 @@ private slots:
private:
TabGame *game;
QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *countersMenu, *sayMenu,
QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu,
*mRevealLibrary, *mRevealTopCard, *mRevealHand, *mRevealRandomHandCard;
QList<QMenu *> playerLists;
QList<QAction *> allPlayersActions;
@ -189,6 +190,8 @@ private:
QList<CardItem *> cardsToDelete;
DeckList *deck;
QStringList predefinedTokens;
PlayerArea *playerArea;
QMap<QString, CardZone *> zones;
StackZone *stack;
@ -258,8 +261,7 @@ public:
void retranslateUi();
void clear();
TabGame *getGame() const { return game; }
DeckList *getDeck() const { return deck; }
void setDeck(DeckList *_deck) { deck = _deck; }
void setDeck(DeckList *_deck);
QMenu *getPlayerMenu() const { return playerMenu; }
int getId() const { return id; }
QString getName() const;

View file

@ -935,6 +935,7 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event, int /*e
DeckList *newDeck = new DeckList(QString::fromStdString(playerInfo.deck_list()));
db->cacheCardPixmaps(newDeck->getCardList());
deckViewContainer->setDeck(newDeck);
player->setDeck(newDeck);
}
deckViewContainer->setReadyStart(prop.ready_start());
deckViewContainer->setSideboardLocked(prop.sideboard_locked());