Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/util/hud.cc @ 10771

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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