summaryrefslogtreecommitdiffstats
path: root/Tools/QtBiomeVisualiser/MainWindow.cpp
blob: 8b98c0b0e52a1f1c11a539b8c4b7ebfda04d588a (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
#include "Globals.h"
#include "MainWindow.h"
#include <QVBoxLayout>
#include <QAction>
#include <QMenuBar>
#include <QApplication>
#include <QFileDialog>
#include "inifile/iniFile.h"
#include "ChunkSource.h"
#include "Generating/BioGen.h"





MainWindow::MainWindow(QWidget * parent) :
	QMainWindow(parent)
{
	createActions();
	createMenus();

	m_BiomeView = new BiomeView(this);
	setCentralWidget(m_BiomeView);
}





MainWindow::~MainWindow()
{

}





void MainWindow::generate()
{
	QString worldIni = QFileDialog::getOpenFileName(this, tr("Open world.ini"), QString(), tr("world.ini (world.ini)"));
	cIniFile ini;
	if (!ini.ReadFile(worldIni.toStdString()))
	{
		return;
	}
	int seed = ini.GetValueSetI("Seed", "Seed", 0);
	bool unused = false;
	cBiomeGen * biomeGen = cBiomeGen::CreateBiomeGen(ini, seed, unused);
	if (biomeGen == nullptr)
	{
		return;
	}
	m_BiomeView->setChunkSource(std::shared_ptr<BioGenSource>(new BioGenSource(biomeGen)));
	m_BiomeView->redraw();
}





void MainWindow::open()
{
	// TODO
}





void MainWindow::createActions()
{
	m_actGen = new QAction(tr("&Generate..."), this);
	m_actGen->setShortcut(tr("Ctrl+N"));
	m_actGen->setStatusTip(tr("Open a generator INI file and display the generated biomes"));
	connect(m_actGen, SIGNAL(triggered()), this, SLOT(generate()));

	m_actOpen = new QAction(tr("&Open world..."), this);
	m_actOpen->setShortcut(tr("Ctrl+O"));
	m_actOpen->setStatusTip(tr("Open an existing world and display its biomes"));
	connect(m_actOpen, SIGNAL(triggered()), this, SLOT(open()));

	m_actExit = new QAction(tr("E&xit"), this);
	m_actExit->setShortcut(tr("Alt+X"));
	m_actExit->setStatusTip(tr("Exit %1").arg(QApplication::instance()->applicationName()));
	connect(m_actExit, SIGNAL(triggered()), this, SLOT(close()));
}





void MainWindow::createMenus()
{
	QMenu * mFile = menuBar()->addMenu(tr("&World"));
	mFile->addAction(m_actGen);
	mFile->addAction(m_actOpen);
	mFile->addSeparator();
	mFile->addAction(m_actExit);
}