Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Gui Shows weapons (simple)

File size: 3.1 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
120
121void Hud::addWeaponWidget(GLGuiWidget* widget)
122{
123}
124
125void Hud::removeWeaponWidget(GLGuiWidget* widget)
126{
127}
128
129void Hud::updateResolution()
130{
131  this->resX = State::resX();
132  this->resY = State::resY();
133  if (this->energyWidget != NULL)
134  {
135    this->energyWidget->setAbsCoor2D(.02 * this->resX, .4 * this->resY);
136    this->energyWidget->setSize2D(.05 * this->resX, .55 * this->resY);
137  }
138
139  this->setSize2D(.2 * this->resX, this->resY);
140
141  std::list<GLGuiWidget*>::iterator weaponWidget;
142  float pos = .2;
143  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos+=.03)
144  {
145    (*weaponWidget)->setSize2D(.02*this->resX, .2 *this->resY);
146    (*weaponWidget)->setAbsCoor2D(pos*this->resX, .75*this->resY);
147  }
148
149}
150
151
152void Hud::tick(float dt)
153{
154  if (this->resY != State::resY() || this->resX != State::resY())
155    this->updateResolution();
156}
157
158void Hud::draw() const
159{
160  GLGuiWidget::draw();
161}
162
163
Note: See TracBrowser for help on using the repository browser.