Skip to content

Commit

Permalink
Fix grid on map resize
Browse files Browse the repository at this point in the history
The grid always remained on the old map bounds if the map had been
resized. This is fixed now.
  • Loading branch information
rueter37 committed Nov 30, 2021
1 parent d15ac95 commit b8809a6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/ui/map/map_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ void MapScene::editMapProperties()
if (m_map->width != old_width || m_map->height != old_height) {
setLayerData(Core::LOWER, m_map->lower_layer);
setLayerData(Core::UPPER, m_map->upper_layer);
redrawGrid();
}

Save(true);
Expand Down Expand Up @@ -388,20 +389,7 @@ void MapScene::Load(bool revert)
core().LoadBackground(QString());

if (!revert) {
QList<QGraphicsItem*> lines;
for (int x = 0; x <= m_map->width; x++)
lines.append(new QGraphicsLineItem(x*core().tileSize(),
0,
x*core().tileSize(),
m_map->height*core().tileSize()));

for (int y = 0; y <= m_map->height; y++)
lines.append(new QGraphicsLineItem(0,
y*core().tileSize(),
m_map->width*core().tileSize(),
y*core().tileSize()));

m_lines = createItemGroup(lines);
redrawGrid();
}

redrawMap();
Expand Down Expand Up @@ -1052,3 +1040,31 @@ int MapScene::getFirstFreeId() {

return id;
}

void MapScene::redrawGrid() {
if (!grid_lines.empty()) {
while (!grid_lines.empty()) {
QGraphicsItem* line = grid_lines.takeLast();
delete line;
}
destroyItemGroup(m_lines);
}

for (int x = 0; x <= m_map->width; x++) {
grid_lines.append(new QGraphicsLineItem(x*core().tileSize(),
0,
x*core().tileSize(),
m_map->height*core().tileSize()));
}

for (int y = 0; y <= m_map->height; y++) {
grid_lines.append(new QGraphicsLineItem(0,
y*core().tileSize(),
m_map->width*core().tileSize(),
y*core().tileSize()));
}

m_lines = createItemGroup(grid_lines);

m_lines->setVisible(core().layer() == Core::EVENT);
}
2 changes: 2 additions & 0 deletions src/ui/map/map_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private slots:
short bind(int x, int y);
lcf::rpg::Event* getEventAt(int x, int y);
int getFirstFreeId();
void redrawGrid();


QMenu *m_eventMenu;
Expand Down Expand Up @@ -150,5 +151,6 @@ private slots:
ProjectData& m_project;
lcf::rpg::Event event_clipboard;
bool event_clipboard_set = false;
QList<QGraphicsItem*> grid_lines;
};

0 comments on commit b8809a6

Please sign in to comment.