2019-06-13 03:20:28 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "wildmoninfo.h"
|
|
|
|
#include "project.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-14 00:36:32 +01:00
|
|
|
// TODO: remove this necessity
|
2019-06-13 03:20:28 +01:00
|
|
|
static QMap<int, QString> landPercentages = QMap<int, QString>({
|
|
|
|
{1, "20"}, {2, "20"},
|
|
|
|
{3, "10"}, {4, "10"}, {5, "10"}, {6, "10"},
|
|
|
|
{7, "5"}, {8, "5"},
|
|
|
|
{9, "4"}, {10, "4"},
|
|
|
|
{11, "1"}, {12, "1"}
|
|
|
|
});
|
|
|
|
|
|
|
|
void clearTabWidget(QLayout *tab) {
|
|
|
|
QLayoutItem *item = tab->itemAt(0);
|
|
|
|
if (item) tab->removeItem(item);
|
|
|
|
}
|
|
|
|
|
2019-06-13 17:14:49 +01:00
|
|
|
void clearTable(QTableWidget *table) {
|
2019-06-14 01:49:28 +01:00
|
|
|
if (table) {
|
|
|
|
table->clear();
|
|
|
|
table->horizontalHeader()->hide();
|
|
|
|
}
|
2019-06-13 17:14:49 +01:00
|
|
|
}
|
|
|
|
|
2019-06-15 23:49:30 +01:00
|
|
|
void createSpeciesTableRow(Project *project, QTableWidget *table, WildPokemon mon, int index, QString fieldName) {
|
2019-06-13 03:20:28 +01:00
|
|
|
//
|
|
|
|
QPixmap monIcon = QPixmap(project->speciesToIconPath.value(mon.species)).copy(0, 0, 32, 32);
|
|
|
|
|
|
|
|
QLabel *monNum = new QLabel(QString("%1.").arg(QString::number(index)));
|
|
|
|
|
|
|
|
QLabel *monLabel = new QLabel();
|
|
|
|
monLabel->setPixmap(monIcon);
|
|
|
|
|
|
|
|
QComboBox *monSelector = new QComboBox;
|
2019-06-14 00:36:32 +01:00
|
|
|
monSelector->setMinimumContentsLength(20);
|
|
|
|
monSelector->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
|
2019-06-13 03:20:28 +01:00
|
|
|
monSelector->addItems(project->speciesToIconPath.keys());
|
|
|
|
monSelector->setCurrentText(mon.species);
|
|
|
|
monSelector->setEditable(true);
|
|
|
|
|
|
|
|
QObject::connect(monSelector, &QComboBox::currentTextChanged, [=](QString newSpecies){
|
|
|
|
QPixmap monIcon = QPixmap(project->speciesToIconPath.value(newSpecies)).copy(0, 0, 32, 32);
|
|
|
|
monLabel->setPixmap(monIcon);
|
|
|
|
});
|
|
|
|
|
|
|
|
QSpinBox *minLevel = new QSpinBox;
|
|
|
|
QSpinBox *maxLevel = new QSpinBox;
|
|
|
|
minLevel->setMinimum(1);
|
|
|
|
minLevel->setMaximum(100);
|
|
|
|
maxLevel->setMinimum(1);
|
|
|
|
maxLevel->setMaximum(100);
|
|
|
|
minLevel->setValue(mon.minLevel);
|
|
|
|
maxLevel->setValue(mon.maxLevel);
|
|
|
|
|
2019-06-15 23:49:30 +01:00
|
|
|
int fieldIndex = 0;
|
|
|
|
for (auto field : project->wildMonFields) {
|
|
|
|
if (field.first == fieldName) break;
|
|
|
|
fieldIndex++;
|
|
|
|
}
|
|
|
|
QLabel *percentLabel = new QLabel(QString("%1%").arg(
|
|
|
|
QString::number(project->wildMonFields[fieldIndex].second[index - 1]
|
|
|
|
)));
|
2019-06-13 03:20:28 +01:00
|
|
|
|
|
|
|
QFrame *speciesSelector = new QFrame;
|
|
|
|
QHBoxLayout *speciesSelectorLayout = new QHBoxLayout;
|
|
|
|
speciesSelectorLayout->addWidget(monLabel);
|
|
|
|
speciesSelectorLayout->addWidget(monSelector);
|
|
|
|
speciesSelector->setLayout(speciesSelectorLayout);
|
|
|
|
|
2019-06-14 00:36:32 +01:00
|
|
|
// prevent the spinboxes from being stupidly tall
|
|
|
|
QFrame *minLevelFrame = new QFrame;
|
|
|
|
QVBoxLayout *minLevelSpinboxLayout = new QVBoxLayout;
|
|
|
|
minLevelSpinboxLayout->addWidget(minLevel);
|
|
|
|
minLevelFrame->setLayout(minLevelSpinboxLayout);
|
|
|
|
QFrame *maxLevelFrame = new QFrame;
|
|
|
|
QVBoxLayout *maxLevelSpinboxLayout = new QVBoxLayout;
|
|
|
|
maxLevelSpinboxLayout->addWidget(maxLevel);
|
|
|
|
maxLevelFrame->setLayout(maxLevelSpinboxLayout);
|
|
|
|
|
|
|
|
// add widgets to the table
|
2019-06-13 03:20:28 +01:00
|
|
|
table->setCellWidget(index - 1, 0, monNum);
|
|
|
|
table->setCellWidget(index - 1, 1, speciesSelector);
|
2019-06-14 00:36:32 +01:00
|
|
|
table->setCellWidget(index - 1, 2, minLevelFrame);
|
|
|
|
table->setCellWidget(index - 1, 3, maxLevelFrame);
|
2019-06-13 03:20:28 +01:00
|
|
|
table->setCellWidget(index - 1, 4, percentLabel);
|
2019-06-20 17:40:36 +01:00
|
|
|
|
|
|
|
// TODO: lock max spinbox to min spinbox
|
2019-06-13 03:20:28 +01:00
|
|
|
}
|
|
|
|
|
2019-06-15 23:49:30 +01:00
|
|
|
void populateWildMonTabWidget(QTabWidget *tabWidget, QVector<QPair<QString, QVector<int>>> fields) {
|
2019-06-20 17:40:36 +01:00
|
|
|
//QPushButton *newTabButton = new QPushButton("Configure JSON...");
|
|
|
|
//QObject::connect(newTabButton, &QPushButton::clicked, [=](){
|
|
|
|
// // TODO
|
|
|
|
// qDebug() << "configure json pressed";
|
|
|
|
//});
|
|
|
|
//tabWidget->setCornerWidget(newTabButton);
|
|
|
|
|
|
|
|
// delete everything in the tab widget here? no
|
2019-06-13 17:14:49 +01:00
|
|
|
|
2019-06-15 23:49:30 +01:00
|
|
|
for (QPair<QString, QVector<int>> field : fields) {
|
2019-06-14 00:36:32 +01:00
|
|
|
QTableWidget *table = new QTableWidget;
|
|
|
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
table->setFocusPolicy(Qt::NoFocus);
|
|
|
|
table->setSelectionMode(QAbstractItemView::NoSelection);
|
2019-06-14 01:49:28 +01:00
|
|
|
table->clearFocus();
|
2019-06-15 23:49:30 +01:00
|
|
|
tabWidget->addTab(table, field.first);
|
2019-06-13 17:14:49 +01:00
|
|
|
}
|
|
|
|
}
|