Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10763 was 10759, checked in by bknecht, 18 years ago

hud updated

File size: 23.8 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  /*
213  if (this->shipValuesBox == NULL)
214    this->createShipValuesBox();
215  */
216
217  // decopple old widget
218  if (this->shieldWidget != NULL)
219  {
220    this->shieldWidget->hide();
221  }
222
223  this->shieldWidget = widget;
224  if (this->shieldWidget != NULL)
225  {
226    //this->shieldWidget->shiftDir2D(270);
227    //this->shipValuesBox->pack(this->shieldWidget);
228    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setStandardSettings();
229    this->shieldWidget->setParent2D(this->leftRect);
230    dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setDisplayedImage("textures/gui/gui_shield_icon.png");
231    if (!this->hidden)
232        this->shieldWidget->show();
233    else
234        this->shieldWidget->hide();
235    /*    this->shieldWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
236        this->shieldWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
237  }
238  else
239    printf("schild im hud nicht uebergeben!!!!!!!!!!!!!!!!!!!!!!!!!");
240
241  this->updateResolution();
242}
243
244void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget)
245{
246        if( this->playmode == FirstPerson )
247        {
248                this->healthWidget = new OrxGui::GLGuiBar();
249                dynamic_cast<OrxGui::GLGuiBar*> (this->healthWidget)->setMaximum(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->maximum());
250                dynamic_cast<OrxGui::GLGuiBar*> (this->healthWidget)->setValue(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (widget)->getBarWidget()->value());
251                this->healthWidget->setParent2D(this->barSocket);
252        }
253        else
254        {
255          /*
256          if (this->shipValuesBox == NULL)
257            this->createShipValuesBox();
258          */
259       
260        // decopple old widget
261          if (this->healthWidget != NULL)
262          {
263            this->healthWidget->hide();
264          }
265       
266          this->healthWidget = widget;
267          if (this->healthWidget != NULL)
268          {
269            //this->healthWidget->shiftDir2D(270);
270            //this->shipValuesBox->pack(this->healthWidget);
271            //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setStandardSettings();
272            this->healthWidget->setParent2D(this->leftRect);
273            //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->healthWidget)->setDisplayedImage("textures/gui/gui_health_icon.png");
274            if(!this->hidden)
275                this->healthWidget->show();
276            else
277                this->healthWidget->hide();
278            /*    this->healthWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
279                this->healthWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
280          }
281        }
282
283  this->updateResolution();
284}
285
286
287void Hud::setImplantWidget(OrxGui::GLGuiWidget* widget)
288{
289  //if (this->shipValuesBox == NULL)
290    //this->createShipValuesBox();
291
292  // decopple old widget
293  if (this->implantWidget != NULL)
294  {
295    this->implantWidget->hide();
296  }
297
298  this->implantWidget = widget;
299  if (this->implantWidget != NULL)
300  {
301    //this->energyWidget->shiftDir2D(270);
302    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics");
303    //this->shipValuesBox->pack(this->energyWidget);
304    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings();
305    this->implantWidget->setParent2D(this->leftRect);
306    dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->implantWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png");
307    if (!this->hidden)
308        this->implantWidget->show();
309    else
310        this->implantWidget->hide();
311    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
312        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
313  }
314
315  this->updateResolution();
316}
317
318void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec)
319{
320  //clearWeaponManager();
321
322  //Hide all widgets
323  if (this->weaponManager != NULL)
324  {
325    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
326    {
327      Weapon* weapon = this->weaponManager->getWeapon(i);
328      if (weapon != NULL)
329      {
330        weapon->getEnergyWidget()->hide();
331        //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
332      }
333    }
334  }
335
336  if (this->weaponManagerSecondary != NULL)
337  {
338    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
339    {
340      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
341      if (weapon != NULL)
342      {
343        weapon->getEnergyWidget()->hide();
344        //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
345      }
346    }
347  }
348
349  this->weaponManager = weaponMan;
350  this->weaponManagerSecondary = weaponManSec; 
351
352  this->updateWeaponManager();
353  //  this->updateResolution();
354}
355
356/*
357void Hud::clearWeaponManager()
358{
359  //Hide all widgets
360  if (this->weaponManager != NULL)
361  {
362    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
363    {
364      Weapon* weapon = this->weaponManager->getWeapon(i);
365      if (weapon != NULL)
366      {
367        weapon->getEnergyWidget()->hide();
368        //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
369      }
370    }
371  }
372
373  if (this->weaponManagerSecondary != NULL)
374  {
375    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
376    {
377      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
378      if (weapon != NULL)
379      {
380        weapon->getEnergyWidget()->hide();
381        //this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
382      }
383    }
384  }
385
386  //this->weaponsWidgetsPrim.clear();
387  //this->weaponsWidgetsSec.clear();
388}
389*/
390
391void Hud::setMode(Hud::Playmode playmode)
392{
393        this->playmode = playmode;
394        this->init();
395}
396
397void Hud::updateWeaponManager()
398{
399  // hide all the Widgets
400 
401  std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget;
402  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
403  {
404    (*weaponWidget)->hide();
405  }
406  this->weaponsWidgetsPrim.clear();
407
408  for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++)
409  {
410    (*weaponWidget)->hide();
411  }
412  this->weaponsWidgetsSec.clear();
413 
414
415  // add all that we need again.
416
417  if (this->weaponManager != NULL)
418    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
419    {
420      Weapon* weapon = this->weaponManager->getWeapon(i);
421      if (weapon != NULL)
422      {
423        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
424        if (this->playmode != FirstPerson)
425                weapon->getEnergyWidget()->setParent2D(this->rightRect);
426        else
427                weapon->getEnergyWidget()->setParent2D(this->bottomRect);
428        if (!this->hidden)
429                weapon->getEnergyWidget()->show();
430        else
431                weapon->getEnergyWidget()->hide();
432        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
433        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
434        weapon->getEnergyWidget()->setWidgetSize(120,30);
435        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
436        this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
437      }
438    }
439
440  if (this->weaponManagerSecondary != NULL)
441    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
442    {
443      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
444      if (weapon != NULL)
445      {
446        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
447        weapon->getEnergyWidget()->setParent2D(this->rightRect);
448                if (!this->hidden)
449                weapon->getEnergyWidget()->show();
450        else
451                weapon->getEnergyWidget()->hide();
452        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
453        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
454        weapon->getEnergyWidget()->setWidgetSize(150,50);
455        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
456        this->weaponsWidgetsSec.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
457      }
458    }
459
460  this->updateResolution();
461
462}
463
464void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget)
465{}
466
467void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget)
468{}
469
470void Hud::getHit()
471{
472        printf("Got hit!\n");
473        this->leftHit->show();
474        this->rightHit->show();
475        hitBarCount = 0.33;
476}
477
478void Hud::tick(float dt)
479{
480
481  if (this->playmode == FirstPerson && this->leftHit != NULL)
482  {
483        if (this->ifinit)
484        {
485                this->leftHit->shiftDir2D(3.1416);
486                this->ifinit = false;
487        }
488        if (this->leftHit->isVisible())
489        {
490                hitBarCount -= dt;
491                printf("Reduce visibilty!\n");
492        }
493        if (hitBarCount <= 0)
494        {
495                hitBarCount = 0;
496                this->leftHit->hide();
497                this->rightHit->hide();
498                printf("Hide again!\n");
499        }
500  }
501  //Crosshair* crosshair = dynamic_cast<Crosshair*>(this->weaponManager->getFixedTarget());
502  if ((State::getCamera())->getName() == "GameWorldCamera")
503  {
504        this->hidden = false;
505        if(this->weaponManager)
506                this->weaponManager->showCrosshair();
507  }
508  else
509  {
510        this->hidden = true;
511        if(this->weaponManager)
512                this->weaponManager->hideCrosshair();
513  }
514  this->updateResolution();
515}
516
517void Hud::updateResolution()
518{
519  this->resX = State::getResX();
520  this->resY = State::getResY();
521
522  this->setSize2D(this->resX, this->resY);
523  if( this->playmode != FirstPerson )
524  {
525          this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY);
526          this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY);
527  }
528
529  int overlayWidth = 0;
530  if (overlayPercentage >= 20)
531    overlayWidth = this->resX * (overlayPercentage)/(200);
532  else
533    overlayWidth = this->resX / 10; // fixed warning!
534  //if (overlayWidth < 100)
535    //overlayWidth = 100;
536
537  this->rightRect->hide();
538  this->leftRect->hide();
539 
540  if( this->playmode != FirstPerson )
541  {
542         
543          this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY));
544          this->leftRect->setAbsCoor2D(0,0);
545          this->leftRect->setBackgroundTexture(Texture());
546          this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2));
547          this->leftRect->setForegroundTexture(Texture());
548          this->leftRect->setForegroundColor(Color(0,0,0,0));
549         
550          this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY));
551          this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0);
552          this->rightRect->setBackgroundTexture(Texture());
553          this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2));
554          this->rightRect->setForegroundTexture(Texture());
555          this->rightRect->setForegroundColor(Color(0,0,0,0));
556  }
557  else
558  {
559        this->bottomRect->setParent2D(this);
560        this->bottomRect->setWidgetSize(float(this->resX), float(overlayWidth));
561        this->bottomRect->setAbsCoor2D(0, this->resY - overlayWidth);
562        //this->bottomRect->show();
563       
564        this->topRect->setParent2D(this);
565        this->topRect->setWidgetSize(float(this->resX), float(overlayWidth));
566        this->topRect->setAbsCoor2D(0, 0);
567        //this->topRect->show();
568       
569        this->middleRect->setParent2D(this);
570        this->middleRect->setWidgetSize(float(this->resY)/2, float(this->resY)/2);
571        this->middleRect->setAbsCoor2D(float(this->resX)/4, float(this->resY)/4/*float(this->resX/2), float(this->resY/2)*/);
572        //this->middleRect->show();
573       
574        /*this->bottomHit->setRelCoor2D(0, this->resY/4);
575        this->bottomHit->setWidgetSize(this->resX/8, this->resX/3);
576        this->bottomHit->show();
577        this->topHit->setRelCoor2D(0, -this->resY/4);
578        this->topHit->setWidgetSize(this->resX/8, this->resX/3);
579        this->topHit->show();*/
580        this->leftHit->setRelCoor2D(0, 0);
581        this->leftHit->setWidgetSize(this->resX/9, this->resX/3);
582        //this->leftHit->hide();
583        this->rightHit->setRelCoor2D(this->resX/3, 0);
584        this->rightHit->setWidgetSize(this->resX/9, this->resX/3);
585        //this->rightHit->hide();
586
587        this->barSocket->setWidgetSize(overlayWidth, overlayWidth);
588        this->barSocket->setRelCoor2D(this->resX - overlayWidth, 0);
589        if (!this->hidden)
590                this->barSocket->show();
591        else
592                this->barSocket->hide();
593
594        //this->middleRect->show();
595       
596       
597  }
598
599  if (this->overlayActive && !this->hidden)
600  {
601    this->rightRect->show();
602    this->leftRect->show();
603  }
604
605
606  if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager())
607  {
608    PRINTF(4)("UPDATING RADAR\n");
609    if( this->playmode != FirstPerson )
610        this->_radar->setParent2D(this->leftRect);
611    else
612        this->_radar->setParent2D(this->topRect);
613    if (radarCenterNode == NULL)
614      this->_radar->setCenterNode(State::getPlayer()->getPlayable());
615    else
616      this->_radar->setCenterNode(this->radarCenterNode);
617
618    //this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0));
619    this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_00), Color(1, 0, 0));
620    this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_01), Color(0, 0, 1));
621    this->_radar->setAbsCoor2D(0, 0.01 * this->resY);
622    this->_radar->setWidgetSize(overlayWidth, overlayWidth);
623    this->_radar->setRange(300);
624    if (!this->hidden)
625        this->_radar->show();
626    else
627        this->_radar->hide();
628   
629    int statWidgetsNumber = 0;
630    float expectedHealthSizeX = 0;
631    float expectedHealthSizeY = 0;
632    float newSizeY = 0; float newSizeX = 0;
633    float moduloWidth = 0;
634
635        if( this->playmode != FirstPerson )
636        {
637            if (this->healthWidget != NULL)
638            {
639              expectedHealthSizeX = 150;
640              expectedHealthSizeY = 50;
641              statWidgetsNumber++;
642            }
643
644            if (this->shieldWidget != NULL)
645              statWidgetsNumber++;
646           
647            if (this->energyWidget != NULL)
648              statWidgetsNumber++;
649       
650            if ((expectedHealthSizeY * statWidgetsNumber) > overlayWidth)
651            {
652              newSizeY = overlayWidth / float(statWidgetsNumber);
653              newSizeX = expectedHealthSizeX;
654              PRINTF(0)("Statwidgets resized\n");
655            }
656            else
657            {
658              newSizeY = expectedHealthSizeY;
659              newSizeX = expectedHealthSizeX;
660              moduloWidth = int(overlayWidth) % int(expectedHealthSizeY * statWidgetsNumber);
661            }
662       
663            float posY = overlayWidth + newSizeX;
664       
665            if (this->healthWidget != NULL)
666            {
667              this->healthWidget->setSize2D(newSizeX, newSizeY);
668              this->healthWidget->setRelCoor2D((statWidgetsNumber - 1) * newSizeY + 3 * moduloWidth / (statWidgetsNumber + 1),posY);
669            }
670            if (this->shieldWidget != NULL)
671            {
672              this->shieldWidget->setSize2D(newSizeX, newSizeY);
673              this->shieldWidget->setRelCoor2D((statWidgetsNumber - 2) * newSizeY + 2 *moduloWidth / (statWidgetsNumber + 1),posY);
674            }
675            if (this->energyWidget != NULL)
676            {
677              this->energyWidget->setSize2D(newSizeX, newSizeY);
678              this->energyWidget->setRelCoor2D(moduloWidth / (statWidgetsNumber + 1),posY);
679            }
680        }
681        else
682        {
683                this->barSocket->setParent2D(this->bottomRect);
684                this->barSocket->setWidgetSize( float(overlayWidth), float(overlayWidth));
685                this->barSocket->setRelCoor2D(this->resX - float(overlayWidth),0);
686                this->barSocket->show();
687               
688                this->healthWidget->setRelCoor2D(10,-20);
689        }
690       
691
692    /*
693    if (this->healthWidget != NULL)
694      this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D());
695    if (this->shieldWidget != NULL)
696      this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D());
697    if (this->energyWidget != NULL)
698      this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D());
699    */
700    //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D(),0);
701    //this->energyWidget->setRelCoor2D(0.1*this->resX + this->healthWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0);
702  }
703
704  /*
705  if (this->shipValuesBox != NULL)
706  {
707    this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY);
708    this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY);
709  }
710  else
711    createShipValuesBox();
712  */
713
714  std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget;
715  Vector2D pos = Vector2D(overlayWidth, 0.4*this->resY);
716  float largestWidgetSizeX = 0;
717  //PRINTF(0)("Cur Pos: %f,%f\n",pos.x,pos.y);
718  // out of reasons i can't get behind, this version is segfaulting when calling getSizeX2D or getSizeY2D. the other
719  // element2D- related function works tough.. :s
720
721  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
722  {
723    float ySize = (*weaponWidget)->getSizeY2D();
724    float xSize = (*weaponWidget)->getSizeX2D();
725    if (xSize > largestWidgetSizeX)
726      largestWidgetSizeX = xSize;
727    if (pos.x < ySize)
728    {
729      pos.x = overlayWidth;
730      pos.y += largestWidgetSizeX;
731    }
732    pos.x -= ySize;
733    (*weaponWidget)->setAbsCoor2D(pos.x + this->rightRect->getAbsCoor2D().x, pos.y);
734    //(*weaponWidget)->setAbsCoor2D(0,100);
735    if (!this->hidden)
736        (*weaponWidget)->show();
737    else
738        (*weaponWidget)->hide();
739    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
740  }
741 
742  weaponWidget = this->weaponsWidgetsSec.begin();
743  float expectedWidgetSizeY = 0;
744  if (weaponWidget != this->weaponsWidgetsSec.end())
745  {
746    expectedWidgetSizeY = (*weaponWidget)->getSizeY2D();
747  }
748  pos.y = resY - expectedWidgetSizeY * 0.6;
749  pos.x = overlayWidth + this->rightRect->getAbsCoor2D().x;
750
751  for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++)
752  {
753    float ySize = (*weaponWidget)->getSizeY2D();
754    float xSize = (*weaponWidget)->getSizeX2D();
755    if (xSize > largestWidgetSizeX)
756      largestWidgetSizeX = xSize;
757    if (pos.x < ySize)
758    {
759      pos.x = overlayWidth;
760      pos.y -= largestWidgetSizeX + expectedWidgetSizeY * 0.6;
761    }
762    pos.x -= ySize;
763    //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D());
764    (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);//+this->rightRect->getAbsCoor2D().x, pos.y);
765    if (!this->hidden)
766        (*weaponWidget)->show();
767    else
768        (*weaponWidget)->hide();
769    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
770  }
771
772}
773
774void Hud::draw() const
775{
776  //  GLGuiWidget::draw();
777}
778
779
780void Hud::process(const Event &event)
781{
782  if (event.type == EV_VIDEO_RESIZE)
783    this->updateResolution();
784  else if (event.type == SDLK_TAB)
785  {
786    /// TODO SHOW THE INPUT-LINE
787  //  this->inputLine->select();
788  }
789}
790
791/*
792void Hud::createShipValuesBox()
793{
794  this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical);
795  //this->shipValuesBox->setWidgetSize(1000,500);
796  //this->shipValuesBox->setBackgroundTexture("textures/gui_container_background.png");
797  this->shipValuesBox->setBackgroundTexture(Texture());
798  this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5));
799  this->shipValuesBox->setVisibility(true);
800}
801*/
802
803
Note: See TracBrowser for help on using the repository browser.