Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tgidronFS16/src/modules/hover/FlagHUD.cc @ 11151

Last change on this file since 11151 was 11151, checked in by tgidron, 8 years ago

New Level Up

  • Property svn:eol-style set to native
File size: 2.9 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/**
28    @file FlagHUD.cc
29    @brief Implementation of the FlagHUD
30*/
31
32#include "FlagHUD.h"
33
34#include <OgreOverlayManager.h>
35#include <OgreMaterialManager.h>
36#include <OgrePanelOverlayElement.h>
37
38#include "util/StringUtils.h"
39#include "core/CoreIncludes.h"
40#include "Hover.h"
41
42namespace orxonox
43{
44    RegisterClass(FlagHUD);
45
46    FlagHUD::FlagHUD(Context* context) : OrxonoxOverlay(context)
47    {
48        RegisterObject(FlagHUD);
49
50        this->hoverGame_ = nullptr;
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_ = 1;
57        setFlagCount(1);
58    }
59
60    FlagHUD::~FlagHUD()
61    {
62        if (this->isInitialized())
63        {
64            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->panel_);
65        }
66    }
67
68/**
69    @brief Sets the amount of flags displayed, once zero it does not reappear
70    @param flagCount
71*/
72    void FlagHUD::setFlagCount(int flagCount) {
73        if(flagCount == 0){
74            this->panel_->hide();
75            return;
76        }
77        this->panel_->setDimensions(
78            this->panel_->_getRelativeWidth() / ((float) flagCount_) * ((float) flagCount),
79            this->panel_->_getRelativeHeight()
80            );
81        this->panel_->setTiling(flagCount*1.0f, 1.0f);
82
83        this->flagCount_ = flagCount;
84    }
85
86    void FlagHUD::tick(float dt)
87    {
88        SUPER(FlagHUD, tick, dt);
89
90        setFlagCount(this->hoverGame_->getNumberOfFlags());
91    }
92
93    void FlagHUD::changedOwner()
94    {
95        SUPER(FlagHUD, changedOwner);
96
97        if (this->getOwner() && this->getOwner()->getGametype())
98        {
99            this->hoverGame_ = orxonox_cast<Hover*>(this->getOwner()->getGametype());
100        }
101        else
102        {
103            this->hoverGame_ = nullptr;
104        }
105    }
106}
Note: See TracBrowser for help on using the repository browser.