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
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: Benjamin Knecht
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "hud.h"
19
20#include "state.h"
21#include "debug.h"
22
23#include "world_entities/weapons/weapon_manager.h"
24#include "glgui.h"
25#include "glgui_widget.h"
26#include "glgui_box.h"
27#include "glgui_bar.h"
28#include "elements/glgui_energywidgetvertical.h"
29
30#include "glgui_inputline.h"
31#include "specials/glgui_notifier.h"
32#include "elements/glgui_radar.h"
33#include "world_entities/space_ships/space_ship.h"
34
35#include "tools/camera.h"
36
37
38
39
40/// HACK
41#include "player.h"
42#include "playable.h"
43
44ObjectListDefinition(Hud);
45/**
46 * standard constructor
47 * @todo this constructor is not jet implemented - do it
48*/
49Hud::Hud ()
50{
51  this->registerObject(this, Hud::_objectList);
52
53  //this->setSize2D(
54  this->playmode = Full3D;
55  this->weaponManager = NULL;
56  this->weaponManagerSecondary = NULL;
57  this->energyWidget = NULL;
58  this->shieldWidget = NULL;
59  this->healthWidget = NULL;
60  this->leftRect = NULL;
61  this->rightRect = NULL;
62  this->resX = 1;
63  this->resY = 1;
64  this->leftHit = NULL;
65  this->rightHit = NULL;
66  this->ifinit = true;
67  this->hidden = false;
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;
76
77  this->init();
78
79 
80}
81
82
83/**
84 * standard deconstructor
85*/
86Hud::~Hud ()
87{
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;
92
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;
100 
101
102  //if (this->shipValuesBox != NULL)
103    //delete this->shipValuesBox;
104
105  // delete what has to be deleted here
106}
107
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();
117
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       
124
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        {
134                /*this->topHit = new OrxGui::GLGuiImage();
135                this->topHit->loadImageFromFile("textures/gui/gui_hitbar.png");
136                this->topHit->setParent2D(this->middleRect);
137                this->topHit->setAbsDir2D(-1.5708);
138               
139                this->bottomHit = new OrxGui::GLGuiImage();
140                this->bottomHit->loadImageFromFile("textures/gui/gui_hitbar.png");
141                this->bottomHit->setParent2D(this->middleRect);
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);
147               
148                this->leftHit = new OrxGui::GLGuiImage();
149                this->leftHit->loadImageFromFile("textures/gui/gui_hitbarl.png");
150                this->leftHit->setParent2D(this->middleRect);
151               
152               
153                this->rightHit = new OrxGui::GLGuiImage();
154                this->rightHit->loadImageFromFile("textures/gui/gui_hitbar.png");
155                this->rightHit->setParent2D(this->middleRect);
156               
157               
158                this->leftRect->setParent2D(this);
159                this->rightRect->setParent2D(this);
160        }
161
162  //this->shipValuesBox = NULL;
163}
164
165
166void Hud::loadParams(const TiXmlElement* root)
167{
168  Element2D::loadParams(root);
169}
170
171void Hud::notifyUser(const std::string& message)
172{
173  this->notifier->pushNotifyMessage(message);
174}
175
176void Hud::setBackGround()
177{}
178
179void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget)
180{
181  //if (this->shipValuesBox == NULL)
182    //this->createShipValuesBox();
183
184  // decopple old widget
185  if (this->energyWidget != NULL)
186  {
187    this->energyWidget->hide();
188  }
189
190  this->energyWidget = widget;
191  if (this->energyWidget != NULL)
192  {
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);
198    dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png");
199    if (!this->hidden)
200        this->energyWidget->show();
201    else
202        this->energyWidget->hide();
203    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
204        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
205  }
206
207  this->updateResolution(); 
208}
209
210void Hud::setShieldWidget(OrxGui::GLGuiWidget* widget)
211{
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        {
236        this->shieldWidget->hide();
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!!!!!!!!!!!!!!!!!!!!!!!!!");
256  }
257
258  this->updateResolution();
259}
260
261void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget)
262{
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());
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);
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);
297            dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setDisplayedImage("textures/gui/gui_health_icon.png");
298            if(!this->hidden)
299                this->healthWidget->show();
300            else
301                this->healthWidget->hide();
302            /*    this->healthWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
303                this->healthWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
304          }
305        }
306
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)
318  {
319    this->implantWidget->hide();
320  }
321
322  this->implantWidget = widget;
323  if (this->implantWidget != NULL)
324  {
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");
331    if (!this->hidden)
332        this->implantWidget->show();
333    else
334        this->implantWidget->hide();
335    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
336        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
337  }
338
339  this->updateResolution();
340}
341
342void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec)
343{
344  //clearWeaponManager();
345
346  //Hide all widgets
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();
355        //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
356      }
357    }
358  }
359
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
373  this->weaponManager = weaponMan;
374  this->weaponManagerSecondary = weaponManSec; 
375
376  this->updateWeaponManager();
377  //  this->updateResolution();
378}
379
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
415void Hud::setMode(Hud::Playmode playmode)
416{
417        this->playmode = playmode;
418        this->init();
419}
420
421void Hud::updateWeaponManager()
422{
423  // hide all the Widgets
424 
425  std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget;
426  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
427  {
428    (*weaponWidget)->hide();
429  }
430  this->weaponsWidgetsPrim.clear();
431
432  for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++)
433  {
434    (*weaponWidget)->hide();
435  }
436  this->weaponsWidgetsSec.clear();
437 
438
439  // add all that we need again.
440
441  if (this->weaponManager != NULL)
442    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
443    {
444      Weapon* weapon = this->weaponManager->getWeapon(i);
445      if (weapon != NULL)
446      {
447        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
448        if (this->playmode != FirstPerson)
449                weapon->getEnergyWidget()->setParent2D(this->rightRect);
450        else
451                weapon->getEnergyWidget()->setParent2D(this->bottomRect);
452        if (!this->hidden)
453                weapon->getEnergyWidget()->show();
454        else
455                weapon->getEnergyWidget()->hide();
456        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
457        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
458        weapon->getEnergyWidget()->setWidgetSize(120,30);
459        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
460        this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
461      }
462    }
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);
472                if (!this->hidden)
473                weapon->getEnergyWidget()->show();
474        else
475                weapon->getEnergyWidget()->hide();
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
484  this->updateResolution();
485
486}
487
488void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget)
489{}
490
491void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget)
492{}
493
494void Hud::getHit()
495{
496        printf("Got hit!\n");
497        this->leftHit->show();
498        this->rightHit->show();
499        hitBarCount = 0.33;
500}
501
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())
513        {
514                hitBarCount -= dt;
515        }
516        if (hitBarCount <= 0)
517        {
518                hitBarCount = 0;
519                this->leftHit->hide();
520                this->rightHit->hide();
521        }
522  }
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();
537}
538
539void Hud::updateResolution()
540{
541  this->resX = State::getResX();
542  this->resY = State::getResY();
543
544  this->setSize2D(this->resX, this->resY);
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  }
550
551  int overlayWidth = 0;
552  if (overlayPercentage >= 20)
553    overlayWidth = this->resX * (overlayPercentage)/(200);
554  else
555    overlayWidth = this->resX / 10; // fixed warning!
556  //if (overlayWidth < 100)
557    //overlayWidth = 100;
558
559  this->rightRect->hide();
560  this->leftRect->hide();
561 
562  if( this->playmode != FirstPerson )
563  {
564         
565          this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY));
566          this->leftRect->setAbsCoor2D(0,0);
567          this->leftRect->setBackgroundTexture(Texture());
568          this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2));
569          this->leftRect->setForegroundTexture(Texture());
570          this->leftRect->setForegroundColor(Color(0,0,0,0));
571         
572          this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY));
573          this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0);
574          this->rightRect->setBackgroundTexture(Texture());
575          this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2));
576          this->rightRect->setForegroundTexture(Texture());
577          this->rightRect->setForegroundColor(Color(0,0,0,0));
578  }
579  else
580  {
581        this->bottomRect->setParent2D(this);
582        this->bottomRect->setWidgetSize(float(this->resX), float(overlayWidth));
583        this->bottomRect->setAbsCoor2D(0, this->resY - overlayWidth);
584        //this->bottomRect->show();
585       
586        this->topRect->setParent2D(this);
587        this->topRect->setWidgetSize(float(this->resX), float(overlayWidth));
588        this->topRect->setAbsCoor2D(0, 0);
589        //this->topRect->show();
590       
591        this->middleRect->setParent2D(this);
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)*/);
594        //this->middleRect->show();
595       
596        /*this->bottomHit->setRelCoor2D(0, this->resY/4);
597        this->bottomHit->setWidgetSize(this->resX/8, this->resX/3);
598        this->bottomHit->show();
599        this->topHit->setRelCoor2D(0, -this->resY/4);
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);
604        //this->leftHit->hide();
605        this->rightHit->setRelCoor2D(this->resX/3, 0);
606        this->rightHit->setWidgetSize(this->resX/9, this->resX/3);
607        //this->rightHit->hide();
608
609        this->barSocket->setWidgetSize(overlayWidth, overlayWidth);
610        this->barSocket->setRelCoor2D(this->resX - overlayWidth, 0);
611        if (!this->hidden)
612                this->barSocket->show();
613        else
614                this->barSocket->hide();
615
616        //this->middleRect->show();
617       
618       
619  }
620
621  if (this->overlayActive && !this->hidden)
622  {
623    this->rightRect->show();
624    this->leftRect->show();
625  }
626
627
628  if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager())
629  {
630    PRINTF(4)("UPDATING RADAR\n");
631    if( this->playmode != FirstPerson )
632        this->_radar->setParent2D(this->leftRect);
633    else
634        this->_radar->setParent2D(this->topRect);
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);
645    this->_radar->setRange(300);
646    if (!this->hidden)
647        this->_radar->show();
648    else
649        this->_radar->hide();
650   
651    int statWidgetsNumber = 0;
652    float expectedHealthSizeX = 0;
653    float expectedHealthSizeY = 0;
654    float newSizeY = 0; float newSizeX = 0;
655    float moduloWidth = 0;
656
657        if( this->playmode != FirstPerson )
658        {
659            if (this->healthWidget != NULL)
660            {
661              expectedHealthSizeX = 150;
662              expectedHealthSizeY = 50;
663              statWidgetsNumber++;
664            }
665
666            if (this->shieldWidget != NULL)
667              statWidgetsNumber++;
668           
669            if (this->energyWidget != NULL)
670              statWidgetsNumber++;
671       
672            if ((expectedHealthSizeY * statWidgetsNumber) > overlayWidth)
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));
707                this->barSocket->setRelCoor2D(this->resX - float(overlayWidth),0);
708                if (!this->hidden)
709                        this->barSocket->show();
710                else
711                        this->barSocket->hide();
712               
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                }
720        }
721       
722
723    /*
724    if (this->healthWidget != NULL)
725      this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D());
726    if (this->shieldWidget != NULL)
727      this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D());
728    if (this->energyWidget != NULL)
729      this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D());
730    */
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);
733  }
734
735  /*
736  if (this->shipValuesBox != NULL)
737  {
738    this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY);
739    this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY);
740  }
741  else
742    createShipValuesBox();
743  */
744
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
751
752  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
753  {
754    float ySize = (*weaponWidget)->getSizeY2D();
755    float xSize = (*weaponWidget)->getSizeX2D();
756    if (xSize > largestWidgetSizeX)
757      largestWidgetSizeX = xSize;
758    if (pos.x < ySize)
759    {
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);
766    if (!this->hidden)
767        (*weaponWidget)->show();
768    else
769        (*weaponWidget)->hide();
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;
781
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;
792    }
793    pos.x -= ySize;
794    //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D());
795    (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);//+this->rightRect->getAbsCoor2D().x, pos.y);
796    if (!this->hidden)
797        (*weaponWidget)->show();
798    else
799        (*weaponWidget)->hide();
800    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
801  }
802
803}
804
805void Hud::draw() const
806{
807  //  GLGuiWidget::draw();
808}
809
810
811void Hud::process(const Event &event)
812{
813  if (event.type == EV_VIDEO_RESIZE)
814    this->updateResolution();
815  else if (event.type == SDLK_TAB)
816  {
817    /// TODO SHOW THE INPUT-LINE
818  //  this->inputLine->select();
819  }
820}
821
822/*
823void Hud::createShipValuesBox()
824{
825  this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical);
826  //this->shipValuesBox->setWidgetSize(1000,500);
827  //this->shipValuesBox->setBackgroundTexture("textures/gui_container_background.png");
828  this->shipValuesBox->setBackgroundTexture(Texture());
829  this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5));
830  this->shipValuesBox->setVisibility(true);
831}
832*/
833
834
Note: See TracBrowser for help on using the repository browser.