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