| 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 | #include "elements/glgui_radar.h" | 
|---|
| 29 |  | 
|---|
| 30 |  | 
|---|
| 31 |  | 
|---|
| 32 | /// HACK | 
|---|
| 33 | #include "player.h" | 
|---|
| 34 | #include "playable.h" | 
|---|
| 35 |  | 
|---|
| 36 | /** | 
|---|
| 37 |  * standard constructor | 
|---|
| 38 |  * @todo this constructor is not jet implemented - do it | 
|---|
| 39 | */ | 
|---|
| 40 | Hud::Hud () | 
|---|
| 41 | { | 
|---|
| 42 |   this->setClassID(CL_HUD, "Hud"); | 
|---|
| 43 |  | 
|---|
| 44 |   //this->setSize2D( | 
|---|
| 45 |   this->weaponManager = NULL; | 
|---|
| 46 |   this->energyWidget = NULL; | 
|---|
| 47 |   this->shieldWidget = NULL; | 
|---|
| 48 |   this->armorWidget = NULL; | 
|---|
| 49 |   this->resX = 1; | 
|---|
| 50 |   this->resY = 1; | 
|---|
| 51 |  | 
|---|
| 52 |   this->inputLine = new OrxGui::GLGuiInputLine(); | 
|---|
| 53 |   this->inputLine->setParent2D(this); | 
|---|
| 54 |   this->notifier = new OrxGui::GLGuiNotifier(); | 
|---|
| 55 |   this->notifier->setParent2D(this); | 
|---|
| 56 |   notifier->setAbsCoor2D(100,100); | 
|---|
| 57 |  | 
|---|
| 58 |   this->_radar = new OrxGui::GLGuiRadar(); | 
|---|
| 59 |  | 
|---|
| 60 |   this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE); | 
|---|
| 61 |   this->subscribeEvent(ES_ALL, SDLK_TAB); | 
|---|
| 62 |  | 
|---|
| 63 |  | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 |  | 
|---|
| 67 | /** | 
|---|
| 68 |  * standard deconstructor | 
|---|
| 69 | */ | 
|---|
| 70 | Hud::~Hud () | 
|---|
| 71 | { | 
|---|
| 72 |   delete this->inputLine; | 
|---|
| 73 |   delete this->notifier; | 
|---|
| 74 |  | 
|---|
| 75 |   delete this->_radar; | 
|---|
| 76 |   // delete what has to be deleted here | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 |  | 
|---|
| 80 | void Hud::loadParams(const TiXmlElement* root) | 
|---|
| 81 | { | 
|---|
| 82 |   Element2D::loadParams(root); | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | void Hud::notifyUser(const std::string& message) | 
|---|
| 86 | { | 
|---|
| 87 |   this->notifier->pushNotifyMessage(message); | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | void Hud::setBackGround() | 
|---|
| 91 | {} | 
|---|
| 92 |  | 
|---|
| 93 | void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 94 | { | 
|---|
| 95 |   // decopple old widget | 
|---|
| 96 |   if (this->energyWidget != NULL) | 
|---|
| 97 |   { | 
|---|
| 98 |     this->energyWidget->hide(); | 
|---|
| 99 |   } | 
|---|
| 100 |  | 
|---|
| 101 |   this->energyWidget = widget; | 
|---|
| 102 |   if (this->energyWidget != NULL) | 
|---|
| 103 |   { | 
|---|
| 104 |     this->energyWidget->show(); | 
|---|
| 105 |     this->energyWidget->setBackgroundTexture( "hud_energy_background.png"); | 
|---|
| 106 |     /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); | 
|---|
| 107 |         this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ | 
|---|
| 108 |   } | 
|---|
| 109 |  | 
|---|
| 110 |   this->updateResolution(); | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 114 | {} | 
|---|
| 115 |  | 
|---|
| 116 | void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 117 | {} | 
|---|
| 118 |  | 
|---|
| 119 | void Hud::setWeaponManager(WeaponManager* weaponMan) | 
|---|
| 120 | { | 
|---|
| 121 |   if (this->weaponManager != NULL) | 
|---|
| 122 |   { | 
|---|
| 123 |     for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) | 
|---|
| 124 |     { | 
|---|
| 125 |       Weapon* weapon = this->weaponManager->getWeapon(i); | 
|---|
| 126 |       if (weapon != NULL) | 
|---|
| 127 |       { | 
|---|
| 128 |         weapon->getEnergyWidget()->hide(); | 
|---|
| 129 |         this->weaponsWidgets.remove(weapon->getEnergyWidget()); | 
|---|
| 130 |       } | 
|---|
| 131 |     } | 
|---|
| 132 |   } | 
|---|
| 133 |  | 
|---|
| 134 |   this->weaponManager = weaponMan; | 
|---|
| 135 |  | 
|---|
| 136 |   this->updateWeaponManager(); | 
|---|
| 137 |   //  this->updateResolution(); | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | void Hud::updateWeaponManager() | 
|---|
| 141 | { | 
|---|
| 142 |   // hide all the Widgets | 
|---|
| 143 |   std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget; | 
|---|
| 144 |   for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++) | 
|---|
| 145 |   { | 
|---|
| 146 |     (*weaponWidget)->hide(); | 
|---|
| 147 |   } | 
|---|
| 148 |   this->weaponsWidgets.clear(); | 
|---|
| 149 |  | 
|---|
| 150 |   // add all that we need again. | 
|---|
| 151 |   if (this->weaponManager != NULL) | 
|---|
| 152 |     for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) | 
|---|
| 153 |     { | 
|---|
| 154 |       Weapon* weapon = this->weaponManager->getWeapon(i); | 
|---|
| 155 |       if (weapon != NULL) | 
|---|
| 156 |       { | 
|---|
| 157 |         //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); | 
|---|
| 158 |         weapon->getEnergyWidget()->show(); | 
|---|
| 159 |         weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); | 
|---|
| 160 |         weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); | 
|---|
| 161 |         //      weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); | 
|---|
| 162 |         this->weaponsWidgets.push_back(weapon->getEnergyWidget()); | 
|---|
| 163 |       } | 
|---|
| 164 |     } | 
|---|
| 165 |   this->updateResolution(); | 
|---|
| 166 | } | 
|---|
| 167 |  | 
|---|
| 168 | void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 169 | {} | 
|---|
| 170 |  | 
|---|
| 171 | void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget) | 
|---|
| 172 | {} | 
|---|
| 173 |  | 
|---|
| 174 | void Hud::updateResolution() | 
|---|
| 175 | { | 
|---|
| 176 |   this->resX = State::getResX(); | 
|---|
| 177 |   this->resY = State::getResY(); | 
|---|
| 178 |  | 
|---|
| 179 |   this->setSize2D(.2 * this->resX, this->resY); | 
|---|
| 180 |   this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY); | 
|---|
| 181 |   this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY); | 
|---|
| 182 |  | 
|---|
| 183 |  | 
|---|
| 184 |   if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager()) | 
|---|
| 185 |   { | 
|---|
| 186 |     printf("UPDATING RADAR\n"); | 
|---|
| 187 |     this->_radar->setCenterNode(State::getPlayer()->getPlayable()); | 
|---|
| 188 |     this->_radar->addEntityList(&State::getObjectManager()->getObjectList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0)); | 
|---|
| 189 |     this->_radar->addEntityList(&State::getObjectManager()->getObjectList(OM_GROUP_02), Color(1.0, .2, .2)); | 
|---|
| 190 |     this->_radar->setAbsCoor2D(0.8 * this->resX, 0.01 * this->resY); | 
|---|
| 191 |     this->_radar->setWidgetSize(0.2 * this->resX, 0.2 * this->resY); | 
|---|
| 192 |     this->_radar->setRange(300); | 
|---|
| 193 |     this->_radar->show(); | 
|---|
| 194 |   } | 
|---|
| 195 |  | 
|---|
| 196 |  | 
|---|
| 197 |   if (this->energyWidget != NULL) | 
|---|
| 198 |   { | 
|---|
| 199 |     this->energyWidget->setAbsCoor2D(0.0 * this->resX, 0.85 * this->resY); | 
|---|
| 200 |     this->energyWidget->setWidgetSize(.25 * this->resX, 0.1 * this->resY); | 
|---|
| 201 |   } | 
|---|
| 202 |  | 
|---|
| 203 |  | 
|---|
| 204 |   std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget; | 
|---|
| 205 |   Vector2D pos(0.3, .9); | 
|---|
| 206 |   for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos.x+=.2) | 
|---|
| 207 |   { | 
|---|
| 208 |     if (pos.x > .8) | 
|---|
| 209 |     { | 
|---|
| 210 |       pos.x = 0.3; | 
|---|
| 211 |       pos.y -= .1; | 
|---|
| 212 |  | 
|---|
| 213 |     } | 
|---|
| 214 |     (*weaponWidget)->setAbsCoor2D(pos.x*this->resX, pos.y*this->resY); | 
|---|
| 215 |     (*weaponWidget)->setWidgetSize(.02*this->resX, .1 *this->resY); | 
|---|
| 216 |     (*weaponWidget)->show(); | 
|---|
| 217 |     //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); | 
|---|
| 218 |   } | 
|---|
| 219 | } | 
|---|
| 220 |  | 
|---|
| 221 | void Hud::draw() const | 
|---|
| 222 | { | 
|---|
| 223 |   //  GLGuiWidget::draw(); | 
|---|
| 224 | } | 
|---|
| 225 |  | 
|---|
| 226 |  | 
|---|
| 227 | void Hud::process(const Event &event) | 
|---|
| 228 | { | 
|---|
| 229 |   if (event.type == EV_VIDEO_RESIZE) | 
|---|
| 230 |     this->updateResolution(); | 
|---|
| 231 |   else if (event.type == SDLK_TAB) | 
|---|
| 232 |   { | 
|---|
| 233 |     /// TODO SHOW THE INPUT-LINE | 
|---|
| 234 |   //  this->inputLine->select(); | 
|---|
| 235 |   } | 
|---|
| 236 |  | 
|---|
| 237 |  | 
|---|
| 238 | } | 
|---|
| 239 |  | 
|---|
| 240 |  | 
|---|