~ubuntu-branches/ubuntu/maverick/lordsawar/maverick

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//  Copyright (C) 2008, 2009 Ben Asselstine
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Library General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
//  02110-1301, USA.

#ifndef SHIELDSTYLE_H
#define SHIELDSTYLE_H

#include <gtkmm.h>
#include <string>
#include <sigc++/trackable.h>
#include "PixMask.h"


class Player;
class XML_Helper;
class Shieldset;

//! A graphic of a shield.
/**
 * This class is the atom of every shield. It contains all data related to
 * a single ShieldStyle type of a Shield.  ShieldStyles come in three sizes: 
 * small, medium and large (ShieldStyle::Type).
 *
 * Every ShieldStyle object has an image and a mask.  The mask identifies the
 * portion of the ShieldStyle to shade in the Player's colour (Player::d_color).
 * The mask appears on the right side the shield image file.
 *
 */
class ShieldStyle : public sigc::trackable
{
    public:

	//! The xml tag of this object in a shieldset configuration file.
	static std::string d_tag; 

	//! The size of the shield.
	enum Type {
	  //! Small shields are shown on the OverviewMap object.
	  SMALL = 0, 
	  //! Medium shields are shown in the top right of the GameWindow.
	  MEDIUM = 1, 
	  //! Large shields are shown in the DiplomacyDialog and FightWindow.
	  LARGE = 2
	};

	//! Loading constructor.
        /**
	 * Make a new ShieldStyle object by readiang it in from an opened shieldset
	 * configuration file.
	 *
         * @param helper  The opened shieldset configuration file to read the
	 *                shield object from.
         */
        ShieldStyle(XML_Helper* helper);


	//! Default constructor.
	ShieldStyle(ShieldStyle::Type type);
        
	//! Destructor.
        virtual ~ShieldStyle();

        
        // Get Methods
        
        //! Get the size of this shield.
        guint32 getType() const {return d_type;}

        //! Get the image of the shield.
	PixMask* getImage() const {return d_image;}

        //! Returns the mask of the shield.
	PixMask* getMask() const {return d_mask;}

	//! Returns the basename of the picture's filename.
	std::string getImageName() const {return d_image_name;}


        // Set Methods
        
        //! Set the basic image of the shield.
        void setImage(PixMask* image) {d_image = image;};

        //! Set the mask of the shield.
        void setMask(PixMask* mask) {d_mask = mask;}

	//! Set the basename of the shield picture's filename.
	void setImageName(std::string name) {d_image_name = name;}


	// Methods that operate on class data and modify the class.

	//! Load the images for this shieldstyle from the given file.
	void instantiateImages(std::string filename, Shieldset *s);

	//! Destroy the images associated with this shieldstyle.
	void uninstantiateImages();


	// Methods that operate on class data but do not modify the class.
	
	//! Save the shieldstyle to an opened shieldset configuration file.
	bool save(XML_Helper *helper) const;


	// Static Methods
	
	//! Convert a ShieldStyle::Type enumerated value to a string.
	static std::string shieldStyleTypeToString(const ShieldStyle::Type type);

	//! Convert a ShieldStyle::Type string to an enumerated value.
	static ShieldStyle::Type shieldStyleTypeFromString(const std::string str);
    protected:

	//! The size of the shield. (small, medium, or large)
	/**
	 * Equates to the shieldset.shield.d_type XML entities in the shieldset
	 * configuration file.
	 * Equates to the ShieldStyle::Type enumeration.
	 */
        guint32 d_type;

	//! The unshaded image portion of the shield's picture.
	PixMask* d_image;

	//! The portion of the shield's image to shade in the player's colour.
	/**
	 * The mask appears to the right of the image in the shield's picture.
	 * The colour that shades the mask is dictated by Player::d_colour.
	 */
	PixMask* d_mask;

	//! The basename of the shield's picture file.
	/**
	 * Returns the filename that holds the image for this ShieldStyle.
	 * The filename does not have a path, and the filename does
	 * not have an extension (e.g. .png).
	 */
	std::string d_image_name;
};

#endif // SHIELDSTYLE_H