Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/orxokart/ShroomHUD.cc @ 12325

Last change on this file since 12325 was 12148, checked in by ottka, 6 years ago

Mushroom GUI

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 ShroomHUD.cc
29    @brief Implementation of the ShroomHUD
30*/
31
32#include "ShroomHUD.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 "OrxoKart.h"
45
46namespace orxonox
47{
48    RegisterClass(ShroomHUD);
49
50    ShroomHUD::ShroomHUD(Context* context) : OrxonoxOverlay(context)
51    {
52        RegisterObject(ShroomHUD);
53
54        this->orxoKartGame_ = nullptr;
55        this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
56            .createOverlayElement("Panel", "ShroomHUD_Panel_" + getUniqueNumberString()));
57        this->panel_->setMaterialName("mushroom");
58        this->overlay_->add2D(this->panel_);
59        this->shroomCount_ = 3;
60        setShroomCount(3);
61    }
62
63    ShroomHUD::~ShroomHUD()
64    {
65        if (this->isInitialized())
66        {
67            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->panel_);
68        }
69    }
70
71/**
72    @brief Sets the amount of shrooms displayed, once zero it does not reappear
73    @param shroomCount
74*/
75    void ShroomHUD::setShroomCount(int shroomCount) {
76        if(shroomCount == 0){
77            this->panel_->hide();
78            return;
79        }
80        this->panel_->setDimensions(
81            this->panel_->_getRelativeWidth() / ((float) shroomCount_) * ((float) shroomCount),
82            this->panel_->_getRelativeHeight()
83            );
84        this->panel_->setTiling(shroomCount*1.0f, 1.0f);
85
86        this->shroomCount_ = shroomCount;
87    }
88
89    void ShroomHUD::tick(float dt)
90    {
91        SUPER(ShroomHUD, tick, dt);
92
93        setShroomCount(this->orxoKartGame_->getNumberOfShrooms());
94    }
95
96    void ShroomHUD::changedOwner()
97    {
98        SUPER(ShroomHUD, changedOwner);
99
100        if (this->getOwner() && this->getOwner()->getGametype())
101        {
102            this->orxoKartGame_ = orxonox_cast<OrxoKart*>(this->getOwner()->getGametype());
103        }
104        else
105        {
106            this->orxoKartGame_ = nullptr;
107        }
108    }
109}
Note: See TracBrowser for help on using the repository browser.