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