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