[10895] | 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 | * Cyrill Burgener |
---|
| 24 | * |
---|
| 25 | */ |
---|
| 26 | |
---|
[10929] | 27 | /** |
---|
| 28 | @file FlagHUD.cc |
---|
| 29 | @brief Implementation of the FlagHUD |
---|
| 30 | */ |
---|
| 31 | |
---|
[10895] | 32 | #include "FlagHUD.h" |
---|
| 33 | |
---|
| 34 | #include <OgreOverlayManager.h> |
---|
| 35 | #include <OgreMaterialManager.h> |
---|
| 36 | #include <OgrePanelOverlayElement.h> |
---|
| 37 | |
---|
[11041] | 38 | #include "util/StringUtils.h" |
---|
[10895] | 39 | #include "core/CoreIncludes.h" |
---|
[11041] | 40 | #include "Hover.h" |
---|
[10895] | 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | RegisterClass(FlagHUD); |
---|
| 45 | |
---|
| 46 | FlagHUD::FlagHUD(Context* context) : OrxonoxOverlay(context) |
---|
| 47 | { |
---|
| 48 | RegisterObject(FlagHUD); |
---|
| 49 | |
---|
[11041] | 50 | this->hoverGame_ = NULL; |
---|
[10895] | 51 | this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() |
---|
| 52 | .createOverlayElement("Panel", "FlagHUD_Panel_" + getUniqueNumberString())); |
---|
| 53 | this->panel_->setMaterialName("Hover/Flag"); |
---|
| 54 | this->overlay_->add2D(this->panel_); |
---|
| 55 | |
---|
| 56 | this->flagCount_ = 5; |
---|
| 57 | setFlagCount(5); |
---|
| 58 | } |
---|
| 59 | |
---|
[11041] | 60 | FlagHUD::~FlagHUD() |
---|
| 61 | { |
---|
| 62 | if (this->isInitialized()) |
---|
| 63 | { |
---|
| 64 | Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->panel_); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
[10929] | 68 | /** |
---|
| 69 | @brief Sets the amount of flags displayed, once zero it does not reappear |
---|
| 70 | @param flagCount |
---|
| 71 | */ |
---|
[10895] | 72 | void FlagHUD::setFlagCount(int flagCount) { |
---|
[10900] | 73 | if(flagCount == 0){ |
---|
| 74 | this->panel_->hide(); |
---|
| 75 | return; |
---|
| 76 | } |
---|
[10895] | 77 | this->panel_->setDimensions( |
---|
| 78 | this->panel_->_getRelativeWidth() / ((float) flagCount_) * ((float) flagCount), |
---|
| 79 | this->panel_->_getRelativeHeight() |
---|
| 80 | ); |
---|
[11030] | 81 | this->panel_->setTiling(flagCount*1.0f, 1.0f); |
---|
[10895] | 82 | |
---|
| 83 | this->flagCount_ = flagCount; |
---|
| 84 | } |
---|
| 85 | |
---|
[10900] | 86 | void FlagHUD::tick(float dt) |
---|
[10895] | 87 | { |
---|
| 88 | SUPER(FlagHUD, tick, dt); |
---|
| 89 | |
---|
[11043] | 90 | setFlagCount(this->hoverGame_->getNumberOfFlags()); |
---|
[10900] | 91 | } |
---|
[10895] | 92 | |
---|
| 93 | void FlagHUD::changedOwner() |
---|
| 94 | { |
---|
| 95 | SUPER(FlagHUD, changedOwner); |
---|
| 96 | |
---|
| 97 | if (this->getOwner() && this->getOwner()->getGametype()) |
---|
| 98 | { |
---|
[11041] | 99 | this->hoverGame_ = orxonox_cast<Hover*>(this->getOwner()->getGametype()); |
---|
[10895] | 100 | } |
---|
| 101 | else |
---|
| 102 | { |
---|
[11041] | 103 | this->hoverGame_ = 0; |
---|
[10895] | 104 | } |
---|
| 105 | } |
---|
| 106 | } |
---|