extend wild encounter tab for all fields (dynamic)

This commit is contained in:
garak 2019-06-13 12:14:49 -04:00
parent 0ad71286b1
commit 3f9ad3afbb
8 changed files with 141 additions and 76 deletions

View file

@ -2710,14 +2710,8 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget_WildMons">
<property name="currentIndex">
<number>0</number>
<number>-1</number>
</property>
<widget class="QWidget" name="tab_LandMons">
<attribute name="title">
<string>Land Mons</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_15"/>
</widget>
</widget>
</item>
</layout>

View file

@ -16,16 +16,22 @@ struct WildMonInfo {
QVector<WildPokemon> wildPokemon;
};
// for extensibility, make a QVector<WildMonInfo>
// or QMap<QString, WildMonInfo>
struct WildPokemonHeader {
WildMonInfo landMons;
WildMonInfo waterMons;
WildMonInfo rockSmashMons;
WildMonInfo fishingMons;
QMap<QString, WildMonInfo> wildMons;
};
class Project;
QWidget *newSpeciesTableEntry(Project *project, WildPokemon mon, int index);
void createSpeciesTableRow(Project *, QTableWidget *, WildPokemon, int);
void clearTabWidget(QLayout *tab);
void clearTable(QTableWidget *table);
void populateWildMonTabWidget(QTabWidget *tabWidget, QVector<QString> fields);
#endif // GUARD_WILDMONINFO_H

View file

@ -56,6 +56,7 @@ public:
void displayMapConnections();
void displayMapBorder();
void displayMapGrid();
void displayWildMonTables();
void setEditingMap();
void setEditingCollision();

View file

@ -89,6 +89,7 @@ public:
// when saving, preserve the extra fields for gBattlePyramidWildMonHeaders, gBattlePikeWildMonHeaders
void readSpeciesIconPaths();
QMap<QString, QString> speciesToIconPath;
QVector<QString> wildMonFields;
QMap<QString, bool> getTopLevelMapFields();
bool loadMapData(Map*);

View file

@ -18,6 +18,11 @@ void clearTabWidget(QLayout *tab) {
if (item) tab->removeItem(item);
}
void clearTable(QTableWidget *table) {
//
if (table) table->clear();
}
void createSpeciesTableRow(Project *project, QTableWidget *table, WildPokemon mon, int index) {
//
@ -70,57 +75,64 @@ void createSpeciesTableRow(Project *project, QTableWidget *table, WildPokemon mo
table->setCellWidget(index - 1, 4, percentLabel);
}
//
QWidget *newSpeciesTableEntry(Project *project, WildPokemon mon, int index) {
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"}
});
// tabWidget_WildMons
void populateWildMonTabWidget(QTabWidget *tabWidget, QVector<QString> fields) {
//
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)));
QLabel *monLabel = new QLabel();
monLabel->setPixmap(monIcon);
QComboBox *monSelector = new QComboBox;
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);
QPushButton *newTabButton = new QPushButton("New Field");
QObject::connect(newTabButton, &QPushButton::clicked, [=](){
qDebug() << "new field pressed";
});
tabWidget->setCornerWidget(newTabButton);
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);
// percentage
QLabel *percentLabel = new QLabel(landPercentages[index]);
speciesHBox->addWidget(monNum);
speciesHBox->addWidget(monLabel);
speciesHBox->addWidget(monSelector);
speciesHBox->addWidget(minLevel);
speciesHBox->addWidget(maxLevel);
speciesHBox->addWidget(percentLabel);
return (QWidget *)speciesHBox;
// change this to for each entry in header
//if (true) {//header.landMons.active) {
for (QString field : fields) {
//
tabWidget->addTab(new QTableWidget(), field);
}
}

View file

@ -151,6 +151,10 @@ void Editor::setEditingConnections() {
}
void Editor::setEditingWildMons() {
// nothing for now
}
void Editor::displayWildMonTables() {
// clear the current layout
//
// move to loadMap? no because loadMap calls this anyways if it's open
@ -161,39 +165,61 @@ void Editor::setEditingWildMons() {
//QFrame *landMonFrame = ui->frame_LandMonInfo;
QLayout *landMonTab = ui->tab_LandMons->layout();
//QTabWidget *tabWidgetWildMons = ui->tabWidget_WildMons;
QTableWidget *landMonTable = new QTableWidget;//ui->tableWidget_RockSmashMonInfo;
//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);
//clearTabWidget(landMonTab);
//clearTable(landMonTable);
//QGridLayout *gridLayout = new QGridLayout(landMonFrame);
landMonTab->addWidget(landMonTable);
//landMonTab->addWidget(landMonTable);
//if (!landMonTable)
//for (auto mon : project->wildMonData.value(map->constantName))
WildPokemonHeader header = project->wildMonData.value(map->constantName);
if (header.landMons.active) { // else,
int i = 1;
//QString field = "land_mons";
landMonTable->setRowCount(header.landMons.wildPokemon.size());
landMonTable->setColumnCount(5);// + 1 for last column stretch
int tabIndex = 0;
for (QString field : project->wildMonFields) {
QTableWidget *speciesTable = static_cast<QTableWidget *>(ui->tabWidget_WildMons->widget(tabIndex));
clearTable(speciesTable);
if (header.wildMons[field].active) {//header.landMons.active) { // else,
int i = 1;
QStringList landMonTableHeaders;
landMonTableHeaders << "Index" << "Species" << "Min Level" << "Max Level" << "Catch Percentage";
landMonTable->setHorizontalHeaderLabels(landMonTableHeaders);
landMonTable->verticalHeader()->hide();
landMonTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
landMonTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
speciesTable->setRowCount(header.wildMons[field].wildPokemon.size());
speciesTable->setColumnCount(5);// + 1 for last column stretch
landMonTable->setShowGrid(false);
QStringList landMonTableHeaders;
landMonTableHeaders << "Index" << "Species" << "Min Level" << "Max Level" << "Catch Percentage";
speciesTable->setHorizontalHeaderLabels(landMonTableHeaders);
speciesTable->verticalHeader()->hide();
speciesTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
speciesTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
for (WildPokemon mon : header.landMons.wildPokemon) {
createSpeciesTableRow(project, landMonTable, mon, i);
i++;
speciesTable->setShowGrid(false);
for (WildPokemon mon : header.wildMons[field].wildPokemon) {
createSpeciesTableRow(project, speciesTable, mon, i);
i++;
}
}
tabIndex++;
}
}
@ -652,6 +678,7 @@ void Editor::displayMap() {
displayMapConnections();
displayMapBorder();
displayMapGrid();
displayWildMonTables();
this->playerViewRect->setZValue(1000);
this->cursorMapTileRect->setZValue(1001);

View file

@ -261,11 +261,13 @@ bool MainWindow::openProject(QString dir) {
setWindowTitle(editor->project->getProjectTitle());
loadDataStructures();
populateMapList();
populateWildMonTabWidget(ui->tabWidget_WildMons, editor->project->wildMonFields);
success = setMap(getDefaultMap(), true);
} else {
setWindowTitle(editor->project->getProjectTitle());
loadDataStructures();
populateMapList();
populateWildMonTabWidget(ui->tabWidget_WildMons, editor->project->wildMonFields);
}
if (success) {
@ -1086,7 +1088,7 @@ void MainWindow::on_tabWidget_currentChanged(int index)
} else if (index == 3) {
editor->setEditingConnections();
} else if (index == 4) {
editor->setEditingWildMons();
//editor->setEditingWildMons();
}
}

View file

@ -1320,6 +1320,11 @@ void Project::readWildMonData() {
QJsonObject subObject = subObjectRef.toObject();
if (!subObject["for_maps"].toBool()) continue;
// fill wildMonFields
for (auto field : subObject["fields"].toArray()) {
wildMonFields.append(field.toString());
}
//qDebug() << subObject["label"].toString();
QJsonArray encounters = subObject["encounters"].toArray();
for (QJsonValue encounter : encounters) {
@ -1330,6 +1335,22 @@ void Project::readWildMonData() {
WildPokemonHeader header;
for (QString field : wildMonFields) {
//
if (encounter[field] != QJsonValue::Undefined) {
header.wildMons[field].active = true;
header.wildMons[field].encounterRate = encounter[field]["encounter_rate"].toInt();
for (QJsonValue mon : encounter[field]["mons"].toArray()) {
header.wildMons[field].wildPokemon.append({
mon["min_level"].toInt(),
mon["max_level"].toInt(),
mon["species"].toString()
});
}
}
}
/*
// land_mons, water_mons, rock_smash_mons, fishing_mons
if (encounter["land_mons"] != QJsonValue::Undefined) {
header.landMons.active = true;
@ -1375,6 +1396,7 @@ void Project::readWildMonData() {
});
}
}
*/
wildMonData.insert(mapConstant, header);
}