Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/height_map_merge/src/util/hud.cc @ 6817

Last change on this file since 6817 was 6446, checked in by bensch, 19 years ago

orxonox/trunk: added grid class

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}
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  this->updateWeaponManager();
106  this->updateResolution();
107}
108
109void Hud::updateWeaponManager()
110{
111  // hide all the Widgets
112  std::list<GLGuiWidget*>::iterator weaponWidget;
113  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++)
114  {
115    (*weaponWidget)->hide();
116  }
117  this->weaponsWidgets.clear();
118
119  // add all that we need again.
120  if (this->weaponManager != NULL)
121    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
122  {
123    Weapon* weapon = this->weaponManager->getWeapon(i);
124    if (weapon != NULL)
125    {
126      weapon->getEnergyWidget()->show();
127      weapon->getLoadedEnergyWidget()->show();
128      this->weaponsWidgets.push_back(weapon->getEnergyWidget());
129      this->weaponsWidgets.push_back(weapon->getLoadedEnergyWidget());
130    }
131  }
132  this->updateResolution();
133}
134
135void Hud::addWeaponWidget(GLGuiWidget* widget)
136{
137}
138
139void Hud::removeWeaponWidget(GLGuiWidget* widget)
140{
141}
142
143void Hud::updateResolution()
144{
145  this->resX = State::resX();
146  this->resY = State::resY();
147  if (this->energyWidget != NULL)
148  {
149    this->energyWidget->setAbsCoor2D(.02 * this->resX, .4 * this->resY);
150    this->energyWidget->setSize2D(.05 * this->resX, .55 * this->resY);
151  }
152
153  this->setSize2D(.2 * this->resX, this->resY);
154
155  std::list<GLGuiWidget*>::iterator weaponWidget;
156  float pos = .2;
157  bool test = true;
158  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos+=.03, test = !test)
159  {
160    if (test)
161    {
162      (*weaponWidget)->setSize2D(.02*this->resX, .2 *this->resY);
163      (*weaponWidget)->setAbsCoor2D(pos*this->resX, .75*this->resY);
164    }
165    else
166    {
167      (*weaponWidget)->setSize2D(.02*this->resX, .17*this->resY);
168      (*weaponWidget)->setAbsCoor2D((pos-.008)*this->resX, .75*this->resY);
169    }
170  }
171}
172
173
174void Hud::tick(float dt)
175{
176  if (this->resY != State::resY() || this->resX != State::resY())
177    this->updateResolution();
178}
179
180void Hud::draw() const
181{
182  GLGuiWidget::draw();
183}
184
185
Note: See TracBrowser for help on using the repository browser.