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