Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Kralle entfernt?

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