Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentationHS14merge/src/modules/pickup/PickupRepresentation.h @ 10257

Last change on this file since 10257 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 9.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 "worldentities/StaticEntity.h"
44
45#include "PickupSpawner.h"
46
47#include "core/BaseObject.h"
48#include "network/synchronisable/Synchronisable.h"
49
50namespace orxonox // tolua_export
51{ // tolua_export
52
53    /**
54    @brief
55        The PickupRepresentation class represents a specific pickup type. It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like.
56        They are created through XML and are registered with the @ref orxonox::PickupManager "PickupManager".
57
58        Creating a PickupRepresentation in XML could look as follows:
59        @code
60        <PickupRepresentation
61            name = "My awesome Pickup"
62            description = "This is the most awesome Pickup ever to exist."
63            spawnerTemplate = "awesomePickupRepresentation"
64            inventoryRepresentation = "AwesomePickup"
65        />
66        @endcode
67        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>.
68        - 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>.
69        - 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).
70        @code
71        <Template name="awesomePickupRepresentation">
72            <PickupRepresentation>
73                <spawner-representation>
74                    <StaticEntity>
75                        <attached>
76                            <!-- Here you can put all the objects which define the look of the spawner. -->
77                        </attached>
78                    </StaticEntity>
79                </spawner-representation>
80            </PickupRepresentation>
81        </Template>
82        @endcode
83
84        For the purpose of them working over the network, they are synchronised.
85
86    @author
87        Damian 'Mozork' Frick
88
89    @ingroup Pickup
90    */
91    class _PickupExport PickupRepresentation // tolua_export
92        : public BaseObject, public Synchronisable
93    { // tolua_export
94
95        public:
96            PickupRepresentation(); //!< Constructor
97            PickupRepresentation(Context* context); //!< Default constructor.
98            virtual ~PickupRepresentation(); //!< Destructor.
99
100            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PickupRepresentation object through XML.
101
102            /**
103            @brief Get the name of the Pickupable represented by this PickupRepresentation.
104            @return Returns the name.
105            */
106            inline const std::string& getPickupName(void) const { return this->name_; } // tolua_export
107            /**
108            @brief Get the description of the Pickupable represented by this PickupRepresentation.
109            @return Returns the description.
110            */
111            inline const std::string& getPickupDescription(void) const { return this->description_; } // tolua_export
112            /**
113            @brief Get the name of spawnerTemplate the Pickupable represented by this PickupRepresentation.
114            @return Returns the name of the spawnerTemplate.
115            */
116            inline const std::string& getSpawnerTemplate(void) const
117                { return this->spawnerTemplate_; }
118            /**
119            @brief Get the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like.
120            @param index The index.
121            @return Returns (for index = 0) a pointer to the StaticEntity. For index > 0 it returns NULL.
122            */
123            inline const StaticEntity* getSpawnerRepresentationIndex(unsigned int index) const
124                { if(index == 0) return this->spawnerRepresentation_; return NULL; }
125            /**
126            @brief Get the name of the image representing the pickup in the PickupInventory.
127            @return Returns the name of the image as a string.
128            */
129            inline const std::string& getInventoryRepresentation(void) const { return this->inventoryRepresentation_; } // tolua_export
130
131            virtual void changedName();
132
133            StaticEntity* createSpawnerRepresentation(PickupSpawner* spawner); //!< Create a spawnerRepresentation for a specific PickupSpawner.
134
135        protected:
136            /**
137            @brief Set the name of the Pickupable represented by this PickupRepresentation.
138            @param name The name.
139            */
140            inline void setPickupName(const std::string& name)
141                { this->name_ = name; }
142            /**
143            @brief Set the description of the Pickupable represented by this PickupRepresentation.
144            @param description The Description.
145            */
146            inline void setPickupDescription(const std::string& description)
147                { this->description_ = description; }
148            /**
149            @brief Set the spawnerTemplate of the Pickupable represented by this PickupRepresentation.
150                   The spawnerTemplate is a name of a template defined in XML that defines the StaticEntity that is the spawnerRepresentation of this PickupRepresentation.
151            @param spawnerTemplate The name of the template.
152            */
153            inline void setSpawnerTemplate(const std::string& spawnerTemplate)
154                { this->spawnerTemplate_ = spawnerTemplate; }
155            /**
156            @brief Set the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like.
157                   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.
158            @param representation A pointer to the StaticEntity that is the spawnerRepresentation of this PickupRepresentation.
159            */
160            void setSpawnerRepresentation(StaticEntity* representation);
161
162            /**
163            @brief Set the image representing the pickup in the PickupInventory.
164            @param image A string with the name of the image representing the pickup.
165            */
166            inline void setInventoryRepresentation(const std::string& image)
167                { this->inventoryRepresentation_ = image; }
168
169        private:
170            void initialize(void); //!< Initializes the member variables of this PickupRepresentation.
171            StaticEntity* getDefaultSpawnerRepresentation(PickupSpawner* spawner); //!< Get the default spawnerRepresentation for a specific PickupSpawner.
172
173            void registerVariables(void); //!< Registers the variables that need to be synchronised.
174
175            std::string name_; //!< The name of the Pickupable represented by this PickupRepresentation.
176            std::string description_; //!< The description of the Pickupable represented by this PickupRepresentation.
177            std::string spawnerTemplate_; //!<  The name of the template of this PickupRepresentation.
178            StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation.
179            std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory.
180
181    }; // tolua_export
182
183} // tolua_export
184
185#endif // _PickupRepresentation_H__
Note: See TracBrowser for help on using the repository browser.