initial commit, lordsawar source, slightly modified
[lordsawar] / src / tilestyle.h
1 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #ifndef TILESTYLE_H
19 #define TILESTYLE_H
20
21 #include <gtkmm.h>
22
23 #include "xmlhelper.h"
24 #include "PixMask.h"
25
26 //! Describes the look of a Tile.
27 /**
28   * A TileStyle describes a single look of a Tile.  It is responsible for
29   * keeping the id, the image, and the kind of style.  The TileStyles for a 
30   * given tile are defined in the Tileset configuration file.
31   * If the kind of tile is `forest', then the TileStyles are defined in 
32   * individual tileset.tile.tilestyleset.tilestyle XML entities.
33   *
34   * There are many different images that can represent a kind of Tile. 
35   * Only certain tiles look right when positioned beside each other.  The
36   * correct styles are assigned by the GameMap::calculatePreferredStyle method.
37   * The id is important because it is referenced by the saved-game file 
38   * (the lordsawar.map.styles XML entity).
39   *
40   * Every TileStyle belongs to a TileStyleSet, which belongs to a Tile.
41   * Every Maptile refers to a TileStyle.
42   */
43 class TileStyle
44 {
45     public:
46         //! The xml tag of this object in a tileset configuration file.
47         static std::string d_tag; 
48
49         //! Describe terrain tile styles.
50           /**
51            * All of the Tilestyle kinds can be described by using the
52            * following template:
53            * @verbatim
54 +-----+
55 |#####|
56 |#+-+#|
57 |#|o|#|
58 |#+-+#|
59 |#####|
60 +-----+
61 @endverbatim
62            * Picture a terrain feature transitioning to grass on the outside 
63            * of the ring and on the inside of the ring also.
64            * In the very center of the template is a single feature that
65            * transitions to grass on all sides.
66            */
67         enum Type { 
68           /**
69            * @verbatim
70 ooooooo
71 ooooooo
72 ooooooo
73 oooxooo
74 ooooooo
75 ooooooo
76 ooooooo
77 @endverbatim
78            */
79           LONE = 0,
80
81           /**
82            * @verbatim
83 xoooooo
84 ooooooo
85 ooooooo
86 ooooooo
87 ooooooo
88 ooooooo
89 ooooooo
90 @endverbatim
91            */
92           OUTERTOPLEFT = 1, 
93           /**
94            * @verbatim
95 oxxxxxo
96 ooooooo
97 ooooooo
98 ooooooo
99 ooooooo
100 ooooooo
101 ooooooo
102 @endverbatim
103            */
104           OUTERTOPCENTER = 2, 
105           /**
106            * @verbatim
107 oooooox
108 ooooooo
109 ooooooo
110 ooooooo
111 ooooooo
112 ooooooo
113 ooooooo
114 @endverbatim
115            */
116           OUTERTOPRIGHT = 3,
117           /**
118            * @verbatim
119 ooooooo
120 ooooooo
121 ooooooo
122 ooooooo
123 ooooooo
124 ooooooo
125 xoooooo
126 @endverbatim
127            */
128           OUTERBOTTOMLEFT = 4, 
129           /**
130            * @verbatim
131 ooooooo
132 ooooooo
133 ooooooo
134 ooooooo
135 ooooooo
136 ooooooo
137 oxxxxxo
138 @endverbatim
139            */
140           OUTERBOTTOMCENTER = 5, 
141           /**
142            * @verbatim
143 ooooooo
144 ooooooo
145 ooooooo
146 ooooooo
147 ooooooo
148 ooooooo
149 oooooox
150 @endverbatim
151            */
152           OUTERBOTTOMRIGHT = 6,
153           /**
154            * @verbatim
155 ooooooo
156 xoooooo
157 xoooooo
158 xoooooo
159 xoooooo
160 xoooooo
161 ooooooo
162 @endverbatim
163            */
164           OUTERMIDDLELEFT = 7, 
165           /**
166            * @verbatim
167 ooooooo
168 oxxxxxo
169 oxoooxo
170 oxoooxo
171 oxoooxo
172 oxxxxxo
173 ooooooo
174 @endverbatim
175            */
176           INNERMIDDLECENTER = 8, 
177           /**
178            * @verbatim
179 ooooooo
180 oooooox
181 oooooox
182 oooooox
183 oooooox
184 oooooox
185 ooooooo
186 @endverbatim
187            */
188           OUTERMIDDLERIGHT = 9,
189           /**
190            * @verbatim
191 ooooooo
192 ooooooo
193 ooxoooo
194 ooooooo
195 ooooooo
196 ooooooo
197 ooooooo
198 @endverbatim
199            */
200           INNERTOPLEFT = 10, 
201           /**
202            * @verbatim
203 ooooooo
204 ooooooo
205 ooooxoo
206 ooooooo
207 ooooooo
208 ooooooo
209 ooooooo
210 @endverbatim
211            */
212           INNERTOPRIGHT = 11, 
213           /**
214            * @verbatim
215 ooooooo
216 ooooooo
217 ooooooo
218 ooooooo
219 ooxoooo
220 ooooooo
221 ooooooo
222 @endverbatim
223            */
224           INNERBOTTOMLEFT = 12, 
225           /**
226            * @verbatim
227 ooooooo
228 ooooooo
229 ooooooo
230 ooooooo
231 ooooxoo
232 ooooooo
233 ooooooo
234 @endverbatim
235            */
236           INNERBOTTOMRIGHT = 13,
237           /**
238            * Visually it's the merging of positions 1 and 2.
239            * @verbatim
240 1oooooo
241 ooooooo
242 ooooooo
243 ooooooo
244 ooooooo
245 ooooooo
246 oooooo2
247 @endverbatim
248            */
249           TOPLEFTTOBOTTOMRIGHTDIAGONAL = 14, 
250           /**
251            * Visually it's the merging of positions 1 and 2.
252            * @verbatim
253 oooooo1
254 ooooooo
255 ooooooo
256 ooooooo
257 ooooooo
258 ooooooo
259 2oooooo
260 @endverbatim
261            */
262           BOTTOMLEFTTOTOPRIGHTDIAGONAL = 15,
263           OTHER = 16,
264         };
265
266         //! Default constructor.
267         TileStyle();
268
269         //! Loading constructor.
270         /**
271          * Load the tileset.tile.tilestyles.tilestyle XML entities from the
272          * tileset configuration files.
273          */
274         TileStyle(XML_Helper* helper);
275
276         //! Destructor.
277         ~TileStyle();
278
279         // Get Methods
280
281         //! Get the id for this tilestyle.
282         /*
283          * The id is unique among all other tilestyles in the Tileset.
284          */
285         guint32 getId() const {return d_id;}
286
287         //! Get the style type of this tile style.
288         Type getType() const {return d_type;}
289
290         //! Get the picture for tile style.
291         PixMask* getImage() const {return d_image;}
292
293         //! Get the name of the current style.
294         std::string getTypeName() const;
295
296
297         // Set Methods
298
299         //! Set the style type of this tile style.
300         /**
301          * @note This method is only used in the tileset editor.
302          */
303         void setType(Type type) {d_type = type;}
304                 
305         //! Set the id for this tilestyle.
306         void setId(guint32 id) {d_id = id;}
307  
308         //! Set the image for the tilestyle.
309         void setImage(PixMask* image) {d_image = image;};
310
311
312         // Methods that operate on the class data but do not modify the class.
313
314         //! Save a TileStyle to an opened tile configuration file.
315         /**
316          * @param  The opened XML tile configuration file.
317          */
318         bool save(XML_Helper *helper);
319
320         // Static Methods
321
322         //! Get the name of the TileStyle::Type in string form.
323         static std::string getTypeName(Type type);
324
325         //! Return the style type enumeration given the type name.
326         static TileStyle::Type typeNameToType(std::string name);
327
328     private:
329         // DATA
330
331         //! The image of this tilestyle.
332         PixMask* d_image; 
333
334         //! The type of the tilestyle.
335         Type d_type;
336
337         //! The unique id for this tilestyle.
338         /**
339          * It must be unique among all other TileStyle objects in the 
340          * Tileset.
341          * This id shows up in the saved-game file in the lordsawar.map.styles
342          * XML entity as a hexidecimal number.
343          */
344         guint32 d_id;
345 };
346
347 #endif // TILESTYLE_H
348
349 // End of file