-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
84 lines (61 loc) · 1.77 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QHBoxLayout>
#include <QSlider>
#include <iostream>
#include "viewer.h"
extern "C" {
#include "callbacks.h"
}
#include "processor.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QFrame *f = new QFrame(this);
v = new Viewer(this);
QHBoxLayout *l = new QHBoxLayout(f);
f->setLayout(l);
l->addWidget(v);
QSlider *s = new QSlider(Qt::Vertical,f);
s->setObjectName("levelSlider");
s->setMinimum(0);
s->setMaximum(127);
s->setSingleStep(1);
l->addWidget(s);
setCentralWidget(f);
connect(ui->actionOpen,SIGNAL(triggered()),this,SLOT(open()));
connect(s,SIGNAL(valueChanged(int)),v,SLOT(repaint()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::open()
{
QString dirName = QFileDialog::getExistingDirectory(this,"Save directory");
if (!dirName.isEmpty()) load(dirName);
}
void MainWindow::load(const QString &dirName)
{
curDir = dirName;
// get where the player is
register_named_tag( "Pos", &position ) ;
QString level(curDir + "/level.dat");
Named_Tag* level_tag = process_file(level.toStdString().c_str());
NT_dispose(level_tag);
unregister_named_tag( "Pos") ;
// set the initial height to where the player is
QSlider *s = findChild<QSlider*>("levelSlider");
s->setValue((int)Player.y);
// load in the block data
register_named_tag( "xPos", set_x_position ) ;
register_named_tag( "zPos", set_z_position ) ;
register_named_tag( "Blocks", save_blocks ) ;
process_dir(curDir.toStdString().c_str()) ;
std::cout << "Load complete" << std::endl;
repaint();
}