Skip to content

Commit

Permalink
Merge pull request #192 from rueter37/map-properties
Browse files Browse the repository at this point in the history
Enable editing of map properties
  • Loading branch information
Ghabry authored Mar 8, 2022
2 parents 269e3ae + f719a59 commit 9206113
Show file tree
Hide file tree
Showing 11 changed files with 567 additions and 161 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,16 @@ set(EDITOR_SOURCES
src/ui/picker/picker_audio_widget.cpp
src/ui/picker/picker_audio_widget.h
src/ui/picker/picker_audio_widget.ui
src/ui/picker/picker_backdrop_widget.cpp
src/ui/picker/picker_backdrop_widget.h
src/ui/picker/picker_child_widget.cpp
src/ui/picker/picker_child_widget.h
src/ui/picker/picker_charset_widget.cpp
src/ui/picker/picker_charset_widget.h
src/ui/picker/picker_faceset_widget.cpp
src/ui/picker/picker_faceset_widget.h
src/ui/picker/picker_panorama_widget.cpp
src/ui/picker/picker_panorama_widget.h
src/ui/picker/picker_dialog.cpp
src/ui/picker/picker_dialog.h
src/ui/picker/picker_dialog.ui
Expand Down
5 changes: 1 addition & 4 deletions src/ui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,9 +1057,6 @@ void MainWindow::on_treeMap_currentItemChanged(QTreeWidgetItem* current, QTreeWi
ui->actionMapDelete->setEnabled(false);
return;
}
ui->actionMapCopy->setEnabled(current->data(1,Qt::DisplayRole).toInt() != 0);
ui->actionMapDelete->setEnabled(current->data(1,Qt::DisplayRole).toInt() != 0);
core().project()->treeMap().active_node = current->data(1,Qt::DisplayRole).toInt() != 0;
}

void MainWindow::on_actionMapCopy_triggered()
Expand Down Expand Up @@ -1306,7 +1303,7 @@ void MainWindow::on_actionMapProperties_triggered()
if (!currentScene())
return;

currentScene()->editMapProperties();
currentScene()->editMapProperties(ui->treeMap->currentItem());
}

void MainWindow::on_actionSearch_triggered()
Expand Down
86 changes: 64 additions & 22 deletions src/ui/map/map_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,29 @@ QMap<int, lcf::rpg::Event*> *MapScene::mapEvents()
return events;
}

void MapScene::editMapProperties()
void MapScene::editMapProperties(QTreeWidgetItem *item)
{
int old_width = m_map->width;
int old_height = m_map->height;
lcf::DBString old_name = n_mapInfo.name;

MapPropertiesDialog dlg(m_project, n_mapInfo, *m_map, m_view);
dlg.exec();
if (dlg.exec() == QDialog::Accepted) {
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);
redrawPanorama();
redrawMap();
setScale(m_scale);

if (n_mapInfo.name != old_name) {
item->setData(0, Qt::DisplayRole, ToQString(n_mapInfo.name));
}
}
}

void MapScene::redrawMap()
Expand Down Expand Up @@ -333,9 +352,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 All @@ -345,6 +364,8 @@ void MapScene::Save()
treeMap.maps[i] = n_mapInfo; //Apply info changes
break;
}
// Remember last active map
treeMap.active_node = n_mapInfo.ID;
// FIXME: ProjectData.Project is Const
core().project()->saveTreeMap();
QString file = QString("Map%1.emu")
Expand All @@ -370,26 +391,11 @@ void MapScene::Load(bool revert)
m_map = m_project.project().loadMap(n_mapInfo.ID);
m_lower = m_map->lower_layer;
m_upper = m_map->upper_layer;
if(m_map->parallax_flag)
core().LoadBackground(m_map->parallax_name.c_str());
else
core().LoadBackground(QString());

redrawPanorama();

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 @@ -1040,3 +1046,39 @@ int MapScene::getFirstFreeId() {

return id;
}

void MapScene::redrawPanorama() {
if (m_map->parallax_flag) {
core().LoadBackground(m_map->parallax_name.c_str());
} else {
core().LoadBackground(QString());
}
}

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);
}
8 changes: 6 additions & 2 deletions src/ui/map/map_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QMap>
#include <QMenu>
#include <QUndoStack>
#include <QTreeWidgetItem>
#include <memory>
#include <lcf/rpg/map.h>
#include <lcf/rpg/mapinfo.h>
Expand All @@ -51,7 +52,7 @@ class MapScene : public QGraphicsScene
void setLayerData(Core::Layer layer, std::vector<short> data);
void setEventData(int id, const lcf::rpg::Event &data);
QMap<int, lcf::rpg::Event *> *mapEvents();
void editMapProperties();
void editMapProperties(QTreeWidgetItem *item);

signals:

Expand All @@ -68,7 +69,7 @@ public slots:

void onToolChanged();

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

void Load(bool revert = false);

Expand Down Expand Up @@ -121,6 +122,8 @@ private slots:
short bind(int x, int y);
lcf::rpg::Event* getEventAt(int x, int y);
int getFirstFreeId();
void redrawPanorama();
void redrawGrid();


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

Loading

0 comments on commit 9206113

Please sign in to comment.