| 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 | |
|---|
| 75 | delete this->_radar; |
|---|
| 76 | delete this->barSocket; |
|---|
| 77 | delete this->rightRect; |
|---|
| 78 | delete this->leftRect; |
|---|
| 79 | delete this->topRect; |
|---|
| 80 | delete this->bottomRect; |
|---|
| 81 | delete this->middleRect; |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | //if (this->shipValuesBox != NULL) |
|---|
| 85 | //delete this->shipValuesBox; |
|---|
| 86 | |
|---|
| 87 | // delete what has to be deleted here |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 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(); |
|---|
| 99 | |
|---|
| 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 | |
|---|
| 144 | void Hud::loadParams(const TiXmlElement* root) |
|---|
| 145 | { |
|---|
| 146 | Element2D::loadParams(root); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | void Hud::notifyUser(const std::string& message) |
|---|
| 150 | { |
|---|
| 151 | this->notifier->pushNotifyMessage(message); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | void Hud::setBackGround() |
|---|
| 155 | {} |
|---|
| 156 | |
|---|
| 157 | void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget) |
|---|
| 158 | { |
|---|
| 159 | //if (this->shipValuesBox == NULL) |
|---|
| 160 | //this->createShipValuesBox(); |
|---|
| 161 | |
|---|
| 162 | // decopple old widget |
|---|
| 163 | if (this->energyWidget != NULL) |
|---|
| 164 | { |
|---|
| 165 | this->energyWidget->hide(); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | this->energyWidget = widget; |
|---|
| 169 | if (this->energyWidget != NULL) |
|---|
| 170 | { |
|---|
| 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); |
|---|
| 176 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png"); |
|---|
| 177 | this->energyWidget->show(); |
|---|
| 178 | /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); |
|---|
| 179 | this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | this->updateResolution(); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | void Hud::setShieldWidget(OrxGui::GLGuiWidget* widget) |
|---|
| 186 | { |
|---|
| 187 | /* |
|---|
| 188 | if (this->shipValuesBox == NULL) |
|---|
| 189 | this->createShipValuesBox(); |
|---|
| 190 | */ |
|---|
| 191 | |
|---|
| 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); |
|---|
| 205 | dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setDisplayedImage("textures/gui/gui_shield_icon.png"); |
|---|
| 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 | |
|---|
| 216 | void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget) |
|---|
| 217 | { |
|---|
| 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 | } |
|---|
| 251 | |
|---|
| 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) |
|---|
| 263 | { |
|---|
| 264 | this->implantWidget->hide(); |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | this->implantWidget = widget; |
|---|
| 268 | if (this->implantWidget != NULL) |
|---|
| 269 | { |
|---|
| 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);*/ |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | this->updateResolution(); |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec) |
|---|
| 285 | { |
|---|
| 286 | //clearWeaponManager(); |
|---|
| 287 | |
|---|
| 288 | //Hide all widgets |
|---|
| 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(); |
|---|
| 297 | //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 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 | |
|---|
| 315 | this->weaponManager = weaponMan; |
|---|
| 316 | this->weaponManagerSecondary = weaponManSec; |
|---|
| 317 | |
|---|
| 318 | this->updateWeaponManager(); |
|---|
| 319 | // this->updateResolution(); |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 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 | |
|---|
| 357 | void Hud::setMode(Hud::Playmode playmode) |
|---|
| 358 | { |
|---|
| 359 | this->playmode = playmode; |
|---|
| 360 | this->init(); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | void Hud::updateWeaponManager() |
|---|
| 364 | { |
|---|
| 365 | // hide all the Widgets |
|---|
| 366 | |
|---|
| 367 | std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; |
|---|
| 368 | for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) |
|---|
| 369 | { |
|---|
| 370 | (*weaponWidget)->hide(); |
|---|
| 371 | } |
|---|
| 372 | this->weaponsWidgetsPrim.clear(); |
|---|
| 373 | |
|---|
| 374 | for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) |
|---|
| 375 | { |
|---|
| 376 | (*weaponWidget)->hide(); |
|---|
| 377 | } |
|---|
| 378 | this->weaponsWidgetsSec.clear(); |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | // add all that we need again. |
|---|
| 382 | |
|---|
| 383 | if (this->weaponManager != NULL) |
|---|
| 384 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
|---|
| 385 | { |
|---|
| 386 | Weapon* weapon = this->weaponManager->getWeapon(i); |
|---|
| 387 | if (weapon != NULL) |
|---|
| 388 | { |
|---|
| 389 | //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); |
|---|
| 390 | weapon->getEnergyWidget()->setParent2D(this->rightRect); |
|---|
| 391 | weapon->getEnergyWidget()->show(); |
|---|
| 392 | weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); |
|---|
| 393 | weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); |
|---|
| 394 | weapon->getEnergyWidget()->setWidgetSize(120,30); |
|---|
| 395 | //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); |
|---|
| 396 | this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); |
|---|
| 397 | } |
|---|
| 398 | } |
|---|
| 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 | |
|---|
| 417 | this->updateResolution(); |
|---|
| 418 | |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget) |
|---|
| 422 | {} |
|---|
| 423 | |
|---|
| 424 | void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget) |
|---|
| 425 | {} |
|---|
| 426 | |
|---|
| 427 | void Hud::updateResolution() |
|---|
| 428 | { |
|---|
| 429 | this->resX = State::getResX(); |
|---|
| 430 | this->resY = State::getResY(); |
|---|
| 431 | |
|---|
| 432 | this->setSize2D(this->resX, this->resY); |
|---|
| 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 | } |
|---|
| 438 | |
|---|
| 439 | int overlayWidth = 0; |
|---|
| 440 | if (overlayPercentage >= 20) |
|---|
| 441 | overlayWidth = this->resX * (overlayPercentage)/(200); |
|---|
| 442 | else |
|---|
| 443 | overlayWidth = this->resX / 10; // fixed warning! |
|---|
| 444 | //if (overlayWidth < 100) |
|---|
| 445 | //overlayWidth = 100; |
|---|
| 446 | |
|---|
| 447 | this->rightRect->hide(); |
|---|
| 448 | this->leftRect->hide(); |
|---|
| 449 | |
|---|
| 450 | if( this->playmode != FirstPerson ) |
|---|
| 451 | { |
|---|
| 452 | |
|---|
| 453 | this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY)); |
|---|
| 454 | this->leftRect->setAbsCoor2D(0,0); |
|---|
| 455 | this->leftRect->setBackgroundTexture(Texture()); |
|---|
| 456 | this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2)); |
|---|
| 457 | this->leftRect->setForegroundTexture(Texture()); |
|---|
| 458 | this->leftRect->setForegroundColor(Color(0,0,0,0)); |
|---|
| 459 | |
|---|
| 460 | this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY)); |
|---|
| 461 | this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0); |
|---|
| 462 | this->rightRect->setBackgroundTexture(Texture()); |
|---|
| 463 | this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2)); |
|---|
| 464 | this->rightRect->setForegroundTexture(Texture()); |
|---|
| 465 | this->rightRect->setForegroundColor(Color(0,0,0,0)); |
|---|
| 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); |
|---|
| 472 | |
|---|
| 473 | this->topRect->setParent2D(this); |
|---|
| 474 | this->topRect->setWidgetSize(float(this->resX), float(overlayWidth)); |
|---|
| 475 | this->topRect->setAbsCoor2D(0, 0); |
|---|
| 476 | |
|---|
| 477 | this->middleRect->setParent2D(this); |
|---|
| 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->bottomHit->setWidgetSize(this->resX/10, this->resX/2); |
|---|
| 483 | this->bottomHit->show(); |
|---|
| 484 | this->topHit->setRelCoor2D(0, -this->resY/4); |
|---|
| 485 | this->topHit->setWidgetSize(this->resX/10, this->resX/2); |
|---|
| 486 | this->topHit->show(); |
|---|
| 487 | this->leftHit->setRelCoor2D(-this->resX/4, 0); |
|---|
| 488 | this->leftHit->setWidgetSize(this->resX/10, this->resX/2); |
|---|
| 489 | this->leftHit->show(); |
|---|
| 490 | this->rightHit->setRelCoor2D(this->resX/4, 0); |
|---|
| 491 | this->rightHit->setWidgetSize(this->resX/10, this->resX/2); |
|---|
| 492 | this->rightHit->show(); |
|---|
| 493 | |
|---|
| 494 | //this->middleRect->show(); |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | if (this->overlayActive) |
|---|
| 500 | { |
|---|
| 501 | this->rightRect->show(); |
|---|
| 502 | this->leftRect->show(); |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager()) |
|---|
| 507 | { |
|---|
| 508 | PRINTF(4)("UPDATING RADAR\n"); |
|---|
| 509 | if( this->playmode != FirstPerson ) |
|---|
| 510 | this->_radar->setParent2D(this->leftRect); |
|---|
| 511 | else |
|---|
| 512 | this->_radar->setParent2D(this->topRect); |
|---|
| 513 | if (radarCenterNode == NULL) |
|---|
| 514 | this->_radar->setCenterNode(State::getPlayer()->getPlayable()); |
|---|
| 515 | else |
|---|
| 516 | this->_radar->setCenterNode(this->radarCenterNode); |
|---|
| 517 | |
|---|
| 518 | //this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0)); |
|---|
| 519 | this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_00), Color(1, 0, 0)); |
|---|
| 520 | this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_01), Color(0, 0, 1)); |
|---|
| 521 | this->_radar->setAbsCoor2D(0, 0.01 * this->resY); |
|---|
| 522 | this->_radar->setWidgetSize(overlayWidth, overlayWidth); |
|---|
| 523 | this->_radar->setRange(300); |
|---|
| 524 | this->_radar->show(); |
|---|
| 525 | |
|---|
| 526 | int statWidgetsNumber = 0; |
|---|
| 527 | float expectedHealthSizeX = 0; |
|---|
| 528 | float expectedHealthSizeY = 0; |
|---|
| 529 | float newSizeY = 0; float newSizeX = 0; |
|---|
| 530 | float moduloWidth = 0; |
|---|
| 531 | |
|---|
| 532 | if( this->playmode != FirstPerson ) |
|---|
| 533 | { |
|---|
| 534 | if (this->healthWidget != NULL) |
|---|
| 535 | { |
|---|
| 536 | expectedHealthSizeX = 150; |
|---|
| 537 | expectedHealthSizeY = 50; |
|---|
| 538 | statWidgetsNumber++; |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | if (this->shieldWidget != NULL) |
|---|
| 542 | statWidgetsNumber++; |
|---|
| 543 | |
|---|
| 544 | if (this->energyWidget != NULL) |
|---|
| 545 | statWidgetsNumber++; |
|---|
| 546 | |
|---|
| 547 | if ((expectedHealthSizeY * statWidgetsNumber) > overlayWidth) |
|---|
| 548 | { |
|---|
| 549 | newSizeY = overlayWidth / float(statWidgetsNumber); |
|---|
| 550 | newSizeX = expectedHealthSizeX; |
|---|
| 551 | PRINTF(0)("Statwidgets resized\n"); |
|---|
| 552 | } |
|---|
| 553 | else |
|---|
| 554 | { |
|---|
| 555 | newSizeY = expectedHealthSizeY; |
|---|
| 556 | newSizeX = expectedHealthSizeX; |
|---|
| 557 | moduloWidth = int(overlayWidth) % int(expectedHealthSizeY * statWidgetsNumber); |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | float posY = overlayWidth + newSizeX; |
|---|
| 561 | |
|---|
| 562 | if (this->healthWidget != NULL) |
|---|
| 563 | { |
|---|
| 564 | this->healthWidget->setSize2D(newSizeX, newSizeY); |
|---|
| 565 | this->healthWidget->setRelCoor2D((statWidgetsNumber - 1) * newSizeY + 3 * moduloWidth / (statWidgetsNumber + 1),posY); |
|---|
| 566 | } |
|---|
| 567 | if (this->shieldWidget != NULL) |
|---|
| 568 | { |
|---|
| 569 | this->shieldWidget->setSize2D(newSizeX, newSizeY); |
|---|
| 570 | this->shieldWidget->setRelCoor2D((statWidgetsNumber - 2) * newSizeY + 2 *moduloWidth / (statWidgetsNumber + 1),posY); |
|---|
| 571 | } |
|---|
| 572 | if (this->energyWidget != NULL) |
|---|
| 573 | { |
|---|
| 574 | this->energyWidget->setSize2D(newSizeX, newSizeY); |
|---|
| 575 | this->energyWidget->setRelCoor2D(moduloWidth / (statWidgetsNumber + 1),posY); |
|---|
| 576 | } |
|---|
| 577 | } |
|---|
| 578 | else |
|---|
| 579 | { |
|---|
| 580 | this->barSocket->setParent2D(this->bottomRect); |
|---|
| 581 | this->barSocket->setWidgetSize( float(overlayWidth), float(overlayWidth)); |
|---|
| 582 | this->barSocket->setRelCoor2D(0,this->resX - float(overlayWidth)); |
|---|
| 583 | |
|---|
| 584 | this->healthWidget->setRelCoor2D(10,-20); |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | /* |
|---|
| 589 | if (this->healthWidget != NULL) |
|---|
| 590 | this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D()); |
|---|
| 591 | if (this->shieldWidget != NULL) |
|---|
| 592 | this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D()); |
|---|
| 593 | if (this->energyWidget != NULL) |
|---|
| 594 | this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D()); |
|---|
| 595 | */ |
|---|
| 596 | //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D(),0); |
|---|
| 597 | //this->energyWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0); |
|---|
| 598 | } |
|---|
| 599 | |
|---|
| 600 | /* |
|---|
| 601 | if (this->shipValuesBox != NULL) |
|---|
| 602 | { |
|---|
| 603 | this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY); |
|---|
| 604 | this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY); |
|---|
| 605 | } |
|---|
| 606 | else |
|---|
| 607 | createShipValuesBox(); |
|---|
| 608 | */ |
|---|
| 609 | |
|---|
| 610 | std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; |
|---|
| 611 | Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY); |
|---|
| 612 | float largestWidgetSizeX = 0; |
|---|
| 613 | //PRINTF(0)("Cur Pos: %f,%f\n",pos.x,pos.y); |
|---|
| 614 | // out of reasons i can't get behind, this version is segfaulting when calling getSizeX2D or getSizeY2D. the other |
|---|
| 615 | // element2D- related function works tough.. :s |
|---|
| 616 | |
|---|
| 617 | for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) |
|---|
| 618 | { |
|---|
| 619 | float ySize = (*weaponWidget)->getSizeY2D(); |
|---|
| 620 | float xSize = (*weaponWidget)->getSizeX2D(); |
|---|
| 621 | if (xSize > largestWidgetSizeX) |
|---|
| 622 | largestWidgetSizeX = xSize; |
|---|
| 623 | if (pos.x < ySize) |
|---|
| 624 | { |
|---|
| 625 | pos.x = overlayWidth; |
|---|
| 626 | pos.y += largestWidgetSizeX; |
|---|
| 627 | } |
|---|
| 628 | pos.x -= ySize; |
|---|
| 629 | (*weaponWidget)->setAbsCoor2D(pos.x + this->rightRect->getAbsCoor2D().x, pos.y); |
|---|
| 630 | //(*weaponWidget)->setAbsCoor2D(0,100); |
|---|
| 631 | (*weaponWidget)->show(); |
|---|
| 632 | //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | weaponWidget = this->weaponsWidgetsSec.begin(); |
|---|
| 636 | float expectedWidgetSizeY = 0; |
|---|
| 637 | if (weaponWidget != this->weaponsWidgetsSec.end()) |
|---|
| 638 | { |
|---|
| 639 | expectedWidgetSizeY = (*weaponWidget)->getSizeY2D(); |
|---|
| 640 | } |
|---|
| 641 | pos.y = resY - expectedWidgetSizeY * 0.6; |
|---|
| 642 | pos.x = overlayWidth + this->rightRect->getAbsCoor2D().x; |
|---|
| 643 | |
|---|
| 644 | for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) |
|---|
| 645 | { |
|---|
| 646 | float ySize = (*weaponWidget)->getSizeY2D(); |
|---|
| 647 | float xSize = (*weaponWidget)->getSizeX2D(); |
|---|
| 648 | if (xSize > largestWidgetSizeX) |
|---|
| 649 | largestWidgetSizeX = xSize; |
|---|
| 650 | if (pos.x < ySize) |
|---|
| 651 | { |
|---|
| 652 | pos.x = overlayWidth; |
|---|
| 653 | pos.y -= largestWidgetSizeX + expectedWidgetSizeY * 0.6; |
|---|
| 654 | } |
|---|
| 655 | pos.x -= ySize; |
|---|
| 656 | //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D()); |
|---|
| 657 | (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);//+this->rightRect->getAbsCoor2D().x, pos.y); |
|---|
| 658 | (*weaponWidget)->show(); |
|---|
| 659 | //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | } |
|---|
| 663 | |
|---|
| 664 | void Hud::draw() const |
|---|
| 665 | { |
|---|
| 666 | // GLGuiWidget::draw(); |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | |
|---|
| 670 | void Hud::process(const Event &event) |
|---|
| 671 | { |
|---|
| 672 | if (event.type == EV_VIDEO_RESIZE) |
|---|
| 673 | this->updateResolution(); |
|---|
| 674 | else if (event.type == SDLK_TAB) |
|---|
| 675 | { |
|---|
| 676 | /// TODO SHOW THE INPUT-LINE |
|---|
| 677 | // this->inputLine->select(); |
|---|
| 678 | } |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| 681 | /* |
|---|
| 682 | void Hud::createShipValuesBox() |
|---|
| 683 | { |
|---|
| 684 | this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical); |
|---|
| 685 | //this->shipValuesBox->setWidgetSize(1000,500); |
|---|
| 686 | //this->shipValuesBox->setBackgroundTexture("textures/gui_container_background.png"); |
|---|
| 687 | this->shipValuesBox->setBackgroundTexture(Texture()); |
|---|
| 688 | this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5)); |
|---|
| 689 | this->shipValuesBox->setVisibility(true); |
|---|
| 690 | } |
|---|
| 691 | */ |
|---|
| 692 | |
|---|
| 693 | |
|---|