| [11263] | 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 | *      Patrick Wintermeyer | 
|---|
|  | 24 | *   Co-authors: | 
|---|
|  | 25 | *      ... | 
|---|
|  | 26 | * | 
|---|
|  | 27 | */ | 
|---|
|  | 28 |  | 
|---|
| [11277] | 29 | #include <vector> | 
|---|
|  | 30 | #include <string> | 
|---|
|  | 31 |  | 
|---|
| [11702] | 32 | #include <OgreOverlayManager.h> | 
|---|
| [11705] | 33 | #include <OgreOverlayElement.h> | 
|---|
| [11702] | 34 | #include <OgrePanelOverlayElement.h> | 
|---|
|  | 35 |  | 
|---|
| [11708] | 36 | #include "HUDPickupSystem.h" | 
|---|
|  | 37 |  | 
|---|
| [11263] | 38 | #include "core/CoreIncludes.h" | 
|---|
|  | 39 | #include "core/class/Super.h" | 
|---|
| [11705] | 40 | #include "util/Convert.h" | 
|---|
| [11305] | 41 | #include "pickup/PickupManager.h" | 
|---|
| [11708] | 42 | #include "worldentities/pawns/Pawn.h" | 
|---|
| [11263] | 43 |  | 
|---|
|  | 44 | namespace orxonox | 
|---|
|  | 45 | { | 
|---|
|  | 46 | RegisterClass(HUDPickupSystem); | 
|---|
|  | 47 |  | 
|---|
|  | 48 | HUDPickupSystem::HUDPickupSystem(Context* context) : OrxonoxOverlay(context) | 
|---|
|  | 49 | { | 
|---|
|  | 50 | RegisterObject(HUDPickupSystem); | 
|---|
|  | 51 |  | 
|---|
| [11705] | 52 | const float offsetX = 0.02f; | 
|---|
|  | 53 | const float offsetY = 0.05f; | 
|---|
|  | 54 | const float x = 0.2; | 
|---|
|  | 55 | const float y = 0.5f; | 
|---|
|  | 56 |  | 
|---|
|  | 57 | for (int index = 0; index < 10; ++index) | 
|---|
|  | 58 | { | 
|---|
|  | 59 | int row = index / 5; | 
|---|
|  | 60 | int column = index % 5; | 
|---|
|  | 61 |  | 
|---|
|  | 62 | std::string name = "HUDPickupItem" + multi_cast<std::string>(index); | 
|---|
|  | 63 | Ogre::OverlayElement* item = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", name); | 
|---|
|  | 64 |  | 
|---|
|  | 65 | item->setDimensions(0.16, 0.4); | 
|---|
|  | 66 | item->setPosition(offsetX + column*x, offsetY + row*y); | 
|---|
|  | 67 | this->items_.push_back(item); | 
|---|
|  | 68 | } | 
|---|
| [11263] | 69 | } | 
|---|
|  | 70 |  | 
|---|
|  | 71 | HUDPickupSystem::~HUDPickupSystem() | 
|---|
|  | 72 | { | 
|---|
| [11705] | 73 | for (Ogre::OverlayElement* item : items_) | 
|---|
|  | 74 | Ogre::OverlayManager::getSingleton().destroyOverlayElement(item); | 
|---|
| [11263] | 75 | } | 
|---|
|  | 76 |  | 
|---|
| [11708] | 77 | void HUDPickupSystem::changedOwner() | 
|---|
|  | 78 | { | 
|---|
|  | 79 | SUPER(HUDPickupSystem, changedOwner); | 
|---|
|  | 80 |  | 
|---|
|  | 81 | this->owner_ = orxonox_cast<Pawn*>(this->getOwner()); | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
| [11704] | 84 | void HUDPickupSystem::tick(float dt) | 
|---|
| [11700] | 85 | { | 
|---|
| [11704] | 86 | SUPER(HUDPickupSystem, tick, dt); | 
|---|
|  | 87 |  | 
|---|
| [11708] | 88 | std::vector<const PickupInventoryContainer*> containers = this->getPickupsForOwner(); | 
|---|
|  | 89 |  | 
|---|
| [11705] | 90 | for (size_t index = 0; index < this->items_.size(); ++index) | 
|---|
| [11277] | 91 | { | 
|---|
| [11705] | 92 | Ogre::OverlayElement* item = this->items_[index]; | 
|---|
| [11336] | 93 |  | 
|---|
| [11708] | 94 | if (index < containers.size()) | 
|---|
| [11705] | 95 | { | 
|---|
| [11708] | 96 | item->setMaterialName(this->getIcon(containers[index]->representationName)); | 
|---|
| [11705] | 97 | if (!item->getParent()) | 
|---|
|  | 98 | this->background_->addChild(item); | 
|---|
|  | 99 | } | 
|---|
|  | 100 | else | 
|---|
|  | 101 | { | 
|---|
|  | 102 | if (item->getParent()) | 
|---|
|  | 103 | this->background_->removeChild(item->getName()); | 
|---|
|  | 104 | } | 
|---|
| [11277] | 105 | } | 
|---|
| [11263] | 106 | } | 
|---|
|  | 107 |  | 
|---|
| [11708] | 108 | std::vector<const PickupInventoryContainer*> HUDPickupSystem::getPickupsForOwner() const | 
|---|
| [11325] | 109 | { | 
|---|
| [11708] | 110 | std::vector<const PickupInventoryContainer*> containers; | 
|---|
|  | 111 |  | 
|---|
|  | 112 | int numPickups = PickupManager::getInstance().getNumPickups(); | 
|---|
|  | 113 | for (int i = 0; i < numPickups; ++i) | 
|---|
|  | 114 | { | 
|---|
|  | 115 | const PickupInventoryContainer* container = PickupManager::getInstance().popPickup(); | 
|---|
|  | 116 | if (this->owner_ && this->owner_->getObjectID() == container->carrierPawnId) | 
|---|
|  | 117 | containers.push_back(container); | 
|---|
|  | 118 | } | 
|---|
|  | 119 |  | 
|---|
|  | 120 | return containers; | 
|---|
|  | 121 | } | 
|---|
|  | 122 |  | 
|---|
|  | 123 | std::string HUDPickupSystem::getIcon(const std::string& repName) const | 
|---|
|  | 124 | { | 
|---|
| [11325] | 125 | if(repName.find("invisible", 0)!=std::string::npos) return "Eye"; | 
|---|
| [11336] | 126 | else if(repName.find("tri", 0)!=std::string::npos) return "Asterisk"; | 
|---|
| [11325] | 127 | else if(repName.find("health", 0)!=std::string::npos || repName.find("Health", 0)!=std::string::npos) return "Cross"; | 
|---|
|  | 128 | else if(repName.find("shield", 0)!=std::string::npos) return "Shield"; | 
|---|
|  | 129 | else if(repName.find("munition", 0)!=std::string::npos) return "Munition"; | 
|---|
|  | 130 | else if(repName.find("shrink", 0)!=std::string::npos) return "Shrink"; | 
|---|
|  | 131 | else if(repName.find("boost", 0)!=std::string::npos) return "Flash"; | 
|---|
|  | 132 | else if(repName.find("speed", 0)!=std::string::npos) return "3arrowsup"; | 
|---|
|  | 133 | else if(repName.find("drone", 0)!=std::string::npos) return "Damage"; | 
|---|
|  | 134 | else return "Unknown"; | 
|---|
|  | 135 | } | 
|---|
| [11263] | 136 | } | 
|---|