initial commit, lordsawar source, slightly modified
[lordsawar] / src / shieldstyle.h
1 //  Copyright (C) 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 SHIELDSTYLE_H
19 #define SHIELDSTYLE_H
20
21 #include <gtkmm.h>
22 #include <string>
23 #include <sigc++/trackable.h>
24 #include "PixMask.h"
25
26
27 class Player;
28 class XML_Helper;
29 class Shieldset;
30
31 //! A graphic of a shield.
32 /**
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).
36  *
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.
40  *
41  */
42 class ShieldStyle : public sigc::trackable
43 {
44     public:
45
46         //! The xml tag of this object in a shieldset configuration file.
47         static std::string d_tag; 
48
49         //! The size of the shield.
50         enum Type {
51           //! Small shields are shown on the OverviewMap object.
52           SMALL = 0, 
53           //! Medium shields are shown in the top right of the GameWindow.
54           MEDIUM = 1, 
55           //! Large shields are shown in the DiplomacyDialog and FightWindow.
56           LARGE = 2
57         };
58
59         //! Loading constructor.
60         /**
61          * Make a new ShieldStyle object by readiang it in from an opened shieldset
62          * configuration file.
63          *
64          * @param helper  The opened shieldset configuration file to read the
65          *                shield object from.
66          */
67         ShieldStyle(XML_Helper* helper);
68
69
70         //! Default constructor.
71         ShieldStyle(ShieldStyle::Type type);
72         
73         //! Destructor.
74         virtual ~ShieldStyle();
75
76         
77         // Get Methods
78         
79         //! Get the size of this shield.
80         guint32 getType() const {return d_type;}
81
82         //! Get the image of the shield.
83         PixMask* getImage() const {return d_image;}
84
85         //! Returns the mask of the shield.
86         PixMask* getMask() const {return d_mask;}
87
88         //! Returns the basename of the picture's filename.
89         std::string getImageName() const {return d_image_name;}
90
91
92         // Set Methods
93         
94         //! Set the basic image of the shield.
95         void setImage(PixMask* image) {d_image = image;};
96
97         //! Set the mask of the shield.
98         void setMask(PixMask* mask) {d_mask = mask;}
99
100         //! Set the basename of the shield picture's filename.
101         void setImageName(std::string name) {d_image_name = name;}
102
103
104         // Methods that operate on class data and modify the class.
105
106         //! Load the images for this shieldstyle from the given file.
107         void instantiateImages(std::string filename, Shieldset *s);
108
109         //! Destroy the images associated with this shieldstyle.
110         void uninstantiateImages();
111
112
113         // Methods that operate on class data but do not modify the class.
114         
115         //! Save the shieldstyle to an opened shieldset configuration file.
116         bool save(XML_Helper *helper) const;
117
118
119         // Static Methods
120         
121         //! Convert a ShieldStyle::Type enumerated value to a string.
122         static std::string shieldStyleTypeToString(const ShieldStyle::Type type);
123
124         //! Convert a ShieldStyle::Type string to an enumerated value.
125         static ShieldStyle::Type shieldStyleTypeFromString(const std::string str);
126     protected:
127
128         //! The size of the shield. (small, medium, or large)
129         /**
130          * Equates to the shieldset.shield.d_type XML entities in the shieldset
131          * configuration file.
132          * Equates to the ShieldStyle::Type enumeration.
133          */
134         guint32 d_type;
135
136         //! The unshaded image portion of the shield's picture.
137         PixMask* d_image;
138
139         //! The portion of the shield's image to shade in the player's colour.
140         /**
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.
143          */
144         PixMask* d_mask;
145
146         //! The basename of the shield's picture file.
147         /**
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).
151          */
152         std::string d_image_name;
153 };
154
155 #endif // SHIELDSTYLE_H