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