Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/pickup/PickupRepresentation.cc @ 7163

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

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 6.2 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.cc
31    @brief Implementation of the PickupRepresentation class.
32*/
33
34#include "PickupRepresentation.h"
35
36#include "core/CoreIncludes.h"
37#include "graphics/Billboard.h"
38#include "util/StringUtils.h"
39#include "PickupManager.h"
40
41namespace orxonox
42{
43
44    CreateFactory(PickupRepresentation);
45
46    /**
47    @brief
48        Constructor. Registers the object and initializes its member variables.
49        This is primarily for use of the PickupManager in creating a default PickupRepresentation.
50    */
51    PickupRepresentation::PickupRepresentation() : BaseObject(NULL), spawnerRepresentation_(NULL), pickup_(NULL)
52    {
53        RegisterObject(PickupRepresentation);
54
55        this->initialize();
56    }
57
58    /**
59    @brief
60        Default Constructor. Registers the object and initializes its member variables.
61    */
62    PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), spawnerRepresentation_(NULL), pickup_(NULL)
63    {
64        RegisterObject(PickupRepresentation);
65
66        this->initialize();
67    }
68
69    /**
70    @brief
71        Destructor.
72    */
73    PickupRepresentation::~PickupRepresentation()
74    {
75        if(this->spawnerRepresentation_ != NULL)
76            this->spawnerRepresentation_->destroy();
77
78        if(this->pickup_ != NULL)
79            PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this);
80    }
81
82    /**
83    @brief
84        Initializes the member variables of this PickupRepresentation.
85    */
86    void PickupRepresentation::initialize(void)
87    {
88        this->description_ = "This is a pickup.";
89        this->name_ = "Pickup";
90        this->spawnerTemplate_ = "";
91        this->inventoryRepresentation_ = "Default";
92    }
93
94    /**
95    @brief
96        Method for creating a PickupRepresentation object through XML.
97    */
98    void PickupRepresentation::XMLPort(Element& xmlelement, XMLPort::Mode mode)
99    {
100        SUPER(PickupRepresentation, XMLPort, xmlelement, mode);
101
102        XMLPortParam(PickupRepresentation, "pickupName", setPickupName, getPickupName, xmlelement, mode);
103        XMLPortParam(PickupRepresentation, "pickupDescription", setPickupDescription, getPickupDescription, xmlelement, mode);
104        XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode);
105        XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode);
106        XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);
107        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
108
109        PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this); //!< Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents.
110
111        if(this->spawnerRepresentation_ != NULL)
112            this->spawnerRepresentation_->setVisible(false);
113
114        COUT(4) << "PickupRepresentation created: name: '" << this->name_ << "', description: '" << this->description_ << "', spawnerTemplate: '" << this->spawnerTemplate_ << "'." << std::endl;
115    }
116
117    /**
118    @brief
119        Get a spawnerRepresentation for a specific PickupSpawner.
120    @param spawner
121        A pointer to the PickupSpawner.
122    @return
123        Returns a pointer to the StaticEntity.
124    */
125    StaticEntity* PickupRepresentation::getSpawnerRepresentation(PickupSpawner* spawner)
126    {
127        if(this->spawnerRepresentation_ == NULL)
128        {
129            COUT(4) << "PickupRepresentation: No spawner representation found." << std::endl;
130            if(this->spawnerTemplate_ == BLANKSTRING)
131            {
132                COUT(4) << "PickupRepresentation: Spawner template is empty." << std::endl;
133                //!< If neither spawnerRepresentation nor spawnerTemplate was specified
134                return this->getDefaultSpawnerRepresentation(spawner);
135            }
136            this->addTemplate(this->spawnerTemplate_);
137        }
138
139        StaticEntity* representation = this->spawnerRepresentation_;
140        representation->setVisible(true);
141
142        this->addTemplate(this->spawnerTemplate_);
143        this->spawnerRepresentation_->setVisible(false);
144
145        return representation;
146    }
147
148    /**
149    @brief
150        Get the default spawnerRepresentation for a specific PickupSpawner.
151        Helper method of internal use.
152    @param spawner
153        A pointer to the PickupSpawner.
154    @return
155        Returns a pointer to the StaticEntity.
156    */
157    //TODO: Possibility to define default representation through XML.
158    StaticEntity* PickupRepresentation::getDefaultSpawnerRepresentation(PickupSpawner* spawner)
159    {
160        StaticEntity* representation = new StaticEntity(spawner);
161        Billboard* sphere = new Billboard(spawner);
162        sphere->setColour(ColourValue(0.95f, 0.85f, 0.27f));
163        sphere->setMaterial("Sphere2");
164        sphere->setScale(0.1f);
165        Billboard* icon = new Billboard(spawner);
166        icon->setColour(ColourValue(0.89f, 0.79f, 0.08f));
167        icon->setMaterial("Asterix");
168        icon->setScale(0.5);
169        sphere->attach(icon);
170        representation->attach(sphere);
171        return representation;
172    }
173
174}
Note: See TracBrowser for help on using the repository browser.