Skip to content

Commit

Permalink
fix change dimensions for layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
garakmon committed Feb 7, 2023
1 parent 953c95e commit 91c7a2a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 27 deletions.
4 changes: 3 additions & 1 deletion include/core/maplayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Layout : public QObject {

static QString layoutConstantFromName(QString mapName);

bool loaded = false;

/// !TODO
/* NEW */
QList<Map *> maps;
Expand Down Expand Up @@ -119,7 +121,7 @@ class Layout : public QObject {

signals:
void layoutChanged(Layout *layout);
void modified();
//void modified();
void layoutDimensionsChanged(const QSize &size);
void needsRedrawing();
};
Expand Down
2 changes: 2 additions & 0 deletions include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private slots:
void onLoadMapRequested(QString, QString);
void onMapChanged(Map *map);
void onMapNeedsRedrawing();
void onLayoutNeedsRedrawing();
void onTilesetsSaved(QString, QString);
void onWildMonDataChanged();
void openNewMapPopupWindow();
Expand Down Expand Up @@ -359,6 +360,7 @@ private slots:
bool setMap(QString, bool scroll = false);
void unsetMap();
void redrawMapScene();
void redrawLayoutScene();
void refreshMapScene();
bool loadDataStructures();
bool loadProjectCombos();
Expand Down
Binary file added resources/icons/minimap.ico
Binary file not shown.
1 change: 1 addition & 0 deletions resources/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<file>icons/sort_map.ico</file>
<file>icons/sort_number.ico</file>
<file>icons/tall_grass.ico</file>
<file>icons/minimap.ico</file>
<file>icons/viewsprites.ico</file>
<file>icons/application_form_edit.ico</file>
<file>icons/connections.ico</file>
Expand Down
2 changes: 2 additions & 0 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,8 @@ bool Editor::setLayout(QString layoutId) {
return false;
}

// !TODO: editGroup addStack

map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight()));
connect(this->layout, &Layout::layoutDimensionsChanged, map_ruler, &MapRuler::setMapDimensions);

Expand Down
47 changes: 31 additions & 16 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void MainWindow::initCustomUI() {
// Set up the tab bar
while (ui->mainTabBar->count()) ui->mainTabBar->removeTab(0);
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->setTabIcon(1, QIcon(QStringLiteral(":/icons/viewsprites.ico")));
ui->mainTabBar->addTab("Header");
Expand Down Expand Up @@ -695,6 +695,9 @@ bool MainWindow::setMap(QString map_name, bool scroll) {
connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing);
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);
updateMapList();

Expand Down Expand Up @@ -728,8 +731,9 @@ bool MainWindow::setLayout(QString layoutId) {

updateMapList();

// connect(editor->map, &Map::mapChanged, this, &MainWindow::onMapChanged);
// connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing);
// !TODO: make sure these connections are not duplicated / cleared later
connect(editor->layout, &Layout::layoutChanged, [this]() { onMapChanged(nullptr); });
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing);
// connect(editor->map, &Map::modified, [this](){ this->markMapEdited(); });

// displayMapProperties
Expand All @@ -746,16 +750,21 @@ bool MainWindow::setLayout(QString layoutId) {
return true;
}

void MainWindow::redrawMapScene()
{
void MainWindow::redrawMapScene() {
if (!editor->displayMap())
return;

this->refreshMapScene();
}

void MainWindow::refreshMapScene()
{
void MainWindow::redrawLayoutScene() {
if (!editor->displayLayout())
return;

this->refreshMapScene();
}

void MainWindow::refreshMapScene() {
on_mainTabBar_tabBarClicked(ui->mainTabBar->currentIndex());

ui->graphicsView_Map->setScene(editor->scene);
Expand Down Expand Up @@ -2524,6 +2533,11 @@ void MainWindow::onMapNeedsRedrawing() {
redrawMapScene();
}

void MainWindow::onLayoutNeedsRedrawing() {
qDebug() << "MainWindow::onLayoutNeedsRedrawing";
redrawLayoutScene();
}

void MainWindow::onMapCacheCleared() {
editor->map = nullptr;
}
Expand Down Expand Up @@ -2721,8 +2735,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);
dialog.setWindowTitle("Change Map Dimensions");
dialog.setWindowModality(Qt::NonModal);
Expand All @@ -2741,10 +2756,10 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
heightSpinBox->setMaximum(editor->project->getMaxMapHeight());
bwidthSpinBox->setMaximum(MAX_BORDER_WIDTH);
bheightSpinBox->setMaximum(MAX_BORDER_HEIGHT);
widthSpinBox->setValue(editor->map->getWidth());
heightSpinBox->setValue(editor->map->getHeight());
bwidthSpinBox->setValue(editor->map->getBorderWidth());
bheightSpinBox->setValue(editor->map->getBorderHeight());
widthSpinBox->setValue(editor->layout->getWidth());
heightSpinBox->setValue(editor->layout->getHeight());
bwidthSpinBox->setValue(editor->layout->getBorderWidth());
bheightSpinBox->setValue(editor->layout->getBorderHeight());
if (projectConfig.getUseCustomBorderSize()) {
form.addRow(new QLabel("Map Width"), widthSpinBox);
form.addRow(new QLabel("Map Height"), heightSpinBox);
Expand Down Expand Up @@ -2772,8 +2787,8 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
dialog.accept();
} else {
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 specified map width and height was: (%2 + 15) * (%3 + 14) = %4")
"The maximum layout width and height is the following: (width + 15) * (height + 14) <= %1\n"
"The specified layout width and height was: (%2 + 15) * (%3 + 14) = %4")
.arg(maxMetatiles)
.arg(widthSpinBox->value())
.arg(heightSpinBox->value())
Expand All @@ -2797,7 +2812,7 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
if (oldMapDimensions != newMapDimensions || oldBorderDimensions != newBorderDimensions) {
layout->setDimensions(newMapDimensions.width(), newMapDimensions.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,
oldMetatiles, layout->blockdata,
oldBorderDimensions, newBorderDimensions,
Expand Down
26 changes: 16 additions & 10 deletions src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,18 +381,24 @@ QString Project::readMapLocation(QString map_name) {
}

bool Project::loadLayout(MapLayout *layout) {
// Force these to run even if one fails
bool loadedTilesets = loadLayoutTilesets(layout);
bool loadedBlockdata = loadBlockdata(layout);
bool loadedBorder = loadLayoutBorder(layout);

return loadedTilesets
&& loadedBlockdata
&& loadedBorder;
// !TODO: make sure this doesn't break anything, maybe do something better. new layouts work too?
if (!layout->loaded) {
// Force these to run even if one fails
bool loadedTilesets = loadLayoutTilesets(layout);
bool loadedBlockdata = loadBlockdata(layout);
bool loadedBorder = loadLayoutBorder(layout);

if (loadedTilesets && loadedBlockdata && loadedBorder) {
layout->loaded = true;
return true;
} else {
return false;
}
}
return true;
}

Layout *Project::loadLayout(QString layoutId) {
//
if (mapLayouts.contains(layoutId)) {
Layout *layout = mapLayouts[layoutId];
if (loadLayout(layout)) {
Expand All @@ -416,7 +422,7 @@ bool Project::loadMapLayout(Map* map) {
return false;
}

if (map->hasUnsavedChanges()) {
if (map->hasUnsavedChanges() /* || map->layout->hasUnsavedChanges() */) {
return true;
} else {
return loadLayout(map->layout);
Expand Down

0 comments on commit 91c7a2a

Please sign in to comment.