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