speed up combobox load for wild mons
This commit is contained in:
parent
3f9ad3afbb
commit
ce002bcb4d
3 changed files with 41 additions and 152 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
|
||||
|
||||
// TODO: remove this necessity
|
||||
static QMap<int, QString> landPercentages = QMap<int, QString>({
|
||||
{1, "20"}, {2, "20"},
|
||||
{3, "10"}, {4, "10"}, {5, "10"}, {6, "10"},
|
||||
|
@ -25,12 +26,6 @@ void clearTable(QTableWidget *table) {
|
|||
|
||||
void createSpeciesTableRow(Project *project, QTableWidget *table, WildPokemon mon, int index) {
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
//QHBoxLayout *speciesHBox = new QHBoxLayout;
|
||||
//QTableWidgetItem *monItem = new QTableWidgetItem();
|
||||
|
||||
QPixmap monIcon = QPixmap(project->speciesToIconPath.value(mon.species)).copy(0, 0, 32, 32);
|
||||
|
||||
QLabel *monNum = new QLabel(QString("%1.").arg(QString::number(index)));
|
||||
|
@ -39,6 +34,8 @@ void createSpeciesTableRow(Project *project, QTableWidget *table, WildPokemon mo
|
|||
monLabel->setPixmap(monIcon);
|
||||
|
||||
QComboBox *monSelector = new QComboBox;
|
||||
monSelector->setMinimumContentsLength(20);
|
||||
monSelector->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
|
||||
monSelector->addItems(project->speciesToIconPath.keys());
|
||||
monSelector->setCurrentText(mon.species);
|
||||
monSelector->setEditable(true);
|
||||
|
@ -66,73 +63,37 @@ void createSpeciesTableRow(Project *project, QTableWidget *table, WildPokemon mo
|
|||
speciesSelectorLayout->addWidget(monSelector);
|
||||
speciesSelector->setLayout(speciesSelectorLayout);
|
||||
|
||||
// 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
|
||||
table->setCellWidget(index - 1, 0, monNum);
|
||||
table->setCellWidget(index - 1, 1, speciesSelector);
|
||||
//table->setCellWidget(index, 1, monLabel);
|
||||
//table->setCellWidget(index, 2, monSelector);
|
||||
table->setCellWidget(index - 1, 2, minLevel);
|
||||
table->setCellWidget(index - 1, 3, maxLevel);
|
||||
table->setCellWidget(index - 1, 2, minLevelFrame);
|
||||
table->setCellWidget(index - 1, 3, maxLevelFrame);
|
||||
table->setCellWidget(index - 1, 4, percentLabel);
|
||||
}
|
||||
|
||||
// tabWidget_WildMons
|
||||
void populateWildMonTabWidget(QTabWidget *tabWidget, QVector<QString> fields) {
|
||||
//
|
||||
QPushButton *newTabButton = new QPushButton("New Field");
|
||||
QPushButton *newTabButton = new QPushButton("Configure JSON...");
|
||||
QObject::connect(newTabButton, &QPushButton::clicked, [=](){
|
||||
qDebug() << "new field pressed";
|
||||
// TODO
|
||||
qDebug() << "configure json pressed";
|
||||
});
|
||||
tabWidget->setCornerWidget(newTabButton);
|
||||
|
||||
// change this to for each entry in header
|
||||
//if (true) {//header.landMons.active) {
|
||||
for (QString field : fields) {
|
||||
//
|
||||
tabWidget->addTab(new QTableWidget(), field);
|
||||
QTableWidget *table = new QTableWidget;
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
table->setFocusPolicy(Qt::NoFocus);
|
||||
table->setSelectionMode(QAbstractItemView::NoSelection);
|
||||
tabWidget->addTab(table, field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -155,59 +155,34 @@ void Editor::setEditingWildMons() {
|
|||
}
|
||||
|
||||
void Editor::displayWildMonTables() {
|
||||
// clear the current layout
|
||||
//
|
||||
// move to loadMap? no because loadMap calls this anyways if it's open
|
||||
// clear tables
|
||||
//int tabIndex = 0;
|
||||
//for (; tabIndex < project->wildMonFields.size(); tabIndex++) {
|
||||
// QTableWidget *speciesTable = static_cast<QTableWidget *>(ui->tabWidget_WildMons->widget(tabIndex));
|
||||
// clearTable(speciesTable);
|
||||
//}
|
||||
|
||||
if (!project->wildMonData.contains(map->constantName)) return;
|
||||
|
||||
//return;// TODO: REMOVE!
|
||||
|
||||
//QFrame *landMonFrame = ui->frame_LandMonInfo;
|
||||
|
||||
//QTabWidget *tabWidgetWildMons = ui->tabWidget_WildMons;
|
||||
|
||||
//QLayout *landMonTab = ui->tabWidget_WildMons->widget(0)->layout();//new QGridLayout(ui->tabWidget_WildMons->findChild<QTabWidget *>("land_mons"));
|
||||
//ui->tabWidget_WildMons->widget(0)->layout();
|
||||
//findChild<QTabWidget *>("land_mons")->layout();
|
||||
//tabWidgetWildMons->widget(0)->layout();
|
||||
//ui->tab_LandMons->layout();
|
||||
|
||||
//if (!landMonTab) qDebug() << "landMonTab is nullptr!";
|
||||
|
||||
//return;
|
||||
|
||||
//QTableWidget *landMonTable = static_cast<QTableWidget *>(ui->tabWidget_WildMons->widget(0));//landMonTab->findChild<QTableWidget *>();//ui->tabWidget_WildMons->findChild<QTabWidget *>("land_mons");
|
||||
//new QTableWidget;//ui->tableWidget_RockSmashMonInfo;
|
||||
|
||||
//return;
|
||||
|
||||
//clearTabWidget(landMonTab);
|
||||
//clearTable(landMonTable);
|
||||
|
||||
//QGridLayout *gridLayout = new QGridLayout(landMonFrame);
|
||||
//landMonTab->addWidget(landMonTable);
|
||||
|
||||
//if (!landMonTable)
|
||||
|
||||
//for (auto mon : project->wildMonData.value(map->constantName))
|
||||
WildPokemonHeader header = project->wildMonData.value(map->constantName);
|
||||
|
||||
//QString field = "land_mons";
|
||||
|
||||
int tabIndex = 0;
|
||||
for (QString field : project->wildMonFields) {
|
||||
QTableWidget *speciesTable = static_cast<QTableWidget *>(ui->tabWidget_WildMons->widget(tabIndex));
|
||||
QTableWidget *speciesTable = static_cast<QTableWidget *>(ui->tabWidget_WildMons->widget(tabIndex++));
|
||||
clearTable(speciesTable);
|
||||
if (header.wildMons[field].active) {//header.landMons.active) { // else,
|
||||
//speciesTable->setFocusPolicy(Qt::NoFocus);
|
||||
if (!project->wildMonData.contains(map->constantName)) continue;
|
||||
|
||||
if (header.wildMons[field].active) {//else,
|
||||
int i = 1;
|
||||
|
||||
speciesTable->setRowCount(header.wildMons[field].wildPokemon.size());
|
||||
speciesTable->setColumnCount(5);// + 1 for last column stretch
|
||||
speciesTable->setColumnCount(5);// + 1 for last column stretch?
|
||||
|
||||
QStringList landMonTableHeaders;
|
||||
landMonTableHeaders << "Index" << "Species" << "Min Level" << "Max Level" << "Catch Percentage";
|
||||
speciesTable->setHorizontalHeaderLabels(landMonTableHeaders);
|
||||
speciesTable->horizontalHeader()->show();
|
||||
speciesTable->verticalHeader()->hide();
|
||||
speciesTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
speciesTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
|
@ -218,8 +193,10 @@ void Editor::displayWildMonTables() {
|
|||
createSpeciesTableRow(project, speciesTable, mon, i);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
speciesTable->horizontalHeader()->hide();
|
||||
// create button to add this field to this map
|
||||
}
|
||||
tabIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1306,6 +1306,7 @@ void Project::deleteFile(QString path) {
|
|||
}
|
||||
|
||||
void Project::readWildMonData() {
|
||||
qDebug() << "Project::readWildMonData";// speed testing
|
||||
//
|
||||
QString wildMonJsonFilepath = QString("%1/src/data/wild_encounters.json").arg(root);
|
||||
QJsonDocument wildMonsJsonDoc;
|
||||
|
@ -1325,7 +1326,6 @@ void Project::readWildMonData() {
|
|||
wildMonFields.append(field.toString());
|
||||
}
|
||||
|
||||
//qDebug() << subObject["label"].toString();
|
||||
QJsonArray encounters = subObject["encounters"].toArray();
|
||||
for (QJsonValue encounter : encounters) {
|
||||
//
|
||||
|
@ -1349,55 +1349,6 @@ void Project::readWildMonData() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// land_mons, water_mons, rock_smash_mons, fishing_mons
|
||||
if (encounter["land_mons"] != QJsonValue::Undefined) {
|
||||
header.landMons.active = true;
|
||||
header.landMons.encounterRate = encounter["land_mons"]["encounter_rate"].toInt();
|
||||
for (QJsonValue mon : encounter["land_mons"]["mons"].toArray()) {
|
||||
header.landMons.wildPokemon.append({
|
||||
mon["min_level"].toInt(),
|
||||
mon["max_level"].toInt(),
|
||||
mon["species"].toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
if (encounter["water_mons"] != QJsonValue::Undefined) {
|
||||
header.waterMons.active = true;
|
||||
header.waterMons.encounterRate = encounter["water_mons"]["encounter_rate"].toInt();
|
||||
for (QJsonValue mon : encounter["water_mons"]["mons"].toArray()) {
|
||||
header.waterMons.wildPokemon.append({
|
||||
mon["min_level"].toInt(),
|
||||
mon["max_level"].toInt(),
|
||||
mon["species"].toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
if (encounter["rock_smash_mons"] != QJsonValue::Undefined) {
|
||||
header.rockSmashMons.active = true;
|
||||
header.rockSmashMons.encounterRate = encounter["rock_smash_mons"]["encounter_rate"].toInt();
|
||||
for (QJsonValue mon : encounter["rock_smash_mons"]["mons"].toArray()) {
|
||||
header.rockSmashMons.wildPokemon.append({
|
||||
mon["min_level"].toInt(),
|
||||
mon["max_level"].toInt(),
|
||||
mon["species"].toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
if (encounter["fishing_mons"] != QJsonValue::Undefined) {
|
||||
header.fishingMons.active = true;
|
||||
header.fishingMons.encounterRate = encounter["fishing_mons"]["encounter_rate"].toInt();
|
||||
for (QJsonValue mon : encounter["fishing_mons"]["mons"].toArray()) {
|
||||
header.fishingMons.wildPokemon.append({
|
||||
mon["min_level"].toInt(),
|
||||
mon["max_level"].toInt(),
|
||||
mon["species"].toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
wildMonData.insert(mapConstant, header);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue