Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/src/modules/pickup/PickupRepresentation.h @ 10422

Last change on this file since 10422 was 7547, checked in by dafrick, 14 years ago

Documenting and cleanup.

  • Property svn:eol-style set to native
File size: 10.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27*/
28
29/**
30    @file PickupRepresentation.h
31    @brief Definition of the PickupRepresentation class.
32    @ingroup Pickup
33*/
34
35#ifndef _PickupRepresentation_H__
36#define _PickupRepresentation_H__
37
38#include "PickupPrereqs.h"
39
40#include "core/XMLPort.h"
41
42#include "interfaces/Pickupable.h"
43#include "pickup/PickupIdentifier.h"
44#include "worldentities/StaticEntity.h"
45
46#include "PickupSpawner.h"
47
48#include "core/BaseObject.h"
49#include "network/synchronisable/Synchronisable.h"
50
51namespace orxonox // tolua_export
52{ // tolua_export
53
54    /**
55    @brief
56        The PickupRepresentation class represents a specific pickup type (identified by its @ref orxonox::PickupIdentifier "PickupIdentifier"). It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like.
57        They are created through XML and are registered with the @ref orxonox::PickupManager "PickupManager".
58
59        Creating a PickupRepresentation in XML could look as follows:
60        @code
61        <PickupRepresentation
62            name = "My awesome Pickup"
63            description = "This is the most awesome Pickup ever to exist."
64            spawnerTemplate = "awesomePickupRepresentation"
65            inventoryRepresentation = "AwesomePickup"
66        >
67            <pickup>
68                <SomePickup />
69            </pickup>
70        </PickupRepresentation>
71        @endcode
72        As you might have noticed, there is a parameter called <em>spawnerTemplate</em> and also another parameter called <em>inventoryRepresentation</em>. Let's first explain the second one, <em>inventoryRepresentation</em>.
73        - The <b>inventoryRepresentation</b> specifies the image that is displayed in the PickupInventory for the specific type of @ref orxonox::Pickupable "Pickupable". More technically, it is the name of an image located in the <code>PickupInventory.imageset</code>, which in turn is located in <code>data_extern/gui/imagesets/</code>.
74        - The <b>spawnerTemplate</b> specifies how the type of @ref orxonox::Pickupable "Pickupable" (or more precisely the @ref orxonox::PickupSpawner "PickupSpawner", that spawns that type of @ref orxonox::Pickupable "Pickupable") is displayed ingame. It is a @ref orxonox::Template "Template" defined in XML. The <em>spawnerTemplate</em> can be specified as follows (keep in mind, that the template needs to have been specified before the definition of the PickupRepresentation that uses it).
75        @code
76        <Template name="awesomePickupRepresentation">
77            <PickupRepresentation>
78                <spawner-representation>
79                    <StaticEntity>
80                        <attached>
81                            <!-- Here you can put all the objects which define the look of the spawner. -->
82                        </attached>
83                    </StaticEntity>
84                </spawner-representation>
85            </PickupRepresentation>
86        </Template>
87        @endcode
88
89        For the purpose of them working over the network, they are synchronised.
90
91    @author
92        Damian 'Mozork' Frick
93
94    @ingroup Pickup
95    */
96    class _PickupExport PickupRepresentation // tolua_export
97        : public BaseObject, public Synchronisable
98    { // tolua_export
99
100        public:
101            PickupRepresentation(); //!< Constructor
102            PickupRepresentation(BaseObject* creator); //!< Default constructor.
103            virtual ~PickupRepresentation(); //!< Destructor.
104
105            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PickupRepresentation object through XML.
106
107            /**
108            @brief Get the name of the Pickupable represented by this PickupRepresentation.
109            @return Returns the name.
110            */
111            inline const std::string& getPickupName(void) const { return this->name_; } // tolua_export
112            /**
113            @brief Get the description of the Pickupable represented by this PickupRepresentation.
114            @return Returns the description.
115            */
116            inline const std::string& getPickupDescription(void) const { return this->description_; } // tolua_export
117            /**
118            @brief Get the name of spawnerTemplate the Pickupable represented by this PickupRepresentation.
119            @return Returns the name of the spawnerTemplate.
120            */
121            inline const std::string& getSpawnerTemplate(void) const
122                { return this->spawnerTemplate_; }
123            /**
124            @brief Get the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like.
125            @param index The index.
126            @return Returns (for index = 0) a pointer to the StaticEntity. For index > 0 it returns NULL.
127            */
128            inline const StaticEntity* getSpawnerRepresentationIndex(unsigned int index) const
129                { if(index == 0) return this->spawnerRepresentation_; return NULL; }
130            /**
131            @brief Get the name of the image representing the pickup in the PickupInventory.
132            @return Returns the name of the image as a string.
133            */
134            inline const std::string& getInventoryRepresentation(void) const { return this->inventoryRepresentation_; } // tolua_export
135            /**
136            @brief Get the Pickupable represented by this PickupRepresentation.
137            @param index The index.
138            @return Returns (for index = 0) a pointer to the Pickupable. For index > 0 it returns NULL.
139            */
140            inline const Pickupable* getPickup(unsigned int index) const
141                { if(index == 0) return this->pickup_; return NULL; }
142
143            StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner); //!< Get a spawnerRepresentation for a specific PickupSpawner.
144
145        protected:
146            /**
147            @brief Set the name of the Pickupable represented by this PickupRepresentation.
148            @param name The name.
149            */
150            inline void setPickupName(const std::string& name)
151                { this->name_ = name; }
152            /**
153            @brief Set the description of the Pickupable represented by this PickupRepresentation.
154            @param description The Description.
155            */
156            inline void setPickupDescription(const std::string& description)
157                { this->description_ = description; }
158            /**
159            @brief Set the spawnerTemplate of the Pickupable represented by this PickupRepresentation.
160                   The spawnerTemplate is a name of a template defined in XML that defines the StaticEntity that is the spawnerRepresentation of this PickupRepresentation.
161            @param spawnerTemplate The name of the template.
162            */
163            inline void setSpawnerTemplate(const std::string& spawnerTemplate)
164                { this->spawnerTemplate_ = spawnerTemplate; }
165            /**
166            @brief Set the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like.
167                   This will be set by the spawnerTemplate. Setting it when creating the PickupRepresentation without creating a template and specifying its name will be futile, because through the course of the game many PickupSpawners for one specific pickup type may have to be created, thus the StaticEntity that is the spawnerRepresentation has to be generated (with the template) for every new PickupSpawner spawning the Pickupable represented by this PickupRepresentation. The spawnerRepresentation that is set here, however can only be used once.
168            @param representation A pointer to the StaticEntity that is the spawnerRepresentation of this PickupRepresentation.
169            */
170            inline void setSpawnerRepresentation(StaticEntity* representation)
171                { this->spawnerRepresentation_ = representation; }
172            /**
173            @brief Set the image representing the pickup in the PickupInventory.
174            @param image A string with the name of the image representing the pickup.
175            */
176            inline void setInventoryRepresentation(const std::string& image)
177                { this->inventoryRepresentation_ = image; }
178            /**
179            @brief Set the Pickupable that is represented by this PickupRepresentation.
180            @param pickup A pointer to the Pickupable.
181            */
182            inline void setPickup(Pickupable* pickup)
183                { this->pickup_ = pickup; }
184
185        private:
186            void initialize(void); //!< Initializes the member variables of this PickupRepresentation.
187            StaticEntity* getDefaultSpawnerRepresentation(PickupSpawner* spawner); //!< Get the default spawnerRepresentation for a specific PickupSpawner.
188
189            void registerVariables(void); //!< Registers the variables that need to be synchronised.
190
191            std::string name_; //!< The name of the Pickupable represented by this PickupRepresentation.
192            std::string description_; //!< The description of the Pickupable represented by this PickupRepresentation.
193            std::string spawnerTemplate_; //!<  The name of the template of this PickupRepresentation.
194            StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation.
195            std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory.
196
197            Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.
198
199    }; // tolua_export
200
201} // tolua_export
202
203#endif // _PickupRepresentation_H__
Note: See TracBrowser for help on using the repository browser.