mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 16:24:45 -07:00
Major Directory Refactoring (#5118)
* refactored cardzone.cpp, added doc and changed if to switch case * started moving every files into different folders * remove undercase to match with other files naming convention * refactored dialog files * ran format.sh * refactored client/tabs folder * refactored client/tabs folder * refactored client/tabs folder * refactored client folder * refactored carddbparser * refactored dialogs * Create sonar-project.properties temporary file for lint * Create build.yml temporary file for lint * removed all files from root directory * removed all files from root directory * added current branch to workflow * fixed most broken import * fixed issues while renaming files * fixed oracle importer * fixed dbconverter * updated translations * made sub-folders for client * removed linter * removed linter folder * fixed oracle import * revert card_zone documentation * renamed db parser files name and deck_view imports * fixed dlg file issue * ran format file and fixed test file * fixed carddb test files * moved player folder in game * updated translations and format files * fixed peglib import * format cmake files * removing vcpkg to try to add it back later * tried fixing vcpkg file * renamed filter to filters and moved database parser to cards folder * reverted translation files * reverted oracle translated * Update cockatrice/src/dialogs/dlg_register.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * Update cockatrice/src/client/ui/window_main.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * removed empty line at file start * removed useless include from tab_supervisor.cpp * refactored cardzone.cpp, added doc and changed if to switch case * started moving every files into different folders * remove undercase to match with other files naming convention * refactored dialog files * ran format.sh * refactored client/tabs folder * refactored client folder * refactored carddbparser * refactored dialogs * removed all files from root directory * Create sonar-project.properties temporary file for lint * Create build.yml temporary file for lint * added current branch to workflow * fixed most broken import * fixed issues while renaming files * fixed oracle importer * fixed dbconverter * updated translations * made sub-folders for client * removed linter * removed linter folder * fixed oracle import * revert card_zone documentation * renamed db parser files name and deck_view imports * fixed dlg file issue * ran format file and fixed test file * fixed carddb test files * moved player folder in game * updated translations and format files * fixed peglib import * reverted translation files * format cmake files * removing vcpkg to try to add it back later * tried fixing vcpkg file * pre-updating of cockatrice changes * removed empty line at file start * reverted oracle translated * Update cockatrice/src/dialogs/dlg_register.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * Update cockatrice/src/client/ui/window_main.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * removed useless include from tab_supervisor.cpp --------- Co-authored-by: tooomm <tooomm@users.noreply.github.com>
This commit is contained in:
parent
d1e0f9dfc5
commit
fa999880ee
261 changed files with 735 additions and 729 deletions
198
cockatrice/src/dialogs/dlg_edit_tokens.cpp
Normal file
198
cockatrice/src/dialogs/dlg_edit_tokens.cpp
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
#include "dlg_edit_tokens.h"
|
||||
|
||||
#include "../client/get_text_with_max.h"
|
||||
#include "../game/cards/card_database.h"
|
||||
#include "../game/cards/card_database_model.h"
|
||||
#include "../main.h"
|
||||
#include "trice_limits.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QInputDialog>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QToolBar>
|
||||
#include <QTreeView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
DlgEditTokens::DlgEditTokens(QWidget *parent) : QDialog(parent), currentCard(nullptr)
|
||||
{
|
||||
nameLabel = new QLabel(tr("&Name:"));
|
||||
nameEdit = new QLineEdit;
|
||||
nameEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
nameEdit->setEnabled(false);
|
||||
nameLabel->setBuddy(nameEdit);
|
||||
|
||||
colorLabel = new QLabel(tr("C&olor:"));
|
||||
colorEdit = new QComboBox;
|
||||
colorEdit->addItem(tr("white"), QChar('w'));
|
||||
colorEdit->addItem(tr("blue"), QChar('u'));
|
||||
colorEdit->addItem(tr("black"), QChar('b'));
|
||||
colorEdit->addItem(tr("red"), QChar('r'));
|
||||
colorEdit->addItem(tr("green"), QChar('g'));
|
||||
colorEdit->addItem(tr("multicolor"), QChar('m'));
|
||||
colorEdit->addItem(tr("colorless"), QChar());
|
||||
colorLabel->setBuddy(colorEdit);
|
||||
connect(colorEdit, SIGNAL(currentIndexChanged(int)), this, SLOT(colorChanged(int)));
|
||||
|
||||
ptLabel = new QLabel(tr("&P/T:"));
|
||||
ptEdit = new QLineEdit;
|
||||
ptEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
ptLabel->setBuddy(ptEdit);
|
||||
connect(ptEdit, SIGNAL(textChanged(QString)), this, SLOT(ptChanged(QString)));
|
||||
|
||||
annotationLabel = new QLabel(tr("&Annotation:"));
|
||||
annotationEdit = new QLineEdit;
|
||||
annotationEdit->setMaxLength(MAX_NAME_LENGTH);
|
||||
annotationLabel->setBuddy(annotationEdit);
|
||||
connect(annotationEdit, SIGNAL(textChanged(QString)), this, SLOT(annotationChanged(QString)));
|
||||
|
||||
auto *grid = new QGridLayout;
|
||||
grid->addWidget(nameLabel, 0, 0);
|
||||
grid->addWidget(nameEdit, 0, 1);
|
||||
grid->addWidget(colorLabel, 1, 0);
|
||||
grid->addWidget(colorEdit, 1, 1);
|
||||
grid->addWidget(ptLabel, 2, 0);
|
||||
grid->addWidget(ptEdit, 2, 1);
|
||||
grid->addWidget(annotationLabel, 3, 0);
|
||||
grid->addWidget(annotationEdit, 3, 1);
|
||||
|
||||
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
|
||||
tokenDataGroupBox->setLayout(grid);
|
||||
|
||||
databaseModel = new CardDatabaseModel(db, false, this);
|
||||
databaseModel->setObjectName("databaseModel");
|
||||
cardDatabaseDisplayModel = new TokenEditModel(this);
|
||||
cardDatabaseDisplayModel->setSourceModel(databaseModel);
|
||||
cardDatabaseDisplayModel->setIsToken(CardDatabaseDisplayModel::ShowTrue);
|
||||
|
||||
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()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||
chooseTokenView->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
||||
|
||||
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this,
|
||||
SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
|
||||
|
||||
QAction *aAddToken = new QAction(tr("Add token"), this);
|
||||
aAddToken->setIcon(QPixmap("theme:icons/increment"));
|
||||
connect(aAddToken, SIGNAL(triggered()), this, SLOT(actAddToken()));
|
||||
QAction *aRemoveToken = new QAction(tr("Remove token"), this);
|
||||
aRemoveToken->setIcon(QPixmap("theme:icons/decrement"));
|
||||
connect(aRemoveToken, SIGNAL(triggered()), this, SLOT(actRemoveToken()));
|
||||
|
||||
auto *databaseToolBar = new QToolBar;
|
||||
databaseToolBar->addAction(aAddToken);
|
||||
databaseToolBar->addAction(aRemoveToken);
|
||||
|
||||
auto *leftVBox = new QVBoxLayout;
|
||||
leftVBox->addWidget(chooseTokenView);
|
||||
leftVBox->addWidget(databaseToolBar);
|
||||
|
||||
auto *hbox = new QHBoxLayout;
|
||||
hbox->addLayout(leftVBox);
|
||||
hbox->addWidget(tokenDataGroupBox);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
auto *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(hbox);
|
||||
mainLayout->addWidget(buttonBox);
|
||||
|
||||
setLayout(mainLayout);
|
||||
setWindowTitle(tr("Edit custom tokens"));
|
||||
}
|
||||
|
||||
void DlgEditTokens::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /* previous */)
|
||||
{
|
||||
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
|
||||
|
||||
if (current.row() >= 0) {
|
||||
currentCard = databaseModel->getCard(realIndex.row());
|
||||
} else {
|
||||
currentCard.clear();
|
||||
}
|
||||
|
||||
if (currentCard) {
|
||||
nameEdit->setText(currentCard->getName());
|
||||
const QChar cardColor = currentCard->getColorChar();
|
||||
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
|
||||
ptEdit->setText(currentCard->getPowTough());
|
||||
annotationEdit->setText(currentCard->getText());
|
||||
} else {
|
||||
nameEdit->setText("");
|
||||
colorEdit->setCurrentIndex(colorEdit->findData(QChar(), Qt::UserRole, Qt::MatchFixedString));
|
||||
ptEdit->setText("");
|
||||
annotationEdit->setText("");
|
||||
}
|
||||
}
|
||||
|
||||
void DlgEditTokens::actAddToken()
|
||||
{
|
||||
QString name;
|
||||
for (;;) {
|
||||
name = getTextWithMax(this, tr("Add token"), tr("Please enter the name of the token:"));
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
if (databaseModel->getDatabase()->getCard(name)) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("The chosen name conflicts with an existing card or token.\nMake sure to enable "
|
||||
"the 'Token' set in the \"Manage sets\" dialog to display them correctly."));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString setName = CardDatabase::TOKENS_SETNAME;
|
||||
CardInfoPerSetMap sets;
|
||||
sets.insert(setName, CardInfoPerSet(databaseModel->getDatabase()->getSet(setName)));
|
||||
CardInfoPtr card = CardInfo::newInstance(name, "", true, QVariantHash(), QList<CardRelation *>(),
|
||||
QList<CardRelation *>(), sets, false, -1, false);
|
||||
card->setCardType("Token");
|
||||
|
||||
databaseModel->getDatabase()->addCard(card);
|
||||
}
|
||||
|
||||
void DlgEditTokens::actRemoveToken()
|
||||
{
|
||||
if (currentCard) {
|
||||
CardInfoPtr cardToRemove = currentCard; // the currentCard property gets modified during db->removeCard()
|
||||
currentCard.clear();
|
||||
databaseModel->getDatabase()->removeCard(cardToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
void DlgEditTokens::colorChanged(int colorIndex)
|
||||
{
|
||||
if (currentCard)
|
||||
currentCard->setColors(QString(colorEdit->itemData(colorIndex).toChar()));
|
||||
}
|
||||
|
||||
void DlgEditTokens::ptChanged(const QString &_pt)
|
||||
{
|
||||
if (currentCard)
|
||||
currentCard->setPowTough(_pt);
|
||||
}
|
||||
|
||||
void DlgEditTokens::annotationChanged(const QString &_annotation)
|
||||
{
|
||||
if (currentCard)
|
||||
currentCard->setText(_annotation);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue