| 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 |  | 
|---|
| 29 | #include <vector> | 
|---|
| 30 | #include <string> | 
|---|
| 31 |  | 
|---|
| 32 | #include "core/CoreIncludes.h" | 
|---|
| 33 | #include "core/XMLPort.h" | 
|---|
| 34 | #include "util/Convert.h" | 
|---|
| 35 | #include "core/class/Super.h" | 
|---|
| 36 | #include "HUDPickupSystem.h" | 
|---|
| 37 | #include "pickup/Pickup.h" | 
|---|
| 38 | #include "HUDPickupItem.h" | 
|---|
| 39 | #include "pickup/PickupManager.h" | 
|---|
| 40 |  | 
|---|
| 41 | namespace orxonox | 
|---|
| 42 | { | 
|---|
| 43 |     RegisterClass(HUDPickupSystem); | 
|---|
| 44 |  | 
|---|
| 45 |     HUDPickupSystem::HUDPickupSystem(Context* context) : OrxonoxOverlay(context) | 
|---|
| 46 |     { | 
|---|
| 47 |         RegisterObject(HUDPickupSystem); | 
|---|
| 48 |  | 
|---|
| 49 |         overlayElement_ = static_cast<Ogre::PanelOverlayElement* >(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDPickupSystem" + getUniqueNumberString())); | 
|---|
| 50 |         overlayElement_->setMaterialName("PickupBar"); | 
|---|
| 51 |         overlayElement_->setPosition(0.0f,0.0f); | 
|---|
| 52 |         overlayElement_->setDimensions(0.70f,0.15f); | 
|---|
| 53 |         this->background_->addChild(overlayElement_); | 
|---|
| 54 |     } | 
|---|
| 55 |  | 
|---|
| 56 |     HUDPickupSystem::~HUDPickupSystem() | 
|---|
| 57 |     { | 
|---|
| 58 |         if (this->isInitialized()) | 
|---|
| 59 |         { | 
|---|
| 60 |             this->picks.clear(); | 
|---|
| 61 |         } | 
|---|
| 62 |     } | 
|---|
| 63 |  | 
|---|
| 64 |     void HUDPickupSystem::sizeChanged() | 
|---|
| 65 |     { | 
|---|
| 66 |         OrxonoxOverlay::sizeChanged(); | 
|---|
| 67 |  | 
|---|
| 68 |     } | 
|---|
| 69 |      | 
|---|
| 70 |  | 
|---|
| 71 |     void HUDPickupSystem::updatePickupList(std::vector<Pickupable*> picks, std::map<Pickupable*, uint32_t> indexes_) | 
|---|
| 72 |     { | 
|---|
| 73 |         int i =0; | 
|---|
| 74 |         const float offsetX = 0.345f; | 
|---|
| 75 |         float offsetY = 0.82f; | 
|---|
| 76 |         const float x = 0.102f; | 
|---|
| 77 |  | 
|---|
| 78 |         if(picks.size()>0) | 
|---|
| 79 |         { | 
|---|
| 80 |             for(Pickupable* p : picks) | 
|---|
| 81 |             { | 
|---|
| 82 |                 i = indexes_.find(p)->second; | 
|---|
| 83 |                 offsetY = 0.82f; | 
|---|
| 84 |  | 
|---|
| 85 |                 if(i>=5) | 
|---|
| 86 |                 { | 
|---|
| 87 |                     offsetY+=0.075f; | 
|---|
| 88 |                     i-=5; | 
|---|
| 89 |                 }    | 
|---|
| 90 |                 if(this->picks.count(p)==0) | 
|---|
| 91 |                 { | 
|---|
| 92 |                     HUDPickupItem* item = new HUDPickupItem(this->getContext()); | 
|---|
| 93 |                     item->initializeMaterial(this->getIcon(((Pickup*)p)->getRepresentationName()), offsetX+i*x, offsetY); | 
|---|
| 94 |                  | 
|---|
| 95 |                     item->setOverlayGroup(this->getOverlayGroup()); | 
|---|
| 96 |                     this->picks[p] = item; | 
|---|
| 97 |                 } | 
|---|
| 98 |             } | 
|---|
| 99 |         } | 
|---|
| 100 |     } | 
|---|
| 101 |  | 
|---|
| 102 |     void HUDPickupSystem::createPickupList() | 
|---|
| 103 |     { | 
|---|
| 104 |     }       | 
|---|
| 105 |  | 
|---|
| 106 |     void HUDPickupSystem::removePickup(Pickupable* pickup) | 
|---|
| 107 |     { | 
|---|
| 108 |         assert(pickup); | 
|---|
| 109 |         HUDPickupItem* item = this->picks.find(pickup)->second; | 
|---|
| 110 |         orxout(internal_info, context::pickups) << "removePickup: pickup= " << pickup << " item= " << item << endl; | 
|---|
| 111 |         assert(item); | 
|---|
| 112 |         item->hideMe(pickup, repaint); | 
|---|
| 113 |         assert(overlayElement_); | 
|---|
| 114 |         assert(this->background_); | 
|---|
| 115 |         this->picks.erase(pickup); | 
|---|
| 116 |     } | 
|---|
| 117 |  | 
|---|
| 118 |     void HUDPickupSystem::destroyAll() | 
|---|
| 119 |     { | 
|---|
| 120 |         this->background_->removeChild(overlayElement_->getName()); | 
|---|
| 121 |     } | 
|---|
| 122 |  | 
|---|
| 123 |     std::string HUDPickupSystem::getIcon(std::string repName) | 
|---|
| 124 |     { | 
|---|
| 125 |         if(repName.find("invisible", 0)!=std::string::npos) return "Eye"; | 
|---|
| 126 |         else if(repName.find("tri", 0)!=std::string::npos) return "Asterisk"; | 
|---|
| 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 |     } | 
|---|
| 136 | } | 
|---|