Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

few changes

File size: 22.6 KB
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[6437]12   main-programmer: Benjamin Grauer
[10698]13   co-programmer: Benjamin Knecht
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[6437]18#include "hud.h"
[1853]19
[6441]20#include "state.h"
[8976]21#include "debug.h"
[6441]22
[6442]23#include "world_entities/weapons/weapon_manager.h"
[10717]24#include "glgui.h"
[8448]25#include "glgui_widget.h"
[10368]26#include "glgui_box.h"
27#include "glgui_bar.h"
28#include "elements/glgui_energywidgetvertical.h"
[6442]29
[8518]30#include "glgui_inputline.h"
31#include "specials/glgui_notifier.h"
[8994]32#include "elements/glgui_radar.h"
[10368]33#include "world_entities/space_ships/space_ship.h"
[8518]34
[8996]35
36
37/// HACK
38#include "player.h"
39#include "playable.h"
40
[9869]41ObjectListDefinition(Hud);
[3245]42/**
[4838]43 * standard constructor
44 * @todo this constructor is not jet implemented - do it
[3245]45*/
[6437]46Hud::Hud ()
[3365]47{
[9869]48  this->registerObject(this, Hud::_objectList);
[4320]49
[6441]50  //this->setSize2D(
[6442]51  this->weaponManager = NULL;
[10368]52  this->weaponManagerSecondary = NULL;
[6440]53  this->energyWidget = NULL;
54  this->shieldWidget = NULL;
[10698]55  this->healthWidget = NULL;
56  this->leftRect = NULL;
57  this->rightRect = NULL;
[6441]58  this->resX = 1;
59  this->resY = 1;
[10748]60  this->leftHit = NULL;
61  this->rightHit = NULL;
62  this->ifinit = true;
[10752]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;
[6442]71
[10752]72  this->init();
[10717]73
[10698]74 
[3365]75}
[1853]76
77
[3245]78/**
[4838]79 * standard deconstructor
[3245]80*/
[6437]81Hud::~Hud ()
[3543]82{
[10752]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;
[8994]87
[10752]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;
[10716]95 
[10698]96
[10368]97  //if (this->shipValuesBox != NULL)
98    //delete this->shipValuesBox;
99
[3543]100  // delete what has to be deleted here
101}
[6438]102
[10716]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();
[6438]112
[10716]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       
[10741]119
[10716]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        {
[10741]129                /*this->topHit = new OrxGui::GLGuiImage();
[10716]130                this->topHit->loadImageFromFile("textures/gui/gui_hitbar.png");
131                this->topHit->setParent2D(this->middleRect);
[10741]132                this->topHit->setAbsDir2D(-1.5708);
[10716]133               
134                this->bottomHit = new OrxGui::GLGuiImage();
135                this->bottomHit->loadImageFromFile("textures/gui/gui_hitbar.png");
136                this->bottomHit->setParent2D(this->middleRect);
[10741]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);
[10716]142               
143                this->leftHit = new OrxGui::GLGuiImage();
[10753]144                this->leftHit->loadImageFromFile("textures/gui/gui_hitbarl.png");
[10716]145                this->leftHit->setParent2D(this->middleRect);
146               
[10748]147               
[10716]148                this->rightHit = new OrxGui::GLGuiImage();
149                this->rightHit->loadImageFromFile("textures/gui/gui_hitbar.png");
150                this->rightHit->setParent2D(this->middleRect);
151               
[10741]152               
[10716]153                this->leftRect->setParent2D(this);
154                this->rightRect->setParent2D(this);
155        }
156
157  //this->shipValuesBox = NULL;
158}
159
160
[6438]161void Hud::loadParams(const TiXmlElement* root)
162{
[6512]163  Element2D::loadParams(root);
[6438]164}
165
[8518]166void Hud::notifyUser(const std::string& message)
[6438]167{
[8518]168  this->notifier->pushNotifyMessage(message);
[6438]169}
170
[8518]171void Hud::setBackGround()
172{}
173
[8145]174void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget)
[6438]175{
[10368]176  //if (this->shipValuesBox == NULL)
177    //this->createShipValuesBox();
178
[6440]179  // decopple old widget
180  if (this->energyWidget != NULL)
181  {
182    this->energyWidget->hide();
183  }
[6438]184
[6440]185  this->energyWidget = widget;
186  if (this->energyWidget != NULL)
187  {
[10368]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);
[10449]193    dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedImage("textures/gui/gui_electronics_icon.png");
[6440]194    this->energyWidget->show();
[8518]195    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
196        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
[6440]197  }
198
[10698]199  this->updateResolution(); 
[6438]200}
201
[10698]202void Hud::setShieldWidget(OrxGui::GLGuiWidget* widget)
[10368]203{
204  /*
205  if (this->shipValuesBox == NULL)
206    this->createShipValuesBox();
207  */
[6438]208
[10368]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);
[10449]222    dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setDisplayedImage("textures/gui/gui_shield_icon.png");
[10368]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
[10698]233void Hud::setHealthWidget(OrxGui::GLGuiWidget* widget)
[10368]234{
[10698]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        }
[6438]268
[10698]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)
[10368]280  {
[10698]281    this->implantWidget->hide();
[10368]282  }
283
[10698]284  this->implantWidget = widget;
285  if (this->implantWidget != NULL)
[10368]286  {
[10698]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);*/
[10368]296  }
297
298  this->updateResolution();
299}
300
301void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec)
[6442]302{
[10368]303  //clearWeaponManager();
304
305  //Hide all widgets
[6442]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();
[10368]314        //this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
[6442]315      }
316    }
317  }
318
[10368]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
[6442]332  this->weaponManager = weaponMan;
[10368]333  this->weaponManagerSecondary = weaponManSec; 
[6442]334
[6445]335  this->updateWeaponManager();
[8996]336  //  this->updateResolution();
[6438]337}
338
[10368]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
[10716]374void Hud::setMode(Hud::Playmode playmode)
375{
376        this->playmode = playmode;
377        this->init();
378}
379
[6443]380void Hud::updateWeaponManager()
381{
382  // hide all the Widgets
[10368]383 
384  std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget;
385  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
[6443]386  {
387    (*weaponWidget)->hide();
388  }
[10368]389  this->weaponsWidgetsPrim.clear();
[6442]390
[10368]391  for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++)
392  {
393    (*weaponWidget)->hide();
394  }
395  this->weaponsWidgetsSec.clear();
396 
397
[6443]398  // add all that we need again.
[10368]399
[6443]400  if (this->weaponManager != NULL)
401    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
402    {
[8518]403      Weapon* weapon = this->weaponManager->getWeapon(i);
404      if (weapon != NULL)
405      {
[9406]406        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
[10741]407        if (this->playmode != FirstPerson)
408                weapon->getEnergyWidget()->setParent2D(this->rightRect);
409        else
410                weapon->getEnergyWidget()->setParent2D(this->bottomRect);
[8518]411        weapon->getEnergyWidget()->show();
[8619]412        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
[8518]413        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
[10368]414        weapon->getEnergyWidget()->setWidgetSize(120,30);
415        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
416        this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
[8518]417      }
[6443]418    }
[10368]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
[6443]437  this->updateResolution();
[10368]438
[6443]439}
440
[8145]441void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]442{}
[6438]443
[8145]444void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]445{}
[6438]446
[10744]447void Hud::getHit()
448{
449        this->leftHit->show();
450        this->rightHit->show();
[10748]451        hitBarCount = 0.33;
[10744]452}
453
[10748]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
[6441]475void Hud::updateResolution()
476{
[6498]477  this->resX = State::getResX();
478  this->resY = State::getResY();
[8976]479
[10716]480  this->setSize2D(this->resX, this->resY);
[10698]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  }
[8976]486
[10368]487  int overlayWidth = 0;
488  if (overlayPercentage >= 20)
489    overlayWidth = this->resX * (overlayPercentage)/(200);
490  else
[10698]491    overlayWidth = this->resX / 10; // fixed warning!
[10368]492  //if (overlayWidth < 100)
493    //overlayWidth = 100;
[8995]494
[10368]495  this->rightRect->hide();
496  this->leftRect->hide();
[10698]497 
498  if( this->playmode != FirstPerson )
499  {
[10716]500         
[10698]501          this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY));
502          this->leftRect->setAbsCoor2D(0,0);
[10736]503          this->leftRect->setBackgroundTexture(Texture());
[10698]504          this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2));
505          this->leftRect->setForegroundTexture(Texture());
[10736]506          this->leftRect->setForegroundColor(Color(0,0,0,0));
[10716]507         
[10698]508          this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY));
509          this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0);
[10736]510          this->rightRect->setBackgroundTexture(Texture());
[10698]511          this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2));
512          this->rightRect->setForegroundTexture(Texture());
[10736]513          this->rightRect->setForegroundColor(Color(0,0,0,0));
[10698]514  }
515  else
516  {
[10736]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);
[10741]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)*/);
[10736]528       
[10741]529        /*this->bottomHit->setRelCoor2D(0, this->resY/4);
530        this->bottomHit->setWidgetSize(this->resX/8, this->resX/3);
[10736]531        this->bottomHit->show();
532        this->topHit->setRelCoor2D(0, -this->resY/4);
[10741]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);
[10748]537        this->leftHit->hide();
[10741]538        this->rightHit->setRelCoor2D(this->resX/3, 0);
539        this->rightHit->setWidgetSize(this->resX/9, this->resX/3);
540        this->rightHit->hide();
[10717]541
[10741]542        this->barSocket->setWidgetSize(overlayWidth, overlayWidth);
543        this->barSocket->setRelCoor2D(this->resX - overlayWidth, 0);
[10748]544        this->barSocket->show();
[10741]545
[10736]546        //this->middleRect->show();
547       
548       
[10698]549  }
[10368]550
[10736]551  if (this->overlayActive)
[10368]552  {
553    this->rightRect->show();
554    this->leftRect->show();
555  }
556
557
[8996]558  if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager())
559  {
[9869]560    PRINTF(4)("UPDATING RADAR\n");
[10698]561    if( this->playmode != FirstPerson )
562        this->_radar->setParent2D(this->leftRect);
563    else
564        this->_radar->setParent2D(this->topRect);
[10368]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);
[9014]575    this->_radar->setRange(300);
[8996]576    this->_radar->show();
[10368]577   
578    int statWidgetsNumber = 0;
[10698]579    float expectedHealthSizeX = 0;
580    float expectedHealthSizeY = 0;
[10368]581    float newSizeY = 0; float newSizeX = 0;
582    float moduloWidth = 0;
583
[10698]584        if( this->playmode != FirstPerson )
585        {
586            if (this->healthWidget != NULL)
587            {
588              expectedHealthSizeX = 150;
589              expectedHealthSizeY = 50;
590              statWidgetsNumber++;
591            }
[10368]592
[10698]593            if (this->shieldWidget != NULL)
594              statWidgetsNumber++;
595           
596            if (this->energyWidget != NULL)
597              statWidgetsNumber++;
598       
[10721]599            if ((expectedHealthSizeY * statWidgetsNumber) > overlayWidth)
[10698]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       
[10368]639
640    /*
[10698]641    if (this->healthWidget != NULL)
642      this->healthWidget->setRelCoor2D(100,0.2*this->resY + this->healthWidget->getSizeX2D());
[10368]643    if (this->shieldWidget != NULL)
[10698]644      this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->healthWidget->getSizeX2D());
[10368]645    if (this->energyWidget != NULL)
[10698]646      this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->healthWidget->getSizeX2D());
[10368]647    */
[10698]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);
[8996]650  }
651
[10368]652  /*
653  if (this->shipValuesBox != NULL)
[6441]654  {
[10368]655    this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY);
656    this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY);
[6441]657  }
[10368]658  else
659    createShipValuesBox();
660  */
[6442]661
[10368]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
[6442]668
[10368]669  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
[6442]670  {
[10368]671    float ySize = (*weaponWidget)->getSizeY2D();
672    float xSize = (*weaponWidget)->getSizeX2D();
673    if (xSize > largestWidgetSizeX)
674      largestWidgetSizeX = xSize;
675    if (pos.x < ySize)
[8987]676    {
[10368]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;
[8987]695
[10368]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;
[8987]706    }
[10368]707    pos.x -= ySize;
708    //PRINTF(0)("secweaponwidget y-size: %f/n", (*weaponWidget)->getSizeY2D());
[10516]709    (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);//+this->rightRect->getAbsCoor2D().x, pos.y);
[8976]710    (*weaponWidget)->show();
[9406]711    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
[6442]712  }
[10368]713
[6441]714}
715
[8990]716void Hud::draw() const
[6441]717{
[8990]718  //  GLGuiWidget::draw();
[6441]719}
720
[8990]721
722void Hud::process(const Event &event)
[6441]723{
[8990]724  if (event.type == EV_VIDEO_RESIZE)
725    this->updateResolution();
[9003]726  else if (event.type == SDLK_TAB)
727  {
728    /// TODO SHOW THE INPUT-LINE
729  //  this->inputLine->select();
730  }
[10368]731}
[9003]732
[10368]733/*
734void Hud::createShipValuesBox()
735{
736  this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical);
737  //this->shipValuesBox->setWidgetSize(1000,500);
[10420]738  //this->shipValuesBox->setBackgroundTexture("textures/gui_container_background.png");
[10368]739  this->shipValuesBox->setBackgroundTexture(Texture());
740  this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5));
741  this->shipValuesBox->setVisibility(true);
[6441]742}
[10368]743*/
[6441]744
745
Note: See TracBrowser for help on using the repository browser.