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