/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... */ //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ #include "hud.h" #include "state.h" #include "debug.h" #include "world_entities/weapons/weapon_manager.h" #include "glgui_widget.h" #include "glgui_inputline.h" #include "specials/glgui_notifier.h" #include "elements/glgui_radar.h" /// HACK #include "player.h" #include "playable.h" ObjectListDefinition(Hud); /** * standard constructor * @todo this constructor is not jet implemented - do it */ Hud::Hud () { this->registerObject(this, Hud::_objectList); //this->setSize2D( this->weaponManager = NULL; this->weaponManagerSecondary = NULL; this->energyWidget = NULL; this->shieldWidget = NULL; this->armorWidget = NULL; this->resX = 1; this->resY = 1; this->inputLine = new OrxGui::GLGuiInputLine(); this->inputLine->setParent2D(this); this->notifier = new OrxGui::GLGuiNotifier(); this->notifier->setParent2D(this); notifier->setAbsCoor2D(100,100); this->_radar = new OrxGui::GLGuiRadar(); this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE); this->subscribeEvent(ES_ALL, SDLK_TAB); } /** * standard deconstructor */ Hud::~Hud () { delete this->inputLine; delete this->notifier; delete this->_radar; // delete what has to be deleted here } void Hud::loadParams(const TiXmlElement* root) { Element2D::loadParams(root); } void Hud::notifyUser(const std::string& message) { this->notifier->pushNotifyMessage(message); } void Hud::setBackGround() {} void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget) { // decopple old widget if (this->energyWidget != NULL) { this->energyWidget->hide(); } this->energyWidget = widget; if (this->energyWidget != NULL) { this->energyWidget->show(); //this->energyWidget->setBackgroundTexture( "hud_energy_background.png"); this->energyWidget->shiftDir2D(270); /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ } this->updateResolution(); } void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget) {} void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget) {} void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec) { if (this->weaponManager != NULL) { for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) { Weapon* weapon = this->weaponManager->getWeapon(i); if (weapon != NULL) { weapon->getEnergyWidget()->hide(); this->weaponsWidgets.remove(weapon->getEnergyWidget()); } } } if (this->weaponManagerSecondary != NULL) { for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) { Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); if (weapon != NULL) { weapon->getEnergyWidget()->hide(); this->weaponsWidgets.remove(weapon->getEnergyWidget()); } } } this->weaponManager = weaponMan; this->weaponManagerSecondary = weaponManSec; this->updateWeaponManager(); // this->updateResolution(); } void Hud::updateWeaponManager() { // hide all the Widgets std::list::iterator weaponWidget; for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++) { (*weaponWidget)->hide(); } this->weaponsWidgets.clear(); // add all that we need again. if (this->weaponManager != NULL) for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++) { Weapon* weapon = this->weaponManager->getWeapon(i); if (weapon != NULL) { //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); weapon->getEnergyWidget()->show(); weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); this->weaponsWidgets.push_back(weapon->getEnergyWidget()); } } if (this->weaponManagerSecondary != NULL) for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++) { Weapon* weapon = this->weaponManagerSecondary->getWeapon(i); if (weapon != NULL) { //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName()); weapon->getEnergyWidget()->show(); weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); this->weaponsWidgets.push_back(weapon->getEnergyWidget()); } } this->updateResolution(); } void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget) {} void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget) {} void Hud::updateResolution() { this->resX = State::getResX(); this->resY = State::getResY(); this->setSize2D(.2 * this->resX, this->resY); this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY); this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY); if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager()) { PRINTF(4)("UPDATING RADAR\n"); this->_radar->setCenterNode(State::getPlayer()->getPlayable()); //this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0)); this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_00), Color(1, 0, 0)); this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_01), Color(0, 0, 1)); this->_radar->setAbsCoor2D(0.8 * this->resX, 0.01 * this->resY); this->_radar->setWidgetSize(0.2 * this->resX, 0.2 * this->resY); this->_radar->setRange(300); this->_radar->show(); } if (this->energyWidget != NULL) { this->energyWidget->setAbsCoor2D(0.2 * this->resX, 0.85 * this->resY); this->energyWidget->setWidgetSize(.25 * this->resX, 0.1 * this->resY); } std::list::iterator weaponWidget; Vector2D pos(0.3, .9); for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos.x+=.1) { if (pos.x > .8) { pos.x = 0.3; pos.y -= .1; } (*weaponWidget)->setAbsCoor2D(pos.x*this->resX, pos.y*this->resY); (*weaponWidget)->setWidgetSize(.02*this->resX, .1 *this->resY); (*weaponWidget)->show(); //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); } } void Hud::draw() const { // GLGuiWidget::draw(); } void Hud::process(const Event &event) { if (event.type == EV_VIDEO_RESIZE) this->updateResolution(); else if (event.type == SDLK_TAB) { /// TODO SHOW THE INPUT-LINE // this->inputLine->select(); } }