- Timestamp:
- Oct 29, 2015, 11:27:32 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/fabienHS15/src/modules/overlays/hud/HUDWeapon.cc
r10715 r10721 21 21 * 22 22 * Author: 23 * Yuning Chai 24 * Felix Schulthess 23 * Fabien Vultier 25 24 * Co-authors: 26 * Reto Grieder 27 * Wolfgang Roenninger 25 * ... 28 26 * 29 27 */ … … 48 46 RegisterObject(HUDWeapon); 49 47 48 weaponModeHUDActualSize_ = Vector2(0.0f,0.0f); 49 50 weaponModes_ = NULL; 51 weaponIndex_ = 0; 52 hudWeaponModes_.clear(); 53 50 54 overlayElement_ = static_cast<Ogre::PanelOverlayElement* >(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDWeapon" + getUniqueNumberString())); 51 55 overlayElement_->setMaterialName("Orxonox/WSHUD_Weapon"); … … 75 79 { 76 80 SUPER(HUDWeapon, tick, dt); 81 82 if (!weapon_) 83 { 84 // TODO: destroy this HUD id the Weapon does no more exist. (Wehen the weak pointer is NULL) 85 } 77 86 } 78 87 … … 82 91 83 92 positionHUDChilds(); 84 } 93 } 94 95 void HUDWeapon::sizeChanged() 96 { 97 OrxonoxOverlay::sizeChanged(); 98 99 positionHUDChilds(); 100 } 85 101 86 102 void HUDWeapon::changedOwner() … … 131 147 weaponModes_ = weapon_->getAllWeaponmodes(); 132 148 149 updateSize(); 133 150 createHUDChilds(); 134 positionHUDChilds(); 151 positionHUDChilds(); 135 152 } 136 153 137 154 void HUDWeapon::createHUDChilds() 138 155 { 156 if (weaponModes_ == NULL) 157 { 158 return; 159 } 160 161 int positionIndex = 0; 162 139 163 for (std::multimap<unsigned int, WeaponMode*>::iterator it = weaponModes_->begin(); it != weaponModes_->end(); ++it) 140 164 { 141 165 HUDWeaponMode* hudWeaponMode = new HUDWeaponMode(this->getContext()); 142 166 hudWeaponMode->setOwner(owner_); 167 hudWeaponMode->setOverlayGroup(this->getOverlayGroup()); 143 168 hudWeaponMode->setWeaponMode(it->second); 169 hudWeaponMode->setWeaponIndex(this->weaponIndex_); 170 hudWeaponMode->setAspectCorrection(false); 171 hudWeaponMode->setPickPoint(Vector2(0.0f,0.0f)); 172 144 173 hudWeaponModes_.push_back(hudWeaponMode); 145 } 174 175 ++ positionIndex; 176 } 146 177 } 147 178 … … 152 183 for (std::vector<WeakPtr<HUDWeaponMode> >::iterator it = hudWeaponModes_.begin(); it != hudWeaponModes_.end(); ++it) 153 184 { 154 (*it)->setOverlayGroup(this->getOverlayGroup()); 155 (*it)->setAspectCorrection(this->getAspectCorrection()); 156 (*it)->setPosition(this->getPosition() + Vector2(0.0f,0.025f*positionIndex)); 157 (*it)->setSize(Vector2(0.15f,0.025f)); 158 (*it)->setPickPoint(Vector2(0.0f,0.0f)); 159 160 ++ positionIndex; 161 } 162 163 overlayElement_->setDimensions(1.0f,0.25f*hudWeaponModes_.size()); 185 (*it)->setWeaponModeIndex(positionIndex); 186 (*it)->setWeaponIndex(this->weaponIndex_); 187 (*it)->setWeaponModeHUDActualSize(this->weaponModeHUDActualSize_); 188 (*it)->positionHUDChilds(); 189 190 ++ positionIndex; 191 } 164 192 } 165 193 … … 173 201 hudWeaponModes_.clear(); 174 202 } 203 204 void HUDWeapon::updateSize() 205 { 206 if (weaponModes_ != NULL) 207 { 208 this->setSize(Vector2(weaponModeHUDActualSize_.x,weaponModeHUDActualSize_.y*weaponModes_->size())); 209 updatePosition(); 210 } 211 } 212 213 void HUDWeapon::updatePosition() 214 { 215 if (weaponModes_ != NULL) 216 { 217 this->setPosition(Vector2(weaponModeHUDActualSize_.x*weaponIndex_,0.0f)); 218 } 219 } 175 220 }
Note: See TracChangeset
for help on using the changeset viewer.