Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed stupid gui segfault

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