Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

blablubb

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