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