aboutsummaryrefslogtreecommitdiff
path: root/mapman/src/mainwindow.cpp
blob: d5a5662179357a4563dce881c3e2a4072f270a49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "mainwindow.hpp"
#include "groupview.hpp"
#include "mapdump.hpp"
#include "sliceview.hpp"
#include "diffview.hpp"
#include "library.hpp"

#include <QMdiArea>
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QFileDialog>
#include <QApplication>
#include <QMessageBox>

#include <filesystem>
#include <vector>

#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 xca = fm->addAction("&Export Current Art...");
    auto xaa = fm->addAction("Export &All Arts...");
    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);
    xca->setEnabled(false);
    xaa->setEnabled(false);
    connect(cra, &QAction::triggered, [this, cla, lda, cta, xca, xaa] {
        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);
            xca->setEnabled(true);
            xaa->setEnabled(true);
        }
    });
    connect(cla, &QAction::triggered, [this, cla, lda, cta, xca, xaa] {
        if (l) delete l;
        l = nullptr;
        cla->setEnabled(false);
        lda->setEnabled(false);
        cta->setEnabled(false);
        xca->setEnabled(false);
        xaa->setEnabled(false);
    });
    connect(xca, &QAction::triggered, gv, &group_view::export_current_group);
    connect(xaa, &QAction::triggered, gv, &group_view::export_all_groups);
    connect(lda, &QAction::triggered, [this] {
        if (!l) return;
        QString fn = QFileDialog::getOpenFileName(this, "Load Map Dump", QString(), "*.gz");
        if (fn.length())
        {
            std::vector<map_t> 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<int> 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;
}