| [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 | { |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | void Hud::setBackGround() |
|---|
| 60 | { |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | void Hud::setEnergyWidget(GLGuiWidget* widget) |
|---|
| 64 | { |
|---|
| [6440] | 65 | // decopple old widget |
|---|
| 66 | if (this->energyWidget != NULL) |
|---|
| 67 | { |
|---|
| 68 | this->energyWidget->hide(); |
|---|
| 69 | } |
|---|
| [6438] | 70 | |
|---|
| [6440] | 71 | this->energyWidget = widget; |
|---|
| 72 | if (this->energyWidget != NULL) |
|---|
| 73 | { |
|---|
| 74 | this->energyWidget->show(); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| [6441] | 77 | this->updateResolution(); |
|---|
| [6438] | 78 | } |
|---|
| 79 | |
|---|
| 80 | void Hud::setShiledWidget(GLGuiWidget* widget) |
|---|
| 81 | { |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | void Hud::setArmorWidget(GLGuiWidget* widget) |
|---|
| 85 | { |
|---|
| [6442] | 86 | } |
|---|
| [6438] | 87 | |
|---|
| [6442] | 88 | void Hud::setWeaponManager(WeaponManager* weaponMan) |
|---|
| 89 | { |
|---|
| 90 | if (this->weaponManager != NULL) |
|---|
| 91 | { |
|---|
| 92 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
|---|
| 93 | { |
|---|
| 94 | Weapon* weapon = this->weaponManager->getWeapon(i); |
|---|
| 95 | if (weapon != NULL) |
|---|
| 96 | { |
|---|
| 97 | weapon->getEnergyWidget()->hide(); |
|---|
| 98 | this->weaponsWidgets.remove(weapon->getEnergyWidget()); |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | this->weaponManager = weaponMan; |
|---|
| 104 | |
|---|
| [6445] | 105 | this->updateWeaponManager(); |
|---|
| 106 | this->updateResolution(); |
|---|
| [6438] | 107 | } |
|---|
| 108 | |
|---|
| [6443] | 109 | void Hud::updateWeaponManager() |
|---|
| 110 | { |
|---|
| 111 | // hide all the Widgets |
|---|
| 112 | std::list<GLGuiWidget*>::iterator weaponWidget; |
|---|
| 113 | for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++) |
|---|
| 114 | { |
|---|
| 115 | (*weaponWidget)->hide(); |
|---|
| 116 | } |
|---|
| 117 | this->weaponsWidgets.clear(); |
|---|
| [6442] | 118 | |
|---|
| [6443] | 119 | // add all that we need again. |
|---|
| 120 | if (this->weaponManager != NULL) |
|---|
| 121 | for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) |
|---|
| 122 | { |
|---|
| 123 | Weapon* weapon = this->weaponManager->getWeapon(i); |
|---|
| 124 | if (weapon != NULL) |
|---|
| 125 | { |
|---|
| 126 | weapon->getEnergyWidget()->show(); |
|---|
| [6445] | 127 | weapon->getLoadedEnergyWidget()->show(); |
|---|
| [6443] | 128 | this->weaponsWidgets.push_back(weapon->getEnergyWidget()); |
|---|
| [6445] | 129 | this->weaponsWidgets.push_back(weapon->getLoadedEnergyWidget()); |
|---|
| [6443] | 130 | } |
|---|
| 131 | } |
|---|
| 132 | this->updateResolution(); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| [6438] | 135 | void Hud::addWeaponWidget(GLGuiWidget* widget) |
|---|
| 136 | { |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | void Hud::removeWeaponWidget(GLGuiWidget* widget) |
|---|
| 140 | { |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| [6441] | 143 | void Hud::updateResolution() |
|---|
| 144 | { |
|---|
| 145 | this->resX = State::resX(); |
|---|
| 146 | this->resY = State::resY(); |
|---|
| 147 | if (this->energyWidget != NULL) |
|---|
| 148 | { |
|---|
| 149 | this->energyWidget->setAbsCoor2D(.02 * this->resX, .4 * this->resY); |
|---|
| 150 | this->energyWidget->setSize2D(.05 * this->resX, .55 * this->resY); |
|---|
| 151 | } |
|---|
| [6442] | 152 | |
|---|
| 153 | this->setSize2D(.2 * this->resX, this->resY); |
|---|
| 154 | |
|---|
| 155 | std::list<GLGuiWidget*>::iterator weaponWidget; |
|---|
| 156 | float pos = .2; |
|---|
| [6445] | 157 | bool test = true; |
|---|
| 158 | for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos+=.03, test = !test) |
|---|
| [6442] | 159 | { |
|---|
| [6445] | 160 | if (test) |
|---|
| 161 | { |
|---|
| 162 | (*weaponWidget)->setSize2D(.02*this->resX, .2 *this->resY); |
|---|
| 163 | (*weaponWidget)->setAbsCoor2D(pos*this->resX, .75*this->resY); |
|---|
| 164 | } |
|---|
| 165 | else |
|---|
| 166 | { |
|---|
| 167 | (*weaponWidget)->setSize2D(.02*this->resX, .17*this->resY); |
|---|
| 168 | (*weaponWidget)->setAbsCoor2D((pos-.008)*this->resX, .75*this->resY); |
|---|
| 169 | } |
|---|
| [6442] | 170 | } |
|---|
| [6441] | 171 | } |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | void Hud::tick(float dt) |
|---|
| 175 | { |
|---|
| 176 | if (this->resY != State::resY() || this->resX != State::resY()) |
|---|
| 177 | this->updateResolution(); |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | void Hud::draw() const |
|---|
| 181 | { |
|---|
| 182 | GLGuiWidget::draw(); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | |
|---|