/* 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: Benjamin Knecht */ //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ #include "hud.h" #include "state.h" #include "debug.h" #include "world_entities/weapons/weapon_manager.h" #include "glgui.h" #include "glgui_widget.h" #include "glgui_box.h" #include "glgui_bar.h" #include "elements/glgui_energywidgetvertical.h" #include "glgui_inputline.h" #include "specials/glgui_notifier.h" #include "elements/glgui_radar.h" #include "world_entities/space_ships/space_ship.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->healthWidget = NULL; this->leftRect = NULL; this->rightRect = NULL; this->resX = 1; this->resY = 1; this->init(); } /** * standard deconstructor */ Hud::~Hud () { delete this->inputLine; delete this->notifier; delete this->_radar; delete this->barSocket; delete this->rightRect; delete this->leftRect; delete this->topRect; delete this->bottomRect; delete this->middleRect; //if (this->shipValuesBox != NULL) //delete this->shipValuesBox; // delete what has to be deleted here } void Hud::init() { this->overlayPercentage = 40; this->overlayActive = false; this->rightRect = new OrxGui::GLGuiImage(); this->leftRect = new OrxGui::GLGuiImage(); this->topRect = new OrxGui::GLGuiImage(); this->bottomRect = new OrxGui::GLGuiImage(); this->middleRect = new OrxGui::GLGuiImage(); this->inputLine = new OrxGui::GLGuiInputLine(); this->inputLine->setParent2D(this); this->notifier = new OrxGui::GLGuiNotifier(); this->notifier->setParent2D(this); notifier->setAbsCoor2D(100,100); this->barSocket = new OrxGui::GLGuiImage(); this->barSocket->setParent2D(this->bottomRect); this->_radar = new OrxGui::GLGuiRadar(); this->radarCenterNode = NULL; this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE); this->subscribeEvent(ES_ALL, SDLK_TAB); if (this->playmode == FirstPerson) { this->topHit = new OrxGui::GLGuiImage(); this->topHit->loadImageFromFile("textures/gui/gui_hitbar.png"); this->topHit->setParent2D(this->middleRect); this->topHit->setRelDir2D(-1.5708); this->bottomHit = new OrxGui::GLGuiImage(); this->bottomHit->loadImageFromFile("textures/gui/gui_hitbar.png"); this->bottomHit->setParent2D(this->middleRect); this->bottomHit->setRelDir2D(1.5708); this->leftHit = new OrxGui::GLGuiImage(); this->leftHit->loadImageFromFile("textures/gui/gui_hitbar.png"); this->leftHit->setParent2D(this->middleRect); this->rightHit = new OrxGui::GLGuiImage(); this->rightHit->loadImageFromFile("textures/gui/gui_hitbar.png"); this->rightHit->setParent2D(this->middleRect); this->rightHit->setRelDir2D(3.1416); this->leftRect->setParent2D(this); this->rightRect->setParent2D(this); } //this->shipValuesBox = NULL; } 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) { //if (this->shipValuesBox == NULL) //this->createShipValuesBox(); // decopple old widget if (this->energyWidget != NULL) { this->energyWidget->hide(); } this->energyWidget = widget; if (this->energyWidget != NULL) { //this->energyWidget->shiftDir2D(270); //dynamic_cast (this->energyWidget)->setDisplayedName("Electronics"); //this->shipValuesBox->pack(this->energyWidget); //dynamic_cast (this->energyWidget)->setStandardSettings(); this->energyWidget->setParent2D(this->leftRect); dynamic_cast (this->energyWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png"); this->energyWidget->show(); /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ } this->updateResolution(); } void Hud::setShieldWidget(OrxGui::GLGuiWidget* widget) { /* if (this->shipValuesBox == NULL) this->createShipValuesBox(); */ // decopple old widget if (this->shieldWidget != NULL) { this->shieldWidget->hide(); } this->shieldWidget = widget; if (this->shieldWidget != NULL) { //this->shieldWidget->shiftDir2D(270); //this->shipValuesBox->pack(this->shieldWidget); //dynamic_cast (this->shieldWidget)->setStandardSettings(); this->shieldWidget->setParent2D(this->leftRect); dynamic_cast (this->shieldWidget)->setDisplayedImage("textures/gui/gui_shield_icon.png"); this->shieldWidget->show(); /* this->shieldWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); this->shieldWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ } else printf("schild im hud nicht uebergeben!!!!!!!!!!!!!!!!!!!!!!!!!"); this->updateResolution(); } void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget) { if( this->playmode == FirstPerson ) { this->healthWidget = new OrxGui::GLGuiBar(); dynamic_cast (this->healthWidget)->setMaximum(dynamic_cast (widget)->getBarWidget()->maximum()); dynamic_cast (this->healthWidget)->setValue(dynamic_cast (widget)->getBarWidget()->value()); this->healthWidget->setParent2D(this->barSocket); } else { /* if (this->shipValuesBox == NULL) this->createShipValuesBox(); */ // decopple old widget if (this->healthWidget != NULL) { this->healthWidget->hide(); } this->healthWidget = widget; if (this->healthWidget != NULL) { //this->healthWidget->shiftDir2D(270); //this->shipValuesBox->pack(this->healthWidget); //dynamic_cast (this->healthWidget)->setStandardSettings(); this->healthWidget->setParent2D(this->leftRect); //dynamic_cast (this->healthWidget)->setDisplayedImage("textures/gui/gui_health_icon.png"); this->healthWidget->show(); /* this->healthWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); this->healthWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ } } this->updateResolution(); } void Hud::setImplantWidget(OrxGui::GLGuiWidget* widget) { //if (this->shipValuesBox == NULL) //this->createShipValuesBox(); // decopple old widget if (this->implantWidget != NULL) { this->implantWidget->hide(); } this->implantWidget = widget; if (this->implantWidget != NULL) { //this->energyWidget->shiftDir2D(270); //dynamic_cast (this->energyWidget)->setDisplayedName("Electronics"); //this->shipValuesBox->pack(this->energyWidget); //dynamic_cast (this->energyWidget)->setStandardSettings(); this->implantWidget->setParent2D(this->leftRect); dynamic_cast (this->implantWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png"); this->implantWidget->show(); /* this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png"); this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ } this->updateResolution(); } void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec) { //clearWeaponManager(); //Hide all widgets 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->weaponsWidgetsPrim.remove(dynamic_cast (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->weaponsWidgetsSec.remove(dynamic_cast (weapon->getEnergyWidget())); } } } this->weaponManager = weaponMan; this->weaponManagerSecondary = weaponManSec; this->updateWeaponManager(); // this->updateResolution(); } /* void Hud::clearWeaponManager() { //Hide all widgets 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->weaponsWidgetsPrim.remove(dynamic_cast (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->weaponsWidgetsSec.remove(dynamic_cast (weapon->getEnergyWidget())); } } } //this->weaponsWidgetsPrim.clear(); //this->weaponsWidgetsSec.clear(); } */ void Hud::setMode(Hud::Playmode playmode) { this->playmode = playmode; this->init(); } void Hud::updateWeaponManager() { // hide all the Widgets std::list::iterator weaponWidget; for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) { (*weaponWidget)->hide(); } this->weaponsWidgetsPrim.clear(); for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) { (*weaponWidget)->hide(); } this->weaponsWidgetsSec.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()->setParent2D(this->rightRect); weapon->getEnergyWidget()->show(); weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); weapon->getEnergyWidget()->setWidgetSize(120,30); //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); this->weaponsWidgetsPrim.push_back(dynamic_cast (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()->setParent2D(this->rightRect); weapon->getEnergyWidget()->show(); weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1)); weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6)); weapon->getEnergyWidget()->setWidgetSize(150,50); //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6); this->weaponsWidgetsSec.push_back(dynamic_cast (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(this->resX, this->resY); if( this->playmode != FirstPerson ) { this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY); this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY); } int overlayWidth = 0; if (overlayPercentage >= 20) overlayWidth = this->resX * (overlayPercentage)/(200); else overlayWidth = this->resX / 10; // fixed warning! //if (overlayWidth < 100) //overlayWidth = 100; this->rightRect->hide(); this->leftRect->hide(); if( this->playmode != FirstPerson ) { this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY)); this->leftRect->setAbsCoor2D(0,0); /*this->leftRect->setBackgroundTexture(Texture()); this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2)); this->leftRect->setForegroundTexture(Texture()); this->leftRect->setForegroundColor(Color(0,0,0,0));*/ this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY)); this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0); /*this->rightRect->setBackgroundTexture(Texture()); this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2)); this->rightRect->setForegroundTexture(Texture()); this->rightRect->setForegroundColor(Color(0,0,0,0));*/ } else { this->bottomRect->setParent2D(this); this->bottomRect->setWidgetSize(float(this->resX), float(overlayWidth)); this->bottomRect->setAbsCoor2D(0, this->resY - overlayWidth); this->topRect->setParent2D(this); this->topRect->setWidgetSize(float(this->resX), float(overlayWidth)); this->topRect->setAbsCoor2D(0, 0); this->middleRect->setParent2D(this); //this->middleRect->setWidgetSize(float(this->resY)/2, float(this->resY)/2); this->middleRect->setAbsCoor2D(/*float(this->resX - this->resY/2)/2, float(this->resY)/4*/float(this->resX/2), float(this->resY/2)); this->bottomHit->setRelCoor2D(0, this->resY/4); this->topHit->setRelCoor2D(0, -this->resY/4); this->leftHit->setRelCoor2D(-this->resX/4, 0); this->rightHit->setRelCoor2D(this->resX/4, 0); this->middleRect->show(); this->rightHit->show(); } if (this->overlayActive == true) { this->rightRect->show(); this->leftRect->show(); } if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager()) { PRINTF(4)("UPDATING RADAR\n"); if( this->playmode != FirstPerson ) this->_radar->setParent2D(this->leftRect); else this->_radar->setParent2D(this->topRect); if (radarCenterNode == NULL) this->_radar->setCenterNode(State::getPlayer()->getPlayable()); else this->_radar->setCenterNode(this->radarCenterNode); //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, 0.01 * this->resY); this->_radar->setWidgetSize(overlayWidth, overlayWidth); this->_radar->setRange(300); this->_radar->show(); int statWidgetsNumber = 0; float expectedHealthSizeX = 0; float expectedHealthSizeY = 0; float newSizeY = 0; float newSizeX = 0; float moduloWidth = 0; if( this->playmode != FirstPerson ) { if (this->healthWidget != NULL) { expectedHealthSizeX = 150; expectedHealthSizeY = 50; statWidgetsNumber++; } if (this->shieldWidget != NULL) statWidgetsNumber++; if (this->energyWidget != NULL) statWidgetsNumber++; if ((expectedHealthSizeY * statWidgetsNumber) > overlayWidth) { newSizeY = overlayWidth / float(statWidgetsNumber); newSizeX = expectedHealthSizeX; PRINTF(0)("Statwidgets resized\n"); } else { newSizeY = expectedHealthSizeY; newSizeX = expectedHealthSizeX; moduloWidth = int(overlayWidth) % int(expectedHealthSizeY * statWidgetsNumber); } float posY = overlayWidth + newSizeX; if (this->healthWidget != NULL) { this->healthWidget->setSize2D(newSizeX, newSizeY); this->healthWidget->setRelCoor2D((statWidgetsNumber - 1) * newSizeY + 3 * moduloWidth / (statWidgetsNumber + 1),posY); } if (this->shieldWidget != NULL) { this->shieldWidget->setSize2D(newSizeX, newSizeY); this->shieldWidget->setRelCoor2D((statWidgetsNumber - 2) * newSizeY + 2 *moduloWidth / (statWidgetsNumber + 1),posY); } if (this->energyWidget != NULL) { this->energyWidget->setSize2D(newSizeX, newSizeY); this->energyWidget->setRelCoor2D(moduloWidth / (statWidgetsNumber + 1),posY); } } else { this->barSocket->setParent2D(this->bottomRect); this->barSocket->setWidgetSize( float(overlayWidth), float(overlayWidth)); this->barSocket->setRelCoor2D(0,this->resX - float(overlayWidth)); this->healthWidget->setRelCoor2D(10,-20); } /* if (this->healthWidget != NULL) this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D()); if (this->shieldWidget != NULL) this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D()); if (this->energyWidget != NULL) this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D()); */ //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D(),0); //this->energyWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0); } /* if (this->shipValuesBox != NULL) { this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY); this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY); } else createShipValuesBox(); */ std::list::iterator weaponWidget; Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY); float largestWidgetSizeX = 0; //PRINTF(0)("Cur Pos: %f,%f\n",pos.x,pos.y); // out of reasons i can't get behind, this version is segfaulting when calling getSizeX2D or getSizeY2D. the other // element2D- related function works tough.. :s for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) { float ySize = (*weaponWidget)->getSizeY2D(); float xSize = (*weaponWidget)->getSizeX2D(); if (xSize > largestWidgetSizeX) largestWidgetSizeX = xSize; if (pos.x < ySize) { pos.x = overlayWidth; pos.y += largestWidgetSizeX; } pos.x -= ySize; (*weaponWidget)->setAbsCoor2D(pos.x + this->rightRect->getAbsCoor2D().x, pos.y); //(*weaponWidget)->setAbsCoor2D(0,100); (*weaponWidget)->show(); //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); } weaponWidget = this->weaponsWidgetsSec.begin(); float expectedWidgetSizeY = 0; if (weaponWidget != this->weaponsWidgetsSec.end()) { expectedWidgetSizeY = (*weaponWidget)->getSizeY2D(); } pos.y = resY - expectedWidgetSizeY * 0.6; pos.x = overlayWidth + this->rightRect->getAbsCoor2D().x; for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++) { float ySize = (*weaponWidget)->getSizeY2D(); float xSize = (*weaponWidget)->getSizeX2D(); if (xSize > largestWidgetSizeX) largestWidgetSizeX = xSize; if (pos.x < ySize) { pos.x = overlayWidth; pos.y -= largestWidgetSizeX + expectedWidgetSizeY * 0.6; } pos.x -= ySize; //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D()); (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);//+this->rightRect->getAbsCoor2D().x, pos.y); (*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(); } } /* void Hud::createShipValuesBox() { this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical); //this->shipValuesBox->setWidgetSize(1000,500); //this->shipValuesBox->setBackgroundTexture("textures/gui_container_background.png"); this->shipValuesBox->setBackgroundTexture(Texture()); this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5)); this->shipValuesBox->setVisibility(true); } */