fix change dimensions for layouts

This commit is contained in:
garak 2023-02-07 13:04:52 -05:00
parent e2ff93e5e7
commit f7f06dab29
7 changed files with 54 additions and 26 deletions

View file

@ -21,6 +21,8 @@ public:
static QString layoutConstantFromName(QString mapName); static QString layoutConstantFromName(QString mapName);
bool loaded = false;
/// !TODO /// !TODO
/* NEW */ /* NEW */
QList<Map *> maps; QList<Map *> maps;
@ -119,7 +121,7 @@ private:
signals: signals:
void layoutChanged(Layout *layout); void layoutChanged(Layout *layout);
void modified(); //void modified();
void layoutDimensionsChanged(const QSize &size); void layoutDimensionsChanged(const QSize &size);
void needsRedrawing(); void needsRedrawing();
}; };

View file

@ -182,6 +182,7 @@ private slots:
void onLoadMapRequested(QString, QString); void onLoadMapRequested(QString, QString);
void onMapChanged(Map *map); void onMapChanged(Map *map);
void onMapNeedsRedrawing(); void onMapNeedsRedrawing();
void onLayoutNeedsRedrawing();
void onTilesetsSaved(QString, QString); void onTilesetsSaved(QString, QString);
void onWildMonDataChanged(); void onWildMonDataChanged();
void openNewMapPopupWindow(); void openNewMapPopupWindow();
@ -362,6 +363,7 @@ private:
bool setMap(QString, bool scroll = false); bool setMap(QString, bool scroll = false);
void unsetMap(); void unsetMap();
void redrawMapScene(); void redrawMapScene();
void redrawLayoutScene();
void refreshMapScene(); void refreshMapScene();
bool loadDataStructures(); bool loadDataStructures();
bool loadProjectCombos(); bool loadProjectCombos();

BIN
resources/icons/minimap.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -33,6 +33,7 @@
<file>icons/sort_map.ico</file> <file>icons/sort_map.ico</file>
<file>icons/sort_number.ico</file> <file>icons/sort_number.ico</file>
<file>icons/tall_grass.ico</file> <file>icons/tall_grass.ico</file>
<file>icons/minimap.ico</file>
<file>icons/viewsprites.ico</file> <file>icons/viewsprites.ico</file>
<file>icons/application_form_edit.ico</file> <file>icons/application_form_edit.ico</file>
<file>icons/connections.ico</file> <file>icons/connections.ico</file>

View file

@ -1151,6 +1151,8 @@ bool Editor::setLayout(QString layoutId) {
return false; return false;
} }
// !TODO: editGroup addStack
map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight())); map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight()));
connect(this->layout, &Layout::layoutDimensionsChanged, map_ruler, &MapRuler::setMapDimensions); connect(this->layout, &Layout::layoutDimensionsChanged, map_ruler, &MapRuler::setMapDimensions);

View file

@ -203,7 +203,7 @@ void MainWindow::initCustomUI() {
// Set up the tab bar // Set up the tab bar
while (ui->mainTabBar->count()) ui->mainTabBar->removeTab(0); while (ui->mainTabBar->count()) ui->mainTabBar->removeTab(0);
ui->mainTabBar->addTab("Map"); ui->mainTabBar->addTab("Map");
ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico"))); ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/minimap.ico")));
ui->mainTabBar->addTab("Events"); ui->mainTabBar->addTab("Events");
ui->mainTabBar->setTabIcon(1, QIcon(QStringLiteral(":/icons/viewsprites.ico"))); ui->mainTabBar->setTabIcon(1, QIcon(QStringLiteral(":/icons/viewsprites.ico")));
ui->mainTabBar->addTab("Header"); ui->mainTabBar->addTab("Header");
@ -714,6 +714,9 @@ bool MainWindow::setMap(QString map_name, bool scroll) {
connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing); connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing);
connect(editor->map, &Map::modified, [this](){ this->markMapEdited(); }); connect(editor->map, &Map::modified, [this](){ this->markMapEdited(); });
connect(editor->layout, &Layout::layoutChanged, [this]() { onMapChanged(nullptr); });
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing);
setRecentMap(map_name); setRecentMap(map_name);
updateMapList(); updateMapList();
@ -747,8 +750,9 @@ bool MainWindow::setLayout(QString layoutId) {
updateMapList(); updateMapList();
// connect(editor->map, &Map::mapChanged, this, &MainWindow::onMapChanged); // !TODO: make sure these connections are not duplicated / cleared later
// connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing); connect(editor->layout, &Layout::layoutChanged, [this]() { onMapChanged(nullptr); });
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing);
// connect(editor->map, &Map::modified, [this](){ this->markMapEdited(); }); // connect(editor->map, &Map::modified, [this](){ this->markMapEdited(); });
// displayMapProperties // displayMapProperties
@ -765,16 +769,21 @@ bool MainWindow::setLayout(QString layoutId) {
return true; return true;
} }
void MainWindow::redrawMapScene() void MainWindow::redrawMapScene() {
{
if (!editor->displayMap()) if (!editor->displayMap())
return; return;
this->refreshMapScene(); this->refreshMapScene();
} }
void MainWindow::refreshMapScene() void MainWindow::redrawLayoutScene() {
{ if (!editor->displayLayout())
return;
this->refreshMapScene();
}
void MainWindow::refreshMapScene() {
on_mainTabBar_tabBarClicked(ui->mainTabBar->currentIndex()); on_mainTabBar_tabBarClicked(ui->mainTabBar->currentIndex());
ui->graphicsView_Map->setScene(editor->scene); ui->graphicsView_Map->setScene(editor->scene);
@ -2519,6 +2528,11 @@ void MainWindow::onMapNeedsRedrawing() {
redrawMapScene(); redrawMapScene();
} }
void MainWindow::onLayoutNeedsRedrawing() {
qDebug() << "MainWindow::onLayoutNeedsRedrawing";
redrawLayoutScene();
}
void MainWindow::onMapCacheCleared() { void MainWindow::onMapCacheCleared() {
editor->map = nullptr; editor->map = nullptr;
} }
@ -2710,8 +2724,9 @@ void MainWindow::on_comboBox_SecondaryTileset_currentTextChanged(const QString &
} }
} }
void MainWindow::on_pushButton_ChangeDimensions_clicked() void MainWindow::on_pushButton_ChangeDimensions_clicked() {
{ if (!editor || !editor->layout) return;
QDialog dialog(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint); QDialog dialog(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
dialog.setWindowTitle("Change Map Dimensions"); dialog.setWindowTitle("Change Map Dimensions");
dialog.setWindowModality(Qt::NonModal); dialog.setWindowModality(Qt::NonModal);
@ -2730,10 +2745,10 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
heightSpinBox->setMaximum(editor->project->getMaxMapHeight()); heightSpinBox->setMaximum(editor->project->getMaxMapHeight());
bwidthSpinBox->setMaximum(MAX_BORDER_WIDTH); bwidthSpinBox->setMaximum(MAX_BORDER_WIDTH);
bheightSpinBox->setMaximum(MAX_BORDER_HEIGHT); bheightSpinBox->setMaximum(MAX_BORDER_HEIGHT);
widthSpinBox->setValue(editor->map->getWidth()); widthSpinBox->setValue(editor->layout->getWidth());
heightSpinBox->setValue(editor->map->getHeight()); heightSpinBox->setValue(editor->layout->getHeight());
bwidthSpinBox->setValue(editor->map->getBorderWidth()); bwidthSpinBox->setValue(editor->layout->getBorderWidth());
bheightSpinBox->setValue(editor->map->getBorderHeight()); bheightSpinBox->setValue(editor->layout->getBorderHeight());
if (projectConfig.getUseCustomBorderSize()) { if (projectConfig.getUseCustomBorderSize()) {
form.addRow(new QLabel("Map Width"), widthSpinBox); form.addRow(new QLabel("Map Width"), widthSpinBox);
form.addRow(new QLabel("Map Height"), heightSpinBox); form.addRow(new QLabel("Map Height"), heightSpinBox);
@ -2761,8 +2776,8 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
dialog.accept(); dialog.accept();
} else { } else {
QString errorText = QString("Error: The specified width and height are too large.\n" QString errorText = QString("Error: The specified width and height are too large.\n"
"The maximum map width and height is the following: (width + 15) * (height + 14) <= %1\n" "The maximum layout width and height is the following: (width + 15) * (height + 14) <= %1\n"
"The specified map width and height was: (%2 + 15) * (%3 + 14) = %4") "The specified layout width and height was: (%2 + 15) * (%3 + 14) = %4")
.arg(maxMetatiles) .arg(maxMetatiles)
.arg(widthSpinBox->value()) .arg(widthSpinBox->value())
.arg(heightSpinBox->value()) .arg(heightSpinBox->value())
@ -2786,7 +2801,7 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
if (oldMapDimensions != newMapDimensions || oldBorderDimensions != newBorderDimensions) { if (oldMapDimensions != newMapDimensions || oldBorderDimensions != newBorderDimensions) {
layout->setDimensions(newMapDimensions.width(), newMapDimensions.height(), true, true); layout->setDimensions(newMapDimensions.width(), newMapDimensions.height(), true, true);
layout->setBorderDimensions(newBorderDimensions.width(), newBorderDimensions.height(), true, true); layout->setBorderDimensions(newBorderDimensions.width(), newBorderDimensions.height(), true, true);
editor->map->editHistory.push(new ResizeMap(layout, editor->layout->editHistory.push(new ResizeMap(layout,
oldMapDimensions, newMapDimensions, oldMapDimensions, newMapDimensions,
oldMetatiles, layout->blockdata, oldMetatiles, layout->blockdata,
oldBorderDimensions, newBorderDimensions, oldBorderDimensions, newBorderDimensions,

View file

@ -380,18 +380,24 @@ QString Project::readMapLocation(QString map_name) {
} }
bool Project::loadLayout(MapLayout *layout) { bool Project::loadLayout(MapLayout *layout) {
// Force these to run even if one fails // !TODO: make sure this doesn't break anything, maybe do something better. new layouts work too?
bool loadedTilesets = loadLayoutTilesets(layout); if (!layout->loaded) {
bool loadedBlockdata = loadBlockdata(layout); // Force these to run even if one fails
bool loadedBorder = loadLayoutBorder(layout); bool loadedTilesets = loadLayoutTilesets(layout);
bool loadedBlockdata = loadBlockdata(layout);
bool loadedBorder = loadLayoutBorder(layout);
return loadedTilesets if (loadedTilesets && loadedBlockdata && loadedBorder) {
&& loadedBlockdata layout->loaded = true;
&& loadedBorder; return true;
} else {
return false;
}
}
return true;
} }
Layout *Project::loadLayout(QString layoutId) { Layout *Project::loadLayout(QString layoutId) {
//
if (mapLayouts.contains(layoutId)) { if (mapLayouts.contains(layoutId)) {
Layout *layout = mapLayouts[layoutId]; Layout *layout = mapLayouts[layoutId];
if (loadLayout(layout)) { if (loadLayout(layout)) {
@ -415,7 +421,7 @@ bool Project::loadMapLayout(Map* map) {
return false; return false;
} }
if (map->hasUnsavedChanges()) { if (map->hasUnsavedChanges() /* || map->layout->hasUnsavedChanges() */) {
return true; return true;
} else { } else {
return loadLayout(map->layout); return loadLayout(map->layout);