Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6444 was 6443, checked in by bensch, 19 years ago

huge pipeline

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