Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: ec7ebe2b8ea86048a2c5c2e13ce077cd297c7a9d (plain)
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
145
146
147
/*
   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 "entitywidget.h"
#include "inistream.h"
#include "mapwidget.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);
	
	connect(editorwindow_mapwidget, SIGNAL(selected(EntityWidget *)), editorwindow_sidebar, SLOT(setEntity(EntityWidget *)));
	connect(editorwindow_sidebar, SIGNAL(entityChanged()), editorwindow_mapwidget, SLOT(resizeChildren()));
}

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;
	
	EntityWidget *entity = 0;
	bool in_entity = false;
	float x, y, z;
	float f;
	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) {
				// read entity properties into the MapWidget instance
				
				if (ini.got_key_vector3f("location" , x, y, z)) {
					entity->set_location(x, y, z);
					//qDebug() << "got location " << x << " " << y << " " << z;
					
				} else if (ini.got_key_string("label", str)) {
					entity->set_label(str);
					
				} else if (ini.got_key_string("name", str)) {
					entity->set_name(str);
					
				} else if (ini.got_key_float("radius", f)) {
					entity->set_radius(f);

				} else if (ini.got_key()) {
					entity->add_property(ini.key(), ini.value());
				}
				
			} 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)
{

	
}

}