Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/src/modules/hover/FlagHUD.cc @ 12068

Last change on this file since 12068 was 11795, checked in by landauf, 7 years ago

merged ogre1.9 (including cegui0.8) into new branch

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