Fix script API undo/redo for layouts, final TODO items

This commit is contained in:
GriffinR 2024-11-08 14:59:41 -05:00
parent 06ece16b93
commit e278d48380
4 changed files with 13 additions and 12 deletions

View file

@ -27,6 +27,7 @@ public:
this->setDropIndicatorShown(true); this->setDropIndicatorShown(true);
this->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); this->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
this->setFocusPolicy(Qt::StrongFocus); this->setFocusPolicy(Qt::StrongFocus);
this->setContextMenuPolicy(Qt::CustomContextMenu);
} }
protected: protected:

View file

@ -486,7 +486,6 @@ int EventPaste::id() const {
************************************************************************ ************************************************************************
******************************************************************************/ ******************************************************************************/
// TODO: Undo/redo for script edits to layout dimensions doesn't render correctly.
ScriptEditLayout::ScriptEditLayout(Layout *layout, ScriptEditLayout::ScriptEditLayout(Layout *layout,
QSize oldLayoutDimensions, QSize newLayoutDimensions, QSize oldLayoutDimensions, QSize newLayoutDimensions,
const Blockdata &oldMetatiles, const Blockdata &newMetatiles, const Blockdata &oldMetatiles, const Blockdata &newMetatiles,
@ -538,7 +537,7 @@ void ScriptEditLayout::redo() {
layout->lastCommitBlocks.border = newBorder; layout->lastCommitBlocks.border = newBorder;
layout->lastCommitBlocks.borderDimensions = QSize(newBorderWidth, newBorderHeight); layout->lastCommitBlocks.borderDimensions = QSize(newBorderWidth, newBorderHeight);
renderBlocks(layout); renderBlocks(layout, true);
layout->borderItem->draw(); layout->borderItem->draw();
} }
@ -564,7 +563,7 @@ void ScriptEditLayout::undo() {
layout->lastCommitBlocks.border = oldBorder; layout->lastCommitBlocks.border = oldBorder;
layout->lastCommitBlocks.borderDimensions = QSize(oldBorderWidth, oldBorderHeight); layout->lastCommitBlocks.borderDimensions = QSize(oldBorderWidth, oldBorderHeight);
renderBlocks(layout); renderBlocks(layout, true);
layout->borderItem->draw(); layout->borderItem->draw();
QUndoCommand::undo(); QUndoCommand::undo();

View file

@ -406,9 +406,6 @@ void MainWindow::initMapList() {
connect(ui->layoutList, &QAbstractItemView::activated, this, &MainWindow::openMapListItem); connect(ui->layoutList, &QAbstractItemView::activated, this, &MainWindow::openMapListItem);
// Right-clicking on items in the map list brings up a context menu. // Right-clicking on items in the map list brings up a context menu.
ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu);
ui->areaList->setContextMenuPolicy(Qt::CustomContextMenu);
ui->layoutList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->mapList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu); connect(ui->mapList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu);
connect(ui->areaList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu); connect(ui->areaList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu);
connect(ui->layoutList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu); connect(ui->layoutList, &QTreeView::customContextMenuRequested, this, &MainWindow::onOpenMapListContextMenu);
@ -1316,7 +1313,6 @@ void MainWindow::scrollMapListToCurrentMap(MapTree *list) {
} }
} }
// TODO: Initial scrolling doesn't center the layout on launch if it's not the current tab.
void MainWindow::scrollMapListToCurrentLayout(MapTree *list) { void MainWindow::scrollMapListToCurrentLayout(MapTree *list) {
if (this->editor->layout) { if (this->editor->layout) {
scrollMapList(list, this->editor->layout->id); scrollMapList(list, this->editor->layout->id);

View file

@ -2266,11 +2266,16 @@ bool Project::readRegionMapSections() {
fileWatcher.addPath(filepath); fileWatcher.addPath(filepath);
QJsonArray mapSections = doc.object()["map_sections"].toArray(); QJsonArray mapSections = doc.object()["map_sections"].toArray();
for (const auto &mapSection : mapSections) { for (int i = 0; i < mapSections.size(); i++) {
// For each map section, "id" is the only required field. This is the field we use QJsonObject mapSectionObj = mapSections.at(i).toObject();
// to display the location names in various drop-downs.
QJsonObject mapSectionObj = mapSection.toObject(); // For each map section, "id" is the only required field. This is the field we use to display the location names in various drop-downs.
const QString idName = ParseUtil::jsonToQString(mapSectionObj["id"]); const QString idField = "id";
if (!mapSectionObj.contains(idField)) {
logWarn(QString("Ignoring data for map section %1. Missing required field \"%2\"").arg(i).arg(idField));
continue;
}
const QString idName = ParseUtil::jsonToQString(mapSectionObj[idField]);
if (!idName.startsWith(requiredPrefix)) { if (!idName.startsWith(requiredPrefix)) {
logWarn(QString("Ignoring data for map section '%1'. IDs must start with the prefix '%2'").arg(idName).arg(requiredPrefix)); logWarn(QString("Ignoring data for map section '%1'. IDs must start with the prefix '%2'").arg(idName).arg(requiredPrefix));
continue; continue;