Skip to content

Commit

Permalink
Maps: Implement map resizing
Browse files Browse the repository at this point in the history
Maps can be resized now.
  • Loading branch information
rueter37 committed Nov 30, 2021
1 parent 82ad776 commit eb03cfb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
57 changes: 54 additions & 3 deletions src/ui/map/map_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,59 @@ QMap<int, lcf::rpg::Event*> *MapScene::mapEvents()

void MapScene::editMapProperties()
{
int old_width = m_map->width;
int old_height = m_map->height;

MapPropertiesDialog dlg(m_project, n_mapInfo, *m_map, m_view);
dlg.exec();
if (dlg.exec() == QDialog::Accepted) {
// Resize map
if (m_map->width != old_width || m_map->height != old_height) {
auto old_lower_layer = m_map->lower_layer;
auto old_upper_layer = m_map->upper_layer;
int old_tile_counter = 0;

m_map->lower_layer.clear();
m_map->upper_layer.clear();
for (int y = 0; y < m_map->height; y++) {
if (y < old_height) {
for (int x = 0; x < m_map->width; x++) {
if (x < old_width) {
m_map->lower_layer.push_back(old_lower_layer[old_tile_counter]);
m_map->upper_layer.push_back(old_upper_layer[old_tile_counter]);
old_tile_counter++;
} else {
m_map->lower_layer.push_back(0);
m_map->upper_layer.push_back(10000);
}
}
if (m_map->width < old_width) {
old_tile_counter += (old_width - m_map->width);
}
} else {
for (int x = 0; x < m_map->width; x++) {
m_map->lower_layer.push_back(0);
m_map->upper_layer.push_back(10000);
}
}
}
setLayerData(Core::LOWER, m_map->lower_layer);
setLayerData(Core::UPPER, m_map->upper_layer);

// Delete out of bounds events
if (m_map->width < old_width || m_map->height < old_height) {
std::vector<lcf::rpg::Event>::iterator ev;
for (ev = m_map->events.begin(); ev != m_map->events.end(); ++ev) {
if (ev->x >= m_map->width || ev->y >= m_map->height) {
m_map->events.erase(ev);
}
}
}
}

Save(true);
redrawMap();
setScale(m_scale);
}
}

void MapScene::redrawMap()
Expand Down Expand Up @@ -333,9 +384,9 @@ void MapScene::onToolChanged()
}
}

void MapScene::Save()
void MapScene::Save(bool properties_changed)
{
if (!isModified())
if (!isModified() && !properties_changed)
return;

auto& treeMap = m_project.treeMap();
Expand Down
2 changes: 1 addition & 1 deletion src/ui/map/map_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public slots:

void onToolChanged();

void Save();
void Save(bool properties_changed = false);

void Load(bool revert = false);

Expand Down
8 changes: 7 additions & 1 deletion src/ui/maptree/map_properties_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ MapPropertiesDialog::MapPropertiesDialog(ProjectData& project, lcf::rpg::MapInfo
m_project(project)
{
ui->setupUi(this);

connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(ok()));

auto& database = project.database();

for (int terrain = 0; terrain < 162; terrain++)
Expand Down Expand Up @@ -224,6 +225,11 @@ MapPropertiesDialog::~MapPropertiesDialog()
delete ui;
}

void MapPropertiesDialog::ok() {
m_map.width = ui->spinWidth->value();
m_map.height = ui->spinHeight->value();
}

void MapPropertiesDialog::on_groupPanorama_toggled(bool arg1)
{
m_panoramaItem->setVisible(arg1);
Expand Down
2 changes: 2 additions & 0 deletions src/ui/maptree/map_properties_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class MapPropertiesDialog : public QDialog
~MapPropertiesDialog();

private slots:
void ok();

void on_groupPanorama_toggled(bool arg1);

void on_groupUseGenerator_toggled(bool arg1);
Expand Down

0 comments on commit eb03cfb

Please sign in to comment.