clean wild encounter code
This commit is contained in:
parent
78a6944a3c
commit
267c71d40e
9 changed files with 28 additions and 269 deletions
|
@ -10,14 +10,11 @@ struct WildPokemon {
|
|||
};
|
||||
|
||||
struct WildMonInfo {
|
||||
//
|
||||
bool active = false;
|
||||
int encounterRate = 0;
|
||||
QVector<WildPokemon> wildPokemon;
|
||||
};
|
||||
|
||||
// for extensibility, make a QVector<WildMonInfo>
|
||||
// or QMap<QString, WildMonInfo>
|
||||
struct WildPokemonHeader {
|
||||
QMap<QString, WildMonInfo> wildMons;
|
||||
};
|
||||
|
@ -25,14 +22,6 @@ struct WildPokemonHeader {
|
|||
typedef QVector<QPair<QString, QVector<int>>> Fields;
|
||||
typedef QPair<QString, QVector<int>> Field;
|
||||
|
||||
//class Project;
|
||||
//class MonTabWidget;
|
||||
//QWidget *newSpeciesTableEntry(Project *project, WildPokemon mon, int index);
|
||||
//void createSpeciesTableRow(Project *, QTableWidget *, WildPokemon, int, QString);
|
||||
void clearTabWidget(QLayout *tab);
|
||||
//void clearTable(QTableWidget *table);
|
||||
//void populateWildMonTabWidget(MonTabWidget *tabWidget, Fields /* QVector<QPair<QString, QVector<int>>> */ fields);
|
||||
|
||||
WildMonInfo getDefaultMonInfo(Field field);
|
||||
WildMonInfo copyMonInfoFromTab(QTableWidget *table, Field field);
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ public:
|
|||
void setEditingCollision();
|
||||
void setEditingObjects();
|
||||
void setEditingConnections();
|
||||
void setEditingWildMons();
|
||||
void clearWildMonTabWidgets();
|
||||
void setCurrentConnectionDirection(QString curDirection);
|
||||
void updateCurrentConnectionDirection(QString curDirection);
|
||||
|
|
|
@ -87,16 +87,13 @@ public:
|
|||
QString readMapLocation(QString map_name);
|
||||
|
||||
void readWildMonData();
|
||||
QMap<QString, QMap<QString, WildPokemonHeader>> wildMonData;// "MAP_CONSTANT": {base_label: wild_encounter_json
|
||||
QMap<QString, QString> encounterMapToBaseLabel;// delete this?
|
||||
QMap<QString, QMap<QString, WildPokemonHeader>> wildMonData;
|
||||
QVector<QPair<QString, QVector<int>>> wildMonFields;
|
||||
QVector<QString> encounterGroupLabels;
|
||||
// when saving, preserve the extra fields for gBattlePyramidWildMonHeaders, gBattlePikeWildMonHeaders
|
||||
QMap<QString, QJsonObject> extraEncounterGroups;
|
||||
|
||||
void readSpeciesIconPaths();
|
||||
QMap<QString, QString> speciesToIconPath;
|
||||
//QVector<QString> wildMonFields;
|
||||
QVector<QPair<QString, QVector<int>>> wildMonFields;
|
||||
// temporary?
|
||||
QMap<QString, QJsonObject> extraEncounterGroups;
|
||||
|
||||
QMap<QString, bool> getTopLevelMapFields();
|
||||
bool loadMapData(Map*);
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// montablewidget.h
|
||||
|
||||
#ifndef MONTABWIDGET_H
|
||||
#define MONTABWIDGET_H
|
||||
|
||||
|
@ -8,7 +6,6 @@
|
|||
#include <QtWidgets>
|
||||
#include <QVector>
|
||||
|
||||
//
|
||||
class Project;
|
||||
|
||||
class MonTabWidget : public QTabWidget {
|
||||
|
@ -28,7 +25,6 @@ public:
|
|||
void clearTableAt(int index);
|
||||
|
||||
QTableWidget *tableAt(int tabIndex);
|
||||
//void setupTableAt(int tabIndex);
|
||||
|
||||
public slots:
|
||||
void setTabActive(int index, bool active = true);
|
||||
|
@ -40,12 +36,6 @@ private:
|
|||
QVector<bool> activeTabs;
|
||||
|
||||
Project *project;
|
||||
|
||||
private slots:
|
||||
//
|
||||
|
||||
signals:
|
||||
// right click
|
||||
};
|
||||
|
||||
#endif // MONTABWIDGET_H
|
||||
|
|
|
@ -1,25 +1,9 @@
|
|||
//
|
||||
|
||||
#include "wildmoninfo.h"
|
||||
#include "montabwidget.h"
|
||||
#include "project.h"
|
||||
|
||||
|
||||
|
||||
// TODO: remove this necessity
|
||||
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);
|
||||
}
|
||||
|
||||
WildMonInfo getDefaultMonInfo(Field field) {
|
||||
WildMonInfo newInfo;
|
||||
newInfo.active = true;
|
||||
|
@ -48,4 +32,3 @@ WildMonInfo copyMonInfoFromTab(QTableWidget *monTable, Field field) {
|
|||
|
||||
return newInfo;
|
||||
}
|
||||
|
||||
|
|
166
src/editor.cpp
166
src/editor.cpp
|
@ -40,7 +40,6 @@ void Editor::save() {
|
|||
}
|
||||
|
||||
void Editor::saveUiFields() {
|
||||
//
|
||||
saveEncounterTabData();
|
||||
}
|
||||
|
||||
|
@ -158,20 +157,12 @@ void Editor::setEditingConnections() {
|
|||
this->cursorMapTileRect->setVisibility(false);
|
||||
}
|
||||
|
||||
void Editor::setEditingWildMons() {
|
||||
// nothing for now
|
||||
}
|
||||
|
||||
// TODO: figure out why this is being called twice
|
||||
void Editor::displayWildMonTables() {
|
||||
QStackedWidget *stack = ui->stackedWidget_WildMons;
|
||||
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
|
||||
// TODO: temp. instead do a for loop here
|
||||
//WildPokemonHeader header = project->wildMonData.value(map->constantName).first();
|
||||
|
||||
// TODO: return when there is no data for the map
|
||||
// delete widgets from previous map data if they exist
|
||||
while (stack->count()) {
|
||||
//
|
||||
QWidget *oldWidget = stack->widget(0);
|
||||
stack->removeWidget(oldWidget);
|
||||
delete oldWidget;
|
||||
|
@ -179,75 +170,41 @@ void Editor::displayWildMonTables() {
|
|||
|
||||
labelCombo->clear();
|
||||
|
||||
// Don't try to read encounter data if it doesn't exist on disk for this map.
|
||||
if (!project->wildMonData.contains(map->constantName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// do I have to disconnect this signal? or set it up only once?
|
||||
//connect(labelCombo, QOverload<int>::of(&QComboBox::activated), [=](int index){
|
||||
// stack->setCurrentIndex(index);//setCurrentWidget(tabWidget);
|
||||
//});
|
||||
labelCombo->addItems(project->wildMonData[map->constantName].keys());
|
||||
labelCombo->setCurrentText(project->wildMonData[map->constantName].firstKey());
|
||||
|
||||
// TODO: instance of this map, use .value()
|
||||
for (int labelIndex = 0; labelIndex < project->wildMonData[map->constantName].keys().size(); labelIndex++) {
|
||||
|
||||
QString label = project->wildMonData.value(map->constantName).keys().at(labelIndex);
|
||||
|
||||
WildPokemonHeader header = project->wildMonData.value(map->constantName).value(label);
|
||||
|
||||
//QTabWidget *tabWidget = new QTabWidget;
|
||||
MonTabWidget *tabWidget = new MonTabWidget(project);
|
||||
stack->insertWidget(labelIndex, tabWidget);
|
||||
//populateWildMonTabWidget(tabWidget, project->wildMonFields);
|
||||
//stack->setCurrentWidget(tabWidget);
|
||||
|
||||
//QVector<int> unusedIndices;
|
||||
|
||||
int tabIndex = 0;
|
||||
for (Field monField : project->wildMonFields) {
|
||||
QString fieldName = monField.first;
|
||||
|
||||
// tabWidget_WildMons
|
||||
//QTableWidget *speciesTable = tabWidget->tableAt(tabIndex);
|
||||
//clearTable(speciesTable);
|
||||
tabWidget->clearTableAt(tabIndex);
|
||||
//speciesTable->horizontalHeader()->hide();
|
||||
|
||||
if (project->wildMonData.contains(map->constantName) && header.wildMons[fieldName].active) {
|
||||
tabWidget->populateTab(tabIndex, header.wildMons[fieldName], fieldName);
|
||||
} else {
|
||||
//unusedIndices.append
|
||||
tabWidget->setTabActive(tabIndex, false);
|
||||
//tabWidget
|
||||
}
|
||||
tabIndex++;
|
||||
}
|
||||
//connect(tabWidget, &QTabWidget::tabBarDoubleClicked, [=](int clickedTab) {
|
||||
// if (!unusedIndices.contains(clickedTab)) return;
|
||||
|
||||
// project->wildMonData.value(map->constantName).value(label).active = true
|
||||
// header.wildMons[field].wildPokemon = QVector<WildPokemon>...
|
||||
|
||||
// qDebug() << "double clicked tab" << clickedTab;
|
||||
|
||||
//displayWildMonTables();
|
||||
//});
|
||||
}
|
||||
stack->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
// TODO: move this funciton?
|
||||
void Editor::addNewWildMonGroup() {
|
||||
// copy the currently displayed group?
|
||||
qDebug() << "new wild encounter group to map" << map->name;
|
||||
|
||||
static bool earlyExit = false;
|
||||
|
||||
if (earlyExit) return;
|
||||
|
||||
// QStackedWidget *stack = ui->stackedWidget_WildMons
|
||||
QStackedWidget *stack = ui->stackedWidget_WildMons;
|
||||
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
|
||||
|
||||
|
@ -278,25 +235,14 @@ void Editor::addNewWildMonGroup() {
|
|||
buttonBox.button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
}
|
||||
});
|
||||
// give a default value to the label
|
||||
lineEdit->setText(QString("g%1%2").arg(map->name).arg(stack->count()));//project->wildMonData.value(map->constantName).size()));
|
||||
// Give a default value to the label.
|
||||
lineEdit->setText(QString("g%1%2").arg(map->name).arg(stack->count()));
|
||||
|
||||
//WildPokemonHeader header;
|
||||
//QString label;
|
||||
//if (project->wildMonData.contains(map->constantName)) {
|
||||
// label = project->wildMonData.value(map->constantName).keys().at(0);// copy the first one
|
||||
//}
|
||||
//if (!label.isEmpty()) {
|
||||
// header = project->wildMonData.value(map->constantName).value(label);
|
||||
//} else {
|
||||
// TODO: change this to default or null
|
||||
//WildPokemonHeader header;// = project->wildMonData.value(map->constantName).value(label);
|
||||
//}
|
||||
// Fields [x] copy from existing
|
||||
QLabel *fieldsLabel = new QLabel("Fields:");
|
||||
form.addRow(fieldsLabel);
|
||||
QCheckBox *copyCheckbox = new QCheckBox;
|
||||
copyCheckbox->setEnabled(stack->count());//project->wildMonData.contains(map->constantName));// disable if there are no
|
||||
copyCheckbox->setEnabled(stack->count());
|
||||
form.addRow(new QLabel("Copy from current group"), copyCheckbox);
|
||||
QVector<QCheckBox *> fieldCheckboxes;
|
||||
for (Field monField : project->wildMonFields) {
|
||||
|
@ -304,13 +250,13 @@ void Editor::addNewWildMonGroup() {
|
|||
fieldCheckboxes.append(fieldCheckbox);
|
||||
form.addRow(new QLabel(monField.first), fieldCheckbox);
|
||||
}
|
||||
// TODO: fix this
|
||||
// Reading from ui here so not saving to disk before user.
|
||||
connect(copyCheckbox, &QCheckBox::stateChanged, [=](int state){
|
||||
if (state == Qt::Checked) {
|
||||
int fieldIndex = 0;
|
||||
MonTabWidget *monWidget = static_cast<MonTabWidget *>(stack->widget(stack->currentIndex()));
|
||||
for (Field monField : project->wildMonFields) {
|
||||
fieldCheckboxes[fieldIndex]->setChecked(monWidget->isTabEnabled(fieldIndex));//header.wildMons.value(monField.first).active);
|
||||
fieldCheckboxes[fieldIndex]->setChecked(monWidget->isTabEnabled(fieldIndex));
|
||||
fieldCheckboxes[fieldIndex]->setEnabled(false);
|
||||
fieldIndex++;
|
||||
}
|
||||
|
@ -326,7 +272,6 @@ void Editor::addNewWildMonGroup() {
|
|||
connect(&buttonBox, &QDialogButtonBox::accepted, [&dialog, &lineEdit, this](){
|
||||
QString newLabel = lineEdit->text();
|
||||
if (!newLabel.isEmpty()) {
|
||||
qDebug() << "new label:" << newLabel;
|
||||
this->project->encounterGroupLabels.append(newLabel);
|
||||
dialog.accept();
|
||||
}
|
||||
|
@ -335,37 +280,25 @@ void Editor::addNewWildMonGroup() {
|
|||
form.addRow(&buttonBox);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
qDebug() << "new encounter group dialog accepted";
|
||||
|
||||
WildPokemonHeader header;
|
||||
for (Field monField : project->wildMonFields) {
|
||||
//
|
||||
QString fieldName = monField.first;
|
||||
header.wildMons[fieldName].active = false;
|
||||
header.wildMons[fieldName].encounterRate = 0;
|
||||
}
|
||||
|
||||
// TODO: check for this signal, or set it up somewhere else
|
||||
//connect(labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){
|
||||
// stack->setCurrentIndex(index);//setCurrentWidget(tabWidget);
|
||||
//});
|
||||
|
||||
MonTabWidget *tabWidget = new MonTabWidget(project);
|
||||
stack->insertWidget(stack->count(), tabWidget);//project->wildMonData[map->constantName].keys().size(), tabWidget);
|
||||
stack->insertWidget(stack->count(), tabWidget);
|
||||
|
||||
labelCombo->addItem(lineEdit->text());
|
||||
labelCombo->setCurrentIndex(labelCombo->count() - 1);
|
||||
|
||||
// populate it -- check for copyFrom checked
|
||||
int tabIndex = 0;
|
||||
for (Field monField : project->wildMonFields) {
|
||||
QString fieldName = monField.first;
|
||||
//header.wildMons[fieldName].active = fieldCheckboxes[tabIndex]->isChecked();
|
||||
tabWidget->clearTableAt(tabIndex);
|
||||
if (fieldCheckboxes[tabIndex]->isChecked()) {//(header.wildMons[fieldName].active) {
|
||||
qDebug() << "checked" << fieldName;
|
||||
if (fieldCheckboxes[tabIndex]->isChecked()) {
|
||||
if (copyCheckbox->isChecked()) {
|
||||
qDebug() << "copying mons from current group";
|
||||
MonTabWidget *copyFrom = static_cast<MonTabWidget *>(stack->widget(stackIndex));
|
||||
if (copyFrom->isTabEnabled(tabIndex))
|
||||
header.wildMons.insert(fieldName, copyMonInfoFromTab(copyFrom->tableAt(tabIndex), monField));
|
||||
|
@ -381,22 +314,16 @@ void Editor::addNewWildMonGroup() {
|
|||
tabIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
//earlyExit = true;
|
||||
}
|
||||
|
||||
void Editor::configureEncounterJSON() {
|
||||
//
|
||||
qDebug() << "configure wild encounter json";
|
||||
|
||||
QVector<QWidget *> fieldSlots;
|
||||
|
||||
Fields tempFields = project->wildMonFields;
|
||||
|
||||
QLabel *totalLabel = new QLabel;
|
||||
|
||||
auto updateTotal = [&fieldSlots, &tempFields, totalLabel](Field ¤tField) {
|
||||
//
|
||||
auto updateTotal = [&fieldSlots, totalLabel](Field ¤tField) {
|
||||
int total = 0, spinnerIndex = 0;
|
||||
for (auto slot : fieldSlots) {
|
||||
QSpinBox *spinner = slot->findChild<QSpinBox *>();
|
||||
|
@ -430,12 +357,11 @@ void Editor::configureEncounterJSON() {
|
|||
return slot;
|
||||
};
|
||||
|
||||
//
|
||||
QDialog dialog(nullptr, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
||||
dialog.setWindowTitle("Configure Wild Encounter Fields");
|
||||
dialog.setWindowModality(Qt::NonModal);
|
||||
|
||||
QGridLayout grid;//(&dialog);
|
||||
QGridLayout grid;
|
||||
|
||||
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
|
||||
|
||||
|
@ -449,8 +375,7 @@ void Editor::configureEncounterJSON() {
|
|||
return fieldNames;
|
||||
};
|
||||
auto drawSlotWidgets = [this, &grid, &createNewSlot, &fieldSlots, &updateTotal, &tempFields](int index) {
|
||||
// clear them first
|
||||
//for (auto slot : slots) {//grid.findChildren<QFrame *>()) {
|
||||
// Clear them first.
|
||||
while (!fieldSlots.isEmpty()) {
|
||||
auto slot = fieldSlots.takeFirst();
|
||||
grid.removeWidget(slot);
|
||||
|
@ -473,14 +398,9 @@ void Editor::configureEncounterJSON() {
|
|||
// Button to create new fields in the JSON.
|
||||
QPushButton *addFieldButton = new QPushButton("Add New Field...");
|
||||
connect(addFieldButton, &QPushButton::clicked, [fieldChoices, &tempFields]() {
|
||||
// fieldChoices
|
||||
qDebug() << "add new field pressed";
|
||||
|
||||
QDialog newNameDialog(nullptr, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
||||
newNameDialog.setWindowModality(Qt::NonModal);
|
||||
|
||||
QDialogButtonBox newFieldButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &newNameDialog);
|
||||
|
||||
connect(&newFieldButtonBox, SIGNAL(accepted()), &newNameDialog, SLOT(accept()));
|
||||
connect(&newFieldButtonBox, SIGNAL(rejected()), &newNameDialog, SLOT(reject()));
|
||||
|
||||
|
@ -492,22 +412,17 @@ void Editor::configureEncounterJSON() {
|
|||
newFieldForm.addRow(&newFieldButtonBox);
|
||||
|
||||
if (newNameDialog.exec() == QDialog::Accepted) {
|
||||
//
|
||||
QString newFieldName = newNameEdit->text();
|
||||
QVector<int> newFieldRates(1, 100);
|
||||
tempFields.append({newFieldName, newFieldRates});
|
||||
fieldChoices->addItem(newFieldName);
|
||||
fieldChoices->setCurrentIndex(fieldChoices->count() - 1);
|
||||
}
|
||||
//QString newFieldName =
|
||||
//tempFields.append();
|
||||
});
|
||||
|
||||
// buttons + / - with icons and flat frame
|
||||
QPushButton *addSlotButton = new QPushButton(QIcon(":/icons/add.ico"), "");
|
||||
addSlotButton->setFlat(true);
|
||||
connect(addSlotButton, &QPushButton::clicked, [this, &fieldChoices, &drawSlotWidgets, &tempFields]() {
|
||||
//
|
||||
Field &field = tempFields[fieldChoices->currentIndex()];
|
||||
field.second.append(1);
|
||||
drawSlotWidgets(fieldChoices->currentIndex());
|
||||
|
@ -515,14 +430,12 @@ void Editor::configureEncounterJSON() {
|
|||
QPushButton *removeSlotButton = new QPushButton(QIcon(":/icons/delete.ico"), "");
|
||||
removeSlotButton->setFlat(true);
|
||||
connect(removeSlotButton, &QPushButton::clicked, [this, &fieldChoices, &drawSlotWidgets, &tempFields]() {
|
||||
//
|
||||
Field &field = tempFields[fieldChoices->currentIndex()];
|
||||
if (field.second.size() > 1)
|
||||
field.second.removeLast();
|
||||
drawSlotWidgets(fieldChoices->currentIndex());
|
||||
});
|
||||
|
||||
|
||||
QFrame firstRow;
|
||||
QHBoxLayout firstRowLayout;
|
||||
firstRowLayout.addWidget(fieldChoiceLabel);
|
||||
|
@ -546,91 +459,44 @@ void Editor::configureEncounterJSON() {
|
|||
frameBottom->setLayout(&lastRow);
|
||||
layout.addWidget(frameBottom);
|
||||
|
||||
// TODO: add create new field name
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
qDebug() << "configure json dialog accepted";
|
||||
// re-load the wild encounters tab ui
|
||||
|
||||
// Copy the temporary modified field info to project.
|
||||
Fields &newFields = project->wildMonFields;
|
||||
newFields = tempFields;
|
||||
|
||||
// re-draw the tab accordingly
|
||||
// Re-draw the tab accordingly.
|
||||
displayWildMonTables();
|
||||
|
||||
// TODO: update values for every single wild encounter entry? like
|
||||
// if there are deleted fields, remove them?
|
||||
// TODO: Update values for every single wild encounter entry?
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move this?
|
||||
void Editor::saveEncounterTabData() {
|
||||
//if (!project->wildMonData.contains(map->constantName)) {
|
||||
// qDebug() << "don't save encounters for this map";
|
||||
// return;
|
||||
//}
|
||||
//
|
||||
QStackedWidget *stack = ui->stackedWidget_WildMons;
|
||||
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
|
||||
|
||||
if (!stack->count()) return;
|
||||
|
||||
// TODO: verify that this exists before accsessing so no seg fault
|
||||
QMap<QString, WildPokemonHeader> &encounterMap = project->wildMonData[map->constantName];
|
||||
|
||||
//for (int groupIndex = 0; groupIndex < encounterMap.keys().size(); groupIndex++) {
|
||||
for (int groupIndex = 0; groupIndex < stack->count(); groupIndex++) {
|
||||
//
|
||||
MonTabWidget *tabWidget = static_cast<MonTabWidget *>(stack->widget(groupIndex));
|
||||
|
||||
// TODO: verify this exists before so no segfault actually no
|
||||
WildPokemonHeader &encounterHeader = encounterMap[labelCombo->itemText(groupIndex)];
|
||||
|
||||
//qDebug() << encounterHeader.wildMons.keys();
|
||||
|
||||
//for (int tabIndex = 0; tabIndex < tabWidget->count(); tabIndex++) {
|
||||
// QTableWidget *monTable =
|
||||
//}
|
||||
int fieldIndex = 0;
|
||||
for (Field monField : project->wildMonFields) {
|
||||
QString fieldName = monField.first;
|
||||
//if (!encounterHeader.wildMons.contains(fieldName)
|
||||
// || encounterHeader.wildMons[fieldName].wildPokemon.empty()
|
||||
// || !encounterHeader.wildMons[fieldName].active) continue;
|
||||
|
||||
if (!tabWidget->isTabEnabled(fieldIndex++)) continue;
|
||||
// project->wildMonData
|
||||
//qDebug() << monField.first << "mons";
|
||||
|
||||
QTableWidget *monTable = static_cast<QTableWidget *>(tabWidget->widget(fieldIndex - 1));
|
||||
|
||||
QVector<WildPokemon> newWildMons;
|
||||
|
||||
encounterHeader.wildMons[fieldName] = copyMonInfoFromTab(monTable, monField);
|
||||
|
||||
//for (auto *speciesCombo : monTable->findChildren<QComboBox *>()) {
|
||||
/*
|
||||
for (int row = 0; row < monTable->rowCount(); row++) {
|
||||
// cellWidget(row, column)
|
||||
WildPokemon newWildMon;
|
||||
newWildMon.species = monTable->cellWidget(row, 1)->findChild<QComboBox *>()->currentText();
|
||||
newWildMon.minLevel = monTable->cellWidget(row, 2)->findChild<QSpinBox *>()->value();//static_cast<QSpinBox *>(monTable->cellWidget(row, 2))->value();
|
||||
newWildMon.maxLevel = monTable->cellWidget(row, 3)->findChild<QSpinBox *>()->value();//static_cast<QSpinBox *>(monTable->cellWidget(row, 3))->value();
|
||||
newWildMons.append(newWildMon);//(speciesCombo->currentText());
|
||||
}
|
||||
// Brackets because need a reference to this object. A safety check is done at the top.
|
||||
encounterHeader.wildMons[fieldName].active = true;
|
||||
encounterHeader.wildMons[fieldName].wildPokemon = newWildMons;
|
||||
encounterHeader.wildMons[fieldName].encounterRate = monTable->findChild<QSlider *>()->value();
|
||||
//fieldIndex++;
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::clearWildMonTabWidgets() {
|
||||
//
|
||||
}
|
||||
|
||||
void Editor::setDiveEmergeControls() {
|
||||
ui->comboBox_DiveMap->blockSignals(true);
|
||||
ui->comboBox_EmergeMap->blockSignals(true);
|
||||
|
|
|
@ -267,13 +267,11 @@ 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) {
|
||||
|
@ -1093,8 +1091,6 @@ void MainWindow::on_tabWidget_currentChanged(int index)
|
|||
editor->setEditingObjects();
|
||||
} else if (index == 3) {
|
||||
editor->setEditingConnections();
|
||||
} else if (index == 4) {
|
||||
//editor->setEditingWildMons();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1974,12 +1970,10 @@ void MainWindow::on_pushButton_RemoveConnection_clicked()
|
|||
}
|
||||
|
||||
void MainWindow::on_pushButton_NewWildMonGroup_clicked() {
|
||||
//
|
||||
editor->addNewWildMonGroup();
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_ConfigureEncountersJSON_clicked() {
|
||||
//
|
||||
editor->configureEncounterJSON();
|
||||
}
|
||||
|
||||
|
|
|
@ -521,9 +521,7 @@ void Project::saveMapGroups() {
|
|||
}
|
||||
|
||||
void Project::saveWildMonData() {
|
||||
//
|
||||
QString wildEncountersJsonFilepath = QString("%1/src/data/wild_encounters.json").arg(root);
|
||||
//QString wildEncountersJsonFilepath = QString("%1/src/data/wild_encounters_test.json").arg(root);
|
||||
QFile wildEncountersFile(wildEncountersJsonFilepath);
|
||||
if (!wildEncountersFile.open(QIODevice::WriteOnly)) {
|
||||
logError(QString("Error: Could not open %1 for writing").arg(wildEncountersJsonFilepath));
|
||||
|
@ -533,7 +531,7 @@ void Project::saveWildMonData() {
|
|||
QJsonObject wildEncountersObject;
|
||||
QJsonArray wildEncounterGroups = QJsonArray();
|
||||
|
||||
// gWildMonHeaders
|
||||
// gWildMonHeaders label is not mutable
|
||||
QJsonObject monHeadersObject;
|
||||
monHeadersObject["label"] = "gWildMonHeaders";
|
||||
monHeadersObject["for_maps"] = true;
|
||||
|
@ -558,46 +556,32 @@ void Project::saveWildMonData() {
|
|||
for (QString groupLabel : wildMonData.value(key).keys()) {
|
||||
QJsonObject encounterObject;
|
||||
encounterObject["map"] = key;
|
||||
encounterObject["base_label"] = groupLabel;//encounterMapToBaseLabel[key];
|
||||
//
|
||||
encounterObject["base_label"] = groupLabel;
|
||||
|
||||
WildPokemonHeader encounterHeader = wildMonData.value(key).value(groupLabel);
|
||||
for (QString fieldName : encounterHeader.wildMons.keys()) {
|
||||
//
|
||||
QJsonObject fieldObject;
|
||||
WildMonInfo monInfo = encounterHeader.wildMons.value(fieldName);
|
||||
fieldObject["encounter_rate"] = monInfo.encounterRate;
|
||||
QJsonArray monArray;
|
||||
for (WildPokemon wildMon : monInfo.wildPokemon) {
|
||||
//
|
||||
QJsonObject monEntry;
|
||||
monEntry["min_level"] = wildMon.minLevel;
|
||||
monEntry["max_level"] = wildMon.maxLevel;
|
||||
monEntry["species"] = wildMon.species;
|
||||
monArray.append(monEntry);
|
||||
}
|
||||
fieldObject["mons"] = monArray;//fieldObject;
|
||||
fieldObject["mons"] = monArray;
|
||||
encounterObject[fieldName] = fieldObject;
|
||||
}
|
||||
//encounterObject[];
|
||||
// QMap<QString, WildMonInfo> wildMons;
|
||||
|
||||
//QJsonArray
|
||||
//for (auto fieldItem : wildMonFields) {
|
||||
// QString fieldLabel = fieldItem.first;
|
||||
// encounterObject[fieldLabel] = ;
|
||||
//}
|
||||
|
||||
encountersArray.append(encounterObject);
|
||||
}
|
||||
// TODO: save fields json data
|
||||
}
|
||||
monHeadersObject["encounters"] = encountersArray;
|
||||
wildEncounterGroups.append(monHeadersObject);
|
||||
|
||||
// add extra Json objects that are not associated with maps to the file
|
||||
for (QString label : extraEncounterGroups.keys()) {
|
||||
qDebug() << "extra label:" << label;
|
||||
wildEncounterGroups.append(extraEncounterGroups[label]);
|
||||
}
|
||||
|
||||
|
@ -1394,7 +1378,6 @@ void Project::deleteFile(QString path) {
|
|||
}
|
||||
|
||||
void Project::readWildMonData() {
|
||||
//
|
||||
QString wildMonJsonFilepath = QString("%1/src/data/wild_encounters.json").arg(root);
|
||||
QJsonDocument wildMonsJsonDoc;
|
||||
if (!parser.tryParseJsonFile(&wildMonsJsonDoc, wildMonJsonFilepath)) {
|
||||
|
@ -1423,12 +1406,9 @@ void Project::readWildMonData() {
|
|||
for (QJsonValue encounter : encounters) {
|
||||
QString mapConstant = encounter["map"].toString();
|
||||
|
||||
encounterMapToBaseLabel.insert(mapConstant, encounter["base_label"].toString());
|
||||
|
||||
WildPokemonHeader header;
|
||||
|
||||
for (QPair<QString, QVector<int>> monField : wildMonFields) {
|
||||
//
|
||||
QString field = monField.first;
|
||||
if (encounter[field] != QJsonValue::Undefined) {
|
||||
header.wildMons[field].active = true;
|
||||
|
@ -1442,15 +1422,10 @@ void Project::readWildMonData() {
|
|||
}
|
||||
}
|
||||
}
|
||||
//if (!wildMonData.contains(mapConstant))
|
||||
// wildMonData.insert(mapConstant, header);
|
||||
//else
|
||||
wildMonData[mapConstant].insert(encounter["base_label"].toString(), header);
|
||||
encounterGroupLabels.append(encounter["base_label"].toString());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
void Project::readMapGroups() {
|
||||
|
|
|
@ -4,39 +4,24 @@
|
|||
#include "project.h"
|
||||
|
||||
MonTabWidget::MonTabWidget(Project *project, QWidget *parent) : QTabWidget(parent) {
|
||||
//
|
||||
this->project = project;
|
||||
populate();
|
||||
installEventFilter(this);
|
||||
}
|
||||
|
||||
bool MonTabWidget::eventFilter(QObject *object, QEvent *event) {
|
||||
//
|
||||
// press right mouse button
|
||||
// Press right mouse button to activate tab.
|
||||
if (event->type() == QEvent::MouseButtonPress
|
||||
&& static_cast<QMouseEvent *>(event)->button() == Qt::RightButton) {
|
||||
//
|
||||
QPoint eventPos = static_cast<QMouseEvent *>(event)->pos();
|
||||
int tabIndex = tabBar()->tabAt(eventPos);
|
||||
if (tabIndex > -1) {
|
||||
askActivateTab(tabIndex, eventPos);
|
||||
}
|
||||
//
|
||||
} else {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
void MonTabWidget::populate() {
|
||||
//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
|
||||
|
||||
Fields fields = project->wildMonFields;
|
||||
activeTabs = QVector<bool>(fields.size(), false);
|
||||
|
||||
|
@ -58,14 +43,11 @@ void MonTabWidget::askActivateTab(int tabIndex, QPoint menuPos) {
|
|||
QString tabText = tabBar()->tabText(tabIndex);
|
||||
QAction actionActivateTab(QString("Add %1 data for this map...").arg(tabText), this);
|
||||
connect(&actionActivateTab, &QAction::triggered, [=](){
|
||||
//
|
||||
//qDebug() << "activate tab" << tabIndex;
|
||||
clearTableAt(tabIndex);
|
||||
populateTab(tabIndex, getDefaultMonInfo(project->wildMonFields.at(tabIndex)), tabText);
|
||||
setCurrentIndex(tabIndex);
|
||||
});//SIGNAL(triggered()), this, SLOT(removeDataPoint()));
|
||||
});
|
||||
contextMenu.addAction(&actionActivateTab);
|
||||
|
||||
contextMenu.exec(mapToGlobal(menuPos));
|
||||
}
|
||||
|
||||
|
@ -78,16 +60,12 @@ void MonTabWidget::clearTableAt(int tabIndex) {
|
|||
}
|
||||
|
||||
void MonTabWidget::populateTab(int tabIndex, WildMonInfo monInfo, QString fieldName) {
|
||||
//
|
||||
int i = 1;
|
||||
|
||||
//ui->stackedWidget_WildMons->insertWidget(0, speciesTable);
|
||||
//return;
|
||||
|
||||
QTableWidget *speciesTable = tableAt(tabIndex);
|
||||
|
||||
speciesTable->setRowCount(monInfo.wildPokemon.size());
|
||||
speciesTable->setColumnCount(6);// TODO: stretch last column?
|
||||
speciesTable->setColumnCount(6);
|
||||
|
||||
QStringList landMonTableHeaders;
|
||||
landMonTableHeaders << "Index" << "Species" << "Min Level" << "Max Level" << "Index Percentage" << "Encounter Rate";
|
||||
|
@ -99,8 +77,6 @@ void MonTabWidget::populateTab(int tabIndex, WildMonInfo monInfo, QString fieldN
|
|||
|
||||
speciesTable->setShowGrid(false);
|
||||
|
||||
// set encounter rate slider
|
||||
// don't forget to add number label next to it
|
||||
QFrame *encounterFrame = new QFrame;
|
||||
QHBoxLayout *encounterLayout = new QHBoxLayout;
|
||||
|
||||
|
@ -128,9 +104,7 @@ void MonTabWidget::populateTab(int tabIndex, WildMonInfo monInfo, QString fieldN
|
|||
this->setTabActive(tabIndex, true);
|
||||
}
|
||||
|
||||
// TODO: just move these funcs to editor.cpp
|
||||
void MonTabWidget::createSpeciesTableRow(QTableWidget *table, WildPokemon mon, int index, QString fieldName) {
|
||||
//
|
||||
QPixmap monIcon = QPixmap(project->speciesToIconPath.value(mon.species)).copy(0, 0, 32, 32);
|
||||
|
||||
QLabel *monNum = new QLabel(QString("%1.").arg(QString::number(index)));
|
||||
|
@ -159,7 +133,7 @@ void MonTabWidget::createSpeciesTableRow(QTableWidget *table, WildPokemon mon, i
|
|||
minLevel->setValue(mon.minLevel);
|
||||
maxLevel->setValue(mon.maxLevel);
|
||||
|
||||
// connect level spinboxes so max is never less than min
|
||||
// Connect level spinboxes so max is never less than min.
|
||||
connect(minLevel, QOverload<int>::of(&QSpinBox::valueChanged), [maxLevel](int min){
|
||||
maxLevel->setMinimum(min);
|
||||
});
|
||||
|
@ -179,7 +153,7 @@ void MonTabWidget::createSpeciesTableRow(QTableWidget *table, WildPokemon mon, i
|
|||
speciesSelectorLayout->addWidget(monSelector);
|
||||
speciesSelector->setLayout(speciesSelectorLayout);
|
||||
|
||||
// prevent the spinboxes from being stupidly tall
|
||||
// Prevent the spinboxes from being stupidly tall.
|
||||
QFrame *minLevelFrame = new QFrame;
|
||||
QVBoxLayout *minLevelSpinboxLayout = new QVBoxLayout;
|
||||
minLevelSpinboxLayout->addWidget(minLevel);
|
||||
|
@ -189,25 +163,17 @@ void MonTabWidget::createSpeciesTableRow(QTableWidget *table, WildPokemon mon, i
|
|||
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, 2, minLevelFrame);
|
||||
table->setCellWidget(index - 1, 3, maxLevelFrame);
|
||||
table->setCellWidget(index - 1, 4, percentLabel);
|
||||
|
||||
// TODO: lock max spinbox to min spinbox
|
||||
}
|
||||
|
||||
QTableWidget *MonTabWidget::tableAt(int tabIndex) {
|
||||
return static_cast<QTableWidget *>(this->widget(tabIndex));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
void MonTabWidget::setTabActive(int index, bool active) {
|
||||
activeTabs[index] = active;
|
||||
setTabEnabled(index, active);
|
||||
|
|
Loading…
Reference in a new issue