add option to copy mon info from another tab [closes #469]

This commit is contained in:
garak 2023-01-16 23:23:41 -05:00 committed by t
parent 06948a97b0
commit 9cc55ef2f7
6 changed files with 62 additions and 18 deletions

View file

@ -11,6 +11,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Add new config options for reorganizing metatile attributes.
- Add `setScale` to the scripting API.
- Add option to turn off the checkerboard fill for new tilesets.
- Add option (via right-click) to copy wild encounters from another tab.
### Changed
- Double-clicking on a connecting map on the Map or Events tabs will now open that map.

View file

@ -30,5 +30,6 @@ struct EncounterField {
typedef QVector<EncounterField> EncounterFields;
WildMonInfo getDefaultMonInfo(EncounterField field);
void combineEncounters(WildMonInfo &to, WildMonInfo from);
#endif // GUARD_WILDMONINFO_H

View file

@ -14,3 +14,17 @@ WildMonInfo getDefaultMonInfo(EncounterField field) {
return newInfo;
}
void combineEncounters(WildMonInfo &to, WildMonInfo from) {
to.encounterRate = from.encounterRate;
if (to.wildPokemon.size() == from.wildPokemon.size()) {
to.wildPokemon = from.wildPokemon;
}
else if (to.wildPokemon.size() > from.wildPokemon.size()) {
to.wildPokemon = from.wildPokemon + to.wildPokemon.mid(from.wildPokemon.size());
}
else {
to.wildPokemon = from.wildPokemon.mid(0, to.wildPokemon.size());
}
}

View file

@ -2376,6 +2376,7 @@ void MainWindow::onTilesetsSaved(QString primaryTilesetLabel, QString secondaryT
}
void MainWindow::onWildMonDataChanged() {
editor->saveEncounterTabData();
markMapEdited();
}

View file

@ -1563,7 +1563,9 @@ void Project::saveTextFile(QString path, QString text) {
QFile file(path);
if (file.open(QIODevice::WriteOnly)) {
file.write(text.toUtf8());
gFileCache[path] = text;
if (gFileCache.contains(path)) {
gFileCache[path] = text;
}
} else {
logError(QString("Could not open '%1' for writing: ").arg(path) + file.errorString());
}

View file

@ -41,27 +41,52 @@ void MonTabWidget::populate() {
}
void MonTabWidget::askActivateTab(int tabIndex, QPoint menuPos) {
if (activeTabs[tabIndex]) return;
if (activeTabs[tabIndex]) {
// copy from another tab
QMenu contextMenu(this);
QMenu contextMenu(this);
for (int i = 0; i < this->tabBar()->count(); i++) {
if (tabIndex == i) continue;
if (!activeTabs[i]) continue;
QString tabText = tabBar()->tabText(tabIndex);
QAction actionActivateTab(QString("Add %1 data for this map...").arg(tabText), this);
connect(&actionActivateTab, &QAction::triggered, [=](){
clearTableAt(tabIndex);
populateTab(tabIndex, getDefaultMonInfo(editor->project->wildMonFields.at(tabIndex)));
editor->saveEncounterTabData();
setCurrentIndex(tabIndex);
emit editor->wildMonDataChanged();
});
contextMenu.addAction(&actionActivateTab);
contextMenu.exec(mapToGlobal(menuPos));
QString tabText = this->tabBar()->tabText(i);
QAction *actionCopyFrom = new QAction(QString("Copy encounters from %1").arg(tabText), &contextMenu);
connect(actionCopyFrom, &QAction::triggered, [=](){
EncounterTableModel *model = static_cast<EncounterTableModel *>(this->tableAt(i)->model());
WildMonInfo copyInfo = model->encounterData();
clearTableAt(tabIndex);
WildMonInfo newInfo = getDefaultMonInfo(editor->project->wildMonFields.at(tabIndex));
combineEncounters(newInfo, copyInfo);
populateTab(tabIndex, newInfo);
emit editor->wildMonDataChanged();
});
contextMenu.addAction(actionCopyFrom);
}
contextMenu.exec(mapToGlobal(menuPos));
}
else {
QMenu contextMenu(this);
QString tabText = tabBar()->tabText(tabIndex);
QAction actionActivateTab(QString("Add %1 data for this map...").arg(tabText), this);
connect(&actionActivateTab, &QAction::triggered, [=](){
clearTableAt(tabIndex);
populateTab(tabIndex, getDefaultMonInfo(editor->project->wildMonFields.at(tabIndex)));
editor->saveEncounterTabData();
setCurrentIndex(tabIndex);
emit editor->wildMonDataChanged();
});
contextMenu.addAction(&actionActivateTab);
contextMenu.exec(mapToGlobal(menuPos));
}
}
void MonTabWidget::clearTableAt(int tabIndex) {
QTableView *table = tableAt(tabIndex);
if (table) {
table->setModel(nullptr);
table->reset();
table->horizontalHeader()->hide();
}
}
@ -78,12 +103,12 @@ void MonTabWidget::populateTab(int tabIndex, WildMonInfo monInfo) {
speciesTable->setItemDelegateForColumn(EncounterTableModel::ColumnType::MaxLevel, new SpinBoxDelegate(editor->project, this));
speciesTable->setItemDelegateForColumn(EncounterTableModel::ColumnType::EncounterRate, new SpinBoxDelegate(editor->project, this));
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::Slot, QHeaderView::ResizeToContents );
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::Group, QHeaderView::ResizeToContents );
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::Slot, QHeaderView::ResizeToContents);
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::Group, QHeaderView::ResizeToContents);
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::Species, QHeaderView::Stretch);
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::MinLevel, QHeaderView::Stretch);
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::MaxLevel, QHeaderView::Stretch);
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::SlotRatio, QHeaderView::Stretch);
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::SlotRatio, QHeaderView::ResizeToContents);
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::EncounterChance, QHeaderView::ResizeToContents);
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::EncounterRate, QHeaderView::ResizeToContents);