Changeset 10739 for code/branches/fabienHS15/src/modules/overlays
- Timestamp:
- Nov 1, 2015, 1:05:54 PM (9 years ago)
- Location:
- code/branches/fabienHS15/src/modules/overlays/hud
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/fabienHS15/src/modules/overlays/hud/HUDBar.cc
r9667 r10739 47 47 RegisterClass(BarColour); 48 48 49 BarColour::BarColour(Context* context) 50 : BaseObject(context) 49 BarColour::BarColour(Context* context) : BaseObject(context) 51 50 { 52 51 RegisterObject(BarColour); 53 52 54 53 this->setColour(ColourValue(1.0, 1.0, 1.0, 1.0)); 55 54 this->setPosition(0.0); … … 69 68 RegisterClass(HUDBar); 70 69 71 HUDBar::HUDBar(Context* context) 72 : OrxonoxOverlay(context), right2Left_(false), autoColour_(false) 70 HUDBar::HUDBar(Context* context) : OrxonoxOverlay(context), right2Left_(false), autoColour_(false) 73 71 { 74 72 RegisterObject(HUDBar); … … 88 86 this->bar_->setMaterialName(materialname); 89 87 88 this->bar_->setPosition(0.0f,0.0f); 89 this->bar_->setDimensions(1.0f,1.0f); 90 91 this->bUseIcon_ = false; 90 92 this->value_ = 1.0f; // initialize with 1.0f to trigger a change when calling setValue(0.0f) on the line below 91 93 this->setAutoColour(true); … … 95 97 96 98 this->background_->addChild(bar_); 99 100 this->icon_ = static_cast<Ogre::PanelOverlayElement* >(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDBar_icon_" + getUniqueNumberString())); 101 this->icon_->setPosition(0.06f,0.0f); 102 this->icon_->setDimensions(0.1f,1.0f); 103 this->background_->addChild(this->icon_); 97 104 } 98 105 … … 115 122 XMLPortParam(HUDBar, "autocolour", setAutoColour, getAutoColour, xmlelement, mode); 116 123 XMLPortParam(HUDBar, "bartexture", setBarTexture, getBarTexture, xmlelement, mode); 124 XMLPortParam(HUDBar, "iconmaterial", setIconMaterial, getIconMaterial, xmlelement, mode); 117 125 XMLPortObject(HUDBar, BarColour, "", addColour, getColour, xmlelement, mode); 118 126 } … … 161 169 } 162 170 171 float height = this->bar_->getHeight(); 172 float top = this->bar_->getTop(); 173 163 174 // set value 164 175 if (this->right2Left_) 165 176 { 166 177 // backward case 167 this->bar_->setPosition(0.06f + 0.88f * (1 - this->value_), 0.0f); 168 this->bar_->setDimensions(0.88f * this->value_, 1.0f); 178 if (this->bUseIcon_) 179 { 180 this->bar_->setPosition(0.16f + 0.78f * (1 - this->value_), top); 181 this->bar_->setDimensions(0.78f * this->value_, height); 182 } 183 else 184 { 185 this->bar_->setPosition(0.06f + 0.88f * (1 - this->value_), top); 186 this->bar_->setDimensions(0.88f * this->value_, height); 187 } 169 188 } 170 189 else 171 190 { 172 191 // default case 173 this->bar_->setPosition(0.06f, 0.0f); 174 this->bar_->setDimensions(0.88f * this->value_, 1.0f); 175 } 192 if (this->bUseIcon_) 193 { 194 this->bar_->setPosition(0.16f, top); 195 this->bar_->setDimensions(0.78f * this->value_, height); 196 } 197 else 198 { 199 this->bar_->setPosition(0.06f, top); 200 this->bar_->setDimensions(0.88f * this->value_, height); 201 } 202 } 203 176 204 if (this->value_ != 0) 177 205 this->bar_->setTiling(this->value_, 1.0); … … 208 236 return this->textureUnitState_->getTextureName(); 209 237 } 238 239 void HUDBar::setIconMaterial(const std::string& iconMaterial) 240 { 241 this->bUseIcon_ = true; 242 this->icon_->setMaterialName(iconMaterial); 243 valueChanged(); 244 } 245 246 const std::string& HUDBar::getIconMaterial() const 247 { 248 return this->icon_->getMaterialName(); 249 } 210 250 } -
code/branches/fabienHS15/src/modules/overlays/hud/HUDBar.h
r9667 r10739 37 37 #include <map> 38 38 #include <vector> 39 #include <OgrePanelOverlayElement.h> 39 40 40 41 #include "util/Math.h" … … 51 52 virtual ~BarColour() { } 52 53 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 55 55 56 void setColour(const ColourValue& colour) { this->colour_ = colour; } … … 115 116 const std::string& getBarTexture() const; 116 117 118 void setIconMaterial(const std::string& iconMaterial); 119 const std::string& getIconMaterial() const; 120 117 121 inline const ColourValue& getCurrentBarColour() const 118 122 { return this->currentColour_; } 119 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 120 129 protected: 121 130 virtual void valueChanged(); 122 123 131 private: 124 132 void addColour(BarColour* colour); … … 129 137 float value_; //!< progress of bar 130 138 ColourValue currentColour_; 139 bool bUseIcon_; 131 140 132 141 Ogre::PanelOverlayElement* bar_; 133 142 Ogre::TextureUnitState* textureUnitState_; 143 Ogre::PanelOverlayElement* icon_; 134 144 std::map<float, ColourValue> colours_; 135 145 std::vector<BarColour*> barColours_; -
code/branches/fabienHS15/src/modules/overlays/hud/HUDBoostBar.cc
r9667 r10739 59 59 if (this->owner_->isBoostCoolingDown()) 60 60 { 61 this->setBackgroundColour(ColourValue(0.7f, 0.2f, 0.2f));61 //this->setBackgroundColour(ColourValue(0.7f, 0.2f, 0.2f)); 62 62 if (this->flashDt_ <= 0.0f) 63 63 { … … 72 72 this->flashDt_ = 0.0f; 73 73 this->show(); 74 this->setBackgroundColour(ColourValue(0.2f, 0.7f, 0.2f));74 //this->setBackgroundColour(ColourValue(0.2f, 0.7f, 0.2f)); 75 75 } 76 76 -
code/branches/fabienHS15/src/modules/overlays/hud/HUDHealthBar.cc
r9667 r10739 45 45 this->owner_ = 0; 46 46 this->bUseBarColour_ = false; 47 this->textOffset_ = Vector2(0.0f, 0.0f); 48 this->textScale_ = 1.0f; 49 50 this->setIconPosition(Vector2(0.05f,0.5f)); 51 this->setIconDimensions(Vector2(0.1f,0.5f)); 47 52 48 53 this->textoverlay_ = new OverlayText(this->getContext()); … … 51 56 52 57 this->textoverlay_->setCaption(""); 58 this->textoverlay_->setAspectCorrection(false); 59 60 positionText(); 53 61 } 54 62 … … 58 66 { 59 67 this->textoverlay_->destroy(); 60 this->textoverlay_ = 0;68 this->textoverlay_ = NULL; 61 69 } 62 70 } … … 70 78 XMLPortParam(HUDHealthBar, "textusebarcolour", setTextUseBarColour, getTextUseBarColour, xmlelement, mode).defaultValues(false); 71 79 XMLPortParam(HUDHealthBar, "textcolour", setTextColour, getTextColour, xmlelement, mode).defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0)); 72 XMLPortParam(HUDHealthBar, "textsize", setTextSize, getTextSize, xmlelement, mode).defaultValues(1.0f);73 80 XMLPortParam(HUDHealthBar, "textalign", setTextAlignmentString, getTextAlignmentString, xmlelement, mode).defaultValues("left"); 74 81 XMLPortParam(HUDHealthBar, "textoffset", setTextOffset, getTextOffset, xmlelement, mode).defaultValues(Vector2::ZERO); 82 XMLPortParam(HUDHealthBar, "textscale", setTextScale, getTextScale, xmlelement, mode).defaultValues(1.0f); 75 83 XMLPortParam(HUDHealthBar, "textpickpoint", setTextPickPoint, getTextPickPoint, xmlelement, mode).defaultValues(Vector2::ZERO); 76 84 XMLPortParam(HUDHealthBar, "textrotation", setTextRotation, getTextRotation, xmlelement, mode).defaultValues(0.0f); 77 XMLPortParam(HUDHealthBar, "textcorrectaspect", setTextAspectCorrection, getTextAspectCorrection, xmlelement, mode).defaultValues(true);78 85 XMLPortParam(HUDHealthBar, "textspacewidth", setTextSpaceWidth, getTextSpaceWidth, xmlelement, mode).defaultValues(true); 79 86 } … … 139 146 this->textoverlay_->setColour(this->textColour_); 140 147 } 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 } 141 166 } -
code/branches/fabienHS15/src/modules/overlays/hud/HUDHealthBar.h
r10624 r10739 75 75 { return this->textoverlay_->getAlignmentString(); } 76 76 77 inline void setTextSize(float size)78 { this->textoverlay_->setTextSize(size); }79 inline float getTextSize() const80 { return this->textoverlay_->getTextSize(); }81 82 77 inline void setTextVisible(bool bVisible) 83 78 { this->textoverlay_->setVisible(bVisible); } 84 79 inline bool getTextVisible() const 85 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_; } 86 88 87 89 inline void setTextPickPoint(const Vector2& pickpoint) … … 91 93 92 94 inline void setTextOffset(const Vector2& position) 93 { this->textoverlay_->setPosition(this->getPosition() + (position - this->getPickPoint()) * this->getSize()); } 95 { this->textOffset_ = position; 96 this->positionText(); 97 } 94 98 inline Vector2 getTextOffset() const 95 { return (this->textoverlay_->getPosition() - this->getPosition()) / this->getSize() + this->getPickPoint(); } 96 97 inline void setTextAspectCorrection(bool correct) 98 { this->textoverlay_->setAspectCorrection(correct); } 99 inline bool getTextAspectCorrection() const 100 { return this->textoverlay_->getAspectCorrection(); } 99 { return this->textOffset_; } 101 100 102 101 inline void setTextRotation(const Degree& angle) … … 112 111 inline void setHealthBarOwner(Pawn* owner) 113 112 { this->owner_ = owner; } 114 113 protected: 114 virtual void positionChanged(); 115 virtual void sizeChanged(); 115 116 private: 117 virtual void positionText(); 116 118 WeakPtr<Pawn> owner_; 117 119 StrongPtr<OverlayText> textoverlay_; 118 120 bool bUseBarColour_; 119 121 ColourValue textColour_; 122 Vector2 textOffset_; 123 float textScale_; 120 124 }; 121 125 } -
code/branches/fabienHS15/src/modules/overlays/hud/HUDWeapon.cc
r10724 r10739 60 60 { 61 61 destroyHUDChilds(); 62 //this->overlayElement_->destroy();63 62 } 64 63 } … … 179 178 for (std::vector<WeakPtr<HUDWeaponMode> >::iterator it = hudWeaponModes_.begin(); it != hudWeaponModes_.end(); ++it) 180 179 { 180 (*it)->setPositionOffset(this->positionOffset_); 181 181 (*it)->setWeaponModeIndex(positionIndex); 182 182 (*it)->setWeaponIndex(this->weaponIndex_); … … 210 210 if (weaponModes_ != NULL) 211 211 { 212 this->setPosition(Vector2(weaponModeHUDActualSize_.x*weaponIndex_,0.0f) );212 this->setPosition(Vector2(weaponModeHUDActualSize_.x*weaponIndex_,0.0f) + this->positionOffset_); 213 213 } 214 214 } -
code/branches/fabienHS15/src/modules/overlays/hud/HUDWeapon.h
r10724 r10739 72 72 inline Vector2 getWeaponModeHUDActualSize() const 73 73 { return weaponModeHUDActualSize_; } 74 inline void setPositionOffset(Vector2 positionOffset) 75 { 76 this->positionOffset_ = positionOffset; 77 this->updatePosition(); 78 } 74 79 inline void setWeaponIndex(int index) 75 { weaponIndex_ = index; 76 this->updatePosition(); 80 { 81 weaponIndex_ = index; 82 this->updatePosition(); 77 83 } 78 84 … … 94 100 95 101 Vector2 weaponModeHUDActualSize_; 102 Vector2 positionOffset_; 96 103 int weaponIndex_; 97 104 }; -
code/branches/fabienHS15/src/modules/overlays/hud/HUDWeaponMode.cc
r10724 r10739 102 102 if (this->isInitialized()) 103 103 { 104 //this->textOverlay_->destroy(); 104 this->textOverlayLeft_->destroy(); 105 this->textOverlayRight_->destroy(); 105 106 } 106 107 } … … 280 281 void HUDWeaponMode::updatePosition() 281 282 { 282 this->setPosition(Vector2(weaponModeHUDActualSize_.x*weaponIndex_,weaponModeHUDActualSize_.y*weaponModeIndex_) );283 this->setPosition(Vector2(weaponModeHUDActualSize_.x*weaponIndex_,weaponModeHUDActualSize_.y*weaponModeIndex_) + this->positionOffset_); 283 284 } 284 285 } -
code/branches/fabienHS15/src/modules/overlays/hud/HUDWeaponMode.h
r10724 r10739 82 82 this->updatePosition(); 83 83 } 84 inline void setPositionOffset(Vector2 positionOffset) 85 { 86 this->positionOffset_ = positionOffset; 87 this->updatePosition(); 88 } 84 89 85 90 private: … … 102 107 103 108 Vector2 weaponModeHUDActualSize_; 109 Vector2 positionOffset_; 104 110 int weaponIndex_; 105 111 int weaponModeIndex_; -
code/branches/fabienHS15/src/modules/overlays/hud/HUDWeaponSystem.cc
r10724 r10739 156 156 { 157 157 int positionIndex = 0; 158 Vector2 offset = this->getPosition(); 158 159 159 160 for (std::vector<WeakPtr<HUDWeapon> >::iterator it = hudWeapons_.begin(); it != hudWeapons_.end(); ++it) 160 161 { 162 (*it)->setPositionOffset(offset); 161 163 (*it)->setWeaponIndex(positionIndex); 162 164 (*it)->setWeaponModeHUDActualSize(this->weaponModeHUDActualSize_);
Note: See TracChangeset
for help on using the changeset viewer.