extend wild encounter tab for all fields (dynamic)
This commit is contained in:
parent
0ad71286b1
commit
3f9ad3afbb
8 changed files with 141 additions and 76 deletions
|
@ -2710,14 +2710,8 @@
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QTabWidget" name="tabWidget_WildMons">
|
<widget class="QTabWidget" name="tabWidget_WildMons">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>-1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab_LandMons">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>Land Mons</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QGridLayout" name="gridLayout_15"/>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
@ -16,16 +16,22 @@ struct WildMonInfo {
|
||||||
QVector<WildPokemon> wildPokemon;
|
QVector<WildPokemon> wildPokemon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// for extensibility, make a QVector<WildMonInfo>
|
||||||
|
// or QMap<QString, WildMonInfo>
|
||||||
struct WildPokemonHeader {
|
struct WildPokemonHeader {
|
||||||
WildMonInfo landMons;
|
WildMonInfo landMons;
|
||||||
WildMonInfo waterMons;
|
WildMonInfo waterMons;
|
||||||
WildMonInfo rockSmashMons;
|
WildMonInfo rockSmashMons;
|
||||||
WildMonInfo fishingMons;
|
WildMonInfo fishingMons;
|
||||||
|
|
||||||
|
QMap<QString, WildMonInfo> wildMons;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Project;
|
class Project;
|
||||||
QWidget *newSpeciesTableEntry(Project *project, WildPokemon mon, int index);
|
QWidget *newSpeciesTableEntry(Project *project, WildPokemon mon, int index);
|
||||||
void createSpeciesTableRow(Project *, QTableWidget *, WildPokemon, int);
|
void createSpeciesTableRow(Project *, QTableWidget *, WildPokemon, int);
|
||||||
void clearTabWidget(QLayout *tab);
|
void clearTabWidget(QLayout *tab);
|
||||||
|
void clearTable(QTableWidget *table);
|
||||||
|
void populateWildMonTabWidget(QTabWidget *tabWidget, QVector<QString> fields);
|
||||||
|
|
||||||
#endif // GUARD_WILDMONINFO_H
|
#endif // GUARD_WILDMONINFO_H
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
void displayMapConnections();
|
void displayMapConnections();
|
||||||
void displayMapBorder();
|
void displayMapBorder();
|
||||||
void displayMapGrid();
|
void displayMapGrid();
|
||||||
|
void displayWildMonTables();
|
||||||
|
|
||||||
void setEditingMap();
|
void setEditingMap();
|
||||||
void setEditingCollision();
|
void setEditingCollision();
|
||||||
|
|
|
@ -89,6 +89,7 @@ public:
|
||||||
// when saving, preserve the extra fields for gBattlePyramidWildMonHeaders, gBattlePikeWildMonHeaders
|
// when saving, preserve the extra fields for gBattlePyramidWildMonHeaders, gBattlePikeWildMonHeaders
|
||||||
void readSpeciesIconPaths();
|
void readSpeciesIconPaths();
|
||||||
QMap<QString, QString> speciesToIconPath;
|
QMap<QString, QString> speciesToIconPath;
|
||||||
|
QVector<QString> wildMonFields;
|
||||||
|
|
||||||
QMap<QString, bool> getTopLevelMapFields();
|
QMap<QString, bool> getTopLevelMapFields();
|
||||||
bool loadMapData(Map*);
|
bool loadMapData(Map*);
|
||||||
|
|
|
@ -18,6 +18,11 @@ void clearTabWidget(QLayout *tab) {
|
||||||
if (item) tab->removeItem(item);
|
if (item) tab->removeItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearTable(QTableWidget *table) {
|
||||||
|
//
|
||||||
|
if (table) table->clear();
|
||||||
|
}
|
||||||
|
|
||||||
void createSpeciesTableRow(Project *project, QTableWidget *table, WildPokemon mon, int index) {
|
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);
|
table->setCellWidget(index - 1, 4, percentLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tabWidget_WildMons
|
||||||
//
|
void populateWildMonTabWidget(QTabWidget *tabWidget, QVector<QString> fields) {
|
||||||
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"}
|
|
||||||
});
|
|
||||||
|
|
||||||
//
|
//
|
||||||
QHBoxLayout *speciesHBox = new QHBoxLayout;
|
QPushButton *newTabButton = new QPushButton("New Field");
|
||||||
QTableWidgetItem *monItem = new QTableWidgetItem();
|
QObject::connect(newTabButton, &QPushButton::clicked, [=](){
|
||||||
|
qDebug() << "new field pressed";
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
tabWidget->setCornerWidget(newTabButton);
|
||||||
|
|
||||||
QSpinBox *minLevel = new QSpinBox;
|
// change this to for each entry in header
|
||||||
QSpinBox *maxLevel = new QSpinBox;
|
//if (true) {//header.landMons.active) {
|
||||||
minLevel->setMinimum(1);
|
for (QString field : fields) {
|
||||||
minLevel->setMaximum(100);
|
//
|
||||||
maxLevel->setMinimum(1);
|
tabWidget->addTab(new QTableWidget(), field);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,10 @@ void Editor::setEditingConnections() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setEditingWildMons() {
|
void Editor::setEditingWildMons() {
|
||||||
|
// nothing for now
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::displayWildMonTables() {
|
||||||
// clear the current layout
|
// clear the current layout
|
||||||
//
|
//
|
||||||
// move to loadMap? no because loadMap calls this anyways if it's open
|
// move to loadMap? no because loadMap calls this anyways if it's open
|
||||||
|
@ -161,40 +165,62 @@ void Editor::setEditingWildMons() {
|
||||||
|
|
||||||
//QFrame *landMonFrame = ui->frame_LandMonInfo;
|
//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();
|
||||||
|
|
||||||
clearTabWidget(landMonTab);
|
//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);
|
//QGridLayout *gridLayout = new QGridLayout(landMonFrame);
|
||||||
landMonTab->addWidget(landMonTable);
|
//landMonTab->addWidget(landMonTable);
|
||||||
|
|
||||||
//if (!landMonTable)
|
//if (!landMonTable)
|
||||||
|
|
||||||
//for (auto mon : project->wildMonData.value(map->constantName))
|
//for (auto mon : project->wildMonData.value(map->constantName))
|
||||||
WildPokemonHeader header = project->wildMonData.value(map->constantName);
|
WildPokemonHeader header = project->wildMonData.value(map->constantName);
|
||||||
|
|
||||||
if (header.landMons.active) { // else,
|
//QString field = "land_mons";
|
||||||
|
|
||||||
|
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;
|
int i = 1;
|
||||||
|
|
||||||
landMonTable->setRowCount(header.landMons.wildPokemon.size());
|
speciesTable->setRowCount(header.wildMons[field].wildPokemon.size());
|
||||||
landMonTable->setColumnCount(5);// + 1 for last column stretch
|
speciesTable->setColumnCount(5);// + 1 for last column stretch
|
||||||
|
|
||||||
QStringList landMonTableHeaders;
|
QStringList landMonTableHeaders;
|
||||||
landMonTableHeaders << "Index" << "Species" << "Min Level" << "Max Level" << "Catch Percentage";
|
landMonTableHeaders << "Index" << "Species" << "Min Level" << "Max Level" << "Catch Percentage";
|
||||||
landMonTable->setHorizontalHeaderLabels(landMonTableHeaders);
|
speciesTable->setHorizontalHeaderLabels(landMonTableHeaders);
|
||||||
landMonTable->verticalHeader()->hide();
|
speciesTable->verticalHeader()->hide();
|
||||||
landMonTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
speciesTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
landMonTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
speciesTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
|
|
||||||
landMonTable->setShowGrid(false);
|
speciesTable->setShowGrid(false);
|
||||||
|
|
||||||
for (WildPokemon mon : header.landMons.wildPokemon) {
|
for (WildPokemon mon : header.wildMons[field].wildPokemon) {
|
||||||
createSpeciesTableRow(project, landMonTable, mon, i);
|
createSpeciesTableRow(project, speciesTable, mon, i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tabIndex++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::clearWildMonTabWidgets() {
|
void Editor::clearWildMonTabWidgets() {
|
||||||
|
@ -652,6 +678,7 @@ void Editor::displayMap() {
|
||||||
displayMapConnections();
|
displayMapConnections();
|
||||||
displayMapBorder();
|
displayMapBorder();
|
||||||
displayMapGrid();
|
displayMapGrid();
|
||||||
|
displayWildMonTables();
|
||||||
|
|
||||||
this->playerViewRect->setZValue(1000);
|
this->playerViewRect->setZValue(1000);
|
||||||
this->cursorMapTileRect->setZValue(1001);
|
this->cursorMapTileRect->setZValue(1001);
|
||||||
|
|
|
@ -261,11 +261,13 @@ bool MainWindow::openProject(QString dir) {
|
||||||
setWindowTitle(editor->project->getProjectTitle());
|
setWindowTitle(editor->project->getProjectTitle());
|
||||||
loadDataStructures();
|
loadDataStructures();
|
||||||
populateMapList();
|
populateMapList();
|
||||||
|
populateWildMonTabWidget(ui->tabWidget_WildMons, editor->project->wildMonFields);
|
||||||
success = setMap(getDefaultMap(), true);
|
success = setMap(getDefaultMap(), true);
|
||||||
} else {
|
} else {
|
||||||
setWindowTitle(editor->project->getProjectTitle());
|
setWindowTitle(editor->project->getProjectTitle());
|
||||||
loadDataStructures();
|
loadDataStructures();
|
||||||
populateMapList();
|
populateMapList();
|
||||||
|
populateWildMonTabWidget(ui->tabWidget_WildMons, editor->project->wildMonFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@ -1086,7 +1088,7 @@ void MainWindow::on_tabWidget_currentChanged(int index)
|
||||||
} else if (index == 3) {
|
} else if (index == 3) {
|
||||||
editor->setEditingConnections();
|
editor->setEditingConnections();
|
||||||
} else if (index == 4) {
|
} else if (index == 4) {
|
||||||
editor->setEditingWildMons();
|
//editor->setEditingWildMons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1320,6 +1320,11 @@ void Project::readWildMonData() {
|
||||||
QJsonObject subObject = subObjectRef.toObject();
|
QJsonObject subObject = subObjectRef.toObject();
|
||||||
if (!subObject["for_maps"].toBool()) continue;
|
if (!subObject["for_maps"].toBool()) continue;
|
||||||
|
|
||||||
|
// fill wildMonFields
|
||||||
|
for (auto field : subObject["fields"].toArray()) {
|
||||||
|
wildMonFields.append(field.toString());
|
||||||
|
}
|
||||||
|
|
||||||
//qDebug() << subObject["label"].toString();
|
//qDebug() << subObject["label"].toString();
|
||||||
QJsonArray encounters = subObject["encounters"].toArray();
|
QJsonArray encounters = subObject["encounters"].toArray();
|
||||||
for (QJsonValue encounter : encounters) {
|
for (QJsonValue encounter : encounters) {
|
||||||
|
@ -1330,6 +1335,22 @@ void Project::readWildMonData() {
|
||||||
|
|
||||||
WildPokemonHeader header;
|
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
|
// land_mons, water_mons, rock_smash_mons, fishing_mons
|
||||||
if (encounter["land_mons"] != QJsonValue::Undefined) {
|
if (encounter["land_mons"] != QJsonValue::Undefined) {
|
||||||
header.landMons.active = true;
|
header.landMons.active = true;
|
||||||
|
@ -1375,6 +1396,7 @@ void Project::readWildMonData() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
wildMonData.insert(mapConstant, header);
|
wildMonData.insert(mapConstant, header);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue