| 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 | #ifndef _HUDHealthBar_H__ |
|---|
| 30 | #define _HUDHealthBar_H__ |
|---|
| 31 | |
|---|
| 32 | #include "overlays/OverlaysPrereqs.h" |
|---|
| 33 | |
|---|
| 34 | #include "util/Math.h" |
|---|
| 35 | #include "tools/interfaces/Tickable.h" |
|---|
| 36 | #include "overlays/OverlayText.h" |
|---|
| 37 | #include "HUDBar.h" |
|---|
| 38 | |
|---|
| 39 | namespace orxonox |
|---|
| 40 | { |
|---|
| 41 | class _OverlaysExport HUDHealthBar : public HUDBar, public Tickable |
|---|
| 42 | { |
|---|
| 43 | public: |
|---|
| 44 | HUDHealthBar(Context* context); |
|---|
| 45 | virtual ~HUDHealthBar(); |
|---|
| 46 | |
|---|
| 47 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; |
|---|
| 48 | virtual void tick(float dt) override; |
|---|
| 49 | virtual void changedOwner() override; |
|---|
| 50 | virtual void changedOverlayGroup() override; |
|---|
| 51 | virtual void changedVisibility() override; |
|---|
| 52 | virtual void changedName() override; |
|---|
| 53 | |
|---|
| 54 | inline void setTextFont(const std::string& font) |
|---|
| 55 | { if (!font.empty()) { this->textoverlay_->setFont(font); } } |
|---|
| 56 | inline const std::string& getTextFont() const |
|---|
| 57 | { return this->textoverlay_->getFont(); } |
|---|
| 58 | |
|---|
| 59 | void setTextColour(const ColourValue& colour); |
|---|
| 60 | inline const ColourValue& getTextColour() const |
|---|
| 61 | { return this->textoverlay_->getColour(); } |
|---|
| 62 | |
|---|
| 63 | void setTextUseBarColour(bool bUseBarColour); |
|---|
| 64 | inline bool getTextUseBarColour() const |
|---|
| 65 | { return this->bUseBarColour_; } |
|---|
| 66 | |
|---|
| 67 | inline void setTextAlignment(OverlayText::Alignment alignment) |
|---|
| 68 | { this->textoverlay_->setAlignment(alignment); } |
|---|
| 69 | inline OverlayText::Alignment getTextAlignment() const |
|---|
| 70 | { return this->textoverlay_->getAlignment(); } |
|---|
| 71 | |
|---|
| 72 | void setTextAlignmentString(const std::string& alignment) |
|---|
| 73 | { this->textoverlay_->setAlignmentString(alignment); } |
|---|
| 74 | std::string getTextAlignmentString() const |
|---|
| 75 | { return this->textoverlay_->getAlignmentString(); } |
|---|
| 76 | |
|---|
| 77 | inline void setTextVisible(bool bVisible) |
|---|
| 78 | { this->textoverlay_->setVisible(bVisible); } |
|---|
| 79 | inline bool getTextVisible() const |
|---|
| 80 | { return this->textoverlay_->isVisible(); } |
|---|
| 81 | |
|---|
| 82 | inline void setTextScale(float scale) |
|---|
| 83 | { this->textScale_ = scale; |
|---|
| 84 | positionText(); |
|---|
| 85 | } |
|---|
| 86 | inline float getTextScale() const |
|---|
| 87 | { return this->textScale_; } |
|---|
| 88 | |
|---|
| 89 | inline void setTextPickPoint(const Vector2& pickpoint) |
|---|
| 90 | { this->textoverlay_->setPickPoint(pickpoint); } |
|---|
| 91 | inline Vector2 getTextPickPoint() const |
|---|
| 92 | { return this->textoverlay_->getPickPoint(); } |
|---|
| 93 | |
|---|
| 94 | inline void setTextOffset(const Vector2& position) |
|---|
| 95 | { this->textOffset_ = position; |
|---|
| 96 | this->positionText(); |
|---|
| 97 | } |
|---|
| 98 | inline Vector2 getTextOffset() const |
|---|
| 99 | { return this->textOffset_; } |
|---|
| 100 | |
|---|
| 101 | inline void setTextRotation(const Degree& angle) |
|---|
| 102 | { this->textoverlay_->setRotation(angle); } |
|---|
| 103 | inline const Degree& getTextRotation() const |
|---|
| 104 | { return this->textoverlay_->getRotation(); } |
|---|
| 105 | |
|---|
| 106 | inline void setTextSpaceWidth(float width) |
|---|
| 107 | { this->textoverlay_->setSpaceWidth(width); } |
|---|
| 108 | inline float getTextSpaceWidth() const |
|---|
| 109 | { return this->textoverlay_->getSpaceWidth(); } |
|---|
| 110 | |
|---|
| 111 | inline void setHealthBarOwner(Pawn* owner) |
|---|
| 112 | { this->owner_ = owner; } |
|---|
| 113 | protected: |
|---|
| 114 | virtual void positionChanged() override; |
|---|
| 115 | virtual void sizeChanged() override; |
|---|
| 116 | private: |
|---|
| 117 | void positionText(); |
|---|
| 118 | WeakPtr<Pawn> owner_; |
|---|
| 119 | StrongPtr<OverlayText> textoverlay_; |
|---|
| 120 | bool bUseBarColour_; |
|---|
| 121 | ColourValue textColour_; |
|---|
| 122 | Vector2 textOffset_; |
|---|
| 123 | float textScale_; |
|---|
| 124 | }; |
|---|
| 125 | } |
|---|
| 126 | #endif /* _HUDHealthBar_H__ */ |
|---|