/* * 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: * Cyrill Burgener * */ /** @file ShroomHUD.cc @brief Implementation of the ShroomHUD */ #include "ShroomHUD.h" #if OGRE_VERSION >= 0x010900 # include # include #else # include # include #endif #include "util/StringUtils.h" #include "core/CoreIncludes.h" #include "OrxoKart.h" namespace orxonox { RegisterClass(ShroomHUD); ShroomHUD::ShroomHUD(Context* context) : OrxonoxOverlay(context) { RegisterObject(ShroomHUD); this->orxoKartGame_ = nullptr; this->panel_ = static_cast(Ogre::OverlayManager::getSingleton() .createOverlayElement("Panel", "ShroomHUD_Panel_" + getUniqueNumberString())); this->panel_->setMaterialName("Hover/Flag"); this->overlay_->add2D(this->panel_); this->shroomCount_ = 3; setShroomCount(3); } ShroomHUD::~ShroomHUD() { if (this->isInitialized()) { Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->panel_); } } /** @brief Sets the amount of shrooms displayed, once zero it does not reappear @param shroomCount */ void ShroomHUD::setShroomCount(int shroomCount) { if(shroomCount == 0){ this->panel_->hide(); return; } this->panel_->setDimensions( this->panel_->_getRelativeWidth() / ((float) shroomCount_) * ((float) shroomCount), this->panel_->_getRelativeHeight() ); this->panel_->setTiling(shroomCount*1.0f, 1.0f); this->shroomCount_ = shroomCount; } void ShroomHUD::tick(float dt) { SUPER(ShroomHUD, tick, dt); setShroomCount(this->orxoKartGame_->getNumberOfShrooms()); } void ShroomHUD::changedOwner() { SUPER(ShroomHUD, changedOwner); if (this->getOwner() && this->getOwner()->getGametype()) { this->orxoKartGame_ = orxonox_cast(this->getOwner()->getGametype()); } else { this->orxoKartGame_ = nullptr; } } }