Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: efde85b10a2a507d38d4df306332ff30e5be93e7 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
   properties.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
*/

#ifndef __INCLUDED_EDITOR_PROPERTIES__
#define __INCLUDED_EDITOR_PROPERTIES__

#include "vector3f.h"

#include <QColor>
#include <QMap>
#include <QString>
#include <QTextStream>

namespace editor
{

/**
 * @brief abstract base class to hold properties for game objects
 * */
class Properties
{
public:
	Properties();
	
	virtual ~Properties();
	
	/* ---- inspectors ---- */
	
	/**
	 * @brief returns the label of this object
	 * */
	inline const QString &label() const {
		return properties_label;
	}
	
	/**
	 * @brief returns the name of this object
	 * */
	inline const QString &name() const {
		return properties_name;
	}
	
	/**
	 * @brief returns the location of this object
	 * */
	inline const Vector3f &location() const {
		return properties_location;
	}
	
	/**
	 * @brief returns the color of this object
	 * */
	inline const QColor &color() const {
		return properties_color;
	}

	/**
	 * @brief returns the comment string of this object
	 * */
	inline const QString &comment() const {
		return properties_comment;
	}
	
	/**
	 * @brief returns the comment string for a specified attribute
	 * */
	inline const QString comment(const QString &attribute) const {
		return properties_comments[attribute];
	}
	
	/**
	 * @brief returns the info string of this object
	 * */
	inline const QString &info() const {
		return properties_info;
	}

	/**
	 * @brief returns the values string of this object
	 * */
	inline const QString &values() const {
		return properties_values;
	}
	
	/* ---- mutators ---- */
	
	/**
	 * @brief set the comments string of this object
	 * */
	inline void set_comment(const QString &text) {
		properties_comment = text;
	}
	
	/**
	 * @brief set the comments string for a specified attribute
	 * */
	inline void set_comment(const QString attribute, const QString &text) {
		properties_comments[attribute] = text;
	}
	
	/**
	 * @brief set the info string of this object
	 * */
	inline void set_info(const QString &text) {
		properties_info = text;
	}
	
	/**
	 * @brief add a line of text to the info string of this object
	 * */
	void add_info(const QString &text);
	
	/**
	 * @brief set the subsection string of this object
	 * */
	inline void set_values(const QString &text) {
		properties_values = text;
	}
	
	/**
	 * @brief add a value key pair to the values string
	 * */
	void add_value(const QString &key, const QString &value, const QString &comment);
	
	/**
	 * @brief set the object label
	 * */
	inline void set_label(const QString &label) {
		properties_label = label;
	}
	
	/**
	 * @brief set the object name
	 * */
	inline void set_name(const QString &name) {
		properties_name = name;
	}
	
	/**
	 * @brief set the object location
	 * */
	inline void set_location(const Vector3f &location) {
		properties_location = location;
	}
	
	/**
	 * @brief set the object location
	 * */
	inline void set_location(const float x, const float y, const float z) {
		properties_location.assign(x, y, z);
	}
	
	/**
	 * @brief set the object color
	 * */
	inline void set_color(const QColor &color) {
		properties_color = color;
	}
		
	/**
	 * @brief set the object color
	 * */
	inline void set_color(const float r, const float g, const float b) {
		float cr = r;
		float cg = g;
		float cb = b;

		// Qt RGB colors are in the 0-255 range
		if ((r <= 1) && (g <= 1) && (b <= 1)) {
			cr *= 255;
			cg *= 255;
			cg *= 255;
		}
		
		properties_color.setRgb(r, g, b);
	}
protected:
	/**
	 * @brief save attribute comments to a textstream
	 * */
	void save_comment(QTextStream &textstream, const QString &attribute);
	
private:
	typedef QMap<QString, QString> Comments;
	
	/// comments for this objects
	QString			properties_comment;
	/// comments for the individual attributes;
	Comments		properties_comments;
	
	QString			properties_label;
	QString			properties_name;
		
	Vector3f		properties_location;
	QColor			properties_color;
	
	QString			properties_info;
	QString			properties_values;
};

} // namespace editor

#endif // __INCLUDED_EDITOR_PROPERTIES__