[4744] | 1 | /* |
---|
[1853] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[6437] | 12 | main-programmer: Benjamin Grauer |
---|
[10698] | 13 | co-programmer: Benjamin Knecht |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[6437] | 18 | #include "hud.h" |
---|
[1853] | 19 | |
---|
[6441] | 20 | #include "state.h" |
---|
[8976] | 21 | #include "debug.h" |
---|
[6441] | 22 | |
---|
[6442] | 23 | #include "world_entities/weapons/weapon_manager.h" |
---|
[10717] | 24 | #include "glgui.h" |
---|
[8448] | 25 | #include "glgui_widget.h" |
---|
[10368] | 26 | #include "glgui_box.h" |
---|
| 27 | #include "glgui_bar.h" |
---|
| 28 | #include "elements/glgui_energywidgetvertical.h" |
---|
[6442] | 29 | |
---|
[8518] | 30 | #include "glgui_inputline.h" |
---|
| 31 | #include "specials/glgui_notifier.h" |
---|
[8994] | 32 | #include "elements/glgui_radar.h" |
---|
[10368] | 33 | #include "world_entities/space_ships/space_ship.h" |
---|
[8518] | 34 | |
---|
[10759] | 35 | #include "tools/camera.h" |
---|
[8996] | 36 | |
---|
| 37 | |
---|
[10759] | 38 | |
---|
| 39 | |
---|
[8996] | 40 | /// HACK |
---|
| 41 | #include "player.h" |
---|
| 42 | #include "playable.h" |
---|
| 43 | |
---|
[9869] | 44 | ObjectListDefinition(Hud); |
---|
[3245] | 45 | /** |
---|
[4838] | 46 | * standard constructor |
---|
| 47 | * @todo this constructor is not jet implemented - do it |
---|
[3245] | 48 | */ |
---|
[6437] | 49 | Hud::Hud () |
---|
[3365] | 50 | { |
---|
[9869] | 51 | this->registerObject(this, Hud::_objectList); |
---|
[4320] | 52 | |
---|
[6441] | 53 | //this->setSize2D( |
---|
[10759] | 54 | this->playmode = Full3D; |
---|
[6442] | 55 | this->weaponManager = NULL; |
---|
[10368] | 56 | this->weaponManagerSecondary = NULL; |
---|
[6440] | 57 | this->energyWidget = NULL; |
---|
| 58 | this->shieldWidget = NULL; |
---|
[10698] | 59 | this->healthWidget = NULL; |
---|
| 60 | this->leftRect = NULL; |
---|
| 61 | this->rightRect = NULL; |
---|
[6441] | 62 | this->resX = 1; |
---|
| 63 | this->resY = 1; |
---|
[10748] | 64 | this->leftHit = NULL; |
---|
| 65 | this->rightHit = NULL; |
---|
| 66 | this->ifinit = true; |
---|
[10759] | 67 | this->hidden = false; |
---|
[10752] | 68 | |
---|
| 69 | this->barSocket = NULL; |
---|
| 70 | this->_radar = NULL; |
---|
| 71 | this->inputLine = NULL; |
---|
| 72 | this->notifier = NULL; |
---|
| 73 | this->topRect = NULL; |
---|
| 74 | this->bottomRect = NULL; |
---|
| 75 | this->middleRect = NULL; |
---|
[6442] | 76 | |
---|
[10752] | 77 | this->init(); |
---|
[10717] | 78 | |
---|
[10698] | 79 | |
---|
[3365] | 80 | } |
---|
[1853] | 81 | |
---|
| 82 | |
---|
[3245] | 83 | /** |
---|
[4838] | 84 | * standard deconstructor |
---|
[3245] | 85 | */ |
---|
[6437] | 86 | Hud::~Hud () |
---|
[3543] | 87 | { |
---|
[10752] | 88 | if (this->inputLine) delete this->inputLine; |
---|
| 89 | if (this->notifier) delete this->notifier; |
---|
| 90 | if (this->leftHit) delete this->leftHit; |
---|
| 91 | if (this->rightHit) delete this->rightHit; |
---|
[8994] | 92 | |
---|
[10752] | 93 | if (this->_radar) delete this->_radar; |
---|
| 94 | if (this->barSocket) delete this->barSocket; |
---|
| 95 | if (this->rightRect) delete this->rightRect; |
---|
| 96 | if (this->leftRect) delete this->leftRect; |
---|
| 97 | if (this->topRect) delete this->topRect; |
---|
| 98 | if (this->bottomRect) delete this->bottomRect; |
---|
| 99 | if (this->middleRect) delete this->middleRect; |
---|
[10716] | 100 | |
---|
[10698] | 101 | |
---|
[10368] | 102 | //if (this->shipValuesBox != NULL) |
---|
| 103 | //delete this->shipValuesBox; |
---|
| 104 | |
---|
[3543] | 105 | // delete what has to be deleted here |
---|
| 106 | } |
---|
[6438] | 107 | |
---|
[10716] | 108 | void Hud::init() |
---|
| 109 | { |
---|
| 110 | this->overlayPercentage = 40; |
---|
| 111 | this->overlayActive = false; |
---|
| 112 | this->rightRect = new OrxGui::GLGuiImage(); |
---|
| 113 | this->leftRect = new OrxGui::GLGuiImage(); |
---|
| 114 | this->topRect = new OrxGui::GLGuiImage(); |
---|
| 115 | this->bottomRect = new OrxGui::GLGuiImage(); |
---|
| 116 | this->middleRect = new OrxGui::GLGuiImage(); |
---|
[6438] | 117 | |
---|
[10716] | 118 | this->inputLine = new OrxGui::GLGuiInputLine(); |
---|
| 119 | this->inputLine->setParent2D(this); |
---|
| 120 | this->notifier = new OrxGui::GLGuiNotifier(); |
---|
| 121 | this->notifier->setParent2D(this); |
---|
| 122 | notifier->setAbsCoor2D(100,100); |
---|
| 123 | |
---|
[10741] | 124 | |
---|
[10716] | 125 | |
---|
| 126 | this->_radar = new OrxGui::GLGuiRadar(); |
---|
| 127 | this->radarCenterNode = NULL; |
---|
| 128 | |
---|
| 129 | this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE); |
---|
| 130 | this->subscribeEvent(ES_ALL, SDLK_TAB); |
---|
| 131 | |
---|
| 132 | if (this->playmode == FirstPerson) |
---|
| 133 | { |
---|
[10741] | 134 | /*this->topHit = new OrxGui::GLGuiImage(); |
---|
[10716] | 135 | this->topHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
| 136 | this->topHit->setParent2D(this->middleRect); |
---|
[10741] | 137 | this->topHit->setAbsDir2D(-1.5708); |
---|
[10716] | 138 | |
---|
| 139 | this->bottomHit = new OrxGui::GLGuiImage(); |
---|
| 140 | this->bottomHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
| 141 | this->bottomHit->setParent2D(this->middleRect); |
---|
[10741] | 142 | this->bottomHit->setAbsDir2D(1.5708);*/ |
---|
| 143 | |
---|
| 144 | this->barSocket = new OrxGui::GLGuiImage(); |
---|
| 145 | this->barSocket->loadImageFromFile("textures/gui/gui_barSocket.png"); |
---|
| 146 | this->barSocket->setParent2D(this->bottomRect); |
---|
[10716] | 147 | |
---|
| 148 | this->leftHit = new OrxGui::GLGuiImage(); |
---|
[10753] | 149 | this->leftHit->loadImageFromFile("textures/gui/gui_hitbarl.png"); |
---|
[10716] | 150 | this->leftHit->setParent2D(this->middleRect); |
---|
| 151 | |
---|
[10748] | 152 | |
---|
[10716] | 153 | this->rightHit = new OrxGui::GLGuiImage(); |
---|
| 154 | this->rightHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
| 155 | this->rightHit->setParent2D(this->middleRect); |
---|
| 156 | |
---|
[10741] | 157 | |
---|
[10716] | 158 | this->leftRect->setParent2D(this); |
---|
| 159 | this->rightRect->setParent2D(this); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | //this->shipValuesBox = NULL; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | |
---|
[6438] | 166 | void Hud::loadParams(const TiXmlElement* root) |
---|
| 167 | { |
---|
[6512] | 168 | Element2D::loadParams(root); |
---|
[6438] | 169 | } |
---|
| 170 | |
---|
[8518] | 171 | void Hud::notifyUser(const std::string& message) |
---|
[6438] | 172 | { |
---|
[8518] | 173 | this->notifier->pushNotifyMessage(message); |
---|
[6438] | 174 | } |
---|
| 175 | |
---|
[8518] | 176 | void Hud::setBackGround() |
---|
| 177 | {} |
---|
| 178 | |
---|
[8145] | 179 | void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget) |
---|
[6438] | 180 | { |
---|
[10368] | 181 | //if (this->shipValuesBox == NULL) |
---|
| 182 | //this->createShipValuesBox(); |
---|
| 183 | |
---|
[6440] | 184 | // decopple old widget |
---|
| 185 | if (this->energyWidget != NULL) |
---|
| 186 | { |
---|
| 187 | this->energyWidget->hide(); |
---|
| 188 | } |
---|
[6438] | 189 | |
---|
[6440] | 190 | this->energyWidget = widget; |
---|
| 191 | if (this->energyWidget != NULL) |
---|
| 192 | { |
---|
[10368] | 193 | //this->energyWidget->shiftDir2D(270); |
---|
| 194 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics"); |
---|
| 195 | //this->shipValuesBox->pack(this->energyWidget); |
---|
| 196 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings(); |
---|
| 197 | this->energyWidget->setParent2D(this->leftRect); |
---|
[10449] | 198 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png"); |
---|
[10759] | 199 | if (!this->hidden) |
---|
| 200 | this->energyWidget->show(); |
---|
| 201 | else |
---|
| 202 | this->energyWidget->hide(); |
---|
[8518] | 203 | /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
---|
| 204 | this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
---|
[6440] | 205 | } |
---|
| 206 | |
---|
[10698] | 207 | this->updateResolution(); |
---|
[6438] | 208 | } |
---|
| 209 | |
---|
[10698] | 210 | void Hud::setShieldWidget(OrxGui::GLGuiWidget* widget) |
---|
[10368] | 211 | { |
---|
| 212 | /* |
---|
| 213 | if (this->shipValuesBox == NULL) |
---|
| 214 | this->createShipValuesBox(); |
---|
| 215 | */ |
---|
[6438] | 216 | |
---|
[10368] | 217 | // decopple old widget |
---|
| 218 | if (this->shieldWidget != NULL) |
---|
| 219 | { |
---|
| 220 | this->shieldWidget->hide(); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | this->shieldWidget = widget; |
---|
| 224 | if (this->shieldWidget != NULL) |
---|
| 225 | { |
---|
| 226 | //this->shieldWidget->shiftDir2D(270); |
---|
| 227 | //this->shipValuesBox->pack(this->shieldWidget); |
---|
| 228 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setStandardSettings(); |
---|
| 229 | this->shieldWidget->setParent2D(this->leftRect); |
---|
[10449] | 230 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setDisplayedImage("textures/gui/gui_shield_icon.png"); |
---|
[10759] | 231 | if (!this->hidden) |
---|
| 232 | this->shieldWidget->show(); |
---|
| 233 | else |
---|
| 234 | this->shieldWidget->hide(); |
---|
[10368] | 235 | /* this->shieldWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
---|
| 236 | this->shieldWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
---|
| 237 | } |
---|
| 238 | else |
---|
| 239 | printf("schild im hud nicht uebergeben!!!!!!!!!!!!!!!!!!!!!!!!!"); |
---|
| 240 | |
---|
| 241 | this->updateResolution(); |
---|
| 242 | } |
---|
| 243 | |
---|
[10698] | 244 | void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget) |
---|
[10368] | 245 | { |
---|
[10698] | 246 | if( this->playmode == FirstPerson ) |
---|
| 247 | { |
---|
| 248 | this->healthWidget = new OrxGui::GLGuiBar(); |
---|
| 249 | dynamic_cast<OrxGui::GLGuiBar*> (this->healthWidget)->setMaximum(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->maximum()); |
---|
| 250 | dynamic_cast<OrxGui::GLGuiBar*> (this->healthWidget)->setValue(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->value()); |
---|
| 251 | this->healthWidget->setParent2D(this->barSocket); |
---|
| 252 | } |
---|
| 253 | else |
---|
| 254 | { |
---|
| 255 | /* |
---|
| 256 | if (this->shipValuesBox == NULL) |
---|
| 257 | this->createShipValuesBox(); |
---|
| 258 | */ |
---|
| 259 | |
---|
| 260 | // decopple old widget |
---|
| 261 | if (this->healthWidget != NULL) |
---|
| 262 | { |
---|
| 263 | this->healthWidget->hide(); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | this->healthWidget = widget; |
---|
| 267 | if (this->healthWidget != NULL) |
---|
| 268 | { |
---|
| 269 | //this->healthWidget->shiftDir2D(270); |
---|
| 270 | //this->shipValuesBox->pack(this->healthWidget); |
---|
| 271 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setStandardSettings(); |
---|
| 272 | this->healthWidget->setParent2D(this->leftRect); |
---|
| 273 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setDisplayedImage("textures/gui/gui_health_icon.png"); |
---|
[10759] | 274 | if(!this->hidden) |
---|
| 275 | this->healthWidget->show(); |
---|
| 276 | else |
---|
| 277 | this->healthWidget->hide(); |
---|
[10698] | 278 | /* this->healthWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
---|
| 279 | this->healthWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
---|
| 280 | } |
---|
| 281 | } |
---|
[6438] | 282 | |
---|
[10698] | 283 | this->updateResolution(); |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | |
---|
| 287 | void Hud::setImplantWidget(OrxGui::GLGuiWidget* widget) |
---|
| 288 | { |
---|
| 289 | //if (this->shipValuesBox == NULL) |
---|
| 290 | //this->createShipValuesBox(); |
---|
| 291 | |
---|
| 292 | // decopple old widget |
---|
| 293 | if (this->implantWidget != NULL) |
---|
[10368] | 294 | { |
---|
[10698] | 295 | this->implantWidget->hide(); |
---|
[10368] | 296 | } |
---|
| 297 | |
---|
[10698] | 298 | this->implantWidget = widget; |
---|
| 299 | if (this->implantWidget != NULL) |
---|
[10368] | 300 | { |
---|
[10698] | 301 | //this->energyWidget->shiftDir2D(270); |
---|
| 302 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics"); |
---|
| 303 | //this->shipValuesBox->pack(this->energyWidget); |
---|
| 304 | //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings(); |
---|
| 305 | this->implantWidget->setParent2D(this->leftRect); |
---|
| 306 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->implantWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png"); |
---|
[10759] | 307 | if (!this->hidden) |
---|
| 308 | this->implantWidget->show(); |
---|
| 309 | else |
---|
| 310 | this->implantWidget->hide(); |
---|
[10698] | 311 | /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
---|
| 312 | this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
---|
[10368] | 313 | } |
---|
| 314 | |
---|
| 315 | this->updateResolution(); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec) |
---|
[6442] | 319 | { |
---|
[10368] | 320 | //clearWeaponManager(); |
---|
| 321 | |
---|
| 322 | //Hide all widgets |
---|
[6442] | 323 | if (this->weaponManager != NULL) |
---|
| 324 | { |
---|
| 325 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
---|
| 326 | { |
---|
| 327 | Weapon* weapon = this->weaponManager->getWeapon(i); |
---|
| 328 | if (weapon != NULL) |
---|
| 329 | { |
---|
| 330 | weapon->getEnergyWidget()->hide(); |
---|
[10368] | 331 | //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
[6442] | 332 | } |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | |
---|
[10368] | 336 | if (this->weaponManagerSecondary != NULL) |
---|
| 337 | { |
---|
| 338 | for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) |
---|
| 339 | { |
---|
| 340 | Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); |
---|
| 341 | if (weapon != NULL) |
---|
| 342 | { |
---|
| 343 | weapon->getEnergyWidget()->hide(); |
---|
| 344 | //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | } |
---|
| 348 | |
---|
[6442] | 349 | this->weaponManager = weaponMan; |
---|
[10368] | 350 | this->weaponManagerSecondary = weaponManSec; |
---|
[6442] | 351 | |
---|
[6445] | 352 | this->updateWeaponManager(); |
---|
[8996] | 353 | // this->updateResolution(); |
---|
[6438] | 354 | } |
---|
| 355 | |
---|
[10368] | 356 | /* |
---|
| 357 | void Hud::clearWeaponManager() |
---|
| 358 | { |
---|
| 359 | //Hide all widgets |
---|
| 360 | if (this->weaponManager != NULL) |
---|
| 361 | { |
---|
| 362 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
---|
| 363 | { |
---|
| 364 | Weapon* weapon = this->weaponManager->getWeapon(i); |
---|
| 365 | if (weapon != NULL) |
---|
| 366 | { |
---|
| 367 | weapon->getEnergyWidget()->hide(); |
---|
| 368 | //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | if (this->weaponManagerSecondary != NULL) |
---|
| 374 | { |
---|
| 375 | for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) |
---|
| 376 | { |
---|
| 377 | Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); |
---|
| 378 | if (weapon != NULL) |
---|
| 379 | { |
---|
| 380 | weapon->getEnergyWidget()->hide(); |
---|
| 381 | //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
| 382 | } |
---|
| 383 | } |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | //this->weaponsWidgetsPrim.clear(); |
---|
| 387 | //this->weaponsWidgetsSec.clear(); |
---|
| 388 | } |
---|
| 389 | */ |
---|
| 390 | |
---|
[10716] | 391 | void Hud::setMode(Hud::Playmode playmode) |
---|
| 392 | { |
---|
| 393 | this->playmode = playmode; |
---|
| 394 | this->init(); |
---|
| 395 | } |
---|
| 396 | |
---|
[6443] | 397 | void Hud::updateWeaponManager() |
---|
| 398 | { |
---|
| 399 | // hide all the Widgets |
---|
[10368] | 400 | |
---|
| 401 | std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; |
---|
| 402 | for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) |
---|
[6443] | 403 | { |
---|
| 404 | (*weaponWidget)->hide(); |
---|
| 405 | } |
---|
[10368] | 406 | this->weaponsWidgetsPrim.clear(); |
---|
[6442] | 407 | |
---|
[10368] | 408 | for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) |
---|
| 409 | { |
---|
| 410 | (*weaponWidget)->hide(); |
---|
| 411 | } |
---|
| 412 | this->weaponsWidgetsSec.clear(); |
---|
| 413 | |
---|
| 414 | |
---|
[6443] | 415 | // add all that we need again. |
---|
[10368] | 416 | |
---|
[6443] | 417 | if (this->weaponManager != NULL) |
---|
| 418 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
---|
| 419 | { |
---|
[8518] | 420 | Weapon* weapon = this->weaponManager->getWeapon(i); |
---|
| 421 | if (weapon != NULL) |
---|
| 422 | { |
---|
[9406] | 423 | //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); |
---|
[10741] | 424 | if (this->playmode != FirstPerson) |
---|
| 425 | weapon->getEnergyWidget()->setParent2D(this->rightRect); |
---|
| 426 | else |
---|
| 427 | weapon->getEnergyWidget()->setParent2D(this->bottomRect); |
---|
[10759] | 428 | if (!this->hidden) |
---|
| 429 | weapon->getEnergyWidget()->show(); |
---|
| 430 | else |
---|
| 431 | weapon->getEnergyWidget()->hide(); |
---|
[8619] | 432 | weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); |
---|
[8518] | 433 | weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); |
---|
[10368] | 434 | weapon->getEnergyWidget()->setWidgetSize(120,30); |
---|
| 435 | //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); |
---|
| 436 | this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
[8518] | 437 | } |
---|
[6443] | 438 | } |
---|
[10368] | 439 | |
---|
| 440 | if (this->weaponManagerSecondary != NULL) |
---|
| 441 | for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) |
---|
| 442 | { |
---|
| 443 | Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); |
---|
| 444 | if (weapon != NULL) |
---|
| 445 | { |
---|
| 446 | //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); |
---|
| 447 | weapon->getEnergyWidget()->setParent2D(this->rightRect); |
---|
[10759] | 448 | if (!this->hidden) |
---|
| 449 | weapon->getEnergyWidget()->show(); |
---|
| 450 | else |
---|
| 451 | weapon->getEnergyWidget()->hide(); |
---|
[10368] | 452 | weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); |
---|
| 453 | weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); |
---|
| 454 | weapon->getEnergyWidget()->setWidgetSize(150,50); |
---|
| 455 | //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); |
---|
| 456 | this->weaponsWidgetsSec.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
| 457 | } |
---|
| 458 | } |
---|
| 459 | |
---|
[6443] | 460 | this->updateResolution(); |
---|
[10368] | 461 | |
---|
[6443] | 462 | } |
---|
| 463 | |
---|
[8145] | 464 | void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget) |
---|
[8518] | 465 | {} |
---|
[6438] | 466 | |
---|
[8145] | 467 | void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget) |
---|
[8518] | 468 | {} |
---|
[6438] | 469 | |
---|
[10744] | 470 | void Hud::getHit() |
---|
| 471 | { |
---|
[10759] | 472 | printf("Got hit!\n"); |
---|
[10744] | 473 | this->leftHit->show(); |
---|
| 474 | this->rightHit->show(); |
---|
[10748] | 475 | hitBarCount = 0.33; |
---|
[10744] | 476 | } |
---|
| 477 | |
---|
[10748] | 478 | void Hud::tick(float dt) |
---|
| 479 | { |
---|
| 480 | |
---|
| 481 | if (this->playmode == FirstPerson && this->leftHit != NULL) |
---|
| 482 | { |
---|
| 483 | if (this->ifinit) |
---|
| 484 | { |
---|
| 485 | this->leftHit->shiftDir2D(3.1416); |
---|
| 486 | this->ifinit = false; |
---|
| 487 | } |
---|
| 488 | if (this->leftHit->isVisible()) |
---|
[10759] | 489 | { |
---|
[10748] | 490 | hitBarCount -= dt; |
---|
[10759] | 491 | printf("Reduce visibilty!\n"); |
---|
| 492 | } |
---|
| 493 | if (hitBarCount <= 0) |
---|
[10748] | 494 | { |
---|
| 495 | hitBarCount = 0; |
---|
| 496 | this->leftHit->hide(); |
---|
| 497 | this->rightHit->hide(); |
---|
[10759] | 498 | printf("Hide again!\n"); |
---|
[10748] | 499 | } |
---|
| 500 | } |
---|
[10759] | 501 | //Crosshair* crosshair = dynamic_cast<Crosshair*>(this->weaponManager->getFixedTarget()); |
---|
| 502 | if ((State::getCamera())->getName() == "GameWorldCamera") |
---|
| 503 | { |
---|
| 504 | this->hidden = false; |
---|
| 505 | if(this->weaponManager) |
---|
| 506 | this->weaponManager->showCrosshair(); |
---|
| 507 | } |
---|
| 508 | else |
---|
| 509 | { |
---|
| 510 | this->hidden = true; |
---|
| 511 | if(this->weaponManager) |
---|
| 512 | this->weaponManager->hideCrosshair(); |
---|
| 513 | } |
---|
| 514 | this->updateResolution(); |
---|
[10748] | 515 | } |
---|
| 516 | |
---|
[6441] | 517 | void Hud::updateResolution() |
---|
| 518 | { |
---|
[6498] | 519 | this->resX = State::getResX(); |
---|
| 520 | this->resY = State::getResY(); |
---|
[8976] | 521 | |
---|
[10716] | 522 | this->setSize2D(this->resX, this->resY); |
---|
[10698] | 523 | if( this->playmode != FirstPerson ) |
---|
| 524 | { |
---|
| 525 | this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY); |
---|
| 526 | this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY); |
---|
| 527 | } |
---|
[8976] | 528 | |
---|
[10368] | 529 | int overlayWidth = 0; |
---|
| 530 | if (overlayPercentage >= 20) |
---|
| 531 | overlayWidth = this->resX * (overlayPercentage)/(200); |
---|
| 532 | else |
---|
[10698] | 533 | overlayWidth = this->resX / 10; // fixed warning! |
---|
[10368] | 534 | //if (overlayWidth < 100) |
---|
| 535 | //overlayWidth = 100; |
---|
[8995] | 536 | |
---|
[10368] | 537 | this->rightRect->hide(); |
---|
| 538 | this->leftRect->hide(); |
---|
[10698] | 539 | |
---|
| 540 | if( this->playmode != FirstPerson ) |
---|
| 541 | { |
---|
[10716] | 542 | |
---|
[10698] | 543 | this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY)); |
---|
| 544 | this->leftRect->setAbsCoor2D(0,0); |
---|
[10736] | 545 | this->leftRect->setBackgroundTexture(Texture()); |
---|
[10698] | 546 | this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2)); |
---|
| 547 | this->leftRect->setForegroundTexture(Texture()); |
---|
[10736] | 548 | this->leftRect->setForegroundColor(Color(0,0,0,0)); |
---|
[10716] | 549 | |
---|
[10698] | 550 | this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY)); |
---|
| 551 | this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0); |
---|
[10736] | 552 | this->rightRect->setBackgroundTexture(Texture()); |
---|
[10698] | 553 | this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2)); |
---|
| 554 | this->rightRect->setForegroundTexture(Texture()); |
---|
[10736] | 555 | this->rightRect->setForegroundColor(Color(0,0,0,0)); |
---|
[10698] | 556 | } |
---|
| 557 | else |
---|
| 558 | { |
---|
[10736] | 559 | this->bottomRect->setParent2D(this); |
---|
| 560 | this->bottomRect->setWidgetSize(float(this->resX), float(overlayWidth)); |
---|
| 561 | this->bottomRect->setAbsCoor2D(0, this->resY - overlayWidth); |
---|
[10759] | 562 | //this->bottomRect->show(); |
---|
[10736] | 563 | |
---|
| 564 | this->topRect->setParent2D(this); |
---|
| 565 | this->topRect->setWidgetSize(float(this->resX), float(overlayWidth)); |
---|
| 566 | this->topRect->setAbsCoor2D(0, 0); |
---|
[10759] | 567 | //this->topRect->show(); |
---|
[10736] | 568 | |
---|
| 569 | this->middleRect->setParent2D(this); |
---|
[10741] | 570 | this->middleRect->setWidgetSize(float(this->resY)/2, float(this->resY)/2); |
---|
| 571 | this->middleRect->setAbsCoor2D(float(this->resX)/4, float(this->resY)/4/*float(this->resX/2), float(this->resY/2)*/); |
---|
[10759] | 572 | //this->middleRect->show(); |
---|
[10736] | 573 | |
---|
[10741] | 574 | /*this->bottomHit->setRelCoor2D(0, this->resY/4); |
---|
| 575 | this->bottomHit->setWidgetSize(this->resX/8, this->resX/3); |
---|
[10736] | 576 | this->bottomHit->show(); |
---|
| 577 | this->topHit->setRelCoor2D(0, -this->resY/4); |
---|
[10741] | 578 | this->topHit->setWidgetSize(this->resX/8, this->resX/3); |
---|
| 579 | this->topHit->show();*/ |
---|
| 580 | this->leftHit->setRelCoor2D(0, 0); |
---|
| 581 | this->leftHit->setWidgetSize(this->resX/9, this->resX/3); |
---|
[10759] | 582 | //this->leftHit->hide(); |
---|
[10741] | 583 | this->rightHit->setRelCoor2D(this->resX/3, 0); |
---|
| 584 | this->rightHit->setWidgetSize(this->resX/9, this->resX/3); |
---|
[10759] | 585 | //this->rightHit->hide(); |
---|
[10717] | 586 | |
---|
[10741] | 587 | this->barSocket->setWidgetSize(overlayWidth, overlayWidth); |
---|
| 588 | this->barSocket->setRelCoor2D(this->resX - overlayWidth, 0); |
---|
[10759] | 589 | if (!this->hidden) |
---|
| 590 | this->barSocket->show(); |
---|
| 591 | else |
---|
| 592 | this->barSocket->hide(); |
---|
[10741] | 593 | |
---|
[10736] | 594 | //this->middleRect->show(); |
---|
| 595 | |
---|
| 596 | |
---|
[10698] | 597 | } |
---|
[10368] | 598 | |
---|
[10759] | 599 | if (this->overlayActive && !this->hidden) |
---|
[10368] | 600 | { |
---|
| 601 | this->rightRect->show(); |
---|
| 602 | this->leftRect->show(); |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | |
---|
[8996] | 606 | if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager()) |
---|
| 607 | { |
---|
[9869] | 608 | PRINTF(4)("UPDATING RADAR\n"); |
---|
[10698] | 609 | if( this->playmode != FirstPerson ) |
---|
| 610 | this->_radar->setParent2D(this->leftRect); |
---|
| 611 | else |
---|
| 612 | this->_radar->setParent2D(this->topRect); |
---|
[10368] | 613 | if (radarCenterNode == NULL) |
---|
| 614 | this->_radar->setCenterNode(State::getPlayer()->getPlayable()); |
---|
| 615 | else |
---|
| 616 | this->_radar->setCenterNode(this->radarCenterNode); |
---|
| 617 | |
---|
| 618 | //this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0)); |
---|
| 619 | this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_00), Color(1, 0, 0)); |
---|
| 620 | this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_01), Color(0, 0, 1)); |
---|
| 621 | this->_radar->setAbsCoor2D(0, 0.01 * this->resY); |
---|
| 622 | this->_radar->setWidgetSize(overlayWidth, overlayWidth); |
---|
[9014] | 623 | this->_radar->setRange(300); |
---|
[10759] | 624 | if (!this->hidden) |
---|
| 625 | this->_radar->show(); |
---|
| 626 | else |
---|
| 627 | this->_radar->hide(); |
---|
[10368] | 628 | |
---|
| 629 | int statWidgetsNumber = 0; |
---|
[10698] | 630 | float expectedHealthSizeX = 0; |
---|
| 631 | float expectedHealthSizeY = 0; |
---|
[10368] | 632 | float newSizeY = 0; float newSizeX = 0; |
---|
| 633 | float moduloWidth = 0; |
---|
| 634 | |
---|
[10698] | 635 | if( this->playmode != FirstPerson ) |
---|
| 636 | { |
---|
| 637 | if (this->healthWidget != NULL) |
---|
| 638 | { |
---|
| 639 | expectedHealthSizeX = 150; |
---|
| 640 | expectedHealthSizeY = 50; |
---|
| 641 | statWidgetsNumber++; |
---|
| 642 | } |
---|
[10368] | 643 | |
---|
[10698] | 644 | if (this->shieldWidget != NULL) |
---|
| 645 | statWidgetsNumber++; |
---|
| 646 | |
---|
| 647 | if (this->energyWidget != NULL) |
---|
| 648 | statWidgetsNumber++; |
---|
| 649 | |
---|
[10721] | 650 | if ((expectedHealthSizeY * statWidgetsNumber) > overlayWidth) |
---|
[10698] | 651 | { |
---|
| 652 | newSizeY = overlayWidth / float(statWidgetsNumber); |
---|
| 653 | newSizeX = expectedHealthSizeX; |
---|
| 654 | PRINTF(0)("Statwidgets resized\n"); |
---|
| 655 | } |
---|
| 656 | else |
---|
| 657 | { |
---|
| 658 | newSizeY = expectedHealthSizeY; |
---|
| 659 | newSizeX = expectedHealthSizeX; |
---|
| 660 | moduloWidth = int(overlayWidth) % int(expectedHealthSizeY * statWidgetsNumber); |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | float posY = overlayWidth + newSizeX; |
---|
| 664 | |
---|
| 665 | if (this->healthWidget != NULL) |
---|
| 666 | { |
---|
| 667 | this->healthWidget->setSize2D(newSizeX, newSizeY); |
---|
| 668 | this->healthWidget->setRelCoor2D((statWidgetsNumber - 1) * newSizeY + 3 * moduloWidth / (statWidgetsNumber + 1),posY); |
---|
| 669 | } |
---|
| 670 | if (this->shieldWidget != NULL) |
---|
| 671 | { |
---|
| 672 | this->shieldWidget->setSize2D(newSizeX, newSizeY); |
---|
| 673 | this->shieldWidget->setRelCoor2D((statWidgetsNumber - 2) * newSizeY + 2 *moduloWidth / (statWidgetsNumber + 1),posY); |
---|
| 674 | } |
---|
| 675 | if (this->energyWidget != NULL) |
---|
| 676 | { |
---|
| 677 | this->energyWidget->setSize2D(newSizeX, newSizeY); |
---|
| 678 | this->energyWidget->setRelCoor2D(moduloWidth / (statWidgetsNumber + 1),posY); |
---|
| 679 | } |
---|
| 680 | } |
---|
| 681 | else |
---|
| 682 | { |
---|
| 683 | this->barSocket->setParent2D(this->bottomRect); |
---|
| 684 | this->barSocket->setWidgetSize( float(overlayWidth), float(overlayWidth)); |
---|
[10759] | 685 | this->barSocket->setRelCoor2D(this->resX - float(overlayWidth),0); |
---|
| 686 | this->barSocket->show(); |
---|
[10698] | 687 | |
---|
| 688 | this->healthWidget->setRelCoor2D(10,-20); |
---|
| 689 | } |
---|
| 690 | |
---|
[10368] | 691 | |
---|
| 692 | /* |
---|
[10698] | 693 | if (this->healthWidget != NULL) |
---|
| 694 | this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D()); |
---|
[10368] | 695 | if (this->shieldWidget != NULL) |
---|
[10698] | 696 | this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D()); |
---|
[10368] | 697 | if (this->energyWidget != NULL) |
---|
[10698] | 698 | this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D()); |
---|
[10368] | 699 | */ |
---|
[10698] | 700 | //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D(),0); |
---|
| 701 | //this->energyWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0); |
---|
[8996] | 702 | } |
---|
| 703 | |
---|
[10368] | 704 | /* |
---|
| 705 | if (this->shipValuesBox != NULL) |
---|
[6441] | 706 | { |
---|
[10368] | 707 | this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY); |
---|
| 708 | this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY); |
---|
[6441] | 709 | } |
---|
[10368] | 710 | else |
---|
| 711 | createShipValuesBox(); |
---|
| 712 | */ |
---|
[6442] | 713 | |
---|
[10368] | 714 | std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; |
---|
| 715 | Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY); |
---|
| 716 | float largestWidgetSizeX = 0; |
---|
| 717 | //PRINTF(0)("Cur Pos: %f,%f\n",pos.x,pos.y); |
---|
| 718 | // out of reasons i can't get behind, this version is segfaulting when calling getSizeX2D or getSizeY2D. the other |
---|
| 719 | // element2D- related function works tough.. :s |
---|
[6442] | 720 | |
---|
[10368] | 721 | for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) |
---|
[6442] | 722 | { |
---|
[10368] | 723 | float ySize = (*weaponWidget)->getSizeY2D(); |
---|
| 724 | float xSize = (*weaponWidget)->getSizeX2D(); |
---|
| 725 | if (xSize > largestWidgetSizeX) |
---|
| 726 | largestWidgetSizeX = xSize; |
---|
| 727 | if (pos.x < ySize) |
---|
[8987] | 728 | { |
---|
[10368] | 729 | pos.x = overlayWidth; |
---|
| 730 | pos.y += largestWidgetSizeX; |
---|
| 731 | } |
---|
| 732 | pos.x -= ySize; |
---|
| 733 | (*weaponWidget)->setAbsCoor2D(pos.x + this->rightRect->getAbsCoor2D().x, pos.y); |
---|
| 734 | //(*weaponWidget)->setAbsCoor2D(0,100); |
---|
[10759] | 735 | if (!this->hidden) |
---|
| 736 | (*weaponWidget)->show(); |
---|
| 737 | else |
---|
| 738 | (*weaponWidget)->hide(); |
---|
[10368] | 739 | //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | weaponWidget = this->weaponsWidgetsSec.begin(); |
---|
| 743 | float expectedWidgetSizeY = 0; |
---|
| 744 | if (weaponWidget != this->weaponsWidgetsSec.end()) |
---|
| 745 | { |
---|
| 746 | expectedWidgetSizeY = (*weaponWidget)->getSizeY2D(); |
---|
| 747 | } |
---|
| 748 | pos.y = resY - expectedWidgetSizeY * 0.6; |
---|
| 749 | pos.x = overlayWidth + this->rightRect->getAbsCoor2D().x; |
---|
[8987] | 750 | |
---|
[10368] | 751 | for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) |
---|
| 752 | { |
---|
| 753 | float ySize = (*weaponWidget)->getSizeY2D(); |
---|
| 754 | float xSize = (*weaponWidget)->getSizeX2D(); |
---|
| 755 | if (xSize > largestWidgetSizeX) |
---|
| 756 | largestWidgetSizeX = xSize; |
---|
| 757 | if (pos.x < ySize) |
---|
| 758 | { |
---|
| 759 | pos.x = overlayWidth; |
---|
| 760 | pos.y -= largestWidgetSizeX + expectedWidgetSizeY * 0.6; |
---|
[8987] | 761 | } |
---|
[10368] | 762 | pos.x -= ySize; |
---|
| 763 | //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D()); |
---|
[10516] | 764 | (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);//+this->rightRect->getAbsCoor2D().x, pos.y); |
---|
[10759] | 765 | if (!this->hidden) |
---|
| 766 | (*weaponWidget)->show(); |
---|
| 767 | else |
---|
| 768 | (*weaponWidget)->hide(); |
---|
[9406] | 769 | //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); |
---|
[6442] | 770 | } |
---|
[10368] | 771 | |
---|
[6441] | 772 | } |
---|
| 773 | |
---|
[8990] | 774 | void Hud::draw() const |
---|
[6441] | 775 | { |
---|
[8990] | 776 | // GLGuiWidget::draw(); |
---|
[6441] | 777 | } |
---|
| 778 | |
---|
[8990] | 779 | |
---|
| 780 | void Hud::process(const Event &event) |
---|
[6441] | 781 | { |
---|
[8990] | 782 | if (event.type == EV_VIDEO_RESIZE) |
---|
| 783 | this->updateResolution(); |
---|
[9003] | 784 | else if (event.type == SDLK_TAB) |
---|
| 785 | { |
---|
| 786 | /// TODO SHOW THE INPUT-LINE |
---|
| 787 | // this->inputLine->select(); |
---|
| 788 | } |
---|
[10368] | 789 | } |
---|
[9003] | 790 | |
---|
[10368] | 791 | /* |
---|
| 792 | void Hud::createShipValuesBox() |
---|
| 793 | { |
---|
| 794 | this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical); |
---|
| 795 | //this->shipValuesBox->setWidgetSize(1000,500); |
---|
[10420] | 796 | //this->shipValuesBox->setBackgroundTexture("textures/gui_container_background.png"); |
---|
[10368] | 797 | this->shipValuesBox->setBackgroundTexture(Texture()); |
---|
| 798 | this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5)); |
---|
| 799 | this->shipValuesBox->setVisibility(true); |
---|
[6441] | 800 | } |
---|
[10368] | 801 | */ |
---|
[6441] | 802 | |
---|
| 803 | |
---|