1 // Copyright (C) 2008, 2009 Ben Asselstine
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.
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.
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
25 #include <sigc++/trackable.h>
27 #include "xmlhelper.h"
33 //! A list of Shield graphic objects in a shield theme.
35 * Every scenario has a shield set; it is the theme of the shield graphics
36 * within the game. Shields come in three sizes -- small, medium and large.
37 * Small shields appear on the OverviewMap. Medium shields appear in the turn
38 * indicator in the top right of the GameWindow. Large shields appear in many
39 * dialogs, chiefly the FightWindow, and DiplomacyDialog.
40 * Every shield belongs to one of 9 players (the ninth is the Neutral player).
41 * The players aren't Player objects in this case; instead it refers to a
42 * Shield::ShieldColour. e.g. Not `The Sirians' but rather the `White player'
45 * The Shieldset dictates the dimensions of these three sizes of shields.
47 * Shieldsets are referred to by their subdirectory name.
49 * The shieldset configuration file is a same named XML file inside the
50 * Shieldset's directory.
51 * E.g. shield/${Shieldset::d_subdir}/${Shieldset::d_subdir}.xml.
53 class Shieldset: public std::list<Shield *>, public sigc::trackable, public Set
57 //! The xml tag of this object in a shieldset configuration file.
58 static std::string d_tag;
60 //! The file extension for shieldset files. It includes the dot.
61 static std::string file_extension;
64 //! Default constructor.
66 * Make a new shieldset given a unique id and a subdir name.
68 Shieldset(guint32 id, std::string name);
70 //! Load a Shieldset from a shieldset configuration file.
72 * Make a new Shieldset object by reading it in from the shieldset
75 * @param helper The opened shieldset configuration file to load the
78 Shieldset(XML_Helper* helper, std::string directory);
85 //! Get the unique identifier for this shieldset.
87 * Analagous to the shieldset.d_id XML entity in the shieldset
90 guint32 getId() const {return d_id;}
92 //! Get the directory in which the shieldset configuration file resides.
93 std::string getSubDir() const {return d_subdir;}
95 //! Return the mask colour for the given player.
96 Gdk::Color getColor(guint32 owner) const;
98 //! Return the number of pixels high the small shields are.
99 guint32 getSmallHeight() const {return d_small_height;}
101 //! Return the number of pixels wide the small shields are.
102 guint32 getSmallWidth() const {return d_small_width;}
104 //! Return the number of pixels high the medium shields are.
105 guint32 getMediumHeight() const {return d_medium_height;}
107 //! Return the number of pixels wide the medium shields are.
108 guint32 getMediumWidth() const {return d_medium_width;}
110 //! Return the number of pixels the large shields are.
111 guint32 getLargeHeight() const {return d_large_height;}
113 //! Return the number of pixels wide the large shields are.
114 guint32 getLargeWidth() const {return d_large_width;}
116 //! Return the total number of shields in this shieldset.
117 guint32 getSize() const {return size();}
119 //! Return the name of the Shieldset.
120 std::string getName() const {return _(d_name.c_str());}
122 //! Return the copyright holders of the shieldset.
123 std::string getCopyright() const {return d_copyright;};
125 //! Return the license of the shieldset.
126 std::string getLicense() const {return d_license;};
128 //! Returns the description of the shieldset.
129 std::string getInfo() const {return _(d_info.c_str());}
134 //! Set the unique identifier for this shieldset.
135 void setId(guint32 id) {d_id = id;}
137 //! Set the name of the Shieldset.
138 void setName(std::string name) {d_name = name;}
140 //! Sets the description of the shieldset.
141 void setInfo(std::string description) {d_info = description;};
143 //! Set the copyright holders of the shieldset.
144 void setCopyright(std::string copy) {d_copyright = copy;};
146 //! Set the license of this shieldset.
147 void setLicense(std::string license) {d_license = license;};
149 //! Set the direction where the shieldset configuration file resides.
150 void setSubDir(std::string dir) {d_subdir = dir;}
153 // Methods that operate on the class data but do not modify the class.
155 bool save(XML_Helper *helper) const;
158 //! Find the shield of a given size and colour in this Shieldset.
160 * Scan through all Shield objects in this set for first one that is
161 * the desired size, and for the desired player.
163 * @param type One of the values in Shield::ShieldType.
164 * @param colour One of the values in Shield::ShieldColour.
166 * @return A pointer to the shield that matches the size and player.
167 * If no Shield object could be found that matches the given
168 * parameters, NULL is returned.
170 ShieldStyle * lookupShieldByTypeAndColour(guint32 type, guint32 colour) const;
172 //! Get filenames in this shieldset, excepting the configuration file.
173 void getFilenames(std::list<std::string> &filenames) const;
175 //! Return the name of this shieldset's configuration file.
176 std::string getConfigurationFile() const;
178 //! Check to see if this shieldset can be used in the game.
179 bool validate() const;
181 //! Check to see if the number of shields is sufficient.
182 bool validateNumberOfShields() const;
184 //! Check to see if the images for the shieldset are supplied.
185 bool validateShieldImages(Shield::Colour c) const;
188 // Methods that operate on the class data and also modify the class.
190 //! Load images associated with this shieldset.
191 void instantiateImages();
193 //! Destroy images associated with this shieldset.
194 void uninstantiateImages();
199 //! Create a shieldset from the given shieldset configuration file.
200 static Shieldset *create(std::string filename);
202 //! Return a list of shieldset subdirs in the system collection.
203 static std::list<std::string> scanSystemCollection();
205 //! Return a list of shieldset subdirs in the users personal collection.
206 static std::list<std::string> scanUserCollection();
210 //! Callback function to load Shield objects into the Shieldset.
211 bool loadShield(std::string tag, XML_Helper* helper);
215 //! A unique numeric identifier among all shieldset.
218 //! The name of the Shieldset.
220 * This equates to the shieldset.d_name XML entity in the shieldset
221 * configuration file.
222 * This name appears in the dialogs where the user is asked to
223 * select a particular Shieldset.
227 //! The copyright holders of the shieldset.
228 std::string d_copyright;
230 //! The license of the shieldset.
231 std::string d_license;
233 //! The description of the shieldset.
235 * Equates to the shieldset.d_info XML entity in the shieldset
236 * configuration file.
240 //! The subdirectory of the Shieldset.
242 * This is the name of the subdirectory that the Shieldset files are
243 * residing in. It does not contain a path (e.g. no slashes).
244 * Shieldset directories sit in the shield/ directory.
246 std::string d_subdir;
248 //! The number of pixels high the small shield occupies onscreen.
250 * Equates to the shieldset.d_small_height XML entity in the shieldset
251 * configuration file.
253 guint32 d_small_height;
255 //! The number of pixels wide the small shield occupies onscreen.
257 * Equates to the shieldset.d_small_width XML entity in the shieldset
258 * configuration file.
260 guint32 d_small_width;
262 //! The number of pixels high the medium shield occupies onscreen.
264 * Equates to the shieldset.d_medium_height XML entity in the shieldset
265 * configuration file.
267 guint32 d_medium_height;
269 //! The number of pixels wide the medium shield occupies onscreen.
271 * Equates to the shieldset.d_medium_width XML entity in the shieldset
272 * configuration file.
274 guint32 d_medium_width;
276 //! The number of pixels high the large shield occupies onscreen.
278 * Equates to the shieldset.d_large_height XML entity in the shieldset
279 * configuration file.
281 guint32 d_large_height;
283 //! The number of pixels wide the large shield occupies onscreen.
285 * Equates to the shieldset.d_large_width XML entity in the shieldset
286 * configuration file.
288 guint32 d_large_width;
291 #endif // SHIELDSET_H