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
18 #ifndef SHIELDSETLIST_H
19 #define SHIELDSETLIST_H
25 #include <sigc++/trackable.h>
27 #include "xmlhelper.h"
29 #include "shieldset.h"
32 //! A list of Shieldset objects available to the game.
34 * This class holds all of the shield themes that are located in shield/.
35 * It is implemented as a singleton.
37 * Other classes use it to lookup Shield and Shieldset objects.
39 class Shieldsetlist : public std::list<Shieldset*>, public sigc::trackable
43 // Methods that operate on the class data but do not modify the class.
45 //! Returns the names of all Shieldset objects available to the game.
46 std::list<std::string> getNames() const;
48 //! Return the directory of a specific Shieldset by name.
50 * Scan all of the Shieldset objects in the list for one with the
53 * @param name The name of the shieldset to search for.
55 * @return The name of the directory that holds the shieldset, or an
56 * empty string if a shieldset by that name could not be found.
57 * This value relates to Shieldset::d_dir.
59 std::string getShieldsetDir(std::string name) const;
61 //! Return a particular Shield object from a given shieldset.
63 * Scan the given shieldset for a Shield of the given type and colour.
65 * @param shieldset The id the shieldset. This value relates to the
66 * Shieldset::d_id member.
67 * @param type The size of the shield to search for. This value
68 * relates to the Shield::ShieldType enumeration.
69 * @param colour The player of the shield. This value relates to
70 * the Shield::ShieldColour enumeration.
72 * @return A pointer to a Shield in the given shieldset that matches
73 * the given parameters. If no shield could be found, NULL
76 ShieldStyle *getShield(guint32 shieldset, guint32 type, guint32 colour) const;
78 //! Return the Shieldset object that is in the given directory.
79 Shieldset *getShieldset(std::string dir) const;
81 Gdk::Color getColor(guint32 shieldset, guint32 owner) const;
83 //! Return the Shieldset object by the id.
85 * @param id A unique numeric identifier that identifies the
86 * shieldset among all shieldsets in the shieldsetlist.
88 Shieldset *getShieldset(guint32 id) const;
91 // Methods that operate on the class data and modify the class.
93 //! Add a shieldset to the list. Use this instead of push_back.
94 void add(Shieldset *shieldset);
96 //! Destroy all of the images associated with shieldsets in this list.
97 void uninstantiateImages();
99 //! Load all of the images associated with all of the shieldsets.
100 void instantiateImages();
102 //! Add the given shieldset to the list, and copy files into place.
104 * This method tries hard to add the shieldset to this list. The
105 * subdir name could be changed, or the id might also be changed so
106 * that it doesn't conflict with any other shieldsets in the list.
108 * @return Returns true if it was added successfully, and the
109 * new_subdir and new_id parameters updated to reflect the
110 * changed subdir and id.
112 bool addToPersonalCollection(Shieldset *shieldset, std::string &new_subdir, guint32 &new_id);
117 //! Return the singleton instance of this class.
118 static Shieldsetlist* getInstance();
120 //! Explicitly delete the singleton instance of this class.
121 static void deleteInstance();
123 //! Return a unique id for a shieldset.
124 static int getNextAvailableId(int after);
127 //! Default Constructor.
129 * Loads all shieldsets it can find in the shield/ directory, and
130 * makes a new Shieldsetlist object from what it finds.
137 //! Loads a specific shieldset.
138 Shieldset *loadShieldset(std::string name);
140 //! Loads a bunch of shieldsets and puts them in this list.
141 void loadShieldsets(std::list<std::string> shieldsets);
145 typedef std::map<std::string, std::string> DirMap;
146 typedef std::map<std::string, Shieldset*> ShieldsetMap;
147 typedef std::map<guint32, Shieldset*> ShieldsetIdMap;
149 //! A map that provides a subdirectory when supplying a Shieldset name.
152 //! A map that provides a Shieldset when supplying a subdirectory name.
153 ShieldsetMap d_shieldsets;
155 //! A map that provides a Shieldset when supplying a shieldset id.
156 ShieldsetIdMap d_shieldsetids;
158 //! A static pointer for the singleton instance.
159 static Shieldsetlist* s_instance;
162 #endif // SHIELDSETLIST_H