allow saving new encounter groups to maps
This commit is contained in:
parent
eb3fb44542
commit
f7022fc3d2
6 changed files with 153 additions and 14 deletions
|
@ -12,7 +12,7 @@ struct WildPokemon {
|
|||
struct WildMonInfo {
|
||||
//
|
||||
bool active = false;
|
||||
int encounterRate;
|
||||
int encounterRate = 0;
|
||||
QVector<WildPokemon> wildPokemon;
|
||||
};
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ public:
|
|||
void readWildMonData();
|
||||
QMap<QString, QMap<QString, WildPokemonHeader>> wildMonData;// "MAP_CONSTANT": {base_label: wild_encounter_json
|
||||
QMap<QString, QString> encounterMapToBaseLabel;// delete this?
|
||||
QVector<QString> encounterGroupLabels;
|
||||
// when saving, preserve the extra fields for gBattlePyramidWildMonHeaders, gBattlePikeWildMonHeaders
|
||||
void readSpeciesIconPaths();
|
||||
QMap<QString, QString> speciesToIconPath;
|
||||
|
|
152
src/editor.cpp
152
src/editor.cpp
|
@ -184,9 +184,9 @@ void Editor::displayWildMonTables() {
|
|||
}
|
||||
|
||||
// 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);
|
||||
});
|
||||
//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());
|
||||
|
||||
|
@ -206,7 +206,7 @@ void Editor::displayWildMonTables() {
|
|||
//QVector<int> unusedIndices;
|
||||
|
||||
int tabIndex = 0;
|
||||
for (QPair<QString, QVector<int>> monField : project->wildMonFields) {
|
||||
for (Field monField : project->wildMonFields) {
|
||||
QString fieldName = monField.first;
|
||||
|
||||
// tabWidget_WildMons
|
||||
|
@ -238,10 +238,133 @@ void Editor::displayWildMonTables() {
|
|||
stack->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
// TODO: move this funciton
|
||||
// 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;
|
||||
|
||||
QDialog dialog(nullptr, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
||||
dialog.setWindowTitle("New Wild Encounter Group Label");
|
||||
dialog.setWindowModality(Qt::NonModal);
|
||||
|
||||
QFormLayout form(&dialog);
|
||||
|
||||
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
|
||||
|
||||
QLineEdit *lineEdit = new QLineEdit();
|
||||
form.addRow(new QLabel("Group Base Label:"), lineEdit);
|
||||
QRegularExpressionValidator *validator = new QRegularExpressionValidator(QRegularExpression("[_A-Za-z0-9]*"));
|
||||
lineEdit->setValidator(validator);
|
||||
connect(lineEdit, &QLineEdit::textChanged, [this, &lineEdit, &buttonBox](QString text){
|
||||
if (this->project->encounterGroupLabels.contains(text)) {
|
||||
QPalette palette = lineEdit->palette();
|
||||
QColor color = Qt::red;
|
||||
color.setAlpha(25);
|
||||
palette.setColor(QPalette::Base, color);
|
||||
lineEdit->setPalette(palette);
|
||||
buttonBox.button(QDialogButtonBox::Ok)->setDisabled(true);
|
||||
} else {
|
||||
lineEdit->setPalette(QPalette());
|
||||
buttonBox.button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
}
|
||||
});
|
||||
// give a default value to the label
|
||||
lineEdit->setText(QString("g%1%2").arg(map->name).arg(project->wildMonData.value(map->constantName).size()));
|
||||
|
||||
//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
|
||||
form.addRow(new QLabel("Copy from current group"), copyCheckbox);
|
||||
QVector<QCheckBox *> fieldCheckboxes;
|
||||
for (Field monField : project->wildMonFields) {
|
||||
QCheckBox *fieldCheckbox = new QCheckBox;
|
||||
fieldCheckboxes.append(fieldCheckbox);
|
||||
form.addRow(new QLabel(monField.first), fieldCheckbox);
|
||||
}
|
||||
// TODO: fix this
|
||||
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);
|
||||
fieldIndex++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
|
||||
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);
|
||||
|
||||
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;
|
||||
header.wildMons.insert(fieldName, getDefaultMonInfo(monField));
|
||||
tabWidget->populateTab(tabIndex, header.wildMons[fieldName], fieldName);
|
||||
} else {
|
||||
tabWidget->setTabActive(tabIndex, false);
|
||||
}
|
||||
tabIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
//earlyExit = true;
|
||||
}
|
||||
|
||||
void Editor::configureEncounterJSON() {
|
||||
|
@ -251,22 +374,25 @@ void Editor::configureEncounterJSON() {
|
|||
|
||||
// TODO: move this?
|
||||
void Editor::saveEncounterTabData() {
|
||||
if (!project->wildMonData.contains(map->constantName)) {
|
||||
qDebug() << "don't save encounters for this map";
|
||||
return;
|
||||
}
|
||||
//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 < 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
|
||||
// TODO: verify this exists before so no segfault actually no
|
||||
WildPokemonHeader &encounterHeader = encounterMap[labelCombo->itemText(groupIndex)];
|
||||
|
||||
//qDebug() << encounterHeader.wildMons.keys();
|
||||
|
@ -275,7 +401,7 @@ void Editor::saveEncounterTabData() {
|
|||
// QTableWidget *monTable =
|
||||
//}
|
||||
int fieldIndex = 0;
|
||||
for (QPair<QString, QVector<int>> monField : project->wildMonFields) {
|
||||
for (Field monField : project->wildMonFields) {
|
||||
QString fieldName = monField.first;
|
||||
//if (!encounterHeader.wildMons.contains(fieldName)
|
||||
// || encounterHeader.wildMons[fieldName].wildPokemon.empty()
|
||||
|
|
|
@ -80,6 +80,12 @@ void MainWindow::initCustomUI() {
|
|||
ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)),
|
||||
this, SLOT(onOpenMapListContextMenu(const QPoint &)));
|
||||
|
||||
QStackedWidget *stack = ui->stackedWidget_WildMons;
|
||||
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
|
||||
connect(labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){
|
||||
stack->setCurrentIndex(index);
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::initExtraSignals() {
|
||||
|
|
|
@ -1446,6 +1446,7 @@ void Project::readWildMonData() {
|
|||
// wildMonData.insert(mapConstant, header);
|
||||
//else
|
||||
wildMonData[mapConstant].insert(encounter["base_label"].toString(), header);
|
||||
encounterGroupLabels.append(encounter["base_label"].toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -159,6 +159,11 @@ 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(minLevel, QOverload<int>::of(&QSpinBox::valueChanged), [maxLevel](int min){
|
||||
maxLevel->setMinimum(min);
|
||||
});
|
||||
|
||||
int fieldIndex = 0;
|
||||
for (auto field : project->wildMonFields) {
|
||||
if (field.first == fieldName) break;
|
||||
|
|
Loading…
Reference in a new issue