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