/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Patrick Wintermeyer * Co-authors: * ... * */ #include #include #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "util/Convert.h" #include "core/class/Super.h" #include "HUDPickupSystem.h" #include "pickup/Pickup.h" #include "HUDPickupItem.h" #include "pickup/PickupManager.h" namespace orxonox { RegisterClass(HUDPickupSystem); HUDPickupSystem::HUDPickupSystem(Context* context) : OrxonoxOverlay(context) { RegisterObject(HUDPickupSystem); overlayElement_ = static_cast(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDPickupSystem" + getUniqueNumberString())); overlayElement_->setMaterialName("PickupBar"); overlayElement_->setPosition(0.0f,0.0f); overlayElement_->setDimensions(0.70f,0.15f); this->background_->addChild(overlayElement_); } HUDPickupSystem::~HUDPickupSystem() { if (this->isInitialized()) { this->picks.clear(); } } void HUDPickupSystem::sizeChanged() { OrxonoxOverlay::sizeChanged(); } void HUDPickupSystem::updatePickupList(std::vector picks, std::map indexes_) { int i =0; const float offsetX = 0.345f; float offsetY = 0.82f; const float x = 0.102f; if(picks.size()>0) { for(Pickupable* p : picks) { i = indexes_.find(p)->second; offsetY = 0.82f; if(i>=5) { offsetY+=0.075f; i-=5; } if(this->picks.count(p)==0) { HUDPickupItem* item = new HUDPickupItem(this->getContext()); item->initializeMaterial(this->getIcon(((Pickup*)p)->getRepresentationName()), offsetX+i*x, offsetY); item->setOverlayGroup(this->getOverlayGroup()); this->picks[p] = item; } } } } void HUDPickupSystem::createPickupList() { } void HUDPickupSystem::removePickup(Pickupable* pickup) { assert(pickup); HUDPickupItem* item = this->picks.find(pickup)->second; orxout(internal_info, context::pickups) << "removePickup: pickup= " << pickup << " item= " << item << endl; assert(item); item->hideMe(pickup, repaint); assert(overlayElement_); assert(this->background_); this->picks.erase(pickup); } void HUDPickupSystem::destroyAll() { this->background_->removeChild(overlayElement_->getName()); } std::string HUDPickupSystem::getIcon(std::string repName) { if(repName.find("invisible", 0)!=std::string::npos) return "Eye"; else if(repName.find("tri", 0)!=std::string::npos) return "Asterisk"; else if(repName.find("health", 0)!=std::string::npos || repName.find("Health", 0)!=std::string::npos) return "Cross"; else if(repName.find("shield", 0)!=std::string::npos) return "Shield"; else if(repName.find("munition", 0)!=std::string::npos) return "Munition"; else if(repName.find("shrink", 0)!=std::string::npos) return "Shrink"; else if(repName.find("boost", 0)!=std::string::npos) return "Flash"; else if(repName.find("speed", 0)!=std::string::npos) return "3arrowsup"; else if(repName.find("drone", 0)!=std::string::npos) return "Damage"; else return "Unknown"; } }