Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10926 was 10900, checked in by meierman, 9 years ago

Judihui it works

File size: 2.6 KB
Line 
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
27#include "FlagHUD.h"
28
29#include <OgreOverlayManager.h>
30#include <OgreMaterialManager.h>
31#include <OgrePanelOverlayElement.h>
32
33#include "core/CoreIncludes.h"
34#include "core/XMLPort.h"
35
36namespace orxonox
37{
38    RegisterClass(FlagHUD);
39
40    FlagHUD::FlagHUD(Context* context) : OrxonoxOverlay(context)
41    {
42        RegisterObject(FlagHUD);
43
44        this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
45            .createOverlayElement("Panel", "FlagHUD_Panel_" + getUniqueNumberString()));
46        this->panel_->setMaterialName("Hover/Flag");
47        this->overlay_->add2D(this->panel_);
48
49        this->flagCount_ = 5;
50        setFlagCount(5);
51    }
52
53    void FlagHUD::setFlagCount(int flagCount) {
54        if(flagCount == 0){
55            this->panel_->hide();
56            return;
57        }
58        this->panel_->setDimensions(
59            this->panel_->_getRelativeWidth() / ((float) flagCount_) * ((float) flagCount),
60            this->panel_->_getRelativeHeight()
61            );
62        this->panel_->setTiling(flagCount, 1.0f);
63
64        this->flagCount_ = flagCount;
65    }
66
67    void FlagHUD::tick(float dt)
68    {
69        SUPER(FlagHUD, tick, dt);
70
71            setFlagCount(this->hoverGame->getFlags());
72       
73    }
74
75    void FlagHUD::changedOwner()
76    {
77        SUPER(FlagHUD, changedOwner);
78
79        if (this->getOwner() && this->getOwner()->getGametype())
80        {
81            this->hoverGame = orxonox_cast<Hover*>(this->getOwner()->getGametype());
82        }
83        else
84        {
85            this->hoverGame = 0;
86        }
87    }
88
89    FlagHUD::~FlagHUD()
90    {
91        if (this->isInitialized())
92        {
93            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->panel_);
94        }
95    }
96}
Note: See TracBrowser for help on using the repository browser.