Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/util/hud.cc @ 10767

Last change on this file since 10767 was 10766, checked in by bknecht, 18 years ago

some finishing stuff

File size: 27.3 KB
RevLine 
[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
[10698]13   co-programmer: Benjamin Knecht
[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"
[10717]24#include "glgui.h"
[8448]25#include "glgui_widget.h"
[10368]26#include "glgui_box.h"
27#include "glgui_bar.h"
28#include "elements/glgui_energywidgetvertical.h"
[6442]29
[8518]30#include "glgui_inputline.h"
31#include "specials/glgui_notifier.h"
[8994]32#include "elements/glgui_radar.h"
[10368]33#include "world_entities/space_ships/space_ship.h"
[8518]34
[10759]35#include "tools/camera.h"
[10766]36#include "multi_type.h"
[8996]37
38
[10759]39
40
[8996]41/// HACK
42#include "player.h"
43#include "playable.h"
44
[9869]45ObjectListDefinition(Hud);
[3245]46/**
[4838]47 * standard constructor
48 * @todo this constructor is not jet implemented - do it
[3245]49*/
[6437]50Hud::Hud ()
[3365]51{
[9869]52  this->registerObject(this, Hud::_objectList);
[4320]53
[6441]54  //this->setSize2D(
[10759]55  this->playmode = Full3D;
[6442]56  this->weaponManager = NULL;
[10368]57  this->weaponManagerSecondary = NULL;
[6440]58  this->energyWidget = NULL;
59  this->shieldWidget = NULL;
[10698]60  this->healthWidget = NULL;
61  this->leftRect = NULL;
62  this->rightRect = NULL;
[6441]63  this->resX = 1;
64  this->resY = 1;
[10748]65  this->leftHit = NULL;
66  this->rightHit = NULL;
67  this->ifinit = true;
[10759]68  this->hidden = false;
[10752]69 
70  this->barSocket = NULL;
71  this->_radar = NULL;
72  this->inputLine = NULL;
73  this->notifier = NULL;
74  this->topRect = NULL;
75  this->bottomRect = NULL;
76  this->middleRect = NULL;
[6442]77
[10752]78  this->init();
[10717]79
[10698]80 
[3365]81}
[1853]82
83
[3245]84/**
[4838]85 * standard deconstructor
[3245]86*/
[6437]87Hud::~Hud ()
[3543]88{
[10752]89  if (this->inputLine) delete this->inputLine;
90  if (this->notifier) delete this->notifier;
91  if (this->leftHit) delete this->leftHit;
92  if (this->rightHit) delete this->rightHit;
[8994]93
[10752]94  if (this->_radar) delete this->_radar;
95  if (this->barSocket) delete this->barSocket;
96  if (this->rightRect) delete this->rightRect;
97  if (this->leftRect) delete this->leftRect;
98  if (this->topRect) delete this->topRect;
99  if (this->bottomRect) delete this->bottomRect;
100  if (this->middleRect) delete this->middleRect;
[10716]101 
[10698]102
[10368]103  //if (this->shipValuesBox != NULL)
104    //delete this->shipValuesBox;
105
[3543]106  // delete what has to be deleted here
107}
[6438]108
[10716]109void Hud::init()
110{
111        this->overlayPercentage = 40;
112        this->overlayActive = false;
113        this->rightRect = new OrxGui::GLGuiImage();
114        this->leftRect = new OrxGui::GLGuiImage();
115        this->topRect = new OrxGui::GLGuiImage();
116        this->bottomRect = new OrxGui::GLGuiImage();
117        this->middleRect = new OrxGui::GLGuiImage();
[6438]118
[10716]119        this->inputLine = new OrxGui::GLGuiInputLine();
120        this->inputLine->setParent2D(this);
121        this->notifier = new OrxGui::GLGuiNotifier();
122        this->notifier->setParent2D(this);
123        notifier->setAbsCoor2D(100,100);
124       
[10741]125
[10716]126       
127        this->_radar = new OrxGui::GLGuiRadar();
128        this->radarCenterNode = NULL;
129       
130        this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE);
131        this->subscribeEvent(ES_ALL, SDLK_TAB);
132 
133        if (this->playmode == FirstPerson)
134        {
[10741]135                /*this->topHit = new OrxGui::GLGuiImage();
[10716]136                this->topHit->loadImageFromFile("textures/gui/gui_hitbar.png");
137                this->topHit->setParent2D(this->middleRect);
[10741]138                this->topHit->setAbsDir2D(-1.5708);
[10716]139               
140                this->bottomHit = new OrxGui::GLGuiImage();
141                this->bottomHit->loadImageFromFile("textures/gui/gui_hitbar.png");
142                this->bottomHit->setParent2D(this->middleRect);
[10741]143                this->bottomHit->setAbsDir2D(1.5708);*/
144
145                this->barSocket = new OrxGui::GLGuiImage();
146                this->barSocket->loadImageFromFile("textures/gui/gui_barSocket.png");
147                this->barSocket->setParent2D(this->bottomRect);
[10716]148               
149                this->leftHit = new OrxGui::GLGuiImage();
[10753]150                this->leftHit->loadImageFromFile("textures/gui/gui_hitbarl.png");
[10716]151                this->leftHit->setParent2D(this->middleRect);
152               
[10748]153               
[10716]154                this->rightHit = new OrxGui::GLGuiImage();
155                this->rightHit->loadImageFromFile("textures/gui/gui_hitbar.png");
156                this->rightHit->setParent2D(this->middleRect);
157               
[10766]158                this->healthText = new OrxGui::GLGuiText();
159                this->healthText->setParent2D(this->barSocket);
[10741]160               
[10766]161                this->shieldText = new OrxGui::GLGuiText();
162                this->shieldText->setParent2D(this->barSocket);
163               
164               
[10716]165                this->leftRect->setParent2D(this);
166                this->rightRect->setParent2D(this);
167        }
168
169  //this->shipValuesBox = NULL;
170}
171
172
[6438]173void Hud::loadParams(const TiXmlElement* root)
174{
[6512]175  Element2D::loadParams(root);
[6438]176}
177
[8518]178void Hud::notifyUser(const std::string& message)
[6438]179{
[8518]180  this->notifier->pushNotifyMessage(message);
[6438]181}
182
[8518]183void Hud::setBackGround()
184{}
185
[8145]186void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget)
[6438]187{
[10368]188  //if (this->shipValuesBox == NULL)
189    //this->createShipValuesBox();
190
[6440]191  // decopple old widget
192  if (this->energyWidget != NULL)
193  {
194    this->energyWidget->hide();
195  }
[6438]196
[6440]197  this->energyWidget = widget;
198  if (this->energyWidget != NULL)
199  {
[10368]200    //this->energyWidget->shiftDir2D(270);
201    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics");
202    //this->shipValuesBox->pack(this->energyWidget);
203    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings();
204    this->energyWidget->setParent2D(this->leftRect);
[10449]205    dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png");
[10759]206    if (!this->hidden)
207        this->energyWidget->show();
208    else
209        this->energyWidget->hide();
[8518]210    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
211        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
[6440]212  }
213
[10698]214  this->updateResolution(); 
[6438]215}
216
[10698]217void Hud::setShieldWidget(OrxGui::GLGuiWidget* widget)
[10368]218{
[10764]219        if( this->playmode == FirstPerson )
220        {
221                this->shieldWidget = new OrxGui::GLGuiBar();
222                dynamic_cast<OrxGui::GLGuiBar*> (this->shieldWidget)->setMaximum(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->maximum());
223                dynamic_cast<OrxGui::GLGuiBar*> (this->shieldWidget)->setValue(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->value());
224                this->shieldWidget->setBackgroundTexture(Texture());
225                this->shieldWidget->setBackgroundColor(Color(0,0,0,0));
226                this->shieldWidget->setForegroundTexture("textures/gui/gui_element_background_faded.png");
[10766]227                this->shieldWidget->setForegroundColor(Color(1,1,0,0.5));
[10764]228                dynamic_cast<OrxGui::GLGuiBar*>(this->shieldWidget)->setChangedValueColor(Color(1,0,0,0.2));
[10766]229                this->shieldWidget->setWidgetSize(150,40);
[10764]230                this->shieldWidget->setRelDir2D(180);
231                this->shieldWidget->setParent2D(this->barSocket);
[10766]232               
233                this->shieldText->setTextSize(50);
234                this->shieldText->setChangedTextColor(Color::white);
235                this->shieldText->setForegroundColor(Color(1,1,0,1));
236                this->shieldText->setBackgroundTexture(Texture());
237                this->shieldText->setBackgroundColor(Color(0,0,0,0));
238                MultiType val(dynamic_cast<OrxGui::GLGuiBar*>(this->shieldWidget)->value());
239                val.setType(MT_INT);
240                this->shieldText->setText(val.getString());
[10764]241        }
242        else
243        {
244        /*
245        if (this->shipValuesBox == NULL)
246        this->createShipValuesBox();
247        */
248       
249        // decopple old widget
250        if (this->shieldWidget != NULL)
251        {
[10759]252        this->shieldWidget->hide();
[10764]253        }
254       
255        this->shieldWidget = widget;
256        if (this->shieldWidget != NULL)
257        {
258        //this->shieldWidget->shiftDir2D(270);
259        //this->shipValuesBox->pack(this->shieldWidget);
260        //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setStandardSettings();
261        this->shieldWidget->setParent2D(this->leftRect);
262        dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setDisplayedImage("textures/gui/gui_shield_icon.png");
263        if (!this->hidden)
264                this->shieldWidget->show();
265        else
266                this->shieldWidget->hide();
267        /*    this->shieldWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
268                this->shieldWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
269        }
270        else
271        printf("schild im hud nicht uebergeben!!!!!!!!!!!!!!!!!!!!!!!!!");
[10368]272  }
273
274  this->updateResolution();
275}
276
[10698]277void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget)
[10368]278{
[10698]279        if( this->playmode == FirstPerson )
280        {
281                this->healthWidget = new OrxGui::GLGuiBar();
282                dynamic_cast<OrxGui::GLGuiBar*> (this->healthWidget)->setMaximum(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->maximum());
283                dynamic_cast<OrxGui::GLGuiBar*> (this->healthWidget)->setValue(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->value());
[10764]284                this->healthWidget->setBackgroundTexture(Texture());
285                this->healthWidget->setBackgroundColor(Color(0,0,0,0));
286                this->healthWidget->setForegroundTexture("textures/gui/gui_element_background_faded.png");
287                this->healthWidget->setForegroundColor(Color::red);
288                dynamic_cast<OrxGui::GLGuiBar*>(this->healthWidget)->setChangedValueColor(Color(1,0,0,0.2));
289                this->healthWidget->setWidgetSize(150,20);
290                this->healthWidget->setRelDir2D(180);
[10698]291                this->healthWidget->setParent2D(this->barSocket);
[10766]292
293                this->healthText->setTextSize(80);
294                this->healthText->setChangedTextColor(Color::white);
295                this->healthText->setForegroundColor(Color::red);
296                this->healthText->setBackgroundTexture(Texture());
297                this->healthText->setBackgroundColor(Color(0,0,0,0));
298                MultiType val(dynamic_cast<OrxGui::GLGuiBar*>(this->healthWidget)->value());
299                val.setType(MT_INT);
300                this->healthText->setText(val.getString());
[10698]301        }
302        else
303        {
304          /*
305          if (this->shipValuesBox == NULL)
306            this->createShipValuesBox();
307          */
308       
309        // decopple old widget
310          if (this->healthWidget != NULL)
311          {
312            this->healthWidget->hide();
313          }
314       
315          this->healthWidget = widget;
316          if (this->healthWidget != NULL)
317          {
318            //this->healthWidget->shiftDir2D(270);
319            //this->shipValuesBox->pack(this->healthWidget);
320            //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setStandardSettings();
321            this->healthWidget->setParent2D(this->leftRect);
[10764]322            dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setDisplayedImage("textures/gui/gui_health_icon.png");
[10759]323            if(!this->hidden)
324                this->healthWidget->show();
325            else
326                this->healthWidget->hide();
[10698]327            /*    this->healthWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
328                this->healthWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
329          }
330        }
[6438]331
[10698]332  this->updateResolution();
333}
334
335
336void Hud::setImplantWidget(OrxGui::GLGuiWidget* widget)
337{
338  //if (this->shipValuesBox == NULL)
339    //this->createShipValuesBox();
340
341  // decopple old widget
342  if (this->implantWidget != NULL)
[10368]343  {
[10698]344    this->implantWidget->hide();
[10368]345  }
346
[10698]347  this->implantWidget = widget;
348  if (this->implantWidget != NULL)
[10368]349  {
[10698]350    //this->energyWidget->shiftDir2D(270);
351    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics");
352    //this->shipValuesBox->pack(this->energyWidget);
353    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings();
354    this->implantWidget->setParent2D(this->leftRect);
355    dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->implantWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png");
[10759]356    if (!this->hidden)
357        this->implantWidget->show();
358    else
359        this->implantWidget->hide();
[10698]360    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
361        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
[10368]362  }
363
364  this->updateResolution();
365}
366
367void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec)
[6442]368{
[10368]369  //clearWeaponManager();
370
371  //Hide all widgets
[6442]372  if (this->weaponManager != NULL)
373  {
374    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
375    {
376      Weapon* weapon = this->weaponManager->getWeapon(i);
377      if (weapon != NULL)
378      {
379        weapon->getEnergyWidget()->hide();
[10368]380        //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
[6442]381      }
382    }
383  }
384
[10368]385  if (this->weaponManagerSecondary != NULL)
386  {
387    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
388    {
389      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
390      if (weapon != NULL)
391      {
392        weapon->getEnergyWidget()->hide();
393        //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
394      }
395    }
396  }
397
[6442]398  this->weaponManager = weaponMan;
[10368]399  this->weaponManagerSecondary = weaponManSec; 
[6442]400
[6445]401  this->updateWeaponManager();
[8996]402  //  this->updateResolution();
[6438]403}
404
[10368]405/*
406void Hud::clearWeaponManager()
407{
408  //Hide all widgets
409  if (this->weaponManager != NULL)
410  {
411    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
412    {
413      Weapon* weapon = this->weaponManager->getWeapon(i);
414      if (weapon != NULL)
415      {
416        weapon->getEnergyWidget()->hide();
417        //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
418      }
419    }
420  }
421
422  if (this->weaponManagerSecondary != NULL)
423  {
424    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
425    {
426      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
427      if (weapon != NULL)
428      {
429        weapon->getEnergyWidget()->hide();
430        //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
431      }
432    }
433  }
434
435  //this->weaponsWidgetsPrim.clear();
436  //this->weaponsWidgetsSec.clear();
437}
438*/
439
[10716]440void Hud::setMode(Hud::Playmode playmode)
441{
442        this->playmode = playmode;
443        this->init();
444}
445
[6443]446void Hud::updateWeaponManager()
447{
448  // hide all the Widgets
[10368]449 
450  std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget;
451  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
[6443]452  {
453    (*weaponWidget)->hide();
454  }
[10368]455  this->weaponsWidgetsPrim.clear();
[6442]456
[10368]457  for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++)
458  {
459    (*weaponWidget)->hide();
460  }
461  this->weaponsWidgetsSec.clear();
462 
463
[6443]464  // add all that we need again.
[10368]465
[6443]466  if (this->weaponManager != NULL)
467    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
468    {
[8518]469      Weapon* weapon = this->weaponManager->getWeapon(i);
470      if (weapon != NULL)
471      {
[9406]472        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
[10741]473        if (this->playmode != FirstPerson)
474                weapon->getEnergyWidget()->setParent2D(this->rightRect);
475        else
476                weapon->getEnergyWidget()->setParent2D(this->bottomRect);
[10759]477        if (!this->hidden)
478                weapon->getEnergyWidget()->show();
479        else
480                weapon->getEnergyWidget()->hide();
[8619]481        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
[8518]482        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
[10368]483        weapon->getEnergyWidget()->setWidgetSize(120,30);
484        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
485        this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
[8518]486      }
[6443]487    }
[10368]488
489  if (this->weaponManagerSecondary != NULL)
490    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
491    {
492      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
493      if (weapon != NULL)
494      {
495        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
496        weapon->getEnergyWidget()->setParent2D(this->rightRect);
[10759]497                if (!this->hidden)
498                weapon->getEnergyWidget()->show();
499        else
500                weapon->getEnergyWidget()->hide();
[10368]501        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
502        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
503        weapon->getEnergyWidget()->setWidgetSize(150,50);
504        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
505        this->weaponsWidgetsSec.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
506      }
507    }
508
[6443]509  this->updateResolution();
[10368]510
[6443]511}
512
[8145]513void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]514{}
[6438]515
[8145]516void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]517{}
[6438]518
[10744]519void Hud::getHit()
520{
521        this->leftHit->show();
522        this->rightHit->show();
[10748]523        hitBarCount = 0.33;
[10744]524}
525
[10748]526void Hud::tick(float dt)
527{
528
529  if (this->playmode == FirstPerson && this->leftHit != NULL)
530  {
531        if (this->ifinit)
532        {
533                this->leftHit->shiftDir2D(3.1416);
534                this->ifinit = false;
535        }
536        if (this->leftHit->isVisible())
[10759]537        {
[10748]538                hitBarCount -= dt;
[10759]539        }
540        if (hitBarCount <= 0)
[10748]541        {
542                hitBarCount = 0;
543                this->leftHit->hide();
544                this->rightHit->hide();
545        }
546  }
[10759]547  //Crosshair* crosshair = dynamic_cast<Crosshair*>(this->weaponManager->getFixedTarget());
548  if ((State::getCamera())->getName() == "GameWorldCamera")
549  {
550        this->hidden = false;
551        if(this->weaponManager)
552                this->weaponManager->showCrosshair();
553  }
554  else
555  {
556        this->hidden = true;
557        if(this->weaponManager)
558                this->weaponManager->hideCrosshair();
559  }
560  this->updateResolution();
[10748]561}
562
[6441]563void Hud::updateResolution()
564{
[6498]565  this->resX = State::getResX();
566  this->resY = State::getResY();
[8976]567
[10716]568  this->setSize2D(this->resX, this->resY);
[10698]569  if( this->playmode != FirstPerson )
570  {
571          this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY);
572          this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY);
573  }
[8976]574
[10368]575  int overlayWidth = 0;
576  if (overlayPercentage >= 20)
577    overlayWidth = this->resX * (overlayPercentage)/(200);
578  else
[10698]579    overlayWidth = this->resX / 10; // fixed warning!
[10368]580  //if (overlayWidth < 100)
581    //overlayWidth = 100;
[8995]582
[10368]583  this->rightRect->hide();
584  this->leftRect->hide();
[10698]585 
586  if( this->playmode != FirstPerson )
587  {
[10716]588         
[10698]589          this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY));
590          this->leftRect->setAbsCoor2D(0,0);
[10736]591          this->leftRect->setBackgroundTexture(Texture());
[10698]592          this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2));
593          this->leftRect->setForegroundTexture(Texture());
[10736]594          this->leftRect->setForegroundColor(Color(0,0,0,0));
[10716]595         
[10698]596          this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY));
597          this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0);
[10736]598          this->rightRect->setBackgroundTexture(Texture());
[10698]599          this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2));
600          this->rightRect->setForegroundTexture(Texture());
[10736]601          this->rightRect->setForegroundColor(Color(0,0,0,0));
[10698]602  }
603  else
604  {
[10736]605        this->bottomRect->setParent2D(this);
606        this->bottomRect->setWidgetSize(float(this->resX), float(overlayWidth));
607        this->bottomRect->setAbsCoor2D(0, this->resY - overlayWidth);
[10759]608        //this->bottomRect->show();
[10736]609       
610        this->topRect->setParent2D(this);
611        this->topRect->setWidgetSize(float(this->resX), float(overlayWidth));
612        this->topRect->setAbsCoor2D(0, 0);
[10759]613        //this->topRect->show();
[10736]614       
615        this->middleRect->setParent2D(this);
[10741]616        this->middleRect->setWidgetSize(float(this->resY)/2, float(this->resY)/2);
617        this->middleRect->setAbsCoor2D(float(this->resX)/4, float(this->resY)/4/*float(this->resX/2), float(this->resY/2)*/);
[10759]618        //this->middleRect->show();
[10736]619       
[10741]620        /*this->bottomHit->setRelCoor2D(0, this->resY/4);
621        this->bottomHit->setWidgetSize(this->resX/8, this->resX/3);
[10736]622        this->bottomHit->show();
623        this->topHit->setRelCoor2D(0, -this->resY/4);
[10741]624        this->topHit->setWidgetSize(this->resX/8, this->resX/3);
625        this->topHit->show();*/
626        this->leftHit->setRelCoor2D(0, 0);
627        this->leftHit->setWidgetSize(this->resX/9, this->resX/3);
[10759]628        //this->leftHit->hide();
[10741]629        this->rightHit->setRelCoor2D(this->resX/3, 0);
630        this->rightHit->setWidgetSize(this->resX/9, this->resX/3);
[10759]631        //this->rightHit->hide();
[10717]632
[10741]633        this->barSocket->setWidgetSize(overlayWidth, overlayWidth);
634        this->barSocket->setRelCoor2D(this->resX - overlayWidth, 0);
[10759]635        if (!this->hidden)
636                this->barSocket->show();
637        else
638                this->barSocket->hide();
[10741]639
[10736]640        //this->middleRect->show();
641       
642       
[10698]643  }
[10368]644
[10759]645  if (this->overlayActive && !this->hidden)
[10368]646  {
647    this->rightRect->show();
648    this->leftRect->show();
649  }
650
651
[8996]652  if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager())
653  {
[9869]654    PRINTF(4)("UPDATING RADAR\n");
[10698]655    if( this->playmode != FirstPerson )
656        this->_radar->setParent2D(this->leftRect);
657    else
658        this->_radar->setParent2D(this->topRect);
[10368]659    if (radarCenterNode == NULL)
660      this->_radar->setCenterNode(State::getPlayer()->getPlayable());
661    else
662      this->_radar->setCenterNode(this->radarCenterNode);
663
664    //this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0));
665    this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_00), Color(1, 0, 0));
666    this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_01), Color(0, 0, 1));
667    this->_radar->setAbsCoor2D(0, 0.01 * this->resY);
668    this->_radar->setWidgetSize(overlayWidth, overlayWidth);
[9014]669    this->_radar->setRange(300);
[10759]670    if (!this->hidden)
671        this->_radar->show();
672    else
673        this->_radar->hide();
[10368]674   
675    int statWidgetsNumber = 0;
[10698]676    float expectedHealthSizeX = 0;
677    float expectedHealthSizeY = 0;
[10368]678    float newSizeY = 0; float newSizeX = 0;
679    float moduloWidth = 0;
680
[10698]681        if( this->playmode != FirstPerson )
682        {
683            if (this->healthWidget != NULL)
684            {
685              expectedHealthSizeX = 150;
686              expectedHealthSizeY = 50;
687              statWidgetsNumber++;
688            }
[10368]689
[10698]690            if (this->shieldWidget != NULL)
691              statWidgetsNumber++;
692           
693            if (this->energyWidget != NULL)
694              statWidgetsNumber++;
695       
[10721]696            if ((expectedHealthSizeY * statWidgetsNumber) > overlayWidth)
[10698]697            {
698              newSizeY = overlayWidth / float(statWidgetsNumber);
699              newSizeX = expectedHealthSizeX;
700              PRINTF(0)("Statwidgets resized\n");
701            }
702            else
703            {
704              newSizeY = expectedHealthSizeY;
705              newSizeX = expectedHealthSizeX;
706              moduloWidth = int(overlayWidth) % int(expectedHealthSizeY * statWidgetsNumber);
707            }
708       
709            float posY = overlayWidth + newSizeX;
710       
711            if (this->healthWidget != NULL)
712            {
713              this->healthWidget->setSize2D(newSizeX, newSizeY);
714              this->healthWidget->setRelCoor2D((statWidgetsNumber - 1) * newSizeY + 3 * moduloWidth / (statWidgetsNumber + 1),posY);
715            }
716            if (this->shieldWidget != NULL)
717            {
718              this->shieldWidget->setSize2D(newSizeX, newSizeY);
719              this->shieldWidget->setRelCoor2D((statWidgetsNumber - 2) * newSizeY + 2 *moduloWidth / (statWidgetsNumber + 1),posY);
720            }
721            if (this->energyWidget != NULL)
722            {
723              this->energyWidget->setSize2D(newSizeX, newSizeY);
724              this->energyWidget->setRelCoor2D(moduloWidth / (statWidgetsNumber + 1),posY);
725            }
726        }
727        else
728        {
729                this->barSocket->setParent2D(this->bottomRect);
730                this->barSocket->setWidgetSize( float(overlayWidth), float(overlayWidth));
[10759]731                this->barSocket->setRelCoor2D(this->resX - float(overlayWidth),0);
[10764]732                if (!this->hidden)
733                        this->barSocket->show();
734                else
735                        this->barSocket->hide();
736                if (this->shieldWidget)
737                {
[10766]738                        this->shieldWidget->setRelCoor2D(40,overlayWidth/2+10);
739                        if (!this->hidden)
740                                this->shieldWidget->show();
741                        else
742                                this->shieldWidget->hide();
743                        this->shieldText->setRelCoor2D(overlayWidth/2-30,overlayWidth/2-60);
744                        if (!this->hidden)
745                                this->shieldText->show();
746                        else
747                                this->shieldText->hide();
[10764]748                }
[10766]749                this->healthWidget->setRelCoor2D(40,overlayWidth/2);
750                if (!this->hidden)
751                        this->healthWidget->show();
752                else
753                        this->healthWidget->hide();
754                this->healthText->setRelCoor2D(overlayWidth/2-50,overlayWidth/2-20);
755                if (!this->hidden)
756                        this->healthText->show();
757                else
758                        this->healthText->hide();
759
[10698]760        }
761       
[10368]762
763    /*
[10698]764    if (this->healthWidget != NULL)
765      this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D());
[10368]766    if (this->shieldWidget != NULL)
[10698]767      this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D());
[10368]768    if (this->energyWidget != NULL)
[10698]769      this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D());
[10368]770    */
[10698]771    //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D(),0);
772    //this->energyWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0);
[8996]773  }
774
[10368]775  /*
776  if (this->shipValuesBox != NULL)
[6441]777  {
[10368]778    this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY);
779    this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY);
[6441]780  }
[10368]781  else
782    createShipValuesBox();
783  */
[10766]784 if (this->playmode != FirstPerson )
785 {
[10368]786  std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget;
787  Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY);
788  float largestWidgetSizeX = 0;
789  //PRINTF(0)("Cur Pos: %f,%f\n",pos.x,pos.y);
790  // out of reasons i can't get behind, this version is segfaulting when calling getSizeX2D or getSizeY2D. the other
791  // element2D- related function works tough.. :s
[6442]792
[10368]793  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
[6442]794  {
[10368]795    float ySize = (*weaponWidget)->getSizeY2D();
796    float xSize = (*weaponWidget)->getSizeX2D();
797    if (xSize > largestWidgetSizeX)
798      largestWidgetSizeX = xSize;
799    if (pos.x < ySize)
[8987]800    {
[10368]801      pos.x = overlayWidth;
802      pos.y += largestWidgetSizeX;
803    }
804    pos.x -= ySize;
805    (*weaponWidget)->setAbsCoor2D(pos.x + this->rightRect->getAbsCoor2D().x, pos.y);
806    //(*weaponWidget)->setAbsCoor2D(0,100);
[10759]807    if (!this->hidden)
808        (*weaponWidget)->show();
809    else
810        (*weaponWidget)->hide();
[10368]811    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
812  }
813 
814  weaponWidget = this->weaponsWidgetsSec.begin();
815  float expectedWidgetSizeY = 0;
816  if (weaponWidget != this->weaponsWidgetsSec.end())
817  {
818    expectedWidgetSizeY = (*weaponWidget)->getSizeY2D();
819  }
820  pos.y = resY - expectedWidgetSizeY * 0.6;
821  pos.x = overlayWidth + this->rightRect->getAbsCoor2D().x;
[8987]822
[10368]823  for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++)
824  {
825    float ySize = (*weaponWidget)->getSizeY2D();
826    float xSize = (*weaponWidget)->getSizeX2D();
827    if (xSize > largestWidgetSizeX)
828      largestWidgetSizeX = xSize;
829    if (pos.x < ySize)
830    {
831      pos.x = overlayWidth;
832      pos.y -= largestWidgetSizeX + expectedWidgetSizeY * 0.6;
[8987]833    }
[10368]834    pos.x -= ySize;
835    //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D());
[10516]836    (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);//+this->rightRect->getAbsCoor2D().x, pos.y);
[10759]837    if (!this->hidden)
838        (*weaponWidget)->show();
839    else
840        (*weaponWidget)->hide();
[9406]841    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
[6442]842  }
[10766]843 }
844 else
845 {
846        std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget;
847        Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY);
848        float largestWidgetSizeX = 0;
[10368]849
[10766]850        for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
851        {
852                (*weaponWidget)->setParent2D(this->barSocket);
853                (*weaponWidget)->setRelCoor2D(overlayWidth/2, 0);
854                //(*weaponWidget)->setAbsCoor2D(0,100);
855                if (!this->hidden)
856                        (*weaponWidget)->show();
857                else
858                        (*weaponWidget)->hide();
859                //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
860        }
861 }
862
[6441]863}
864
[8990]865void Hud::draw() const
[6441]866{
[8990]867  //  GLGuiWidget::draw();
[6441]868}
869
[8990]870
871void Hud::process(const Event &event)
[6441]872{
[8990]873  if (event.type == EV_VIDEO_RESIZE)
874    this->updateResolution();
[9003]875  else if (event.type == SDLK_TAB)
876  {
877    /// TODO SHOW THE INPUT-LINE
878  //  this->inputLine->select();
879  }
[10368]880}
[9003]881
[10368]882/*
883void Hud::createShipValuesBox()
884{
885  this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical);
886  //this->shipValuesBox->setWidgetSize(1000,500);
[10420]887  //this->shipValuesBox->setBackgroundTexture("textures/gui_container_background.png");
[10368]888  this->shipValuesBox->setBackgroundTexture(Texture());
889  this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5));
890  this->shipValuesBox->setVisibility(true);
[6441]891}
[10368]892*/
[6441]893
894
Note: See TracBrowser for help on using the repository browser.