add 'groups' field to encounter json to accomodate fishing
This commit is contained in:
parent
09dd9380bb
commit
10c99dd0a2
7 changed files with 208 additions and 81 deletions
|
@ -19,10 +19,15 @@ struct WildPokemonHeader {
|
||||||
QMap<QString, WildMonInfo> wildMons;
|
QMap<QString, WildMonInfo> wildMons;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QVector<QPair<QString, QVector<int>>> Fields;
|
struct EncounterField {
|
||||||
typedef QPair<QString, QVector<int>> Field;
|
QString name;
|
||||||
|
QVector<int> encounterRates;
|
||||||
|
QMap<QString, QVector<int>> groups;
|
||||||
|
};
|
||||||
|
|
||||||
WildMonInfo getDefaultMonInfo(Field field);
|
typedef QVector<EncounterField> EncounterFields;
|
||||||
WildMonInfo copyMonInfoFromTab(QTableWidget *table);
|
|
||||||
|
WildMonInfo getDefaultMonInfo(EncounterField field);
|
||||||
|
WildMonInfo copyMonInfoFromTab(QTableWidget *table, EncounterField monField);
|
||||||
|
|
||||||
#endif // GUARD_WILDMONINFO_H
|
#endif // GUARD_WILDMONINFO_H
|
||||||
|
|
|
@ -146,7 +146,7 @@ private:
|
||||||
void updateMirroredConnectionDirection(MapConnection*, QString);
|
void updateMirroredConnectionDirection(MapConnection*, QString);
|
||||||
void updateMirroredConnectionMap(MapConnection*, QString);
|
void updateMirroredConnectionMap(MapConnection*, QString);
|
||||||
void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false);
|
void updateMirroredConnection(MapConnection*, QString, QString, bool isDelete = false);
|
||||||
void updateEncounterFields(Fields newFields);
|
void updateEncounterFields(EncounterFields newFields);
|
||||||
Event* createNewObjectEvent();
|
Event* createNewObjectEvent();
|
||||||
Event* createNewWarpEvent();
|
Event* createNewWarpEvent();
|
||||||
Event* createNewHealLocationEvent();
|
Event* createNewHealLocationEvent();
|
||||||
|
|
|
@ -91,7 +91,7 @@ public:
|
||||||
|
|
||||||
void readWildMonData();
|
void readWildMonData();
|
||||||
QMap<QString, QMap<QString, WildPokemonHeader>> wildMonData;
|
QMap<QString, QMap<QString, WildPokemonHeader>> wildMonData;
|
||||||
QVector<QPair<QString, QVector<int>>> wildMonFields;
|
QVector<EncounterField> wildMonFields;
|
||||||
QVector<QString> encounterGroupLabels;
|
QVector<QString> encounterGroupLabels;
|
||||||
QMap<QString, QJsonObject> extraEncounterGroups;
|
QMap<QString, QJsonObject> extraEncounterGroups;
|
||||||
|
|
||||||
|
|
|
@ -4,26 +4,28 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WildMonInfo getDefaultMonInfo(Field field) {
|
WildMonInfo getDefaultMonInfo(EncounterField field) {
|
||||||
WildMonInfo newInfo;
|
WildMonInfo newInfo;
|
||||||
newInfo.active = true;
|
newInfo.active = true;
|
||||||
newInfo.encounterRate = 0;
|
newInfo.encounterRate = 0;
|
||||||
|
|
||||||
for (int row : field.second)
|
int size = field.encounterRates.size();
|
||||||
|
while (size--)
|
||||||
newInfo.wildPokemon.append(WildPokemon());
|
newInfo.wildPokemon.append(WildPokemon());
|
||||||
|
|
||||||
return newInfo;
|
return newInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
WildMonInfo copyMonInfoFromTab(QTableWidget *monTable) {
|
WildMonInfo copyMonInfoFromTab(QTableWidget *monTable, EncounterField monField) {
|
||||||
WildMonInfo newInfo;
|
WildMonInfo newInfo;
|
||||||
QVector<WildPokemon> newWildMons;
|
QVector<WildPokemon> newWildMons;
|
||||||
|
|
||||||
|
bool extraColumn = !monField.groups.isEmpty();
|
||||||
for (int row = 0; row < monTable->rowCount(); row++) {
|
for (int row = 0; row < monTable->rowCount(); row++) {
|
||||||
WildPokemon newWildMon;
|
WildPokemon newWildMon;
|
||||||
newWildMon.species = monTable->cellWidget(row, 1)->findChild<QComboBox *>()->currentText();
|
newWildMon.species = monTable->cellWidget(row, extraColumn ? 2 : 1)->findChild<QComboBox *>()->currentText();
|
||||||
newWildMon.minLevel = monTable->cellWidget(row, 2)->findChild<QSpinBox *>()->value();
|
newWildMon.minLevel = monTable->cellWidget(row, extraColumn ? 3 : 2)->findChild<QSpinBox *>()->value();
|
||||||
newWildMon.maxLevel = monTable->cellWidget(row, 3)->findChild<QSpinBox *>()->value();
|
newWildMon.maxLevel = monTable->cellWidget(row, extraColumn ? 4 : 3)->findChild<QSpinBox *>()->value();
|
||||||
newWildMons.append(newWildMon);
|
newWildMons.append(newWildMon);
|
||||||
}
|
}
|
||||||
newInfo.active = true;
|
newInfo.active = true;
|
||||||
|
|
151
src/editor.cpp
151
src/editor.cpp
|
@ -188,8 +188,8 @@ void Editor::displayWildMonTables() {
|
||||||
stack->insertWidget(labelIndex, tabWidget);
|
stack->insertWidget(labelIndex, tabWidget);
|
||||||
|
|
||||||
int tabIndex = 0;
|
int tabIndex = 0;
|
||||||
for (Field monField : project->wildMonFields) {
|
for (EncounterField monField : project->wildMonFields) {
|
||||||
QString fieldName = monField.first;
|
QString fieldName = monField.name;
|
||||||
|
|
||||||
tabWidget->clearTableAt(tabIndex);
|
tabWidget->clearTableAt(tabIndex);
|
||||||
|
|
||||||
|
@ -245,24 +245,24 @@ void Editor::addNewWildMonGroup(QWidget *window) {
|
||||||
copyCheckbox->setEnabled(stack->count());
|
copyCheckbox->setEnabled(stack->count());
|
||||||
form.addRow(new QLabel("Copy from current group"), copyCheckbox);
|
form.addRow(new QLabel("Copy from current group"), copyCheckbox);
|
||||||
QVector<QCheckBox *> fieldCheckboxes;
|
QVector<QCheckBox *> fieldCheckboxes;
|
||||||
for (Field monField : project->wildMonFields) {
|
for (EncounterField monField : project->wildMonFields) {
|
||||||
QCheckBox *fieldCheckbox = new QCheckBox;
|
QCheckBox *fieldCheckbox = new QCheckBox;
|
||||||
fieldCheckboxes.append(fieldCheckbox);
|
fieldCheckboxes.append(fieldCheckbox);
|
||||||
form.addRow(new QLabel(monField.first), fieldCheckbox);
|
form.addRow(new QLabel(monField.name), fieldCheckbox);
|
||||||
}
|
}
|
||||||
// Reading from ui here so not saving to disk before user.
|
// Reading from ui here so not saving to disk before user.
|
||||||
connect(copyCheckbox, &QCheckBox::stateChanged, [=](int state){
|
connect(copyCheckbox, &QCheckBox::stateChanged, [=](int state){
|
||||||
if (state == Qt::Checked) {
|
if (state == Qt::Checked) {
|
||||||
int fieldIndex = 0;
|
int fieldIndex = 0;
|
||||||
MonTabWidget *monWidget = static_cast<MonTabWidget *>(stack->widget(stack->currentIndex()));
|
MonTabWidget *monWidget = static_cast<MonTabWidget *>(stack->widget(stack->currentIndex()));
|
||||||
for (Field monField : project->wildMonFields) {
|
for (EncounterField monField : project->wildMonFields) {
|
||||||
fieldCheckboxes[fieldIndex]->setChecked(monWidget->isTabEnabled(fieldIndex));
|
fieldCheckboxes[fieldIndex]->setChecked(monWidget->isTabEnabled(fieldIndex));
|
||||||
fieldCheckboxes[fieldIndex]->setEnabled(false);
|
fieldCheckboxes[fieldIndex]->setEnabled(false);
|
||||||
fieldIndex++;
|
fieldIndex++;
|
||||||
}
|
}
|
||||||
} else if (state == Qt::Unchecked) {
|
} else if (state == Qt::Unchecked) {
|
||||||
int fieldIndex = 0;
|
int fieldIndex = 0;
|
||||||
for (Field monField : project->wildMonFields) {
|
for (EncounterField monField : project->wildMonFields) {
|
||||||
fieldCheckboxes[fieldIndex]->setEnabled(true);
|
fieldCheckboxes[fieldIndex]->setEnabled(true);
|
||||||
fieldIndex++;
|
fieldIndex++;
|
||||||
}
|
}
|
||||||
|
@ -281,8 +281,8 @@ void Editor::addNewWildMonGroup(QWidget *window) {
|
||||||
|
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
WildPokemonHeader header;
|
WildPokemonHeader header;
|
||||||
for (Field monField : project->wildMonFields) {
|
for (EncounterField monField : project->wildMonFields) {
|
||||||
QString fieldName = monField.first;
|
QString fieldName = monField.name;
|
||||||
header.wildMons[fieldName].active = false;
|
header.wildMons[fieldName].active = false;
|
||||||
header.wildMons[fieldName].encounterRate = 0;
|
header.wildMons[fieldName].encounterRate = 0;
|
||||||
}
|
}
|
||||||
|
@ -294,14 +294,14 @@ void Editor::addNewWildMonGroup(QWidget *window) {
|
||||||
labelCombo->setCurrentIndex(labelCombo->count() - 1);
|
labelCombo->setCurrentIndex(labelCombo->count() - 1);
|
||||||
|
|
||||||
int tabIndex = 0;
|
int tabIndex = 0;
|
||||||
for (Field monField : project->wildMonFields) {
|
for (EncounterField monField : project->wildMonFields) {
|
||||||
QString fieldName = monField.first;
|
QString fieldName = monField.name;
|
||||||
tabWidget->clearTableAt(tabIndex);
|
tabWidget->clearTableAt(tabIndex);
|
||||||
if (fieldCheckboxes[tabIndex]->isChecked()) {
|
if (fieldCheckboxes[tabIndex]->isChecked()) {
|
||||||
if (copyCheckbox->isChecked()) {
|
if (copyCheckbox->isChecked()) {
|
||||||
MonTabWidget *copyFrom = static_cast<MonTabWidget *>(stack->widget(stackIndex));
|
MonTabWidget *copyFrom = static_cast<MonTabWidget *>(stack->widget(stackIndex));
|
||||||
if (copyFrom->isTabEnabled(tabIndex))
|
if (copyFrom->isTabEnabled(tabIndex))
|
||||||
header.wildMons.insert(fieldName, copyMonInfoFromTab(copyFrom->tableAt(tabIndex)));
|
header.wildMons.insert(fieldName, copyMonInfoFromTab(copyFrom->tableAt(tabIndex), monField));
|
||||||
else
|
else
|
||||||
header.wildMons.insert(fieldName, getDefaultMonInfo(monField));
|
header.wildMons.insert(fieldName, getDefaultMonInfo(monField));
|
||||||
} else {
|
} else {
|
||||||
|
@ -319,25 +319,52 @@ void Editor::addNewWildMonGroup(QWidget *window) {
|
||||||
void Editor::configureEncounterJSON(QWidget *window) {
|
void Editor::configureEncounterJSON(QWidget *window) {
|
||||||
QVector<QWidget *> fieldSlots;
|
QVector<QWidget *> fieldSlots;
|
||||||
|
|
||||||
Fields tempFields = project->wildMonFields;
|
EncounterFields tempFields = project->wildMonFields;
|
||||||
|
|
||||||
QLabel *totalLabel = new QLabel;
|
QLabel *totalLabel = new QLabel;
|
||||||
|
|
||||||
auto updateTotal = [&fieldSlots, totalLabel](Field ¤tField) {
|
// lambda: Update the total displayed at the bottom of the Configure JSON
|
||||||
|
// window. Take groups into account when applicable.
|
||||||
|
auto updateTotal = [&fieldSlots, totalLabel](EncounterField ¤tField) {
|
||||||
int total = 0, spinnerIndex = 0;
|
int total = 0, spinnerIndex = 0;
|
||||||
|
QString groupTotalMessage;
|
||||||
|
QMap<QString, int> groupTotals;
|
||||||
|
for (QString key : currentField.groups.keys())
|
||||||
|
groupTotals.insert(key, 0);// add to group map and initialize total to zero
|
||||||
for (auto slot : fieldSlots) {
|
for (auto slot : fieldSlots) {
|
||||||
QSpinBox *spinner = slot->findChild<QSpinBox *>();
|
QSpinBox *spinner = slot->findChild<QSpinBox *>();
|
||||||
int val = spinner->value();
|
int val = spinner->value();
|
||||||
currentField.second[spinnerIndex++] = spinner->value();
|
currentField.encounterRates[spinnerIndex] = val;
|
||||||
total += val;
|
if (!currentField.groups.isEmpty()) {
|
||||||
|
for (QString key : currentField.groups.keys()) {
|
||||||
|
if (currentField.groups[key].contains(spinnerIndex)) {
|
||||||
|
groupTotals[key] += val;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
total += val;
|
||||||
|
}
|
||||||
|
spinnerIndex++;
|
||||||
|
}
|
||||||
|
if (!currentField.groups.isEmpty()) {
|
||||||
|
groupTotalMessage += "Totals: ";
|
||||||
|
for (QString key : currentField.groups.keys()) {
|
||||||
|
groupTotalMessage += QString("%1 (%2),\t").arg(groupTotals[key]).arg(key);
|
||||||
|
}
|
||||||
|
groupTotalMessage.chop(2);
|
||||||
|
totalLabel->setText(groupTotalMessage);
|
||||||
|
} else {
|
||||||
|
totalLabel->setText(QString("Total: %1").arg(QString::number(total)));
|
||||||
}
|
}
|
||||||
totalLabel->setText(QString("Total: %1").arg(QString::number(total)));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto createNewSlot = [&fieldSlots, &updateTotal](int index, Field ¤tField) {
|
// lambda: Create a new "slot", which is the widget containing a spinner and an index label.
|
||||||
|
// Add the slot to a list of fieldSlots, which exists to keep track of them for memory management.
|
||||||
|
auto createNewSlot = [&fieldSlots, &tempFields, &updateTotal](int index, EncounterField ¤tField) {
|
||||||
QLabel *indexLabel = new QLabel(QString("Index: %1").arg(QString::number(index)));
|
QLabel *indexLabel = new QLabel(QString("Index: %1").arg(QString::number(index)));
|
||||||
QSpinBox *chanceSpinner = new QSpinBox;
|
QSpinBox *chanceSpinner = new QSpinBox;
|
||||||
int chance = currentField.second.at(index);
|
int chance = currentField.encounterRates.at(index);
|
||||||
chanceSpinner->setMinimum(1);
|
chanceSpinner->setMinimum(1);
|
||||||
chanceSpinner->setMaximum(9999);
|
chanceSpinner->setMaximum(9999);
|
||||||
chanceSpinner->setValue(chance);
|
chanceSpinner->setValue(chance);
|
||||||
|
@ -345,11 +372,46 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
||||||
updateTotal(currentField);
|
updateTotal(currentField);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bool useGroups = !currentField.groups.isEmpty();
|
||||||
|
|
||||||
|
QFrame *slotChoiceFrame = new QFrame;
|
||||||
|
QVBoxLayout *slotChoiceLayout = new QVBoxLayout;
|
||||||
|
if (useGroups) {
|
||||||
|
QComboBox *groupCombo = new QComboBox;
|
||||||
|
connect(groupCombo, QOverload<const QString &>::of(&QComboBox::activated), [&tempFields, ¤tField, index](QString newGroupName) {
|
||||||
|
for (EncounterField &field : tempFields) {
|
||||||
|
if (field.name == currentField.name) {
|
||||||
|
for (QString groupName : field.groups.keys()) {
|
||||||
|
if (field.groups[groupName].contains(index)) {
|
||||||
|
field.groups[groupName].removeAll(index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (QString groupName : field.groups.keys()) {
|
||||||
|
if (groupName == newGroupName) field.groups[newGroupName].append(index);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
groupCombo->addItems(currentField.groups.keys());
|
||||||
|
QString currentGroupName;
|
||||||
|
for (QString groupName : currentField.groups.keys()) {
|
||||||
|
if (currentField.groups[groupName].contains(index)) {
|
||||||
|
currentGroupName = groupName;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
groupCombo->setCurrentText(currentGroupName);
|
||||||
|
slotChoiceLayout->addWidget(groupCombo);
|
||||||
|
}
|
||||||
|
slotChoiceLayout->addWidget(chanceSpinner);
|
||||||
|
slotChoiceFrame->setLayout(slotChoiceLayout);
|
||||||
|
|
||||||
QFrame *slot = new QFrame;
|
QFrame *slot = new QFrame;
|
||||||
QHBoxLayout *slotLayout = new QHBoxLayout;
|
QHBoxLayout *slotLayout = new QHBoxLayout;
|
||||||
slotLayout->addStretch();
|
|
||||||
slotLayout->addWidget(indexLabel);
|
slotLayout->addWidget(indexLabel);
|
||||||
slotLayout->addWidget(chanceSpinner);
|
slotLayout->addWidget(slotChoiceFrame);
|
||||||
slot->setLayout(slotLayout);
|
slot->setLayout(slotLayout);
|
||||||
|
|
||||||
fieldSlots.append(slot);
|
fieldSlots.append(slot);
|
||||||
|
@ -368,13 +430,16 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
||||||
connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
|
||||||
connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
||||||
|
|
||||||
|
// lambda: Get a QStringList of the existing field names.
|
||||||
auto getFieldNames = [&tempFields]() {
|
auto getFieldNames = [&tempFields]() {
|
||||||
QStringList fieldNames;
|
QStringList fieldNames;
|
||||||
for (Field field : tempFields)
|
for (EncounterField field : tempFields)
|
||||||
fieldNames.append(field.first);
|
fieldNames.append(field.name);
|
||||||
return fieldNames;
|
return fieldNames;
|
||||||
};
|
};
|
||||||
auto drawSlotWidgets = [this, &grid, &createNewSlot, &fieldSlots, &updateTotal, &tempFields](int index) {
|
|
||||||
|
// lambda: Draws the slot widgets onto a grid (4 wide) on the dialog window.
|
||||||
|
auto drawSlotWidgets = [this, &dialog, &grid, &createNewSlot, &fieldSlots, &updateTotal, &tempFields](int index) {
|
||||||
// Clear them first.
|
// Clear them first.
|
||||||
while (!fieldSlots.isEmpty()) {
|
while (!fieldSlots.isEmpty()) {
|
||||||
auto slot = fieldSlots.takeFirst();
|
auto slot = fieldSlots.takeFirst();
|
||||||
|
@ -382,12 +447,14 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
||||||
delete slot;
|
delete slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
Field ¤tField = tempFields[index];
|
EncounterField ¤tField = tempFields[index];
|
||||||
for (int i = 0; i < currentField.second.size(); i++) {
|
for (int i = 0; i < currentField.encounterRates.size(); i++) {
|
||||||
grid.addWidget(createNewSlot(i, currentField), i / 4 + 1, i % 4);
|
grid.addWidget(createNewSlot(i, currentField), i / 4 + 1, i % 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTotal(currentField);
|
updateTotal(currentField);
|
||||||
|
|
||||||
|
dialog.adjustSize();// TODO: why is this updating only on second call? reproduce: land->fishing->rock_smash->water
|
||||||
};
|
};
|
||||||
QComboBox *fieldChoices = new QComboBox;
|
QComboBox *fieldChoices = new QComboBox;
|
||||||
connect(fieldChoices, QOverload<int>::of(&QComboBox::currentIndexChanged), drawSlotWidgets);
|
connect(fieldChoices, QOverload<int>::of(&QComboBox::currentIndexChanged), drawSlotWidgets);
|
||||||
|
@ -414,7 +481,7 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
||||||
if (newNameDialog.exec() == QDialog::Accepted) {
|
if (newNameDialog.exec() == QDialog::Accepted) {
|
||||||
QString newFieldName = newNameEdit->text();
|
QString newFieldName = newNameEdit->text();
|
||||||
QVector<int> newFieldRates(1, 100);
|
QVector<int> newFieldRates(1, 100);
|
||||||
tempFields.append({newFieldName, newFieldRates});
|
tempFields.append({newFieldName, newFieldRates, {}});
|
||||||
fieldChoices->addItem(newFieldName);
|
fieldChoices->addItem(newFieldName);
|
||||||
fieldChoices->setCurrentIndex(fieldChoices->count() - 1);
|
fieldChoices->setCurrentIndex(fieldChoices->count() - 1);
|
||||||
}
|
}
|
||||||
|
@ -431,16 +498,16 @@ void Editor::configureEncounterJSON(QWidget *window) {
|
||||||
QPushButton *addSlotButton = new QPushButton(QIcon(":/icons/add.ico"), "");
|
QPushButton *addSlotButton = new QPushButton(QIcon(":/icons/add.ico"), "");
|
||||||
addSlotButton->setFlat(true);
|
addSlotButton->setFlat(true);
|
||||||
connect(addSlotButton, &QPushButton::clicked, [this, &fieldChoices, &drawSlotWidgets, &tempFields]() {
|
connect(addSlotButton, &QPushButton::clicked, [this, &fieldChoices, &drawSlotWidgets, &tempFields]() {
|
||||||
Field &field = tempFields[fieldChoices->currentIndex()];
|
EncounterField &field = tempFields[fieldChoices->currentIndex()];
|
||||||
field.second.append(1);
|
field.encounterRates.append(1);
|
||||||
drawSlotWidgets(fieldChoices->currentIndex());
|
drawSlotWidgets(fieldChoices->currentIndex());
|
||||||
});
|
});
|
||||||
QPushButton *removeSlotButton = new QPushButton(QIcon(":/icons/delete.ico"), "");
|
QPushButton *removeSlotButton = new QPushButton(QIcon(":/icons/delete.ico"), "");
|
||||||
removeSlotButton->setFlat(true);
|
removeSlotButton->setFlat(true);
|
||||||
connect(removeSlotButton, &QPushButton::clicked, [this, &fieldChoices, &drawSlotWidgets, &tempFields]() {
|
connect(removeSlotButton, &QPushButton::clicked, [this, &fieldChoices, &drawSlotWidgets, &tempFields]() {
|
||||||
Field &field = tempFields[fieldChoices->currentIndex()];
|
EncounterField &field = tempFields[fieldChoices->currentIndex()];
|
||||||
if (field.second.size() > 1)
|
if (field.encounterRates.size() > 1)
|
||||||
field.second.removeLast();
|
field.encounterRates.removeLast();
|
||||||
drawSlotWidgets(fieldChoices->currentIndex());
|
drawSlotWidgets(fieldChoices->currentIndex());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -490,39 +557,39 @@ void Editor::saveEncounterTabData() {
|
||||||
WildPokemonHeader &encounterHeader = encounterMap[labelCombo->itemText(groupIndex)];
|
WildPokemonHeader &encounterHeader = encounterMap[labelCombo->itemText(groupIndex)];
|
||||||
|
|
||||||
int fieldIndex = 0;
|
int fieldIndex = 0;
|
||||||
for (Field monField : project->wildMonFields) {
|
for (EncounterField monField : project->wildMonFields) {
|
||||||
QString fieldName = monField.first;
|
QString fieldName = monField.name;
|
||||||
|
|
||||||
if (!tabWidget->isTabEnabled(fieldIndex++)) continue;
|
if (!tabWidget->isTabEnabled(fieldIndex++)) continue;
|
||||||
|
|
||||||
QTableWidget *monTable = static_cast<QTableWidget *>(tabWidget->widget(fieldIndex - 1));
|
QTableWidget *monTable = static_cast<QTableWidget *>(tabWidget->widget(fieldIndex - 1));
|
||||||
QVector<WildPokemon> newWildMons;
|
QVector<WildPokemon> newWildMons;
|
||||||
encounterHeader.wildMons[fieldName] = copyMonInfoFromTab(monTable);
|
encounterHeader.wildMons[fieldName] = copyMonInfoFromTab(monTable, monField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update encounters for every map based on the new encounter JSON field data.
|
// Update encounters for every map based on the new encounter JSON field data.
|
||||||
void Editor::updateEncounterFields(Fields newFields) {
|
void Editor::updateEncounterFields(EncounterFields newFields) {
|
||||||
Fields oldFields = project->wildMonFields;
|
EncounterFields oldFields = project->wildMonFields;
|
||||||
// Go through fields and determine whether we need to update a field.
|
// Go through fields and determine whether we need to update a field.
|
||||||
// If the field is new, do nothing.
|
// If the field is new, do nothing.
|
||||||
// If the field is deleted, remove from all maps.
|
// If the field is deleted, remove from all maps.
|
||||||
// If the field is changed, change all maps accordingly.
|
// If the field is changed, change all maps accordingly.
|
||||||
for (Field oldField : oldFields) {
|
for (EncounterField oldField : oldFields) {
|
||||||
QString oldFieldName = oldField.first;
|
QString oldFieldName = oldField.name;
|
||||||
bool fieldDeleted = true;
|
bool fieldDeleted = true;
|
||||||
for (Field newField : newFields) {
|
for (EncounterField newField : newFields) {
|
||||||
QString newFieldName = newField.first;
|
QString newFieldName = newField.name;
|
||||||
if (oldFieldName == newFieldName) {
|
if (oldFieldName == newFieldName) {
|
||||||
fieldDeleted = false;
|
fieldDeleted = false;
|
||||||
if (oldField.second.size() != newField.second.size()) {
|
if (oldField.encounterRates.size() != newField.encounterRates.size()) {
|
||||||
for (QString map : project->wildMonData.keys()) {
|
for (QString map : project->wildMonData.keys()) {
|
||||||
for (QString groupName : project->wildMonData.value(map).keys()) {
|
for (QString groupName : project->wildMonData.value(map).keys()) {
|
||||||
WildPokemonHeader &monHeader = project->wildMonData[map][groupName];
|
WildPokemonHeader &monHeader = project->wildMonData[map][groupName];
|
||||||
for (QString fieldName : monHeader.wildMons.keys()) {
|
for (QString fieldName : monHeader.wildMons.keys()) {
|
||||||
if (fieldName == oldFieldName) {
|
if (fieldName == oldFieldName) {
|
||||||
monHeader.wildMons[fieldName].wildPokemon.resize(newField.second.size());
|
monHeader.wildMons[fieldName].wildPokemon.resize(newField.encounterRates.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -539,16 +539,27 @@ void Project::saveWildMonData() {
|
||||||
monHeadersObject["for_maps"] = true;
|
monHeadersObject["for_maps"] = true;
|
||||||
|
|
||||||
QJsonArray fieldsInfoArray;
|
QJsonArray fieldsInfoArray;
|
||||||
for (QPair<QString, QVector<int>> fieldInfo : wildMonFields) {
|
for (EncounterField fieldInfo : wildMonFields) {
|
||||||
QJsonObject fieldObject;
|
QJsonObject fieldObject;
|
||||||
QJsonArray rateArray;
|
QJsonArray rateArray;
|
||||||
|
|
||||||
for (int rate : fieldInfo.second)
|
for (int rate : fieldInfo.encounterRates) {
|
||||||
rateArray.append(rate);
|
rateArray.append(rate);
|
||||||
|
}
|
||||||
|
|
||||||
fieldObject["type"] = fieldInfo.first;
|
fieldObject["type"] = fieldInfo.name;
|
||||||
fieldObject["encounter_rates"] = rateArray;
|
fieldObject["encounter_rates"] = rateArray;
|
||||||
|
|
||||||
|
QJsonObject groupsObject;
|
||||||
|
for (QString groupName : fieldInfo.groups.keys()) {
|
||||||
|
QJsonArray subGroupIndices;
|
||||||
|
for (int slotIndex : fieldInfo.groups[groupName]) {
|
||||||
|
subGroupIndices.append(slotIndex);
|
||||||
|
}
|
||||||
|
groupsObject[groupName] = subGroupIndices;
|
||||||
|
}
|
||||||
|
fieldObject["groups"] = groupsObject;
|
||||||
|
|
||||||
fieldsInfoArray.append(fieldObject);
|
fieldsInfoArray.append(fieldObject);
|
||||||
}
|
}
|
||||||
monHeadersObject["fields"] = fieldsInfoArray;
|
monHeadersObject["fields"] = fieldsInfoArray;
|
||||||
|
@ -1399,10 +1410,16 @@ void Project::readWildMonData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto field : subObject["fields"].toArray()) {
|
for (auto field : subObject["fields"].toArray()) {
|
||||||
QPair<QString, QVector<int>> encounterField;
|
EncounterField encounterField;
|
||||||
encounterField.first = field.toObject()["type"].toString();
|
encounterField.name = field.toObject()["type"].toString();
|
||||||
for (auto val : field.toObject()["encounter_rates"].toArray())
|
for (auto val : field.toObject()["encounter_rates"].toArray()) {
|
||||||
encounterField.second.append(val.toInt());
|
encounterField.encounterRates.append(val.toInt());
|
||||||
|
}
|
||||||
|
for (QString group : field.toObject()["groups"].toObject().keys()) {
|
||||||
|
for (auto slotNum : field.toObject()["groups"].toObject()[group].toArray()) {
|
||||||
|
encounterField.groups[group].append(slotNum.toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
wildMonFields.append(encounterField);
|
wildMonFields.append(encounterField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1412,8 +1429,8 @@ void Project::readWildMonData() {
|
||||||
|
|
||||||
WildPokemonHeader header;
|
WildPokemonHeader header;
|
||||||
|
|
||||||
for (QPair<QString, QVector<int>> monField : wildMonFields) {
|
for (EncounterField monField : wildMonFields) {
|
||||||
QString field = monField.first;
|
QString field = monField.name;
|
||||||
if (encounter.toObject().value(field) != QJsonValue::Undefined) {
|
if (encounter.toObject().value(field) != QJsonValue::Undefined) {
|
||||||
header.wildMons[field].active = true;
|
header.wildMons[field].active = true;
|
||||||
header.wildMons[field].encounterRate = encounter.toObject().value(field).toObject().value("encounter_rate").toInt();
|
header.wildMons[field].encounterRate = encounter.toObject().value(field).toObject().value("encounter_rate").toInt();
|
||||||
|
|
|
@ -22,16 +22,16 @@ bool MonTabWidget::eventFilter(QObject *, QEvent *event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonTabWidget::populate() {
|
void MonTabWidget::populate() {
|
||||||
Fields fields = project->wildMonFields;
|
EncounterFields fields = project->wildMonFields;
|
||||||
activeTabs = QVector<bool>(fields.size(), false);
|
activeTabs = QVector<bool>(fields.size(), false);
|
||||||
|
|
||||||
for (QPair<QString, QVector<int>> field : fields) {
|
for (EncounterField field : fields) {
|
||||||
QTableWidget *table = new QTableWidget;
|
QTableWidget *table = new QTableWidget;
|
||||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
table->setFocusPolicy(Qt::NoFocus);
|
table->setFocusPolicy(Qt::NoFocus);
|
||||||
table->setSelectionMode(QAbstractItemView::NoSelection);
|
table->setSelectionMode(QAbstractItemView::NoSelection);
|
||||||
table->clearFocus();
|
table->clearFocus();
|
||||||
addTab(table, field.first);
|
addTab(table, field.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +62,21 @@ void MonTabWidget::clearTableAt(int tabIndex) {
|
||||||
void MonTabWidget::populateTab(int tabIndex, WildMonInfo monInfo, QString fieldName) {
|
void MonTabWidget::populateTab(int tabIndex, WildMonInfo monInfo, QString fieldName) {
|
||||||
QTableWidget *speciesTable = tableAt(tabIndex);
|
QTableWidget *speciesTable = tableAt(tabIndex);
|
||||||
|
|
||||||
|
int fieldIndex = 0;
|
||||||
|
for (EncounterField field : project->wildMonFields) {
|
||||||
|
if (field.name == fieldName) break;
|
||||||
|
fieldIndex++;
|
||||||
|
}
|
||||||
|
bool insertGroupLabel = false;
|
||||||
|
if (!project->wildMonFields[fieldIndex].groups.isEmpty()) insertGroupLabel = true;
|
||||||
|
|
||||||
speciesTable->setRowCount(monInfo.wildPokemon.size());
|
speciesTable->setRowCount(monInfo.wildPokemon.size());
|
||||||
speciesTable->setColumnCount(7);
|
speciesTable->setColumnCount(insertGroupLabel ? 8 : 7);
|
||||||
|
|
||||||
QStringList landMonTableHeaders;
|
QStringList landMonTableHeaders;
|
||||||
landMonTableHeaders << "Slot" << "Species" << "Min Level" << "Max Level"
|
landMonTableHeaders << "Slot";
|
||||||
|
if (insertGroupLabel) landMonTableHeaders << "Group";
|
||||||
|
landMonTableHeaders << "Species" << "Min Level" << "Max Level"
|
||||||
<< "Encounter Chance" << "Slot Ratio" << "Encounter Rate";
|
<< "Encounter Chance" << "Slot Ratio" << "Encounter Rate";
|
||||||
speciesTable->setHorizontalHeaderLabels(landMonTableHeaders);
|
speciesTable->setHorizontalHeaderLabels(landMonTableHeaders);
|
||||||
speciesTable->horizontalHeader()->show();
|
speciesTable->horizontalHeader()->show();
|
||||||
|
@ -85,7 +95,7 @@ void MonTabWidget::populateTab(int tabIndex, WildMonInfo monInfo, QString fieldN
|
||||||
encounterRate->setValue(monInfo.encounterRate);
|
encounterRate->setValue(monInfo.encounterRate);
|
||||||
encounterLayout->addWidget(encounterRate);
|
encounterLayout->addWidget(encounterRate);
|
||||||
encounterFrame->setLayout(encounterLayout);
|
encounterFrame->setLayout(encounterLayout);
|
||||||
speciesTable->setCellWidget(0, 6, encounterFrame);
|
speciesTable->setCellWidget(0, insertGroupLabel? 7 : 6, encounterFrame);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (WildPokemon mon : monInfo.wildPokemon) {
|
for (WildPokemon mon : monInfo.wildPokemon) {
|
||||||
|
@ -127,19 +137,32 @@ void MonTabWidget::createSpeciesTableRow(QTableWidget *table, WildPokemon mon, i
|
||||||
});
|
});
|
||||||
|
|
||||||
int fieldIndex = 0;
|
int fieldIndex = 0;
|
||||||
for (auto field : project->wildMonFields) {
|
for (EncounterField field : project->wildMonFields) {
|
||||||
if (field.first == fieldName) break;
|
if (field.name == fieldName) break;
|
||||||
fieldIndex++;
|
fieldIndex++;
|
||||||
}
|
}
|
||||||
double slotChanceTotal = 0;
|
|
||||||
for (auto chance : project->wildMonFields[fieldIndex].second) {
|
double slotChanceTotal = 0.0;
|
||||||
slotChanceTotal += static_cast<double>(chance);
|
if (!project->wildMonFields[fieldIndex].groups.isEmpty()) {
|
||||||
|
for (QString groupKey : project->wildMonFields[fieldIndex].groups.keys()) {
|
||||||
|
if (project->wildMonFields[fieldIndex].groups[groupKey].contains(index)) {
|
||||||
|
for (int chanceIndex : project->wildMonFields[fieldIndex].groups[groupKey]) {
|
||||||
|
slotChanceTotal += static_cast<double>(project->wildMonFields[fieldIndex].encounterRates[chanceIndex]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (auto chance : project->wildMonFields[fieldIndex].encounterRates) {
|
||||||
|
slotChanceTotal += static_cast<double>(chance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QLabel *percentLabel = new QLabel(QString("%1%").arg(
|
QLabel *percentLabel = new QLabel(QString("%1%").arg(
|
||||||
QString::number(project->wildMonFields[fieldIndex].second[index] / slotChanceTotal * 100.0, 'f', 2)
|
QString::number(project->wildMonFields[fieldIndex].encounterRates[index] / slotChanceTotal * 100.0, 'f', 2)
|
||||||
));
|
));
|
||||||
QLabel *ratioLabel = new QLabel(QString("%1").arg(
|
QLabel *ratioLabel = new QLabel(QString("%1").arg(
|
||||||
QString::number(project->wildMonFields[fieldIndex].second[index]
|
QString::number(project->wildMonFields[fieldIndex].encounterRates[index]
|
||||||
)));
|
)));
|
||||||
|
|
||||||
QFrame *speciesSelector = new QFrame;
|
QFrame *speciesSelector = new QFrame;
|
||||||
|
@ -158,12 +181,25 @@ void MonTabWidget::createSpeciesTableRow(QTableWidget *table, WildPokemon mon, i
|
||||||
maxLevelSpinboxLayout->addWidget(maxLevel);
|
maxLevelSpinboxLayout->addWidget(maxLevel);
|
||||||
maxLevelFrame->setLayout(maxLevelSpinboxLayout);
|
maxLevelFrame->setLayout(maxLevelSpinboxLayout);
|
||||||
|
|
||||||
|
bool insertGroupLabel = false;
|
||||||
|
if (!project->wildMonFields[fieldIndex].groups.isEmpty()) insertGroupLabel = true;
|
||||||
table->setCellWidget(index, 0, monNum);
|
table->setCellWidget(index, 0, monNum);
|
||||||
table->setCellWidget(index, 1, speciesSelector);
|
if (insertGroupLabel) {
|
||||||
table->setCellWidget(index, 2, minLevelFrame);
|
QString groupName = QString();
|
||||||
table->setCellWidget(index, 3, maxLevelFrame);
|
for (QString groupKey : project->wildMonFields[fieldIndex].groups.keys()) {
|
||||||
table->setCellWidget(index, 4, percentLabel);
|
if (project->wildMonFields[fieldIndex].groups[groupKey].contains(index)) {
|
||||||
table->setCellWidget(index, 5, ratioLabel);
|
groupName = groupKey;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QLabel *groupNameLabel = new QLabel(groupName);
|
||||||
|
table->setCellWidget(index, 1, groupNameLabel);
|
||||||
|
}
|
||||||
|
table->setCellWidget(index, insertGroupLabel? 2 : 1, speciesSelector);
|
||||||
|
table->setCellWidget(index, insertGroupLabel? 3 : 2, minLevelFrame);
|
||||||
|
table->setCellWidget(index, insertGroupLabel? 4 : 3, maxLevelFrame);
|
||||||
|
table->setCellWidget(index, insertGroupLabel? 5 : 4, percentLabel);
|
||||||
|
table->setCellWidget(index, insertGroupLabel? 6 : 5, ratioLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTableWidget *MonTabWidget::tableAt(int tabIndex) {
|
QTableWidget *MonTabWidget::tableAt(int tabIndex) {
|
||||||
|
|
Loading…
Reference in a new issue