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