[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" |
---|
[6475] | 37 | #include "graphics/Billboard.h" |
---|
| 38 | #include "util/StringUtils.h" |
---|
[6474] | 39 | #include "PickupManager.h" |
---|
| 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[7127] | 43 | |
---|
[6474] | 44 | CreateFactory(PickupRepresentation); |
---|
[7127] | 45 | |
---|
[6475] | 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 | */ |
---|
[6725] | 51 | PickupRepresentation::PickupRepresentation() : BaseObject(NULL), spawnerRepresentation_(NULL), pickup_(NULL) |
---|
[6474] | 52 | { |
---|
| 53 | RegisterObject(PickupRepresentation); |
---|
[7127] | 54 | |
---|
[6474] | 55 | this->initialize(); |
---|
| 56 | } |
---|
[7127] | 57 | |
---|
[6475] | 58 | /** |
---|
| 59 | @brief |
---|
| 60 | Default Constructor. Registers the object and initializes its member variables. |
---|
| 61 | */ |
---|
[6725] | 62 | PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), spawnerRepresentation_(NULL), pickup_(NULL) |
---|
[6474] | 63 | { |
---|
| 64 | RegisterObject(PickupRepresentation); |
---|
[7127] | 65 | |
---|
[6474] | 66 | this->initialize(); |
---|
| 67 | } |
---|
[7127] | 68 | |
---|
[6475] | 69 | /** |
---|
| 70 | @brief |
---|
| 71 | Destructor. |
---|
| 72 | */ |
---|
[6474] | 73 | PickupRepresentation::~PickupRepresentation() |
---|
| 74 | { |
---|
[6475] | 75 | if(this->spawnerRepresentation_ != NULL) |
---|
| 76 | this->spawnerRepresentation_->destroy(); |
---|
[7127] | 77 | |
---|
[6725] | 78 | if(this->pickup_ != NULL) |
---|
| 79 | PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this); |
---|
[6474] | 80 | } |
---|
[7127] | 81 | |
---|
[6475] | 82 | /** |
---|
| 83 | @brief |
---|
| 84 | Initializes the member variables of this PickupRepresentation. |
---|
| 85 | */ |
---|
[6474] | 86 | void PickupRepresentation::initialize(void) |
---|
| 87 | { |
---|
| 88 | this->description_ = "This is a pickup."; |
---|
| 89 | this->name_ = "Pickup"; |
---|
| 90 | this->spawnerTemplate_ = ""; |
---|
[6711] | 91 | this->inventoryRepresentation_ = "Default"; |
---|
[6474] | 92 | } |
---|
[7127] | 93 | |
---|
[6475] | 94 | /** |
---|
| 95 | @brief |
---|
| 96 | Method for creating a PickupRepresentation object through XML. |
---|
| 97 | */ |
---|
[6474] | 98 | void PickupRepresentation::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 99 | { |
---|
| 100 | SUPER(PickupRepresentation, XMLPort, xmlelement, mode); |
---|
[7127] | 101 | |
---|
[6711] | 102 | XMLPortParam(PickupRepresentation, "pickupName", setPickupName, getPickupName, xmlelement, mode); |
---|
| 103 | XMLPortParam(PickupRepresentation, "pickupDescription", setPickupDescription, getPickupDescription, xmlelement, mode); |
---|
[6474] | 104 | XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode); |
---|
[6711] | 105 | XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode); |
---|
[6474] | 106 | XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode); |
---|
| 107 | XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode); |
---|
[7127] | 108 | |
---|
[6475] | 109 | PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this); //!< Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents. |
---|
[7127] | 110 | |
---|
[6484] | 111 | if(this->spawnerRepresentation_ != NULL) |
---|
| 112 | this->spawnerRepresentation_->setVisible(false); |
---|
[7127] | 113 | |
---|
[6484] | 114 | COUT(4) << "PickupRepresentation created: name: '" << this->name_ << "', description: '" << this->description_ << "', spawnerTemplate: '" << this->spawnerTemplate_ << "'." << std::endl; |
---|
[6474] | 115 | } |
---|
[7127] | 116 | |
---|
[6475] | 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 | */ |
---|
[6474] | 125 | StaticEntity* PickupRepresentation::getSpawnerRepresentation(PickupSpawner* spawner) |
---|
| 126 | { |
---|
| 127 | if(this->spawnerRepresentation_ == NULL) |
---|
| 128 | { |
---|
| 129 | COUT(4) << "PickupRepresentation: No spawner representation found." << std::endl; |
---|
[6475] | 130 | if(this->spawnerTemplate_ == BLANKSTRING) |
---|
[6474] | 131 | { |
---|
| 132 | COUT(4) << "PickupRepresentation: Spawner template is empty." << std::endl; |
---|
[6475] | 133 | //!< If neither spawnerRepresentation nor spawnerTemplate was specified |
---|
[6474] | 134 | return this->getDefaultSpawnerRepresentation(spawner); |
---|
| 135 | } |
---|
| 136 | this->addTemplate(this->spawnerTemplate_); |
---|
| 137 | } |
---|
[7127] | 138 | |
---|
[6474] | 139 | StaticEntity* representation = this->spawnerRepresentation_; |
---|
[6484] | 140 | representation->setVisible(true); |
---|
[7127] | 141 | |
---|
[6474] | 142 | this->addTemplate(this->spawnerTemplate_); |
---|
[6484] | 143 | this->spawnerRepresentation_->setVisible(false); |
---|
[7127] | 144 | |
---|
[6474] | 145 | return representation; |
---|
| 146 | } |
---|
[7127] | 147 | |
---|
[6475] | 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 | */ |
---|
[6540] | 157 | //TODO: Possibility to define default representation through XML. |
---|
[6474] | 158 | StaticEntity* PickupRepresentation::getDefaultSpawnerRepresentation(PickupSpawner* spawner) |
---|
| 159 | { |
---|
| 160 | StaticEntity* representation = new StaticEntity(spawner); |
---|
[6512] | 161 | Billboard* sphere = new Billboard(spawner); |
---|
[6676] | 162 | sphere->setColour(ColourValue(0.95f, 0.85f, 0.27f)); |
---|
[6512] | 163 | sphere->setMaterial("Sphere2"); |
---|
[6676] | 164 | sphere->setScale(0.1f); |
---|
[6512] | 165 | Billboard* icon = new Billboard(spawner); |
---|
[6676] | 166 | icon->setColour(ColourValue(0.89f, 0.79f, 0.08f)); |
---|
[6512] | 167 | icon->setMaterial("Asterix"); |
---|
| 168 | icon->setScale(0.5); |
---|
| 169 | sphere->attach(icon); |
---|
| 170 | representation->attach(sphere); |
---|
[6474] | 171 | return representation; |
---|
| 172 | } |
---|
[7127] | 173 | |
---|
[6474] | 174 | } |
---|