Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10764 was 10764, checked in by bknecht, 17 years ago

hud is slowly cooler

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