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
|
/*
editorwindow.h
This file is part of the Project::OSiRiON world editor
and is distributed under the terms and conditions of
the GNU General Public License version 2
*/
#include "editorwindow.h"
#include "inistream.h"
#include "mapwidget.h"
#include "mapentity.h"
#include "sidebar.h"
#include <QtGui>
#include <QFile>
#include <QTextStream>
#include <QDebug>
namespace editor
{
EditorWindow::EditorWindow(QWidget *parent) : QWidget(parent)
{
editorwindow_mapwidget = new MapWidget(this);
editorwindow_sidebar = new SideBar(this);
}
void EditorWindow::resizeEvent (QResizeEvent *event)
{
editorwindow_sidebar->resize(256, height());
editorwindow_mapwidget->setGeometry(
editorwindow_sidebar->width(), 0,
width() - editorwindow_sidebar->width(), height()
);
}
bool EditorWindow::loadFile(const QString &filename)
{
QFile file(filename);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Open Zone"),
tr("Could not open file %1:\n%2.")
.arg(filename)
.arg(file.errorString()));
return false;
}
QTextStream textstream(&file);
QApplication::setOverrideCursor(Qt::WaitCursor);
IniStream ini;
MapEntity *entity = 0;
bool in_entity = false;
float x, y, z;
QString str;
while (ini.getline(textstream)) {
if (ini.got_section()) {
qDebug() << "got section" << ini.section();
if (ini.got_section("zone")) {
in_entity = false;
} else if (ini.got_section("entity")) {
in_entity = true;
} else if (ini.got_section("jumpgate")) {
in_entity = true;
} else if (ini.got_section("jumpoint")) {
in_entity = true;
} else if (ini.got_section("navpoint")) {
in_entity = true;
} else if (ini.got_section("station")) {
in_entity = true;
} else if (ini.got_section("star")) {
in_entity = true;
} else if (ini.got_section("planet")) {
in_entity = true;
} else {
entity = 0;
in_entity = false;
}
if (in_entity) {
entity = editorwindow_mapwidget->addEntity();
}
} else if(ini.got_key()) {
if (in_entity) {
if (ini.got_key_vector3f("location" , x, y, z)) {
entity->set_location(x, y, z);
//qDebug() << "got location " << x << " " << y << " " << z;
}
} else if (ini.in_section("zone")) {
if (ini.got_key_string("name", str)) {
editorwindow_sidebar->setZoneName(str);
}
}
}
}
QApplication::restoreOverrideCursor();
//setCurrentFile(fileName);
//connect(document(), SIGNAL(contentsChanged()),this, SLOT(documentWasModified()));
return true;
}
bool EditorWindow::saveFile(const QString &filename)
{
}
}
|