| 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: ... | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ | 
|---|
| 17 |  | 
|---|
| 18 | #include "hud.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "state.h" | 
|---|
| 21 |  | 
|---|
| 22 | #include "world_entities/weapons/weapon_manager.h" | 
|---|
| 23 | #include "glgui_widget.h" | 
|---|
| 24 |  | 
|---|
| 25 | /** | 
|---|
| 26 | * standard constructor | 
|---|
| 27 | * @todo this constructor is not jet implemented - do it | 
|---|
| 28 | */ | 
|---|
| 29 | Hud::Hud () | 
|---|
| 30 | { | 
|---|
| 31 | this->setClassID(CL_HUD, "Hud"); | 
|---|
| 32 |  | 
|---|
| 33 | //this->setSize2D( | 
|---|
| 34 | this->weaponManager = NULL; | 
|---|
| 35 | this->energyWidget = NULL; | 
|---|
| 36 | this->shieldWidget = NULL; | 
|---|
| 37 | this->armorWidget = NULL; | 
|---|
| 38 | this->resX = 1; | 
|---|
| 39 | this->resY = 1; | 
|---|
| 40 |  | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | /** | 
|---|
| 45 | * standard deconstructor | 
|---|
| 46 | */ | 
|---|
| 47 | Hud::~Hud () | 
|---|
| 48 | { | 
|---|
| 49 | // delete what has to be deleted here | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | void Hud::loadParams(const TiXmlElement* root) | 
|---|
| 54 | { | 
|---|
| 55 | Element2D::loadParams(root); | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | void Hud::setBackGround() | 
|---|
| 59 | { | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 63 | { | 
|---|
| 64 | // decopple old widget | 
|---|
| 65 | if (this->energyWidget != NULL) | 
|---|
| 66 | { | 
|---|
| 67 | this->energyWidget->hide(); | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | this->energyWidget = widget; | 
|---|
| 71 | if (this->energyWidget != NULL) | 
|---|
| 72 | { | 
|---|
| 73 | this->energyWidget->show(); | 
|---|
| 74 | this->energyWidget->backMaterial().setDiffuseMap("hud_energy_background.png"); | 
|---|
| 75 | this->energyWidget->backMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 
|---|
| 76 | /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); | 
|---|
| 77 | this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | this->updateResolution(); | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 84 | { | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 | void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 88 | { | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | void Hud::setWeaponManager(WeaponManager* weaponMan) | 
|---|
| 92 | { | 
|---|
| 93 | if (this->weaponManager != NULL) | 
|---|
| 94 | { | 
|---|
| 95 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) | 
|---|
| 96 | { | 
|---|
| 97 | Weapon* weapon = this->weaponManager->getWeapon(i); | 
|---|
| 98 | if (weapon != NULL) | 
|---|
| 99 | { | 
|---|
| 100 | weapon->getEnergyWidget()->hide(); | 
|---|
| 101 | this->weaponsWidgets.remove(weapon->getEnergyWidget()); | 
|---|
| 102 | } | 
|---|
| 103 | } | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | this->weaponManager = weaponMan; | 
|---|
| 107 |  | 
|---|
| 108 | this->updateWeaponManager(); | 
|---|
| 109 | this->updateResolution(); | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | void Hud::updateWeaponManager() | 
|---|
| 113 | { | 
|---|
| 114 | // hide all the Widgets | 
|---|
| 115 | std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget; | 
|---|
| 116 | for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++) | 
|---|
| 117 | { | 
|---|
| 118 | (*weaponWidget)->hide(); | 
|---|
| 119 | } | 
|---|
| 120 | this->weaponsWidgets.clear(); | 
|---|
| 121 |  | 
|---|
| 122 | // add all that we need again. | 
|---|
| 123 | if (this->weaponManager != NULL) | 
|---|
| 124 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) | 
|---|
| 125 | { | 
|---|
| 126 | Weapon* weapon = this->weaponManager->getWeapon(i); | 
|---|
| 127 | if (weapon != NULL) | 
|---|
| 128 | { | 
|---|
| 129 | weapon->getEnergyWidget()->show(); | 
|---|
| 130 | weapon->getEnergyWidget()->backMaterial().setDiffuse( .8,.2,.11); | 
|---|
| 131 | weapon->getEnergyWidget()->backMaterial().setTransparency(.1); | 
|---|
| 132 | weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); | 
|---|
| 133 | //      weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); | 
|---|
| 134 | this->weaponsWidgets.push_back(weapon->getEnergyWidget()); | 
|---|
| 135 | } | 
|---|
| 136 | } | 
|---|
| 137 | this->updateResolution(); | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 141 | { | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 145 | { | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | void Hud::updateResolution() | 
|---|
| 149 | { | 
|---|
| 150 | this->resX = State::getResX(); | 
|---|
| 151 | this->resY = State::getResY(); | 
|---|
| 152 | if (this->energyWidget != NULL) | 
|---|
| 153 | { | 
|---|
| 154 | this->energyWidget->setAbsCoor2D(0 * this->resX, 0 * this->resY); | 
|---|
| 155 | this->energyWidget->setSize2D(.25 * this->resX, 1 * this->resY); | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 | this->setSize2D(.2 * this->resX, this->resY); | 
|---|
| 159 |  | 
|---|
| 160 | std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget; | 
|---|
| 161 | float pos = .3; | 
|---|
| 162 | for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos+=.03) | 
|---|
| 163 | { | 
|---|
| 164 | (*weaponWidget)->setSize2D(.02*this->resX, .2 *this->resY); | 
|---|
| 165 | (*weaponWidget)->setAbsCoor2D(pos*this->resX, .75*this->resY); | 
|---|
| 166 |  | 
|---|
| 167 | } | 
|---|
| 168 | } | 
|---|
| 169 |  | 
|---|
| 170 |  | 
|---|
| 171 | void Hud::tick(float dt) | 
|---|
| 172 | { | 
|---|
| 173 | if (this->resY != State::getResY() || this->resX != State::getResY()) | 
|---|
| 174 | this->updateResolution(); | 
|---|
| 175 | } | 
|---|
| 176 |  | 
|---|
| 177 | void Hud::draw() const | 
|---|
| 178 | { | 
|---|
| 179 | //  GLGuiWidget::draw(); | 
|---|
| 180 | } | 
|---|
| 181 |  | 
|---|
| 182 |  | 
|---|