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
23 #include <sigc++/trackable.h>
31 //! A graphic of a shield.
33 * This class is the atom of every shield. It contains all data related to
34 * a single ShieldStyle type of a Shield. ShieldStyles come in three sizes:
35 * small, medium and large (ShieldStyle::Type).
37 * Every ShieldStyle object has an image and a mask. The mask identifies the
38 * portion of the ShieldStyle to shade in the Player's colour (Player::d_color).
39 * The mask appears on the right side the shield image file.
42 class ShieldStyle : public sigc::trackable
46 //! The xml tag of this object in a shieldset configuration file.
47 static std::string d_tag;
49 //! The size of the shield.
51 //! Small shields are shown on the OverviewMap object.
53 //! Medium shields are shown in the top right of the GameWindow.
55 //! Large shields are shown in the DiplomacyDialog and FightWindow.
59 //! Loading constructor.
61 * Make a new ShieldStyle object by readiang it in from an opened shieldset
64 * @param helper The opened shieldset configuration file to read the
67 ShieldStyle(XML_Helper* helper);
70 //! Default constructor.
71 ShieldStyle(ShieldStyle::Type type);
74 virtual ~ShieldStyle();
79 //! Get the size of this shield.
80 guint32 getType() const {return d_type;}
82 //! Get the image of the shield.
83 PixMask* getImage() const {return d_image;}
85 //! Returns the mask of the shield.
86 PixMask* getMask() const {return d_mask;}
88 //! Returns the basename of the picture's filename.
89 std::string getImageName() const {return d_image_name;}
94 //! Set the basic image of the shield.
95 void setImage(PixMask* image) {d_image = image;};
97 //! Set the mask of the shield.
98 void setMask(PixMask* mask) {d_mask = mask;}
100 //! Set the basename of the shield picture's filename.
101 void setImageName(std::string name) {d_image_name = name;}
104 // Methods that operate on class data and modify the class.
106 //! Load the images for this shieldstyle from the given file.
107 void instantiateImages(std::string filename, Shieldset *s);
109 //! Destroy the images associated with this shieldstyle.
110 void uninstantiateImages();
113 // Methods that operate on class data but do not modify the class.
115 //! Save the shieldstyle to an opened shieldset configuration file.
116 bool save(XML_Helper *helper) const;
121 //! Convert a ShieldStyle::Type enumerated value to a string.
122 static std::string shieldStyleTypeToString(const ShieldStyle::Type type);
124 //! Convert a ShieldStyle::Type string to an enumerated value.
125 static ShieldStyle::Type shieldStyleTypeFromString(const std::string str);
128 //! The size of the shield. (small, medium, or large)
130 * Equates to the shieldset.shield.d_type XML entities in the shieldset
131 * configuration file.
132 * Equates to the ShieldStyle::Type enumeration.
136 //! The unshaded image portion of the shield's picture.
139 //! The portion of the shield's image to shade in the player's colour.
141 * The mask appears to the right of the image in the shield's picture.
142 * The colour that shades the mask is dictated by Player::d_colour.
146 //! The basename of the shield's picture file.
148 * Returns the filename that holds the image for this ShieldStyle.
149 * The filename does not have a path, and the filename does
150 * not have an extension (e.g. .png).
152 std::string d_image_name;
155 #endif // SHIELDSTYLE_H