Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/util/hud.cc @ 8598

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

style enbedded into gui, as it was redundant

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