| 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 |  *      Yuning Chai | 
|---|
| 24 |  *   Co-authors: | 
|---|
| 25 |  *      Felix Schulthess | 
|---|
| 26 |  *      Fabian 'x3n' Landau | 
|---|
| 27 |  *      Reto Grieder | 
|---|
| 28 |  *      Benjamin Knecht | 
|---|
| 29 |  * | 
|---|
| 30 |  */ | 
|---|
| 31 |  | 
|---|
| 32 | #ifndef _HUDBar_H__ | 
|---|
| 33 | #define _HUDBar_H__ | 
|---|
| 34 |  | 
|---|
| 35 | #include "overlays/OverlaysPrereqs.h" | 
|---|
| 36 |  | 
|---|
| 37 | #include <map> | 
|---|
| 38 | #include <vector> | 
|---|
| 39 | #include <OgrePanelOverlayElement.h> | 
|---|
| 40 |  | 
|---|
| 41 | #include "util/Math.h" | 
|---|
| 42 | #include "util/OgreForwardRefs.h" | 
|---|
| 43 | #include "core/BaseObject.h" | 
|---|
| 44 | #include "overlays/OrxonoxOverlay.h" | 
|---|
| 45 |  | 
|---|
| 46 | namespace orxonox | 
|---|
| 47 | { | 
|---|
| 48 |     class _OverlaysExport BarColour : public BaseObject | 
|---|
| 49 |     { | 
|---|
| 50 |     public: | 
|---|
| 51 |         BarColour(Context* context); | 
|---|
| 52 |         virtual ~BarColour() { } | 
|---|
| 53 |  | 
|---|
| 54 |         virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; | 
|---|
| 55 |  | 
|---|
| 56 |         void setColour(const ColourValue& colour) { this->colour_ = colour; } | 
|---|
| 57 |         const ColourValue& getColour() const { return this->colour_; } | 
|---|
| 58 |  | 
|---|
| 59 |         void setPosition(float pos) { this->position_ = pos; } | 
|---|
| 60 |         float getPosition() const    { return this->position_; } | 
|---|
| 61 |  | 
|---|
| 62 |     private: | 
|---|
| 63 |         ColourValue colour_; | 
|---|
| 64 |         float position_; | 
|---|
| 65 |     }; | 
|---|
| 66 |  | 
|---|
| 67 |  | 
|---|
| 68 |     class _OverlaysExport HUDBar : public OrxonoxOverlay | 
|---|
| 69 |     { | 
|---|
| 70 |     public: | 
|---|
| 71 |         HUDBar(Context* context); | 
|---|
| 72 |         virtual ~HUDBar(); | 
|---|
| 73 |  | 
|---|
| 74 |         virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; | 
|---|
| 75 |  | 
|---|
| 76 |         void clearColours(); | 
|---|
| 77 |  | 
|---|
| 78 |         inline void setRightToLeft(bool r2l) | 
|---|
| 79 |         { | 
|---|
| 80 |             if (r2l != this->right2Left_) | 
|---|
| 81 |             { | 
|---|
| 82 |                 this->right2Left_ = r2l; | 
|---|
| 83 |                 this->valueChanged(); | 
|---|
| 84 |             } | 
|---|
| 85 |         } | 
|---|
| 86 |         inline bool getRightToLeft() const | 
|---|
| 87 |             { return this->right2Left_; } | 
|---|
| 88 |  | 
|---|
| 89 |         inline void setValue(float value) | 
|---|
| 90 |         { | 
|---|
| 91 |             float temp = clamp(value, 0.0f, 1.0f); | 
|---|
| 92 |             if (temp != this->value_) | 
|---|
| 93 |             { | 
|---|
| 94 |                 this->value_ = temp; | 
|---|
| 95 |                 this->valueChanged(); | 
|---|
| 96 |             } | 
|---|
| 97 |         } | 
|---|
| 98 |         inline float getValue() const | 
|---|
| 99 |             { return this->value_; } | 
|---|
| 100 |  | 
|---|
| 101 |         inline void setAutoColour(bool val) | 
|---|
| 102 |         { | 
|---|
| 103 |             if (val != this->autoColour_) | 
|---|
| 104 |             { | 
|---|
| 105 |                 this->autoColour_ = val; | 
|---|
| 106 |                 this->valueChanged(); | 
|---|
| 107 |  | 
|---|
| 108 |                 if (!val) | 
|---|
| 109 |                     this->currentColour_ = ColourValue::White; | 
|---|
| 110 |             } | 
|---|
| 111 |         } | 
|---|
| 112 |         inline bool getAutoColour() const | 
|---|
| 113 |             { return this->autoColour_; } | 
|---|
| 114 |  | 
|---|
| 115 |         void setBarTexture(const std::string& texture); | 
|---|
| 116 |         const std::string& getBarTexture() const; | 
|---|
| 117 |  | 
|---|
| 118 |         void setIconMaterial(const std::string& iconMaterial); | 
|---|
| 119 |         const std::string& getIconMaterial() const; | 
|---|
| 120 |  | 
|---|
| 121 |         inline const ColourValue& getCurrentBarColour() const | 
|---|
| 122 |             { return this->currentColour_; } | 
|---|
| 123 |  | 
|---|
| 124 |         inline void setIconPosition(Vector2 position) | 
|---|
| 125 |             { this->icon_->setPosition(position.x, position.y); } | 
|---|
| 126 |         inline void setIconDimensions(Vector2 dimensions) | 
|---|
| 127 |             { this->icon_->setDimensions(dimensions.x, dimensions.y); } | 
|---|
| 128 |  | 
|---|
| 129 |     protected: | 
|---|
| 130 |         virtual void valueChanged(); | 
|---|
| 131 |     private: | 
|---|
| 132 |         void addColour(BarColour* colour); | 
|---|
| 133 |         BarColour* getColour(unsigned int index); | 
|---|
| 134 |  | 
|---|
| 135 |         bool right2Left_; | 
|---|
| 136 |         bool autoColour_;                   //!< whether bar changes colour automatically | 
|---|
| 137 |         float value_;                       //!< progress of bar | 
|---|
| 138 |         ColourValue currentColour_; | 
|---|
| 139 |         bool bUseIcon_; | 
|---|
| 140 |  | 
|---|
| 141 |         Ogre::PanelOverlayElement* bar_; | 
|---|
| 142 |         Ogre::TextureUnitState* textureUnitState_; | 
|---|
| 143 |         Ogre::PanelOverlayElement* icon_; | 
|---|
| 144 |         std::map<float, ColourValue> colours_; | 
|---|
| 145 |         std::vector<BarColour*> barColours_; | 
|---|
| 146 |  | 
|---|
| 147 |         static unsigned int materialcount_s; | 
|---|
| 148 |     }; | 
|---|
| 149 | } | 
|---|
| 150 | #endif /* _HUDBar_H__ */ | 
|---|