add option to copy mon info from another tab [closes #469]
This commit is contained in:
parent
06948a97b0
commit
9cc55ef2f7
6 changed files with 62 additions and 18 deletions
|
@ -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 new config options for reorganizing metatile attributes.
|
||||||
- Add `setScale` to the scripting API.
|
- Add `setScale` to the scripting API.
|
||||||
- Add option to turn off the checkerboard fill for new tilesets.
|
- Add option to turn off the checkerboard fill for new tilesets.
|
||||||
|
- Add option (via right-click) to copy wild encounters from another tab.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Double-clicking on a connecting map on the Map or Events tabs will now open that map.
|
- Double-clicking on a connecting map on the Map or Events tabs will now open that map.
|
||||||
|
|
|
@ -30,5 +30,6 @@ struct EncounterField {
|
||||||
typedef QVector<EncounterField> EncounterFields;
|
typedef QVector<EncounterField> EncounterFields;
|
||||||
|
|
||||||
WildMonInfo getDefaultMonInfo(EncounterField field);
|
WildMonInfo getDefaultMonInfo(EncounterField field);
|
||||||
|
void combineEncounters(WildMonInfo &to, WildMonInfo from);
|
||||||
|
|
||||||
#endif // GUARD_WILDMONINFO_H
|
#endif // GUARD_WILDMONINFO_H
|
||||||
|
|
|
@ -14,3 +14,17 @@ WildMonInfo getDefaultMonInfo(EncounterField field) {
|
||||||
|
|
||||||
return newInfo;
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2376,6 +2376,7 @@ void MainWindow::onTilesetsSaved(QString primaryTilesetLabel, QString secondaryT
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onWildMonDataChanged() {
|
void MainWindow::onWildMonDataChanged() {
|
||||||
|
editor->saveEncounterTabData();
|
||||||
markMapEdited();
|
markMapEdited();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1563,7 +1563,9 @@ void Project::saveTextFile(QString path, QString text) {
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
file.write(text.toUtf8());
|
file.write(text.toUtf8());
|
||||||
gFileCache[path] = text;
|
if (gFileCache.contains(path)) {
|
||||||
|
gFileCache[path] = text;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logError(QString("Could not open '%1' for writing: ").arg(path) + file.errorString());
|
logError(QString("Could not open '%1' for writing: ").arg(path) + file.errorString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,27 +41,52 @@ void MonTabWidget::populate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonTabWidget::askActivateTab(int tabIndex, QPoint menuPos) {
|
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);
|
QString tabText = this->tabBar()->tabText(i);
|
||||||
QAction actionActivateTab(QString("Add %1 data for this map...").arg(tabText), this);
|
QAction *actionCopyFrom = new QAction(QString("Copy encounters from %1").arg(tabText), &contextMenu);
|
||||||
connect(&actionActivateTab, &QAction::triggered, [=](){
|
|
||||||
clearTableAt(tabIndex);
|
connect(actionCopyFrom, &QAction::triggered, [=](){
|
||||||
populateTab(tabIndex, getDefaultMonInfo(editor->project->wildMonFields.at(tabIndex)));
|
EncounterTableModel *model = static_cast<EncounterTableModel *>(this->tableAt(i)->model());
|
||||||
editor->saveEncounterTabData();
|
WildMonInfo copyInfo = model->encounterData();
|
||||||
setCurrentIndex(tabIndex);
|
clearTableAt(tabIndex);
|
||||||
emit editor->wildMonDataChanged();
|
WildMonInfo newInfo = getDefaultMonInfo(editor->project->wildMonFields.at(tabIndex));
|
||||||
});
|
combineEncounters(newInfo, copyInfo);
|
||||||
contextMenu.addAction(&actionActivateTab);
|
populateTab(tabIndex, newInfo);
|
||||||
contextMenu.exec(mapToGlobal(menuPos));
|
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) {
|
void MonTabWidget::clearTableAt(int tabIndex) {
|
||||||
QTableView *table = tableAt(tabIndex);
|
QTableView *table = tableAt(tabIndex);
|
||||||
if (table) {
|
if (table) {
|
||||||
table->setModel(nullptr);
|
table->reset();
|
||||||
table->horizontalHeader()->hide();
|
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::MaxLevel, new SpinBoxDelegate(editor->project, this));
|
||||||
speciesTable->setItemDelegateForColumn(EncounterTableModel::ColumnType::EncounterRate, 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::Slot, QHeaderView::ResizeToContents);
|
||||||
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::Group, QHeaderView::ResizeToContents );
|
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::Group, QHeaderView::ResizeToContents);
|
||||||
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::Species, QHeaderView::Stretch);
|
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::Species, QHeaderView::Stretch);
|
||||||
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::MinLevel, QHeaderView::Stretch);
|
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::MinLevel, QHeaderView::Stretch);
|
||||||
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::MaxLevel, 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::EncounterChance, QHeaderView::ResizeToContents);
|
||||||
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::EncounterRate, QHeaderView::ResizeToContents);
|
speciesTable->horizontalHeader()->setSectionResizeMode(EncounterTableModel::ColumnType::EncounterRate, QHeaderView::ResizeToContents);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue