Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentationHS15/src/modules/overlays/hud/HUDHealthBar.cc @ 11056

Last change on this file since 11056 was 10961, checked in by maxima, 10 years ago

Merged presentation and fabiens branch. Had to modify hoverHUD and invaderHUD, because the text of the healthbar wasn't correctly displayed and the weapon settings of the hovership.

  • Property svn:eol-style set to native
File size: 5.6 KB
RevLine 
[2369]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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "HUDHealthBar.h"
30
[3196]31#include "util/Convert.h"
[2369]32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
[5735]34#include "worldentities/pawns/Pawn.h"
[2369]35#include "overlays/OverlayGroup.h"
36
37namespace orxonox
38{
[9667]39    RegisterClass(HUDHealthBar);
[2369]40
[9667]41    HUDHealthBar::HUDHealthBar(Context* context) : HUDBar(context)
[2369]42    {
43        RegisterObject(HUDHealthBar);
44
45        this->owner_ = 0;
46        this->bUseBarColour_ = false;
[10961]47        this->textOffset_ = Vector2(0.0f, 0.0f);
48        this->textScale_ = 1.0f;
[2369]49
[10961]50        this->setIconPosition(Vector2(0.05f,0.5f));
51        this->setIconDimensions(Vector2(0.1f,0.5f));
52
[9667]53        this->textoverlay_ = new OverlayText(this->getContext());
[2369]54
[6054]55        assert(this->textoverlay_.get());
[2369]56
57        this->textoverlay_->setCaption("");
[10961]58        this->textoverlay_->setAspectCorrection(false);
59
60        positionText();
[2369]61    }
62
63    HUDHealthBar::~HUDHealthBar()
64    {
65        if (this->isInitialized())
[6054]66        {
[5929]67            this->textoverlay_->destroy();
[10961]68            this->textoverlay_ = NULL;
[6054]69        }
[2369]70    }
71
72    void HUDHealthBar::XMLPort(Element& xmlelement, XMLPort::Mode mode)
73    {
74        SUPER(HUDHealthBar, XMLPort, xmlelement, mode);
75
76        XMLPortParam(HUDHealthBar, "showtext",          setTextVisible,          getTextVisible,          xmlelement, mode).defaultValues(true);
77        XMLPortParam(HUDHealthBar, "textfont",          setTextFont,             getTextFont,             xmlelement, mode).defaultValues("Monofur");
78        XMLPortParam(HUDHealthBar, "textusebarcolour",  setTextUseBarColour,     getTextUseBarColour,     xmlelement, mode).defaultValues(false);
79        XMLPortParam(HUDHealthBar, "textcolour",        setTextColour,           getTextColour,           xmlelement, mode).defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0));
80        XMLPortParam(HUDHealthBar, "textalign",         setTextAlignmentString,  getTextAlignmentString,  xmlelement, mode).defaultValues("left");
81        XMLPortParam(HUDHealthBar, "textoffset",        setTextOffset,           getTextOffset,           xmlelement, mode).defaultValues(Vector2::ZERO);
[10961]82        XMLPortParam(HUDHealthBar, "textscale",         setTextScale,            getTextScale,            xmlelement, mode).defaultValues(1.0f);
[2369]83        XMLPortParam(HUDHealthBar, "textpickpoint",     setTextPickPoint,        getTextPickPoint,        xmlelement, mode).defaultValues(Vector2::ZERO);
84        XMLPortParam(HUDHealthBar, "textrotation",      setTextRotation,         getTextRotation,         xmlelement, mode).defaultValues(0.0f);
85        XMLPortParam(HUDHealthBar, "textspacewidth",    setTextSpaceWidth,       getTextSpaceWidth,       xmlelement, mode).defaultValues(true);
86    }
87
88    void HUDHealthBar::tick(float dt)
89    {
90        SUPER(HUDHealthBar, tick, dt);
91
92        if (this->owner_)
93        {
94            this->setValue(this->owner_->getHealth() / this->owner_->getInitialHealth());
[3300]95            this->textoverlay_->setCaption(multi_cast<std::string>(static_cast<int>(this->owner_->getHealth())));
[2369]96        }
[5929]97        else
98        {
99            this->setValue(0);
100            this->textoverlay_->setCaption("0");
101        }
[2369]102
103        if (this->bUseBarColour_)
104            this->textoverlay_->setColour(this->getCurrentBarColour());
105    }
106
107    void HUDHealthBar::changedOwner()
108    {
109        SUPER(HUDHealthBar, changedOwner);
110
[3325]111        this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
[2369]112    }
113
114    void HUDHealthBar::changedOverlayGroup()
115    {
116        SUPER(HUDHealthBar, changedOverlayGroup);
117
[6054]118        this->getOverlayGroup()->addElement(this->textoverlay_.get());
[2369]119    }
120
121    void HUDHealthBar::changedVisibility()
122    {
123        SUPER(HUDHealthBar, changedVisibility);
124
125        this->textoverlay_->setVisible(this->isVisible());
126    }
127
128    void HUDHealthBar::changedName()
129    {
130        SUPER(HUDHealthBar, changedName);
131
132        this->textoverlay_->setName(this->getName() + "text");
133    }
134
135    void HUDHealthBar::setTextColour(const ColourValue& colour)
136    {
137        this->textColour_ = colour;
138        if (!this->bUseBarColour_)
139            this->textoverlay_->setColour(colour);
140    }
141
142    void HUDHealthBar::setTextUseBarColour(bool bUseBarColour)
143    {
144        this->bUseBarColour_ = bUseBarColour;
145        if (!bUseBarColour)
146            this->textoverlay_->setColour(this->textColour_);
147    }
[10961]148
149    void HUDHealthBar::positionText()
150    {
151        this->textoverlay_->setPosition(this->getPosition() + this->textOffset_*this->getActualSize());
152        this->textoverlay_->setTextSize(this->getActualSize().y*this->textScale_);
153    }
154
155    void HUDHealthBar::positionChanged()
156    {
157        HUDBar::positionChanged();
158        positionText();
159    }
160
161    void HUDHealthBar::sizeChanged()
162    {
163        HUDBar::sizeChanged();
164        positionText();
165    }   
[2369]166}
Note: See TracBrowser for help on using the repository browser.