#include "mainwindow.hpp" #include "groupview.hpp" #include "mapdump.hpp" #include "sliceview.hpp" #include "diffview.hpp" #include "library.hpp" #include #include #include #include #include #include #include #include #include #define MAPMAN_VERSION "pre-alpha" mapman_main_window::mapman_main_window() : QMainWindow() { l = nullptr; cw = new QMdiArea(); setCentralWidget(cw); gv = new group_view(); sv = new slice_view(); dv = new diff_view(); cw->addSubWindow(gv); cw->addSubWindow(sv); dv->hide(); this->setWindowTitle("Mapman"); cw->cascadeSubWindows(); auto fm = this->menuBar()->addMenu("&File"); auto cra = fm->addAction("Create / L&oad MapDB..."); auto cla = fm->addAction("&Close MapDB"); fm->addSeparator(); auto lda = fm->addAction("&Load Map Dump..."); fm->addSeparator(); auto cta = fm->addAction("&Compare Map Tally..."); fm->addSeparator(); auto qa = fm->addAction("&Quit"); cla->setEnabled(false); lda->setEnabled(false); cta->setEnabled(false); connect(cra, &QAction::triggered, [this, cla, lda, cta] { QString fn = QFileDialog::getSaveFileName(this, "Create / Load MapDB", QString(), "*.mapdb", nullptr, QFileDialog::Option::DontConfirmOverwrite); if (fn.length()) { if (l) delete l; l = new map_library(); std::filesystem::path p(fn.toStdWString()); if (!l->open_db(p)) { delete l; l = nullptr; return; } sv->set_library(l); gv->set_library(l); sv->refresh(); gv->refresh_list(); cla->setEnabled(true); lda->setEnabled(true); cta->setEnabled(true); } }); connect(cla, &QAction::triggered, [this, cla, lda, cta] { if (l) delete l; l = nullptr; cla->setEnabled(false); lda->setEnabled(false); cta->setEnabled(false); }); connect(lda, &QAction::triggered, [this] { if (!l) return; QString fn = QFileDialog::getOpenFileName(this, "Load Map Dump", QString(), "*.gz"); if (fn.length()) { std::vector m; if (load_dumps(fn.toStdString().c_str(), m)) { for (auto &map : m) l->set_map(map); sv->refresh(); } } }); connect(cta, &QAction::triggered, [this] { if (!l) return; QString fn = QFileDialog::getOpenFileName(this, "Select Map Tally", QString(), "*.gz"); if (fn.length()) { auto tally = load_tally(fn.toStdString().c_str()); std::vector a_b, b_a; l->tally_diff(tally, a_b, b_a); dv->set_results(a_b, b_a); dv->show(); } }); connect(qa, &QAction::triggered, [] { QApplication::exit(); }); auto wm = this->menuBar()->addMenu("&Windows"); auto swa = wm->addAction("Map &listings"); auto gwa = wm->addAction("Map &art listings"); connect(swa, &QAction::triggered, [this]{ sv->widget()->show(); sv->show(); }); connect(gwa, &QAction::triggered, [this]{ gv->widget()->show(); gv->show(); }); auto hm = this->menuBar()->addMenu("&Help"); auto aba = hm->addAction("&About"); auto aqa = hm->addAction("About &Qt"); connect(aba, &QAction::triggered, [this]{ QMessageBox::about(this, "About Mapman", QString(R"( Mapman A minecraft map art manager. %1 Chris Xiong 2023 License: MIT (expat) )") .arg(MAPMAN_VERSION).trimmed()); }); connect(aqa, &QAction::triggered, []{ QApplication::aboutQt(); }); } mapman_main_window::~mapman_main_window() { if (l) delete l; delete dv; }