File: shieldset.h

package info (click to toggle)
lordsawar 0.3.2%2Bfrogknows-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,716 kB
  • sloc: cpp: 103,193; sh: 4,965; xml: 2,220; makefile: 1,371
file content (275 lines) | stat: -rw-r--r-- 9,460 bytes parent folder | download | duplicates (3)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//  Copyright (C) 2008, 2009, 2010, 2011, 2014, 2020 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.

#pragma once
#ifndef SHIELDSET_H
#define SHIELDSET_H

#include <gtkmm.h>
#include <map>
#include <vector>
#include <sigc++/trackable.h>

#include "shield.h"
#include "tartan.h"
#include "set.h"
#include "defs.h"

class XML_Helper;
class ShieldStyle;

//! A list of Shield graphic objects in a shield theme.
/**
 * Every scenario has a shield set; it is the theme of the shield graphics 
 * within the game.  Shields come in three sizes -- small, medium and large.  
 * Small shields appear on the OverviewMap.  Medium shields appear in the turn 
 * indicator in the top right of the GameWindow.  Large shields appear in many 
 * dialogs, chiefly the FightWindow, and DiplomacyDialog.
 * Every shield belongs to one of 9 players (the ninth is the Neutral player).
 * The players aren't Player objects in this case; instead it refers to a 
 * Shield::ShieldColour.  e.g. Not `The Sirians' but rather the `White player'
 * of the scenario.
 *
 * The Shieldset dictates the dimensions of these three sizes of shields.
 *
 * Shieldsets are referred to by their basename.  This is the last part of the
 * filename, minus the file extension.
 *
 * The shieldset configuration file is a tar file that contains an XML file, 
 * and a set of png files.  Filenames have the following form:
 * shield/${Shieldset::d_basename}.lws.
 */
class Shieldset: public std::list<Shield *>, public sigc::trackable, public Set
{
    public:

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

	//! The file extension for shieldset files.  It includes the dot.
	static Glib::ustring file_extension;


	//! Default constructor.
	/**
	 * Make a new shieldset given a unique id and a basename name.
	 */
	Shieldset(guint32 id, Glib::ustring name);

        //! Copy constructor.
        Shieldset(const Shieldset& s);

	//! Load a Shieldset from an opened shieldset configuration file.
	/**
	 * Make a new Shieldset object by reading it in from the shieldset
	 * configuration file.
	 *
	 * @param helper  The opened shieldset configuration file to load the
	 *                Shieldset from.
	 */
        Shieldset(XML_Helper* helper, Glib::ustring directory);

	//! Destructor.
        ~Shieldset();

	// Get Methods

	//! Return the mask colour for the given player.
	Gdk::RGBA getColor(guint32 owner) const;

	//! Return the number of pixels high the small shields are.
	guint32 getSmallHeight() const {return d_small_height;}

	//! Return the number of pixels wide the small shields are.
	guint32 getSmallWidth() const {return d_small_width;}

	//! Return the number of pixels high the medium shields are.
	guint32 getMediumHeight() const {return d_medium_height;}

	//! Return the number of pixels wide the medium shields are.
	guint32 getMediumWidth() const {return d_medium_width;}

	//! Return the number of pixels the large shields are.
	guint32 getLargeHeight() const {return d_large_height;}

	//! Return the number of pixels wide the large shields are.
	guint32 getLargeWidth() const {return d_large_width;}

	//! Return the total number of shields in this shieldset.
        guint32 getSize() const {return size();}

        bool isAnyHeightAndWidthSet();
        bool isSmallHeightAndWidthSet();
        bool isMediumHeightAndWidthSet();
        bool isLargeHeightAndWidthSet();

	// Set Methods

	//! Return the number of pixels high the small shields are.
	void setSmallHeight(guint32 n) {d_small_height = n;}

	//! Set how wide in pixels small shields are scaled to.
	void setSmallWidth(guint32 n) {d_small_width = n;}

	//! Set how high in pixels medium shields are scaled to.
	void setMediumHeight(guint32 n) {d_medium_height = n;}

	//! Set how wide in pixels medium shields are scaled to.
	void setMediumWidth(guint32 n) {d_medium_width = n;}

	//! Set how high in pixels large shields are scaled to.
	void setLargeHeight(guint32 n) {d_large_height = n;}

	//! Set how wide in pixels large shields are scaled to.
	void setLargeWidth(guint32 n) {d_large_width = n;}

        //! Load the shieldset again.
        void reload(bool &broken);

        //! Set the dimensions based on the largest image of that shieldstyle.
        void setHeightsAndWidthsFromImages(ShieldStyle *s);
        void setHeightsAndWidthsFromImages();
        void setSmallHeightsAndWidthsFromImages();
        void setMediumHeightsAndWidthsFromImages();
        void setLargeHeightsAndWidthsFromImages();

	// Methods that operate on the class data but do not modify the class.

	bool save(XML_Helper *helper) const;

        bool save(Glib::ustring filename, Glib::ustring extension) const;

	//! Find the shield of a given size and colour in this Shieldset.
	/**
	 * Scan through all Shield objects in this set for first one that is 
	 * the desired size, and for the desired player.
	 *
	 * @param type    One of the values in Shield::ShieldType.
	 * @param colour  One of the values in Shield::ShieldColour.
	 *
	 * @return A pointer to the shield that matches the size and player.
	 *         If no Shield object could be found that matches the given
	 *         parameters, NULL is returned.
	 */
	ShieldStyle* lookupShieldByTypeAndColour(guint32 type, guint32 colour) const;
        Shield* lookupShieldByColour(guint32 colour) const;

        //! Get the image and mask associated with the shield of a given colour.
        /**
         * This gets the left tartan image and mask for a player denoted by
         * colour.
         */
        void lookupTartanImage(guint32 colour, Tartan::Type type,
                               PixMask **image, PixMask **mask);

	//! Check to see if this shieldset can be used in the game.
	bool validate() const;

	//! Check to see if the number of shields is sufficient.
	bool validateNumberOfShields() const;

	//! Check to see if the images for the shields are supplied.
	bool validateShieldImages(Shield::Colour c) const;

	//! Check to see if the images for the tartans are supplied.
	bool validateTartanImages(Shield::Colour c) const;

        guint32 countEmptyImageNames() const;

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

        //! Load the images associated with this shieldset.
        /**
         * Go get the image files from the shieldset file and create the
         * various pixmask objects.
         *
         * @param scale   The images are clamped to the sizes held in
         *                d_small_width, d_small_height (for the small
         *                shields) and so on.
         * @param broken  True when couldn't read the shieldset file.
         */
	void instantiateImages(bool scale, bool &broken);

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

        //! destroy any image that has this name
        void uninstantiateSameNamedImages (Glib::ustring imgname);

	// Static Methods

	//! Create a shieldset from the given shieldset configuration file.
	static Shieldset *create(Glib::ustring filename, bool &unsupported);

        static Shieldset *copy (const Shieldset *orig);

        //! rewrite old shieldset files.
        static bool upgrade(Glib::ustring filename, Glib::ustring old_version, Glib::ustring new_version);
        static void support_backward_compatibility();

    private:

	//! Callback function to load Shield objects into the Shieldset.
	bool loadShield(Glib::ustring tag, XML_Helper* helper);

	// DATA

	//! The number of pixels high the small shield images are scaled to.
	/**
	 * Equates to the shieldset.d_small_height XML entity in the shieldset 
	 * configuration file.
	 */
	guint32 d_small_height;

	//! The number of pixels wide the small shield images are scaled to.
	/**
	 * Equates to the shieldset.d_small_width XML entity in the shieldset 
	 * configuration file.
	 */
	guint32 d_small_width;

	//! The number of pixels high the medium shield images are scaled to.
	/**
	 * Equates to the shieldset.d_medium_height XML entity in the shieldset 
	 * configuration file.
	 */
	guint32 d_medium_height;

	//! The number of pixels wide the medium shield images are scaled to.
	/**
	 * Equates to the shieldset.d_medium_width XML entity in the shieldset 
	 * configuration file.
	 */
	guint32 d_medium_width;

	//! The number of pixels high the large shield images are scaled to.
	/**
	 * Equates to the shieldset.d_large_height XML entity in the shieldset 
	 * configuration file.
	 */
	guint32 d_large_height;

	//! The number of pixels wide the large shield images are scaled to.
	/**
	 * Equates to the shieldset.d_large_width XML entity in the shieldset 
	 * configuration file.
	 */
	guint32 d_large_width;
};

#endif // SHIELDSET_H