Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/util/hud.cc @ 10101

Last change on this file since 10101 was 10092, checked in by muellmic, 18 years ago

work of last week: radar set-up, Gui- Widget class draws itself according to Dir of 2d- element.

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