Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10758 was 10753, checked in by bknecht, 18 years ago

few changes

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