Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: new Functionality to widget, so one can set a foreground texture, for Widgets requesting it.

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