| 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 | * ... |
|---|
| 26 | * |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #include "OrxonoxStableHeaders.h" |
|---|
| 30 | #include "HUD.h" |
|---|
| 31 | |
|---|
| 32 | #include <OgreOverlayManager.h> |
|---|
| 33 | #include <OgreOverlayElement.h> |
|---|
| 34 | #include <OgreStringConverter.h> |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | namespace orxonox |
|---|
| 38 | { |
|---|
| 39 | using namespace Ogre; |
|---|
| 40 | |
|---|
| 41 | HUD::HUD(void) |
|---|
| 42 | { |
|---|
| 43 | init(); |
|---|
| 44 | |
|---|
| 45 | setTime(99,55); |
|---|
| 46 | |
|---|
| 47 | setTargetWindowName("HURRA"); |
|---|
| 48 | setTargetWindowDistance(12); |
|---|
| 49 | setTargetWindowStatus("Dead"); |
|---|
| 50 | setTargetWindowDistance(30); |
|---|
| 51 | |
|---|
| 52 | setEnergyValue(60); |
|---|
| 53 | |
|---|
| 54 | setShieldLeftTopValue(true); |
|---|
| 55 | setShieldRightTopValue(false); |
|---|
| 56 | setShieldLeftBottomValue(false); |
|---|
| 57 | setShieldRightBottomValue(true); |
|---|
| 58 | |
|---|
| 59 | setRocket1(11); |
|---|
| 60 | setRocket2(22); |
|---|
| 61 | setRocket3(33); |
|---|
| 62 | setRocket4(44); |
|---|
| 63 | |
|---|
| 64 | setEnergyDistr(33,33,34); |
|---|
| 65 | |
|---|
| 66 | setPrimar(3); |
|---|
| 67 | |
|---|
| 68 | energyDistrPixelX_ = 100; |
|---|
| 69 | energyDistrPixelY_ = 86; |
|---|
| 70 | |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | HUD::~HUD( void ){ |
|---|
| 75 | |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | void HUD::setTime(int i, int j){ |
|---|
| 79 | timeMin_=i; |
|---|
| 80 | timeSec_=j; |
|---|
| 81 | timeText_->setCaption(StringConverter::toString(timeMin_) + ":" + StringConverter::toString(timeSec_)); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | void HUD::setTargetWindowName(std::string i){ |
|---|
| 85 | targetWindowName_=i; |
|---|
| 86 | targetWindowNameText_->setCaption( targetWindowName_ ); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | void HUD::setTargetWindowStatus(std::string i){ |
|---|
| 90 | targetWindowStatus_=i; |
|---|
| 91 | targetWindowStatusText_->setCaption( targetWindowStatus_ ); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | void HUD::setTargetWindowDistance(int i){ |
|---|
| 95 | targetWindowDistance_=i; |
|---|
| 96 | targetWindowDistanceText_->setCaption(StringConverter::toString(targetWindowDistance_) + "km" ); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | void HUD::setTargetWindowHitRating(int i){ |
|---|
| 100 | targetWindowHitRating_=i; |
|---|
| 101 | targetWindowHitRatingText_->setCaption(StringConverter::toString(targetWindowHitRating_) + "%" ); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | void HUD::setEnergyValue(int i){ |
|---|
| 105 | energyValue_=i; |
|---|
| 106 | energyLength_->setWidth((int)((float)energyValue_/(float)100*200)); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | void HUD::setShieldLeftTopValue(bool i){ |
|---|
| 110 | shieldLeftTopValue_=i; |
|---|
| 111 | if (shieldLeftTopValue_) shieldLeftTop_->show(); |
|---|
| 112 | else shieldLeftTop_->hide(); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | void HUD::setShieldRightTopValue(bool i){ |
|---|
| 116 | shieldRightTopValue_=i; |
|---|
| 117 | if (shieldRightTopValue_) shieldRightTop_->show(); |
|---|
| 118 | else shieldRightTop_->hide(); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | void HUD::setShieldLeftBottomValue(bool i){ |
|---|
| 122 | shieldLeftBottomValue_=i; |
|---|
| 123 | if (shieldLeftBottomValue_) shieldLeftBottom_->show(); |
|---|
| 124 | else shieldLeftBottom_->hide(); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | void HUD::setShieldRightBottomValue(bool i){ |
|---|
| 128 | shieldRightBottomValue_=i; |
|---|
| 129 | if (shieldRightBottomValue_) shieldRightBottom_->show(); |
|---|
| 130 | else shieldRightBottom_->hide(); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | void HUD::setRocket1(int i){ |
|---|
| 134 | rocket1_=i; |
|---|
| 135 | rocketNum1_->setCaption(StringConverter::toString(rocket1_)); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | void HUD::setRocket2(int i){ |
|---|
| 139 | rocket2_=i; |
|---|
| 140 | rocketNum2_->setCaption(StringConverter::toString(rocket2_)); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | void HUD::setRocket3(int i){ |
|---|
| 144 | rocket3_=i; |
|---|
| 145 | rocketNum3_->setCaption(StringConverter::toString(rocket3_)); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | void HUD::setRocket4(int i){ |
|---|
| 149 | rocket4_=i; |
|---|
| 150 | rocketNum4_->setCaption(StringConverter::toString(rocket4_)); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | void HUD::setEnergyDistr(float s, float e, float l){ |
|---|
| 154 | energyDistrShield_=s; |
|---|
| 155 | energyDistrEngine_=e; |
|---|
| 156 | energyDistrLaser_=l; |
|---|
| 157 | |
|---|
| 158 | float energyDistrShieldInv_ = 100 - energyDistrShield_; |
|---|
| 159 | float energyDistrEngineInv_ = 100 - energyDistrEngine_; |
|---|
| 160 | float energyDistrLaserInv_ = 100 - energyDistrLaser_; |
|---|
| 161 | |
|---|
| 162 | float energyDistrT_ = -energyDistrPixelX_/((energyDistrPixelX_-energyDistrPixelX_/2*energyDistrShieldInv_/(energyDistrShieldInv_+energyDistrEngineInv_))*energyDistrLaserInv_*(energyDistrShieldInv_+energyDistrEngineInv_)/energyDistrShieldInv_/(energyDistrLaserInv_+energyDistrEngineInv_)+energyDistrPixelX_/2+energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_)); |
|---|
| 163 | float energyDistrX_ = (-energyDistrPixelX_/2-energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_))*energyDistrT_; |
|---|
| 164 | float energyDistrY_ = energyDistrPixelY_+energyDistrPixelY_*energyDistrLaserInv_/(energyDistrLaserInv_+energyDistrEngineInv_)*energyDistrT_; |
|---|
| 165 | |
|---|
| 166 | energyDistrPoint_->setLeft((int)energyDistrX_-3); |
|---|
| 167 | energyDistrPoint_->setTop((int)energyDistrY_-3); |
|---|
| 168 | |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | void HUD::setPrimar(int i){ |
|---|
| 172 | primarValue_=i; |
|---|
| 173 | if(i==1){ |
|---|
| 174 | primarChoice_->setLeft(2); |
|---|
| 175 | primarChoice_->setWidth(48); |
|---|
| 176 | } |
|---|
| 177 | if(i==2){ |
|---|
| 178 | primarChoice_->setLeft(51); |
|---|
| 179 | primarChoice_->setWidth(49); |
|---|
| 180 | } |
|---|
| 181 | else{ |
|---|
| 182 | primarChoice_->setLeft(101); |
|---|
| 183 | primarChoice_->setWidth(48); |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | void HUD::init(void) |
|---|
| 190 | { |
|---|
| 191 | timeText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/Time/Text"); |
|---|
| 192 | |
|---|
| 193 | targetWindowNameText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/Name"); |
|---|
| 194 | targetWindowDistanceText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/DistanceText"); |
|---|
| 195 | targetWindowStatusText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/StatusText"); |
|---|
| 196 | targetWindowHitRatingText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/HitRatingText"); |
|---|
| 197 | |
|---|
| 198 | energyLength_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyBackground"); |
|---|
| 199 | |
|---|
| 200 | shieldLeftTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftTop"); |
|---|
| 201 | shieldRightTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightTop"); |
|---|
| 202 | shieldLeftBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftBottom"); |
|---|
| 203 | shieldRightBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightBottom"); |
|---|
| 204 | |
|---|
| 205 | rocketNum1_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum1"); |
|---|
| 206 | rocketNum2_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum2"); |
|---|
| 207 | rocketNum3_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum3"); |
|---|
| 208 | rocketNum4_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum4"); |
|---|
| 209 | |
|---|
| 210 | // FIXME: unused vars! |
|---|
| 211 | float energyDistrPixelX_ = 100; |
|---|
| 212 | float energyDistrPixelY_ = 86; |
|---|
| 213 | energyDistrPoint_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyDistrPoint"); |
|---|
| 214 | |
|---|
| 215 | primarChoice_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/PrimarChoice"); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | } |
|---|