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