initial commit, lordsawar source, slightly modified
[lordsawar] / src / tilestyleset.h
1 //  Copyright (C) 2007, 2008 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 TILESTYLESET_H
19 #define TILESTYLESET_H
20
21 #include <string>
22 #include <vector>
23 #include <gtkmm.h>
24 #include <sigc++/trackable.h>
25
26 #include "tilestyle.h"
27
28 class XML_Helper;
29
30 /** 
31  * TileStyleSet is an array of tilestyles (the look of terrain tile objects).
32  * All of the TileStyles describe one of the many looks of a particular kind
33  * of Tile.  e.g. `Forest'.
34  * Every TileStyleSet belongs to a Tile.
35  * The TileStyleSet images are located in on disk in the Tileset's directory.
36  */
37 //! This class manages a set of TileStyle objects.
38 class TileStyleSet : public sigc::trackable, public std::vector<TileStyle*>
39 {
40     public:
41
42         //! The xml tag of this object in a tileset configuration file.
43         static std::string d_tag; 
44
45         //! The default constructor.
46         TileStyleSet();
47
48         //! The loading constuctor loads the TileStyleSet from the config file.
49         /**
50          * Read the tileset.tile.tilestyleset XML entities in the tileset
51          * configuration file.
52          *
53          * @param helper  The opened tileset configuration file.
54          */
55         TileStyleSet(XML_Helper* helper);
56
57         //! Destructor.
58         ~TileStyleSet();
59
60
61         // Get Methods
62
63         //! Get the name of this tilestyleset.
64         /**
65          * Returns the text loaded from a tileset.tile.tilestyles.d_name
66          * XML entity of the tileset configuration flie.
67          * This name refers to the filename that holds the imagery for this
68          * tilestyleset.  It is a basename of the filename.  It doesn't
69          * contain any slashes, or an ending file extension.  eg. ".png".
70          */
71         std::string getName() const {return d_name;}
72
73         //! Return the subdirectory of this Tilestyleset.
74         std::string getSubDir() const {return d_dir;};
75
76
77         // Set Methods
78
79         //! Set the name of this tilestyleset.
80         void setName(std::string name) {d_name = name;}
81
82         //! Set the subdirectory of where this Tilestyleset resides on disk.
83         void setSubDir(std::string dir) {d_dir = dir;};
84
85
86         //Methods that operate on the class data but do not modify the class.
87
88         //! Save a TileStyleSet to an opened tile configuration file.
89         /**
90          * @param  The opened XML tile configuration file.
91          */
92         bool save(XML_Helper *helper) const;
93
94         //! Return a list of all of the tilestyle types in this tilestyleset.
95         void getUniqueTileStyleTypes(std::list<TileStyle::Type> &types) const;
96
97         //! Check to see if this tilestyleset is usable in the game.
98         bool validate() const;
99
100
101         //Methods that operate on the class data and modify the class.
102
103         //! Instantiate the tilestyleset's images from the given file.
104         void instantiateImages(int tilesize, std::string image_filename);
105
106         //! Destroy the images associated with this tilestyleset.
107         void uninstantiateImages();
108
109     private:
110
111         // DATA
112
113         //! The name of the tilestyleset.
114         /**
115          * This is the basename of the image that contains a row of
116          * cells where each cell is tilesize pixels high, and tilesize
117          * pixels wide.  Each cell is another image of a tilestyle.  There is
118          * one cell per TileStyle in this TileStyleSet.
119          * The tilesize comes from the TileStyleSet::instantiateImages
120          * method.
121          * The name does not contain a path, and does not contain an
122          * extension (e.g. .png).  It must refer to a PNG file.
123          */
124         std::string d_name;
125
126         //! The directory of where the image file lives.
127         /**
128          * @param This is a hack used for the tileset editor.
129          */
130         std::string d_dir;
131 };
132
133 #endif // TILESTYLESET_H
134
135 // End of file