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