Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/hud.cc @ 6929

Last change on this file since 6929 was 6756, checked in by bensch, 19 years ago

trunk: Burst Particles

File size: 3.5 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
[1855]13   co-programmer: ...
[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"
21
[6442]22#include "world_entities/weapons/weapon_manager.h"
23
[1856]24using namespace std;
[1853]25
[1856]26
[3245]27/**
[4838]28 * standard constructor
29 * @todo this constructor is not jet implemented - do it
[3245]30*/
[6437]31Hud::Hud ()
[3365]32{
[6438]33  this->setClassID(CL_HUD, "Hud");
[4320]34
[6441]35  //this->setSize2D(
[6442]36  this->weaponManager = NULL;
[6440]37  this->energyWidget = NULL;
38  this->shieldWidget = NULL;
39  this->armorWidget = NULL;
[6441]40  this->resX = 1;
41  this->resY = 1;
[6442]42
[3365]43}
[1853]44
45
[3245]46/**
[4838]47 * standard deconstructor
[3245]48*/
[6437]49Hud::~Hud ()
[3543]50{
51  // delete what has to be deleted here
52}
[6438]53
54
55void Hud::loadParams(const TiXmlElement* root)
56{
[6512]57  Element2D::loadParams(root);
[6438]58}
59
60void Hud::setBackGround()
61{
62}
63
64void Hud::setEnergyWidget(GLGuiWidget* widget)
65{
[6440]66  // decopple old widget
67  if (this->energyWidget != NULL)
68  {
69    this->energyWidget->hide();
70  }
[6438]71
[6440]72  this->energyWidget = widget;
73  if (this->energyWidget != NULL)
74  {
75    this->energyWidget->show();
76  }
77
[6441]78  this->updateResolution();
[6438]79}
80
81void Hud::setShiledWidget(GLGuiWidget* widget)
82{
83}
84
85void Hud::setArmorWidget(GLGuiWidget* widget)
86{
[6442]87}
[6438]88
[6442]89void Hud::setWeaponManager(WeaponManager* weaponMan)
90{
91  if (this->weaponManager != NULL)
92  {
93    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
94    {
95      Weapon* weapon = this->weaponManager->getWeapon(i);
96      if (weapon != NULL)
97      {
98        weapon->getEnergyWidget()->hide();
99        this->weaponsWidgets.remove(weapon->getEnergyWidget());
100      }
101    }
102  }
103
104  this->weaponManager = weaponMan;
105
[6445]106  this->updateWeaponManager();
107  this->updateResolution();
[6438]108}
109
[6443]110void Hud::updateWeaponManager()
111{
112  // hide all the Widgets
113  std::list<GLGuiWidget*>::iterator weaponWidget;
114  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++)
115  {
116    (*weaponWidget)->hide();
117  }
118  this->weaponsWidgets.clear();
[6442]119
[6443]120  // add all that we need again.
121  if (this->weaponManager != NULL)
122    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
123  {
124    Weapon* weapon = this->weaponManager->getWeapon(i);
125    if (weapon != NULL)
126    {
127      weapon->getEnergyWidget()->show();
128      this->weaponsWidgets.push_back(weapon->getEnergyWidget());
129    }
130  }
131  this->updateResolution();
132}
133
[6438]134void Hud::addWeaponWidget(GLGuiWidget* widget)
135{
136}
137
138void Hud::removeWeaponWidget(GLGuiWidget* widget)
139{
140}
141
[6441]142void Hud::updateResolution()
143{
[6498]144  this->resX = State::getResX();
145  this->resY = State::getResY();
[6441]146  if (this->energyWidget != NULL)
147  {
148    this->energyWidget->setAbsCoor2D(.02 * this->resX, .4 * this->resY);
149    this->energyWidget->setSize2D(.05 * this->resX, .55 * this->resY);
150  }
[6442]151
152  this->setSize2D(.2 * this->resX, this->resY);
153
154  std::list<GLGuiWidget*>::iterator weaponWidget;
155  float pos = .2;
[6756]156  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos+=.03)
[6442]157  {
[6445]158      (*weaponWidget)->setSize2D(.02*this->resX, .2 *this->resY);
159      (*weaponWidget)->setAbsCoor2D(pos*this->resX, .75*this->resY);
[6756]160
[6442]161  }
[6441]162}
163
164
165void Hud::tick(float dt)
166{
[6498]167  if (this->resY != State::getResY() || this->resX != State::getResY())
[6441]168    this->updateResolution();
169}
170
171void Hud::draw() const
172{
173  GLGuiWidget::draw();
174}
175
176
Note: See TracBrowser for help on using the repository browser.