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
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{
57}
58
59void Hud::setBackGround()
60{
61}
62
63void Hud::setEnergyWidget(GLGuiWidget* widget)
64{
[6440]65  // decopple old widget
66  if (this->energyWidget != NULL)
67  {
68    this->energyWidget->hide();
69  }
[6438]70
[6440]71  this->energyWidget = widget;
72  if (this->energyWidget != NULL)
73  {
74    this->energyWidget->show();
75  }
76
[6441]77  this->updateResolution();
[6438]78}
79
80void Hud::setShiledWidget(GLGuiWidget* widget)
81{
82}
83
84void Hud::setArmorWidget(GLGuiWidget* widget)
85{
[6442]86}
[6438]87
[6442]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();
[6438]118}
119
[6443]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();
[6442]129
[6443]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
[6438]144void Hud::addWeaponWidget(GLGuiWidget* widget)
145{
146}
147
148void Hud::removeWeaponWidget(GLGuiWidget* widget)
149{
150}
151
[6441]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  }
[6442]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
[6441]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.