Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: RADAR RENDERS

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