Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9471 was 9348, checked in by landauf, 12 years ago

merged branch presentation2012merge back to trunk

  • Property svn:eol-style set to native
File size: 6.9 KB
RevLine 
[6474]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
[6540]29/**
30    @file PickupRepresentation.cc
31    @brief Implementation of the PickupRepresentation class.
32*/
33
[6474]34#include "PickupRepresentation.h"
35
36#include "core/CoreIncludes.h"
[7504]37#include "core/GameMode.h"
[7540]38#include "util/StringUtils.h"
39
[6475]40#include "graphics/Billboard.h"
[7540]41
[6474]42#include "PickupManager.h"
43
44namespace orxonox
45{
[7163]46
[6474]47    CreateFactory(PickupRepresentation);
[7163]48
[6475]49    /**
50    @brief
51        Constructor. Registers the object and initializes its member variables.
52        This is primarily for use of the PickupManager in creating a default PickupRepresentation.
53    */
[9348]54    PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL)
[6474]55    {
56        RegisterObject(PickupRepresentation);
[7163]57
[6474]58        this->initialize();
[8706]59        this->setSyncMode(ObjectDirection::None); // The default PickupRperesentation created by each PickupManager is not synchronised, since it only exists locally.
[6474]60    }
[7163]61
[6475]62    /**
63    @brief
64        Default Constructor. Registers the object and initializes its member variables.
65    */
[9348]66    PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL)
[6474]67    {
68        RegisterObject(PickupRepresentation);
[7163]69
[6474]70        this->initialize();
[7504]71        this->registerVariables();
[6474]72    }
[7163]73
[6475]74    /**
75    @brief
76        Destructor.
77    */
[6474]78    PickupRepresentation::~PickupRepresentation()
79    {
[6475]80        if(this->spawnerRepresentation_ != NULL)
81            this->spawnerRepresentation_->destroy();
[7163]82
[7504]83        if(this->isInitialized())
[9348]84            PickupManager::getInstance().unregisterRepresentation(this->getName());
[6474]85    }
[7163]86
[6475]87    /**
88    @brief
89        Initializes the member variables of this PickupRepresentation.
90    */
[6474]91    void PickupRepresentation::initialize(void)
92    {
93        this->description_ = "This is a pickup.";
94        this->name_ = "Pickup";
95        this->spawnerTemplate_ = "";
[6711]96        this->inventoryRepresentation_ = "Default";
[6474]97    }
[7163]98
[7540]99    /**
100    @brief
101        Registers the variables that need to be synchornised.
102    */
[7504]103    void PickupRepresentation::registerVariables(void)
104    {
105        registerVariable(this->description_, VariableDirection::ToClient);
106        registerVariable(this->name_, VariableDirection::ToClient);
107        registerVariable(this->inventoryRepresentation_, VariableDirection::ToClient);
108    }
109
[6475]110    /**
111    @brief
112        Method for creating a PickupRepresentation object through XML.
113    */
[6474]114    void PickupRepresentation::XMLPort(Element& xmlelement, XMLPort::Mode mode)
115    {
116        SUPER(PickupRepresentation, XMLPort, xmlelement, mode);
[7163]117
[6711]118        XMLPortParam(PickupRepresentation, "pickupName", setPickupName, getPickupName, xmlelement, mode);
119        XMLPortParam(PickupRepresentation, "pickupDescription", setPickupDescription, getPickupDescription, xmlelement, mode);
[6474]120        XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode);
[6711]121        XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode);
[6474]122        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
[7163]123
[8858]124        orxout(verbose, context::pickups) << "PickupRepresentation created: name: '" << this->name_ << "', description: '" << this->description_ << "', spawnerTemplate: '" << this->spawnerTemplate_ << "'." << endl;
[6474]125    }
[7163]126
[6475]127    /**
128    @brief
129        Get a spawnerRepresentation for a specific PickupSpawner.
130    @param spawner
131        A pointer to the PickupSpawner.
132    @return
133        Returns a pointer to the StaticEntity.
134    */
[9348]135    StaticEntity* PickupRepresentation::createSpawnerRepresentation(PickupSpawner* spawner)
[6474]136    {
137        if(this->spawnerRepresentation_ == NULL)
138        {
[8858]139            orxout(verbose, context::pickups) << "PickupRepresentation: No spawner representation found." << endl;
[8079]140            if(this->spawnerTemplate_ == "")
[6474]141            {
[9348]142                orxout(internal_warning, context::pickups) << "PickupRepresentation: Spawner template is empty." << endl;
[7540]143                // If neither spawnerRepresentation nor spawnerTemplate was specified
[6474]144                return this->getDefaultSpawnerRepresentation(spawner);
145            }
146            this->addTemplate(this->spawnerTemplate_);
147        }
[7163]148
[9348]149        this->spawnerRepresentation_->setVisible(true);
150        StaticEntity* temp = this->spawnerRepresentation_;
151        this->spawnerRepresentation_ = NULL;
[7163]152
[9348]153        return temp;
154    }
[7163]155
[9348]156    void PickupRepresentation::changedName()
157    {
158        // Registers the PickupRepresentation with the PickupManager.
159        PickupManager::getInstance().unregisterRepresentation(this->getOldName());
160        PickupManager::getInstance().registerRepresentation(this->getName(), this);
[6474]161    }
[7163]162
[9348]163    void PickupRepresentation::setSpawnerRepresentation(StaticEntity* representation)
164    {
165        this->spawnerRepresentation_ = representation;
166        if(this->spawnerRepresentation_ != NULL)
167            this->spawnerRepresentation_->setVisible(false);
168    }
169
[6475]170    /**
171    @brief
172        Get the default spawnerRepresentation for a specific PickupSpawner.
173        Helper method of internal use.
174    @param spawner
175        A pointer to the PickupSpawner.
176    @return
177        Returns a pointer to the StaticEntity.
178    */
[7540]179    //TODO: Possibility to define default representation through XML?
[6474]180    StaticEntity* PickupRepresentation::getDefaultSpawnerRepresentation(PickupSpawner* spawner)
181    {
182        StaticEntity* representation = new StaticEntity(spawner);
[6512]183        Billboard* sphere = new Billboard(spawner);
[6676]184        sphere->setColour(ColourValue(0.95f, 0.85f, 0.27f));
[6512]185        sphere->setMaterial("Sphere2");
[6676]186        sphere->setScale(0.1f);
[6512]187        Billboard* icon = new Billboard(spawner);
[6676]188        icon->setColour(ColourValue(0.89f, 0.79f, 0.08f));
[8713]189        icon->setMaterial("asterisk");
[6512]190        icon->setScale(0.5);
191        sphere->attach(icon);
192        representation->attach(sphere);
[6474]193        return representation;
194    }
[7163]195
[6474]196}
Note: See TracBrowser for help on using the repository browser.