/* 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" #include "tools/camera.h" #include "multi_type.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->playmode = Full3D; 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->leftHit = NULL; this->rightHit = NULL; this->ifinit = true; this->hidden = false; this->barSocket = NULL; this->_radar = NULL; this->inputLine = NULL; this->notifier = NULL; this->topRect = NULL; this->bottomRect = NULL; this->middleRect = NULL; this->init(); } /** * standard deconstructor */ Hud::~Hud () { if (this->inputLine) delete this->inputLine; if (this->notifier) delete this->notifier; if (this->leftHit) delete this->leftHit; if (this->rightHit) delete this->rightHit; if (this->_radar) delete this->_radar; if (this->barSocket) delete this->barSocket; if (this->rightRect) delete this->rightRect; if (this->leftRect) delete this->leftRect; if (this->topRect) delete this->topRect; if (this->bottomRect) delete this->bottomRect; if (this->middleRect) 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->_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->setAbsDir2D(-1.5708); this->bottomHit = new OrxGui::GLGuiImage(); this->bottomHit->loadImageFromFile("textures/gui/gui_hitbar.png"); this->bottomHit->setParent2D(this->middleRect); this->bottomHit->setAbsDir2D(1.5708);*/ this->barSocket = new OrxGui::GLGuiImage(); this->barSocket->loadImageFromFile("textures/gui/gui_barSocket.png"); this->barSocket->setParent2D(this->bottomRect); this->leftHit = new OrxGui::GLGuiImage(); this->leftHit->loadImageFromFile("textures/gui/gui_hitbarl.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->healthText = new OrxGui::GLGuiText(); this->healthText->setParent2D(this->barSocket); this->shieldText = new OrxGui::GLGuiText(); this->shieldText->setParent2D(this->barSocket); 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"); if (!this->hidden) this->energyWidget->show(); else this->energyWidget->hide(); /* 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->playmode == FirstPerson ) { this->shieldWidget = new OrxGui::GLGuiBar(); dynamic_cast (this->shieldWidget)->setMaximum(dynamic_cast (widget)->getBarWidget()->maximum()); dynamic_cast (this->shieldWidget)->setValue(dynamic_cast (widget)->getBarWidget()->value()); this->shieldWidget->setBackgroundTexture(Texture()); this->shieldWidget->setBackgroundColor(Color(0,0,0,0)); this->shieldWidget->setForegroundTexture("textures/gui/gui_element_background_faded.png"); this->shieldWidget->setForegroundColor(Color(1,1,0,0.5)); dynamic_cast(this->shieldWidget)->setChangedValueColor(Color(1,0,0,0.2)); this->shieldWidget->setWidgetSize(150,40); this->shieldWidget->setRelDir2D(180); this->shieldWidget->setParent2D(this->barSocket); this->shieldText->setTextSize(50); this->shieldText->setChangedTextColor(Color::white); this->shieldText->setForegroundColor(Color(1,1,0,1)); this->shieldText->setBackgroundTexture(Texture()); this->shieldText->setBackgroundColor(Color(0,0,0,0)); MultiType val(dynamic_cast(this->shieldWidget)->value()); val.setType(MT_INT); this->shieldText->setText(val.getString()); } else { /* 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"); if (!this->hidden) this->shieldWidget->show(); else this->shieldWidget->hide(); /* 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->setBackgroundTexture(Texture()); this->healthWidget->setBackgroundColor(Color(0,0,0,0)); this->healthWidget->setForegroundTexture("textures/gui/gui_element_background_faded.png"); this->healthWidget->setForegroundColor(Color::red); dynamic_cast(this->healthWidget)->setChangedValueColor(Color(1,0,0,0.2)); this->healthWidget->setWidgetSize(150,20); this->healthWidget->setRelDir2D(180); this->healthWidget->setParent2D(this->barSocket); this->healthText->setTextSize(80); this->healthText->setChangedTextColor(Color::white); this->healthText->setForegroundColor(Color::red); this->healthText->setBackgroundTexture(Texture()); this->healthText->setBackgroundColor(Color(0,0,0,0)); MultiType val(dynamic_cast(this->healthWidget)->value()); val.setType(MT_INT); this->healthText->setText(val.getString()); } 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"); if(!this->hidden) this->healthWidget->show(); else this->healthWidget->hide(); /* 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"); if (!this->hidden) this->implantWidget->show(); else this->implantWidget->hide(); /* 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()); if (this->playmode != FirstPerson) weapon->getEnergyWidget()->setParent2D(this->rightRect); else weapon->getEnergyWidget()->setParent2D(this->bottomRect); if (!this->hidden) weapon->getEnergyWidget()->show(); else weapon->getEnergyWidget()->hide(); 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); if (!this->hidden) weapon->getEnergyWidget()->show(); else weapon->getEnergyWidget()->hide(); 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::getHit() { this->leftHit->show(); this->rightHit->show(); hitBarCount = 0.33; } void Hud::tick(float dt) { if (this->playmode == FirstPerson && this->leftHit != NULL) { if (this->ifinit) { this->leftHit->shiftDir2D(3.1416); this->ifinit = false; } if (this->leftHit->isVisible()) { hitBarCount -= dt; } if (hitBarCount <= 0) { hitBarCount = 0; this->leftHit->hide(); this->rightHit->hide(); } } //Crosshair* crosshair = dynamic_cast(this->weaponManager->getFixedTarget()); if ((State::getCamera())->getName() == "GameWorldCamera") { this->hidden = false; if(this->weaponManager) this->weaponManager->showCrosshair(); } else { this->hidden = true; if(this->weaponManager) this->weaponManager->hideCrosshair(); } this->updateResolution(); } 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->bottomRect->show(); this->topRect->setParent2D(this); this->topRect->setWidgetSize(float(this->resX), float(overlayWidth)); this->topRect->setAbsCoor2D(0, 0); //this->topRect->show(); this->middleRect->setParent2D(this); this->middleRect->setWidgetSize(float(this->resY)/2, float(this->resY)/2); this->middleRect->setAbsCoor2D(float(this->resX)/4, float(this->resY)/4/*float(this->resX/2), float(this->resY/2)*/); //this->middleRect->show(); /*this->bottomHit->setRelCoor2D(0, this->resY/4); this->bottomHit->setWidgetSize(this->resX/8, this->resX/3); this->bottomHit->show(); this->topHit->setRelCoor2D(0, -this->resY/4); this->topHit->setWidgetSize(this->resX/8, this->resX/3); this->topHit->show();*/ this->leftHit->setRelCoor2D(0, 0); this->leftHit->setWidgetSize(this->resX/9, this->resX/3); //this->leftHit->hide(); this->rightHit->setRelCoor2D(this->resX/3, 0); this->rightHit->setWidgetSize(this->resX/9, this->resX/3); //this->rightHit->hide(); this->barSocket->setWidgetSize(overlayWidth, overlayWidth); this->barSocket->setRelCoor2D(this->resX - overlayWidth, 0); if (!this->hidden) this->barSocket->show(); else this->barSocket->hide(); //this->middleRect->show(); } if (this->overlayActive && !this->hidden) { 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); if (!this->hidden) this->_radar->show(); else this->_radar->hide(); 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(this->resX - float(overlayWidth),0); if (!this->hidden) this->barSocket->show(); else this->barSocket->hide(); if (this->shieldWidget) { this->shieldWidget->setRelCoor2D(40,overlayWidth/2+10); if (!this->hidden) this->shieldWidget->show(); else this->shieldWidget->hide(); this->shieldText->setRelCoor2D(overlayWidth/2-30,overlayWidth/2-60); if (!this->hidden) this->shieldText->show(); else this->shieldText->hide(); } this->healthWidget->setRelCoor2D(40,overlayWidth/2); if (!this->hidden) this->healthWidget->show(); else this->healthWidget->hide(); this->healthText->setRelCoor2D(overlayWidth/2-50,overlayWidth/2-20); if (!this->hidden) this->healthText->show(); else this->healthText->hide(); } /* 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(); */ if (this->playmode != FirstPerson ) { 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); if (!this->hidden) (*weaponWidget)->show(); else (*weaponWidget)->hide(); //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); if (!this->hidden) (*weaponWidget)->show(); else (*weaponWidget)->hide(); //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName()); } } else { std::list::iterator weaponWidget; Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY); // float largestWidgetSizeX = 0; //unused variable for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++) { (*weaponWidget)->setParent2D(this->barSocket); (*weaponWidget)->setRelCoor2D(overlayWidth/2, 0); //(*weaponWidget)->setAbsCoor2D(0,100); if (!this->hidden) (*weaponWidget)->show(); else (*weaponWidget)->hide(); //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); } */