[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 | |
---|
[8996] | 35 | |
---|
| 36 | |
---|
| 37 | /// HACK |
---|
| 38 | #include "player.h" |
---|
| 39 | #include "playable.h" |
---|
| 40 | |
---|
[9869] | 41 | ObjectListDefinition(Hud); |
---|
[3245] | 42 | /** |
---|
[4838] | 43 | * standard constructor |
---|
| 44 | * @todo this constructor is not jet implemented - do it |
---|
[3245] | 45 | */ |
---|
[6437] | 46 | Hud::Hud () |
---|
[3365] | 47 | { |
---|
[9869] | 48 | this->registerObject(this, Hud::_objectList); |
---|
[4320] | 49 | |
---|
[6441] | 50 | //this->setSize2D( |
---|
[6442] | 51 | this->weaponManager = NULL; |
---|
[10368] | 52 | this->weaponManagerSecondary = NULL; |
---|
[6440] | 53 | this->energyWidget = NULL; |
---|
| 54 | this->shieldWidget = NULL; |
---|
[10698] | 55 | this->healthWidget = NULL; |
---|
| 56 | this->leftRect = NULL; |
---|
| 57 | this->rightRect = NULL; |
---|
[6441] | 58 | this->resX = 1; |
---|
| 59 | this->resY = 1; |
---|
[6442] | 60 | |
---|
[10716] | 61 | this->init(); |
---|
[10717] | 62 | |
---|
[10698] | 63 | |
---|
[3365] | 64 | } |
---|
[1853] | 65 | |
---|
| 66 | |
---|
[3245] | 67 | /** |
---|
[4838] | 68 | * standard deconstructor |
---|
[3245] | 69 | */ |
---|
[6437] | 70 | Hud::~Hud () |
---|
[3543] | 71 | { |
---|
[8518] | 72 | delete this->inputLine; |
---|
| 73 | delete this->notifier; |
---|
[10741] | 74 | delete this->leftHit; |
---|
| 75 | delete this->rightHit; |
---|
[8994] | 76 | |
---|
[8995] | 77 | delete this->_radar; |
---|
[10698] | 78 | delete this->barSocket; |
---|
[10368] | 79 | delete this->rightRect; |
---|
| 80 | delete this->leftRect; |
---|
[10698] | 81 | delete this->topRect; |
---|
| 82 | delete this->bottomRect; |
---|
| 83 | delete this->middleRect; |
---|
[10716] | 84 | |
---|
[10698] | 85 | |
---|
[10368] | 86 | //if (this->shipValuesBox != NULL) |
---|
| 87 | //delete this->shipValuesBox; |
---|
| 88 | |
---|
[3543] | 89 | // delete what has to be deleted here |
---|
| 90 | } |
---|
[6438] | 91 | |
---|
[10716] | 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(); |
---|
[6438] | 101 | |
---|
[10716] | 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 | |
---|
[10741] | 108 | |
---|
[10716] | 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 | { |
---|
[10741] | 118 | /*this->topHit = new OrxGui::GLGuiImage(); |
---|
[10716] | 119 | this->topHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
| 120 | this->topHit->setParent2D(this->middleRect); |
---|
[10741] | 121 | this->topHit->setAbsDir2D(-1.5708); |
---|
[10716] | 122 | |
---|
| 123 | this->bottomHit = new OrxGui::GLGuiImage(); |
---|
| 124 | this->bottomHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
| 125 | this->bottomHit->setParent2D(this->middleRect); |
---|
[10741] | 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); |
---|
[10716] | 131 | |
---|
| 132 | this->leftHit = new OrxGui::GLGuiImage(); |
---|
| 133 | this->leftHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
| 134 | this->leftHit->setParent2D(this->middleRect); |
---|
[10741] | 135 | this->leftHit->shiftDir2D(0.5); |
---|
[10716] | 136 | |
---|
| 137 | this->rightHit = new OrxGui::GLGuiImage(); |
---|
| 138 | this->rightHit->loadImageFromFile("textures/gui/gui_hitbar.png"); |
---|
| 139 | this->rightHit->setParent2D(this->middleRect); |
---|
| 140 | |
---|
[10741] | 141 | |
---|
[10716] | 142 | this->leftRect->setParent2D(this); |
---|
| 143 | this->rightRect->setParent2D(this); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | //this->shipValuesBox = NULL; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | |
---|
[6438] | 150 | void Hud::loadParams(const TiXmlElement* root) |
---|
| 151 | { |
---|
[6512] | 152 | Element2D::loadParams(root); |
---|
[6438] | 153 | } |
---|
| 154 | |
---|
[8518] | 155 | void Hud::notifyUser(const std::string& message) |
---|
[6438] | 156 | { |
---|
[8518] | 157 | this->notifier->pushNotifyMessage(message); |
---|
[6438] | 158 | } |
---|
| 159 | |
---|
[8518] | 160 | void Hud::setBackGround() |
---|
| 161 | {} |
---|
| 162 | |
---|
[8145] | 163 | void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget) |
---|
[6438] | 164 | { |
---|
[10368] | 165 | //if (this->shipValuesBox == NULL) |
---|
| 166 | //this->createShipValuesBox(); |
---|
| 167 | |
---|
[6440] | 168 | // decopple old widget |
---|
| 169 | if (this->energyWidget != NULL) |
---|
| 170 | { |
---|
| 171 | this->energyWidget->hide(); |
---|
| 172 | } |
---|
[6438] | 173 | |
---|
[6440] | 174 | this->energyWidget = widget; |
---|
| 175 | if (this->energyWidget != NULL) |
---|
| 176 | { |
---|
[10368] | 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); |
---|
[10449] | 182 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png"); |
---|
[6440] | 183 | this->energyWidget->show(); |
---|
[8518] | 184 | /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
---|
| 185 | this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
---|
[6440] | 186 | } |
---|
| 187 | |
---|
[10698] | 188 | this->updateResolution(); |
---|
[6438] | 189 | } |
---|
| 190 | |
---|
[10698] | 191 | void Hud::setShieldWidget(OrxGui::GLGuiWidget* widget) |
---|
[10368] | 192 | { |
---|
| 193 | /* |
---|
| 194 | if (this->shipValuesBox == NULL) |
---|
| 195 | this->createShipValuesBox(); |
---|
| 196 | */ |
---|
[6438] | 197 | |
---|
[10368] | 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); |
---|
[10449] | 211 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setDisplayedImage("textures/gui/gui_shield_icon.png"); |
---|
[10368] | 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 | |
---|
[10698] | 222 | void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget) |
---|
[10368] | 223 | { |
---|
[10698] | 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 | } |
---|
[6438] | 257 | |
---|
[10698] | 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) |
---|
[10368] | 269 | { |
---|
[10698] | 270 | this->implantWidget->hide(); |
---|
[10368] | 271 | } |
---|
| 272 | |
---|
[10698] | 273 | this->implantWidget = widget; |
---|
| 274 | if (this->implantWidget != NULL) |
---|
[10368] | 275 | { |
---|
[10698] | 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);*/ |
---|
[10368] | 285 | } |
---|
| 286 | |
---|
| 287 | this->updateResolution(); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec) |
---|
[6442] | 291 | { |
---|
[10368] | 292 | //clearWeaponManager(); |
---|
| 293 | |
---|
| 294 | //Hide all widgets |
---|
[6442] | 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(); |
---|
[10368] | 303 | //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
[6442] | 304 | } |
---|
| 305 | } |
---|
| 306 | } |
---|
| 307 | |
---|
[10368] | 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 | |
---|
[6442] | 321 | this->weaponManager = weaponMan; |
---|
[10368] | 322 | this->weaponManagerSecondary = weaponManSec; |
---|
[6442] | 323 | |
---|
[6445] | 324 | this->updateWeaponManager(); |
---|
[8996] | 325 | // this->updateResolution(); |
---|
[6438] | 326 | } |
---|
| 327 | |
---|
[10368] | 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 | |
---|
[10716] | 363 | void Hud::setMode(Hud::Playmode playmode) |
---|
| 364 | { |
---|
| 365 | this->playmode = playmode; |
---|
| 366 | this->init(); |
---|
| 367 | } |
---|
| 368 | |
---|
[6443] | 369 | void Hud::updateWeaponManager() |
---|
| 370 | { |
---|
| 371 | // hide all the Widgets |
---|
[10368] | 372 | |
---|
| 373 | std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; |
---|
| 374 | for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) |
---|
[6443] | 375 | { |
---|
| 376 | (*weaponWidget)->hide(); |
---|
| 377 | } |
---|
[10368] | 378 | this->weaponsWidgetsPrim.clear(); |
---|
[6442] | 379 | |
---|
[10368] | 380 | for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) |
---|
| 381 | { |
---|
| 382 | (*weaponWidget)->hide(); |
---|
| 383 | } |
---|
| 384 | this->weaponsWidgetsSec.clear(); |
---|
| 385 | |
---|
| 386 | |
---|
[6443] | 387 | // add all that we need again. |
---|
[10368] | 388 | |
---|
[6443] | 389 | if (this->weaponManager != NULL) |
---|
| 390 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
---|
| 391 | { |
---|
[8518] | 392 | Weapon* weapon = this->weaponManager->getWeapon(i); |
---|
| 393 | if (weapon != NULL) |
---|
| 394 | { |
---|
[9406] | 395 | //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); |
---|
[10741] | 396 | if (this->playmode != FirstPerson) |
---|
| 397 | weapon->getEnergyWidget()->setParent2D(this->rightRect); |
---|
| 398 | else |
---|
| 399 | weapon->getEnergyWidget()->setParent2D(this->bottomRect); |
---|
[8518] | 400 | weapon->getEnergyWidget()->show(); |
---|
[8619] | 401 | weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); |
---|
[8518] | 402 | weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); |
---|
[10368] | 403 | weapon->getEnergyWidget()->setWidgetSize(120,30); |
---|
| 404 | //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); |
---|
| 405 | this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
---|
[8518] | 406 | } |
---|
[6443] | 407 | } |
---|
[10368] | 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 | |
---|
[6443] | 426 | this->updateResolution(); |
---|
[10368] | 427 | |
---|
[6443] | 428 | } |
---|
| 429 | |
---|
[8145] | 430 | void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget) |
---|
[8518] | 431 | {} |
---|
[6438] | 432 | |
---|
[8145] | 433 | void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget) |
---|
[8518] | 434 | {} |
---|
[6438] | 435 | |
---|
[10744] | 436 | void Hud::getHit() |
---|
| 437 | { |
---|
| 438 | this->leftHit->show(); |
---|
| 439 | this->rightHit->show(); |
---|
| 440 | } |
---|
| 441 | |
---|
[6441] | 442 | void Hud::updateResolution() |
---|
| 443 | { |
---|
[6498] | 444 | this->resX = State::getResX(); |
---|
| 445 | this->resY = State::getResY(); |
---|
[8976] | 446 | |
---|
[10716] | 447 | this->setSize2D(this->resX, this->resY); |
---|
[10698] | 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 | } |
---|
[8976] | 453 | |
---|
[10368] | 454 | int overlayWidth = 0; |
---|
| 455 | if (overlayPercentage >= 20) |
---|
| 456 | overlayWidth = this->resX * (overlayPercentage)/(200); |
---|
| 457 | else |
---|
[10698] | 458 | overlayWidth = this->resX / 10; // fixed warning! |
---|
[10368] | 459 | //if (overlayWidth < 100) |
---|
| 460 | //overlayWidth = 100; |
---|
[8995] | 461 | |
---|
[10368] | 462 | this->rightRect->hide(); |
---|
| 463 | this->leftRect->hide(); |
---|
[10698] | 464 | |
---|
| 465 | if( this->playmode != FirstPerson ) |
---|
| 466 | { |
---|
[10716] | 467 | |
---|
[10698] | 468 | this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY)); |
---|
| 469 | this->leftRect->setAbsCoor2D(0,0); |
---|
[10736] | 470 | this->leftRect->setBackgroundTexture(Texture()); |
---|
[10698] | 471 | this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2)); |
---|
| 472 | this->leftRect->setForegroundTexture(Texture()); |
---|
[10736] | 473 | this->leftRect->setForegroundColor(Color(0,0,0,0)); |
---|
[10716] | 474 | |
---|
[10698] | 475 | this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY)); |
---|
| 476 | this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0); |
---|
[10736] | 477 | this->rightRect->setBackgroundTexture(Texture()); |
---|
[10698] | 478 | this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2)); |
---|
| 479 | this->rightRect->setForegroundTexture(Texture()); |
---|
[10736] | 480 | this->rightRect->setForegroundColor(Color(0,0,0,0)); |
---|
[10698] | 481 | } |
---|
| 482 | else |
---|
| 483 | { |
---|
[10736] | 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); |
---|
[10741] | 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)*/); |
---|
[10736] | 495 | |
---|
[10741] | 496 | /*this->bottomHit->setRelCoor2D(0, this->resY/4); |
---|
| 497 | this->bottomHit->setWidgetSize(this->resX/8, this->resX/3); |
---|
[10736] | 498 | this->bottomHit->show(); |
---|
| 499 | this->topHit->setRelCoor2D(0, -this->resY/4); |
---|
[10741] | 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); |
---|
[10736] | 504 | this->leftHit->show(); |
---|
[10741] | 505 | this->rightHit->setRelCoor2D(this->resX/3, 0); |
---|
| 506 | this->rightHit->setWidgetSize(this->resX/9, this->resX/3); |
---|
| 507 | this->rightHit->hide(); |
---|
[10717] | 508 | |
---|
[10741] | 509 | this->barSocket->setWidgetSize(overlayWidth, overlayWidth); |
---|
| 510 | this->barSocket->setRelCoor2D(this->resX - overlayWidth, 0); |
---|
| 511 | this->barSocket->hide(); |
---|
| 512 | |
---|
[10736] | 513 | //this->middleRect->show(); |
---|
| 514 | |
---|
| 515 | |
---|
[10698] | 516 | } |
---|
[10368] | 517 | |
---|
[10736] | 518 | if (this->overlayActive) |
---|
[10368] | 519 | { |
---|
| 520 | this->rightRect->show(); |
---|
| 521 | this->leftRect->show(); |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | |
---|
[8996] | 525 | if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager()) |
---|
| 526 | { |
---|
[9869] | 527 | PRINTF(4)("UPDATING RADAR\n"); |
---|
[10698] | 528 | if( this->playmode != FirstPerson ) |
---|
| 529 | this->_radar->setParent2D(this->leftRect); |
---|
| 530 | else |
---|
| 531 | this->_radar->setParent2D(this->topRect); |
---|
[10368] | 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); |
---|
[9014] | 542 | this->_radar->setRange(300); |
---|
[8996] | 543 | this->_radar->show(); |
---|
[10368] | 544 | |
---|
| 545 | int statWidgetsNumber = 0; |
---|
[10698] | 546 | float expectedHealthSizeX = 0; |
---|
| 547 | float expectedHealthSizeY = 0; |
---|
[10368] | 548 | float newSizeY = 0; float newSizeX = 0; |
---|
| 549 | float moduloWidth = 0; |
---|
| 550 | |
---|
[10698] | 551 | if( this->playmode != FirstPerson ) |
---|
| 552 | { |
---|
| 553 | if (this->healthWidget != NULL) |
---|
| 554 | { |
---|
| 555 | expectedHealthSizeX = 150; |
---|
| 556 | expectedHealthSizeY = 50; |
---|
| 557 | statWidgetsNumber++; |
---|
| 558 | } |
---|
[10368] | 559 | |
---|
[10698] | 560 | if (this->shieldWidget != NULL) |
---|
| 561 | statWidgetsNumber++; |
---|
| 562 | |
---|
| 563 | if (this->energyWidget != NULL) |
---|
| 564 | statWidgetsNumber++; |
---|
| 565 | |
---|
[10721] | 566 | if ((expectedHealthSizeY * statWidgetsNumber) > overlayWidth) |
---|
[10698] | 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 | |
---|
[10368] | 606 | |
---|
| 607 | /* |
---|
[10698] | 608 | if (this->healthWidget != NULL) |
---|
| 609 | this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D()); |
---|
[10368] | 610 | if (this->shieldWidget != NULL) |
---|
[10698] | 611 | this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D()); |
---|
[10368] | 612 | if (this->energyWidget != NULL) |
---|
[10698] | 613 | this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D()); |
---|
[10368] | 614 | */ |
---|
[10698] | 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); |
---|
[8996] | 617 | } |
---|
| 618 | |
---|
[10368] | 619 | /* |
---|
| 620 | if (this->shipValuesBox != NULL) |
---|
[6441] | 621 | { |
---|
[10368] | 622 | this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY); |
---|
| 623 | this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY); |
---|
[6441] | 624 | } |
---|
[10368] | 625 | else |
---|
| 626 | createShipValuesBox(); |
---|
| 627 | */ |
---|
[6442] | 628 | |
---|
[10368] | 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 |
---|
[6442] | 635 | |
---|
[10368] | 636 | for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) |
---|
[6442] | 637 | { |
---|
[10368] | 638 | float ySize = (*weaponWidget)->getSizeY2D(); |
---|
| 639 | float xSize = (*weaponWidget)->getSizeX2D(); |
---|
| 640 | if (xSize > largestWidgetSizeX) |
---|
| 641 | largestWidgetSizeX = xSize; |
---|
| 642 | if (pos.x < ySize) |
---|
[8987] | 643 | { |
---|
[10368] | 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; |
---|
[8987] | 662 | |
---|
[10368] | 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; |
---|
[8987] | 673 | } |
---|
[10368] | 674 | pos.x -= ySize; |
---|
| 675 | //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D()); |
---|
[10516] | 676 | (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);//+this->rightRect->getAbsCoor2D().x, pos.y); |
---|
[8976] | 677 | (*weaponWidget)->show(); |
---|
[9406] | 678 | //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); |
---|
[6442] | 679 | } |
---|
[10368] | 680 | |
---|
[6441] | 681 | } |
---|
| 682 | |
---|
[8990] | 683 | void Hud::draw() const |
---|
[6441] | 684 | { |
---|
[8990] | 685 | // GLGuiWidget::draw(); |
---|
[6441] | 686 | } |
---|
| 687 | |
---|
[8990] | 688 | |
---|
| 689 | void Hud::process(const Event &event) |
---|
[6441] | 690 | { |
---|
[8990] | 691 | if (event.type == EV_VIDEO_RESIZE) |
---|
| 692 | this->updateResolution(); |
---|
[9003] | 693 | else if (event.type == SDLK_TAB) |
---|
| 694 | { |
---|
| 695 | /// TODO SHOW THE INPUT-LINE |
---|
| 696 | // this->inputLine->select(); |
---|
| 697 | } |
---|
[10368] | 698 | } |
---|
[9003] | 699 | |
---|
[10368] | 700 | /* |
---|
| 701 | void Hud::createShipValuesBox() |
---|
| 702 | { |
---|
| 703 | this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical); |
---|
| 704 | //this->shipValuesBox->setWidgetSize(1000,500); |
---|
[10420] | 705 | //this->shipValuesBox->setBackgroundTexture("textures/gui_container_background.png"); |
---|
[10368] | 706 | this->shipValuesBox->setBackgroundTexture(Texture()); |
---|
| 707 | this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5)); |
---|
| 708 | this->shipValuesBox->setVisibility(true); |
---|
[6441] | 709 | } |
---|
[10368] | 710 | */ |
---|
[6441] | 711 | |
---|
| 712 | |
---|