Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hoverHS15/src/modules/hover/FlagHUD.cc @ 10938

Last change on this file since 10938 was 10929, checked in by bucyril, 9 years ago

Added documentation

File size: 2.8 KB
RevLine 
[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
38#include "core/CoreIncludes.h"
39#include "core/XMLPort.h"
40
41namespace orxonox
42{
43    RegisterClass(FlagHUD);
44
45    FlagHUD::FlagHUD(Context* context) : OrxonoxOverlay(context)
46    {
47        RegisterObject(FlagHUD);
48
49        this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
50            .createOverlayElement("Panel", "FlagHUD_Panel_" + getUniqueNumberString()));
51        this->panel_->setMaterialName("Hover/Flag");
52        this->overlay_->add2D(this->panel_);
53
54        this->flagCount_ = 5;
55        setFlagCount(5);
56    }
57
[10929]58/**
59    @brief Sets the amount of flags displayed, once zero it does not reappear
60    @param flagCount
61*/
[10895]62    void FlagHUD::setFlagCount(int flagCount) {
[10900]63        if(flagCount == 0){
64            this->panel_->hide();
65            return;
66        }
[10895]67        this->panel_->setDimensions(
68            this->panel_->_getRelativeWidth() / ((float) flagCount_) * ((float) flagCount),
69            this->panel_->_getRelativeHeight()
70            );
71        this->panel_->setTiling(flagCount, 1.0f);
72
73        this->flagCount_ = flagCount;
74    }
75
[10900]76    void FlagHUD::tick(float dt)
[10895]77    {
78        SUPER(FlagHUD, tick, dt);
79
[10900]80            setFlagCount(this->hoverGame->getFlags());
81       
82    }
[10895]83
84    void FlagHUD::changedOwner()
85    {
86        SUPER(FlagHUD, changedOwner);
87
88        if (this->getOwner() && this->getOwner()->getGametype())
89        {
90            this->hoverGame = orxonox_cast<Hover*>(this->getOwner()->getGametype());
91        }
92        else
93        {
94            this->hoverGame = 0;
95        }
96    }
97
98    FlagHUD::~FlagHUD()
99    {
100        if (this->isInitialized())
101        {
102            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->panel_);
103        }
104    }
105}
Note: See TracBrowser for help on using the repository browser.