From 442a13a6122d8954827fcd6e7dc4f2571297927e Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 11 May 2025 21:27:49 -0400 Subject: [PATCH] Map Editor: Move the map list widget to an open dialog --- apps/mapeditor/include/mainwindow.h | 3 ++ apps/mapeditor/mapeditor.rc | 2 ++ apps/mapeditor/src/mainwindow.cpp | 56 +++++++++++++++++++---------- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/apps/mapeditor/include/mainwindow.h b/apps/mapeditor/include/mainwindow.h index 8bdbf38..f1373a9 100644 --- a/apps/mapeditor/include/mainwindow.h +++ b/apps/mapeditor/include/mainwindow.h @@ -8,6 +8,7 @@ #include "filecache.h" struct GameData; +class MapView; class MainWindow : public KXmlGuiWindow { @@ -18,7 +19,9 @@ public: private: void setupActions(); + void openMap(const QString &basePath); GameData *data = nullptr; FileCache cache; + MapView *mapView = nullptr; }; diff --git a/apps/mapeditor/mapeditor.rc b/apps/mapeditor/mapeditor.rc index f04de8c..fa39459 100644 --- a/apps/mapeditor/mapeditor.rc +++ b/apps/mapeditor/mapeditor.rc @@ -8,6 +8,8 @@ File + diff --git a/apps/mapeditor/src/mainwindow.cpp b/apps/mapeditor/src/mainwindow.cpp index e712a83..f4fd934 100644 --- a/apps/mapeditor/src/mainwindow.cpp +++ b/apps/mapeditor/src/mainwindow.cpp @@ -6,11 +6,10 @@ #include #include #include +#include #include -#include #include #include -#include #include #include "maplistwidget.h" @@ -27,25 +26,9 @@ MainWindow::MainWindow(GameData *data) dummyWidget->setChildrenCollapsible(false); setCentralWidget(dummyWidget); - auto listWidget = new MapListWidget(data); - listWidget->setMaximumWidth(400); - dummyWidget->addWidget(listWidget); - - auto mapView = new MapView(data, cache); + mapView = new MapView(data, cache); dummyWidget->addWidget(mapView); - connect(listWidget, &MapListWidget::mapSelected, this, [data, mapView](const QString &basePath) { - QString base2Path = basePath.left(basePath.lastIndexOf(QStringLiteral("/level/"))); - QString bgPath = QStringLiteral("bg/%1/bgplate/").arg(base2Path); - - std::string bgPathStd = bgPath.toStdString() + "terrain.tera"; - - auto tera_buffer = physis_gamedata_extract_file(data, bgPathStd.c_str()); - - auto tera = physis_parse_tera(tera_buffer); - mapView->addTerrain(bgPath, tera); - }); - setupActions(); setupGUI(Keys | Save | Create); @@ -57,7 +40,42 @@ MainWindow::MainWindow(GameData *data) void MainWindow::setupActions() { + KStandardAction::open( + qApp, + [this] { + auto dialog = new QDialog(); + + auto layout = new QVBoxLayout(); + layout->setContentsMargins({}); + dialog->setLayout(layout); + + auto listWidget = new MapListWidget(data); + connect(listWidget, &MapListWidget::mapSelected, this, [this, dialog](const QString &basePath) { + dialog->close(); + openMap(basePath); + }); + layout->addWidget(listWidget); + + dialog->exec(); + }, + actionCollection()); + KStandardAction::quit(qApp, &QCoreApplication::quit, actionCollection()); } +void MainWindow::openMap(const QString &basePath) +{ + QString base2Path = basePath.left(basePath.lastIndexOf(QStringLiteral("/level/"))); + QString bgPath = QStringLiteral("bg/%1/bgplate/").arg(base2Path); + + std::string bgPathStd = bgPath.toStdString() + "terrain.tera"; + + auto tera_buffer = physis_gamedata_extract_file(data, bgPathStd.c_str()); + + auto tera = physis_parse_tera(tera_buffer); + mapView->addTerrain(bgPath, tera); + + setWindowTitle(basePath); +} + #include "moc_mainwindow.cpp"