Changeset 10366 in orxonox.OLD for branches/playability.merge/src/util/hud.cc
- Timestamp:
- Jan 25, 2007, 12:48:13 PM (18 years ago)
- Location:
- branches/playability.merge
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/playability.merge
- Property svn:ignore
-
old new 10 10 autom4te.cache 11 11 aclocal.m4 12 tags 13 test.bmp 14 config.sub 15 config.guess 16 OrxonoxPlayability.kdevses 17 OrxonoxPlayability.kdevelop.pcs
-
- Property svn:ignore
-
branches/playability.merge/src/util/hud.cc
r9869 r10366 23 23 #include "world_entities/weapons/weapon_manager.h" 24 24 #include "glgui_widget.h" 25 #include "glgui_box.h" 26 #include "glgui_bar.h" 27 #include "elements/glgui_energywidgetvertical.h" 25 28 26 29 #include "glgui_inputline.h" 27 30 #include "specials/glgui_notifier.h" 28 31 #include "elements/glgui_radar.h" 32 #include "world_entities/space_ships/space_ship.h" 29 33 30 34 … … 45 49 //this->setSize2D( 46 50 this->weaponManager = NULL; 51 this->weaponManagerSecondary = NULL; 47 52 this->energyWidget = NULL; 48 53 this->shieldWidget = NULL; 49 54 this->armorWidget = NULL; 55 //this->leftRect = NULL; 56 //this->rightRect = NULL; 50 57 this->resX = 1; 51 58 this->resY = 1; 59 60 this->overlayPercentage = 40; 61 this->overlayActive = false; 62 this->rightRect = new OrxGui::GLGuiImage(); 63 this->leftRect = new OrxGui::GLGuiImage(); 52 64 53 65 this->inputLine = new OrxGui::GLGuiInputLine(); … … 58 70 59 71 this->_radar = new OrxGui::GLGuiRadar(); 72 this->radarCenterNode = NULL; 60 73 61 74 this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE); 62 75 this->subscribeEvent(ES_ALL, SDLK_TAB); 63 76 64 77 //this->shipValuesBox = NULL; 65 78 } 66 79 … … 75 88 76 89 delete this->_radar; 90 delete this->rightRect; 91 delete this->leftRect; 92 //if (this->shipValuesBox != NULL) 93 //delete this->shipValuesBox; 94 77 95 // delete what has to be deleted here 78 96 } … … 94 112 void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget) 95 113 { 114 //if (this->shipValuesBox == NULL) 115 //this->createShipValuesBox(); 116 96 117 // decopple old widget 97 118 if (this->energyWidget != NULL) … … 103 124 if (this->energyWidget != NULL) 104 125 { 126 //this->energyWidget->shiftDir2D(270); 127 //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics"); 128 //this->shipValuesBox->pack(this->energyWidget); 129 //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings(); 130 this->energyWidget->setParent2D(this->leftRect); 105 131 this->energyWidget->show(); 106 this->energyWidget->setBackgroundTexture( "hud_energy_background.png");107 132 /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); 108 133 this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ … … 113 138 114 139 void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget) 115 {} 140 { 141 /* 142 if (this->shipValuesBox == NULL) 143 this->createShipValuesBox(); 144 */ 145 146 // decopple old widget 147 if (this->shieldWidget != NULL) 148 { 149 this->shieldWidget->hide(); 150 } 151 152 this->shieldWidget = widget; 153 if (this->shieldWidget != NULL) 154 { 155 //this->shieldWidget->shiftDir2D(270); 156 //this->shipValuesBox->pack(this->shieldWidget); 157 //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setStandardSettings(); 158 this->shieldWidget->setParent2D(this->leftRect); 159 this->shieldWidget->show(); 160 /* this->shieldWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); 161 this->shieldWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ 162 } 163 else 164 printf("schild im hud nicht uebergeben!!!!!!!!!!!!!!!!!!!!!!!!!"); 165 166 this->updateResolution(); 167 } 116 168 117 169 void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget) 118 {} 119 120 void Hud::setWeaponManager(WeaponManager* weaponMan) 121 { 170 { 171 /* 172 if (this->shipValuesBox == NULL) 173 this->createShipValuesBox(); 174 */ 175 176 // decopple old widget 177 if (this->armorWidget != NULL) 178 { 179 this->armorWidget->hide(); 180 } 181 182 this->armorWidget = widget; 183 if (this->armorWidget != NULL) 184 { 185 //this->armorWidget->shiftDir2D(270); 186 //this->shipValuesBox->pack(this->armorWidget); 187 //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->armorWidget)->setStandardSettings(); 188 this->armorWidget->setParent2D(this->leftRect); 189 this->armorWidget->show(); 190 /* this->armorWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); 191 this->armorWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ 192 } 193 194 this->updateResolution(); 195 } 196 197 void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec) 198 { 199 //clearWeaponManager(); 200 201 //Hide all widgets 122 202 if (this->weaponManager != NULL) 123 203 { … … 128 208 { 129 209 weapon->getEnergyWidget()->hide(); 130 this->weaponsWidgets.remove(weapon->getEnergyWidget());210 //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); 131 211 } 132 212 } 133 213 } 134 214 215 if (this->weaponManagerSecondary != NULL) 216 { 217 for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) 218 { 219 Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); 220 if (weapon != NULL) 221 { 222 weapon->getEnergyWidget()->hide(); 223 //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); 224 } 225 } 226 } 227 135 228 this->weaponManager = weaponMan; 229 this->weaponManagerSecondary = weaponManSec; 136 230 137 231 this->updateWeaponManager(); … … 139 233 } 140 234 235 /* 236 void Hud::clearWeaponManager() 237 { 238 //Hide all widgets 239 if (this->weaponManager != NULL) 240 { 241 for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) 242 { 243 Weapon* weapon = this->weaponManager->getWeapon(i); 244 if (weapon != NULL) 245 { 246 weapon->getEnergyWidget()->hide(); 247 //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); 248 } 249 } 250 } 251 252 if (this->weaponManagerSecondary != NULL) 253 { 254 for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) 255 { 256 Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); 257 if (weapon != NULL) 258 { 259 weapon->getEnergyWidget()->hide(); 260 //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); 261 } 262 } 263 } 264 265 //this->weaponsWidgetsPrim.clear(); 266 //this->weaponsWidgetsSec.clear(); 267 } 268 */ 269 141 270 void Hud::updateWeaponManager() 142 271 { 143 272 // hide all the Widgets 144 std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget; 145 for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++) 273 274 std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; 275 for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) 146 276 { 147 277 (*weaponWidget)->hide(); 148 278 } 149 this->weaponsWidgets.clear(); 279 this->weaponsWidgetsPrim.clear(); 280 281 for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) 282 { 283 (*weaponWidget)->hide(); 284 } 285 this->weaponsWidgetsSec.clear(); 286 150 287 151 288 // add all that we need again. 289 152 290 if (this->weaponManager != NULL) 153 291 for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) … … 157 295 { 158 296 //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); 297 weapon->getEnergyWidget()->setParent2D(this->rightRect); 159 298 weapon->getEnergyWidget()->show(); 160 299 weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); 161 300 weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); 162 // weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); 163 this->weaponsWidgets.push_back(weapon->getEnergyWidget()); 301 weapon->getEnergyWidget()->setWidgetSize(120,30); 302 //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); 303 this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); 164 304 } 165 305 } 306 307 if (this->weaponManagerSecondary != NULL) 308 for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) 309 { 310 Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); 311 if (weapon != NULL) 312 { 313 //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); 314 weapon->getEnergyWidget()->setParent2D(this->rightRect); 315 weapon->getEnergyWidget()->show(); 316 weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); 317 weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); 318 weapon->getEnergyWidget()->setWidgetSize(150,50); 319 //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); 320 this->weaponsWidgetsSec.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget())); 321 } 322 } 323 166 324 this->updateResolution(); 325 167 326 } 168 327 … … 182 341 this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY); 183 342 343 int overlayWidth = 0; 344 if (overlayPercentage >= 20) 345 overlayWidth = this->resX * (overlayPercentage)/(200); 346 else 347 overlayWidth = this->resX * 0.1; 348 //if (overlayWidth < 100) 349 //overlayWidth = 100; 350 351 this->rightRect->hide(); 352 this->leftRect->hide(); 353 354 this->leftRect->setParent2D(this); 355 this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY)); 356 this->leftRect->setAbsCoor2D(0,0); 357 this->leftRect->setBackgroundTexture(Texture()); 358 this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2)); 359 this->leftRect->setForegroundTexture(Texture()); 360 this->leftRect->setForegroundColor(Color(0,0,0,0)); 361 362 this->rightRect->setParent2D(this); 363 this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY)); 364 this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0); 365 this->rightRect->setBackgroundTexture(Texture()); 366 this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2)); 367 this->rightRect->setForegroundTexture(Texture()); 368 this->rightRect->setForegroundColor(Color(0,0,0,0)); 369 370 371 if (this->overlayActive == true) 372 { 373 this->rightRect->show(); 374 this->leftRect->show(); 375 } 376 184 377 185 378 if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager()) 186 379 { 187 380 PRINTF(4)("UPDATING RADAR\n"); 188 this->_radar->setCenterNode(State::getPlayer()->getPlayable()); 189 this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0)); 190 this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_02), Color(1.0, .2, .2)); 191 this->_radar->setAbsCoor2D(0.8 * this->resX, 0.01 * this->resY); 192 this->_radar->setWidgetSize(0.2 * this->resX, 0.2 * this->resY); 381 this->_radar->setParent2D(this->leftRect); 382 if (radarCenterNode == NULL) 383 this->_radar->setCenterNode(State::getPlayer()->getPlayable()); 384 else 385 this->_radar->setCenterNode(this->radarCenterNode); 386 387 //this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0)); 388 this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_00), Color(1, 0, 0)); 389 this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_01), Color(0, 0, 1)); 390 this->_radar->setAbsCoor2D(0, 0.01 * this->resY); 391 this->_radar->setWidgetSize(overlayWidth, overlayWidth); 193 392 this->_radar->setRange(300); 194 393 this->_radar->show(); 195 } 196 197 198 if (this->energyWidget != NULL) 199 { 200 this->energyWidget->setAbsCoor2D(0.0 * this->resX, 0.85 * this->resY); 201 this->energyWidget->setWidgetSize(.25 * this->resX, 0.1 * this->resY); 202 } 203 204 205 std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget; 206 Vector2D pos(0.3, .9); 207 for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos.x+=.2) 208 { 209 if (pos.x > .8) 210 { 211 pos.x = 0.3; 212 pos.y -= .1; 213 214 } 215 (*weaponWidget)->setAbsCoor2D(pos.x*this->resX, pos.y*this->resY); 216 (*weaponWidget)->setWidgetSize(.02*this->resX, .1 *this->resY); 394 395 int statWidgetsNumber = 0; 396 float expectedArmorSizeX = 0; 397 float expectedArmorSizeY = 0; 398 float newSizeY = 0; float newSizeX = 0; 399 float moduloWidth = 0; 400 401 if (this->armorWidget != NULL) 402 { 403 expectedArmorSizeX = 150; 404 expectedArmorSizeY = 50; 405 statWidgetsNumber++; 406 } 407 408 if (this->shieldWidget != NULL) 409 statWidgetsNumber++; 410 411 if (this->energyWidget != NULL) 412 statWidgetsNumber++; 413 414 if (expectedArmorSizeY * statWidgetsNumber > overlayWidth) 415 { 416 newSizeY = overlayWidth / float(statWidgetsNumber); 417 newSizeX = expectedArmorSizeX; 418 PRINTF(0)("Statwidgets resized\n"); 419 } 420 else 421 { 422 newSizeY = expectedArmorSizeY; 423 newSizeX = expectedArmorSizeX; 424 moduloWidth = int(overlayWidth) % int(expectedArmorSizeY * statWidgetsNumber); 425 } 426 427 float posY = overlayWidth + newSizeX; 428 429 if (this->armorWidget != NULL) 430 { 431 this->armorWidget->setSize2D(newSizeX, newSizeY); 432 this->armorWidget->setRelCoor2D((statWidgetsNumber - 1) * newSizeY + 3 * moduloWidth / (statWidgetsNumber + 1),posY); 433 } 434 if (this->shieldWidget != NULL) 435 { 436 this->shieldWidget->setSize2D(newSizeX, newSizeY); 437 this->shieldWidget->setRelCoor2D((statWidgetsNumber - 2) * newSizeY + 2 *moduloWidth / (statWidgetsNumber + 1),posY); 438 } 439 if (this->energyWidget != NULL) 440 { 441 this->energyWidget->setSize2D(newSizeX, newSizeY); 442 this->energyWidget->setRelCoor2D(moduloWidth / (statWidgetsNumber + 1),posY); 443 } 444 445 /* 446 if (this->armorWidget != NULL) 447 this->armorWidget->setRelCoor2D(100,0.2*this->resY + this->armorWidget->getSizeX2D()); 448 if (this->shieldWidget != NULL) 449 this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->armorWidget->getSizeX2D()); 450 if (this->energyWidget != NULL) 451 this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->armorWidget->getSizeX2D()); 452 */ 453 //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->armorWidget->getSizeX2D(),0); 454 //this->energyWidget->setRelCoor2D(0.1*this->resX + this->armorWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0); 455 } 456 457 /* 458 if (this->shipValuesBox != NULL) 459 { 460 this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY); 461 this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY); 462 } 463 else 464 createShipValuesBox(); 465 */ 466 467 std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget; 468 Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY); 469 float largestWidgetSizeX = 0; 470 //PRINTF(0)("Cur Pos: %f,%f\n",pos.x,pos.y); 471 // out of reasons i can't get behind, this version is segfaulting when calling getSizeX2D or getSizeY2D. the other 472 // element2D- related function works tough.. :s 473 474 for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) 475 { 476 float ySize = (*weaponWidget)->getSizeY2D(); 477 float xSize = (*weaponWidget)->getSizeX2D(); 478 if (xSize > largestWidgetSizeX) 479 largestWidgetSizeX = xSize; 480 if (pos.x < ySize) 481 { 482 pos.x = overlayWidth; 483 pos.y += largestWidgetSizeX; 484 } 485 pos.x -= ySize; 486 (*weaponWidget)->setAbsCoor2D(pos.x + this->rightRect->getAbsCoor2D().x, pos.y); 487 //(*weaponWidget)->setAbsCoor2D(0,100); 217 488 (*weaponWidget)->show(); 218 489 //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); 219 490 } 491 492 weaponWidget = this->weaponsWidgetsSec.begin(); 493 float expectedWidgetSizeY = 0; 494 if (weaponWidget != this->weaponsWidgetsSec.end()) 495 { 496 expectedWidgetSizeY = (*weaponWidget)->getSizeY2D(); 497 } 498 pos.y = resY - expectedWidgetSizeY * 0.6; 499 pos.x = overlayWidth + this->rightRect->getAbsCoor2D().x; 500 501 for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) 502 { 503 float ySize = (*weaponWidget)->getSizeY2D(); 504 float xSize = (*weaponWidget)->getSizeX2D(); 505 if (xSize > largestWidgetSizeX) 506 largestWidgetSizeX = xSize; 507 if (pos.x < ySize) 508 { 509 pos.x = overlayWidth; 510 pos.y -= largestWidgetSizeX + expectedWidgetSizeY * 0.6; 511 } 512 pos.x -= ySize; 513 //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D()); 514 (*weaponWidget)->setAbsCoor2D(pos.x + this->rightRect->getAbsCoor2D().x, pos.y); 515 (*weaponWidget)->show(); 516 //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); 517 } 518 220 519 } 221 520 … … 235 534 // this->inputLine->select(); 236 535 } 237 238 239 } 240 241 536 } 537 538 /* 539 void Hud::createShipValuesBox() 540 { 541 this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical); 542 //this->shipValuesBox->setWidgetSize(1000,500); 543 //this->shipValuesBox->setBackgroundTexture("maps/gui_container_background.png"); 544 this->shipValuesBox->setBackgroundTexture(Texture()); 545 this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5)); 546 this->shipValuesBox->setVisibility(true); 547 } 548 */ 549 550
Note: See TracChangeset
for help on using the changeset viewer.