Changeset 11189 for code/branches/sagerjFS16/src/modules/overlays/hud
- Timestamp:
- May 19, 2016, 5:04:41 PM (8 years ago)
- Location:
- code/branches/sagerjFS16/src/modules/overlays/hud
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/sagerjFS16/src/modules/overlays/hud/HUDChargeBar.cc
r11185 r11189 31 31 #include "util/Convert.h" 32 32 #include "core/CoreIncludes.h" 33 #include "core/XMLPort.h"34 33 #include "worldentities/pawns/Pawn.h" 35 34 #include "overlays/OverlayGroup.h" … … 45 44 46 45 this->owner_ = nullptr; 47 this->bUseBarColour_ = false; 48 this->textOffset_ = Vector2(0.0f, 0.0f); 49 this->textScale_ = 1.0f; 50 this->correspondingMode_ = nullptr; 51 52 this->setIconPosition(Vector2(0.05f,0.5f)); 53 this->setIconDimensions(Vector2(0.1f,0.5f)); 54 55 this->textoverlay_ = new OverlayText(this->getContext()); 56 57 assert(this->textoverlay_.get()); 58 59 this->textoverlay_->setCaption(""); 60 this->textoverlay_->setAspectCorrection(false); 61 62 positionText(); 46 this->correspondingMode_ = nullptr; // usually no chargeable weapon equipped 63 47 } 64 48 65 HUDChargeBar::~HUDChargeBar() 66 { 67 if (this->isInitialized()) 68 { 69 this->textoverlay_->destroy(); 70 this->textoverlay_ = nullptr; 71 } 72 } 73 74 void HUDChargeBar::XMLPort(Element& xmlelement, XMLPort::Mode mode) 75 { 76 SUPER(HUDChargeBar, XMLPort, xmlelement, mode); 77 78 XMLPortParam(HUDChargeBar, "showtext", setTextVisible, getTextVisible, xmlelement, mode).defaultValues(true); 79 XMLPortParam(HUDChargeBar, "textfont", setTextFont, getTextFont, xmlelement, mode).defaultValues("Monofur"); 80 XMLPortParam(HUDChargeBar, "textusebarcolour", setTextUseBarColour, getTextUseBarColour, xmlelement, mode).defaultValues(false); 81 XMLPortParam(HUDChargeBar, "textcolour", setTextColour, getTextColour, xmlelement, mode).defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0)); 82 XMLPortParam(HUDChargeBar, "textalign", setTextAlignmentString, getTextAlignmentString, xmlelement, mode).defaultValues("left"); 83 XMLPortParam(HUDChargeBar, "textoffset", setTextOffset, getTextOffset, xmlelement, mode).defaultValues(Vector2::ZERO); 84 XMLPortParam(HUDChargeBar, "textscale", setTextScale, getTextScale, xmlelement, mode).defaultValues(1.0f); 85 XMLPortParam(HUDChargeBar, "textpickpoint", setTextPickPoint, getTextPickPoint, xmlelement, mode).defaultValues(Vector2::ZERO); 86 XMLPortParam(HUDChargeBar, "textrotation", setTextRotation, getTextRotation, xmlelement, mode).defaultValues(0.0f); 87 XMLPortParam(HUDChargeBar, "textspacewidth", setTextSpaceWidth, getTextSpaceWidth, xmlelement, mode).defaultValues(true); 88 } 49 HUDChargeBar::~HUDChargeBar() { } 89 50 90 51 void HUDChargeBar::tick(float dt) … … 94 55 if (this->owner_) 95 56 { 96 if(correspondingMode_ != nullptr){ 97 this->setValue( correspondingMode_->getCharges() * 1.0f / correspondingMode_->getMaxCharges() ); 98 this->textoverlay_->setCaption(multi_cast<std::string>(static_cast<int>(this->owner_->getHealth()))); 57 if(correspondingMode_ != nullptr) // if there is a chargeable weapon equipped we want to show the charged amount with a HUDBar 58 { 59 this->setValue( correspondingMode_->getCharges() * 1.0f / correspondingMode_->getMaxCharges() ); // The Value of the HUDBar is the ratio of current Charges and the maximum Charges possible 60 61 if(this->correspondingMode_->getCharges() > 0) // The HUDBar should only be visible when we are charging up 62 this->setVisible(true); 63 } 64 else 65 { 66 this->setVisible(false); 67 } 99 68 } 100 101 102 69 } 103 70 else 104 71 { 105 72 this->setValue(0); 106 this->textoverlay_->setCaption("0");107 73 } 108 109 if (this->bUseBarColour_)110 this->textoverlay_->setColour(this->getCurrentBarColour());111 112 74 113 75 } … … 116 78 { 117 79 SUPER(HUDChargeBar, changedOwner); 80 81 this->setVisible(false); 82 this->correspondingMode_ = nullptr; 118 83 119 84 this->owner_ = orxonox_cast<Pawn*>(this->getOwner()); … … 141 106 } 142 107 } 143 144 void HUDChargeBar::changedOverlayGroup()145 {146 SUPER(HUDChargeBar, changedOverlayGroup);147 148 this->getOverlayGroup()->addElement(this->textoverlay_.get());149 }150 151 void HUDChargeBar::changedVisibility()152 {153 SUPER(HUDChargeBar, changedVisibility);154 155 this->textoverlay_->setVisible(this->isVisible());156 }157 158 void HUDChargeBar::changedName()159 {160 SUPER(HUDChargeBar, changedName);161 162 this->textoverlay_->setName(this->getName() + "text");163 }164 165 void HUDChargeBar::setTextColour(const ColourValue& colour)166 {167 this->textColour_ = colour;168 if (!this->bUseBarColour_)169 this->textoverlay_->setColour(colour);170 }171 172 void HUDChargeBar::setTextUseBarColour(bool bUseBarColour)173 {174 this->bUseBarColour_ = bUseBarColour;175 if (!bUseBarColour)176 this->textoverlay_->setColour(this->textColour_);177 }178 179 void HUDChargeBar::positionText()180 {181 this->textoverlay_->setPosition(this->getPosition() + this->textOffset_*this->getActualSize());182 this->textoverlay_->setTextSize(this->getActualSize().y*this->textScale_);183 }184 185 void HUDChargeBar::positionChanged()186 {187 HUDBar::positionChanged();188 positionText();189 }190 191 void HUDChargeBar::sizeChanged()192 {193 HUDBar::sizeChanged();194 positionText();195 }196 108 } -
code/branches/sagerjFS16/src/modules/overlays/hud/HUDChargeBar.h
r11185 r11189 22 22 * 23 23 * Author: 24 * Fabian 'x3n' Landau24 * Johannes Sager 25 25 * Co-authors: 26 26 * ... … … 28 28 */ 29 29 30 #ifndef _HUD HealthBar_H__31 #define _HUD HealthBar_H__30 #ifndef _HUDChargeBar_H__ 31 #define _HUDChargeBar_H__ 32 32 33 33 #include "overlays/OverlaysPrereqs.h" 34 35 34 #include "util/Math.h" 36 35 #include "tools/interfaces/Tickable.h" 37 36 #include "overlays/OverlayText.h" 38 37 #include "HUDBar.h" 38 39 39 #include "weaponsystem/WeaponSystem.h" 40 40 #include "weaponsystem/WeaponPack.h" … … 44 44 namespace orxonox 45 45 { 46 /** 47 @brief 48 The HUDChargeBar displays the amount of charges of its owner (a @ref Pawn). 49 The length of the bar is given by the ratio of the current charges and the maximal charges of the @ref Pawn. 50 */ 51 46 52 class _OverlaysExport HUDChargeBar : public HUDBar, public Tickable 47 53 { … … 50 56 virtual ~HUDChargeBar(); 51 57 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;53 58 virtual void tick(float dt) override; 54 59 virtual void changedOwner() override; 55 virtual void changedOverlayGroup() override;56 virtual void changedVisibility() override;57 virtual void changedName() override;58 59 inline void setTextFont(const std::string& font)60 { if (!font.empty()) { this->textoverlay_->setFont(font); } }61 inline const std::string& getTextFont() const62 { return this->textoverlay_->getFont(); }63 64 void setTextColour(const ColourValue& colour);65 inline const ColourValue& getTextColour() const66 { return this->textoverlay_->getColour(); }67 68 void setTextUseBarColour(bool bUseBarColour);69 inline bool getTextUseBarColour() const70 { return this->bUseBarColour_; }71 72 inline void setTextAlignment(OverlayText::Alignment alignment)73 { this->textoverlay_->setAlignment(alignment); }74 inline OverlayText::Alignment getTextAlignment() const75 { return this->textoverlay_->getAlignment(); }76 77 void setTextAlignmentString(const std::string& alignment)78 { this->textoverlay_->setAlignmentString(alignment); }79 std::string getTextAlignmentString() const80 { return this->textoverlay_->getAlignmentString(); }81 82 inline void setTextVisible(bool bVisible)83 { this->textoverlay_->setVisible(bVisible); }84 inline bool getTextVisible() const85 { return this->textoverlay_->isVisible(); }86 87 inline void setTextScale(float scale)88 { this->textScale_ = scale;89 positionText();90 }91 inline float getTextScale() const92 { return this->textScale_; }93 94 inline void setTextPickPoint(const Vector2& pickpoint)95 { this->textoverlay_->setPickPoint(pickpoint); }96 inline Vector2 getTextPickPoint() const97 { return this->textoverlay_->getPickPoint(); }98 99 inline void setTextOffset(const Vector2& position)100 { this->textOffset_ = position;101 this->positionText();102 }103 inline Vector2 getTextOffset() const104 { return this->textOffset_; }105 106 inline void setTextRotation(const Degree& angle)107 { this->textoverlay_->setRotation(angle); }108 inline const Degree& getTextRotation() const109 { return this->textoverlay_->getRotation(); }110 111 inline void setTextSpaceWidth(float width)112 { this->textoverlay_->setSpaceWidth(width); }113 inline float getTextSpaceWidth() const114 { return this->textoverlay_->getSpaceWidth(); }115 60 116 61 inline void setHealthBarOwner(Pawn* owner) 117 62 { this->owner_ = owner; } 118 protected: 119 virtual void positionChanged() override; 120 virtual void sizeChanged() override; 63 121 64 private: 122 WeaponMode* correspondingMode_; 123 void positionText(); 65 WeaponMode* correspondingMode_; // pointer on the chargeable weaponmode (=nullptr if no chargeable weapons equipped) 124 66 WeakPtr<Pawn> owner_; 125 StrongPtr<OverlayText> textoverlay_;126 bool bUseBarColour_;127 ColourValue textColour_;128 Vector2 textOffset_;129 float textScale_;130 67 }; 131 68 }
Note: See TracChangeset
for help on using the changeset viewer.