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