Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7062 was 7062, checked in by bensch, 18 years ago

hud

File size: 3.8 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  Element2D::loadParams(root);
58}
59
60void Hud::setBackGround()
61{
62}
63
64void Hud::setEnergyWidget(GLGuiWidget* widget)
65{
66  // decopple old widget
67  if (this->energyWidget != NULL)
68  {
69    this->energyWidget->hide();
70  }
71
72  this->energyWidget = widget;
73  if (this->energyWidget != NULL)
74  {
75    this->energyWidget->show();
76    this->energyWidget->backMaterial().setDiffuseMap("hud_energy_background.png");
77    this->energyWidget->backMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
78    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
79    this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
80  }
81
82  this->updateResolution();
83}
84
85void Hud::setShiledWidget(GLGuiWidget* widget)
86{
87}
88
89void Hud::setArmorWidget(GLGuiWidget* widget)
90{
91}
92
93void Hud::setWeaponManager(WeaponManager* weaponMan)
94{
95  if (this->weaponManager != NULL)
96  {
97    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
98    {
99      Weapon* weapon = this->weaponManager->getWeapon(i);
100      if (weapon != NULL)
101      {
102        weapon->getEnergyWidget()->hide();
103        this->weaponsWidgets.remove(weapon->getEnergyWidget());
104      }
105    }
106  }
107
108  this->weaponManager = weaponMan;
109
110  this->updateWeaponManager();
111  this->updateResolution();
112}
113
114void Hud::updateWeaponManager()
115{
116  // hide all the Widgets
117  std::list<GLGuiWidget*>::iterator weaponWidget;
118  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++)
119  {
120    (*weaponWidget)->hide();
121  }
122  this->weaponsWidgets.clear();
123
124  // add all that we need again.
125  if (this->weaponManager != NULL)
126    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
127  {
128    Weapon* weapon = this->weaponManager->getWeapon(i);
129    if (weapon != NULL)
130    {
131      weapon->getEnergyWidget()->show();
132      this->weaponsWidgets.push_back(weapon->getEnergyWidget());
133    }
134  }
135  this->updateResolution();
136}
137
138void Hud::addWeaponWidget(GLGuiWidget* widget)
139{
140}
141
142void Hud::removeWeaponWidget(GLGuiWidget* widget)
143{
144}
145
146void Hud::updateResolution()
147{
148  this->resX = State::getResX();
149  this->resY = State::getResY();
150  if (this->energyWidget != NULL)
151  {
152    this->energyWidget->setAbsCoor2D(0 * this->resX, 0 * this->resY);
153    this->energyWidget->setSize2D(.3 * this->resX, 1 * this->resY);
154  }
155
156  this->setSize2D(.2 * this->resX, this->resY);
157
158  std::list<GLGuiWidget*>::iterator weaponWidget;
159  float pos = .2;
160  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos+=.03)
161  {
162      (*weaponWidget)->setSize2D(.02*this->resX, .2 *this->resY);
163      (*weaponWidget)->setAbsCoor2D(pos*this->resX, .75*this->resY);
164
165  }
166}
167
168
169void Hud::tick(float dt)
170{
171  if (this->resY != State::getResY() || this->resX != State::getResY())
172    this->updateResolution();
173}
174
175void Hud::draw() const
176{
177//  GLGuiWidget::draw();
178}
179
180
Note: See TracBrowser for help on using the repository browser.