Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10270 was 10270, checked in by muellmic, 17 years ago

1) the centerpoint of the radar is now the centerpoint of the camera, so the enemies won't move in the radar when the player is moving; 2)fovy and cameradistance of each viewmode can now be set dynamically. so one would't have to readjust the fovy for each viewmode, when it has been manually changed once. (it's better to just change the fovy or distance for the viewmode where you need it); 3)unlike in the last revision, it doesnt have a soft- zoom- effect when setting a fovy anymore.

File size: 13.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#include "glgui_box.h"
26#include "glgui_bar.h"
27#include "elements/glgui_energywidgetvertical.h"
28
29#include "glgui_inputline.h"
30#include "specials/glgui_notifier.h"
31#include "elements/glgui_radar.h"
32#include "world_entities/space_ships/space_ship.h"
33
34
35
36/// HACK
37#include "player.h"
38#include "playable.h"
39
40ObjectListDefinition(Hud);
41/**
42 * standard constructor
43 * @todo this constructor is not jet implemented - do it
44*/
45Hud::Hud ()
46{
47  this->registerObject(this, Hud::_objectList);
48
49  //this->setSize2D(
50  this->weaponManager = NULL;
51  this->weaponManagerSecondary = NULL;
52  this->energyWidget = NULL;
53  this->shieldWidget = NULL;
54  this->armorWidget = NULL;
55  //this->leftRect = NULL;
56  //this->rightRect = NULL;
57  this->resX = 1;
58  this->resY = 1;
59
60  this->overlayPercentage = 40;
61  this->overlayActive = false;
62  this->rightRect = new OrxGui::GLGuiImage();
63  this->leftRect = new OrxGui::GLGuiImage();
64
65  this->inputLine = new OrxGui::GLGuiInputLine();
66  this->inputLine->setParent2D(this);
67  this->notifier = new OrxGui::GLGuiNotifier();
68  this->notifier->setParent2D(this);
69  notifier->setAbsCoor2D(100,100);
70
71  this->_radar = new OrxGui::GLGuiRadar();
72  this->radarCenterNode = NULL;
73
74  this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE);
75  this->subscribeEvent(ES_ALL, SDLK_TAB);
76
77  //this->shipValuesBox = NULL;
78}
79
80
81/**
82 * standard deconstructor
83*/
84Hud::~Hud ()
85{
86  delete this->inputLine;
87  delete this->notifier;
88
89  delete this->_radar;
90  delete this->rightRect;
91  delete this->leftRect;
92  //if (this->shipValuesBox != NULL)
93    //delete this->shipValuesBox;
94
95  // delete what has to be deleted here
96}
97
98
99void Hud::loadParams(const TiXmlElement* root)
100{
101  Element2D::loadParams(root);
102}
103
104void Hud::notifyUser(const std::string& message)
105{
106  this->notifier->pushNotifyMessage(message);
107}
108
109void Hud::setBackGround()
110{}
111
112void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget)
113{
114  //if (this->shipValuesBox == NULL)
115    //this->createShipValuesBox();
116
117  // decopple old widget
118  if (this->energyWidget != NULL)
119  {
120    this->energyWidget->hide();
121  }
122
123  this->energyWidget = widget;
124  if (this->energyWidget != NULL)
125  {
126    //this->energyWidget->shiftDir2D(270);
127    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics");
128    //this->shipValuesBox->pack(this->energyWidget);
129    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setStandardSettings();
130    this->energyWidget->setParent2D(this->leftRect);
131    this->energyWidget->show();
132    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
133        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
134  }
135
136  this->updateResolution();
137}
138
139void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget)
140{
141  /*
142  if (this->shipValuesBox == NULL)
143    this->createShipValuesBox();
144  */
145
146  // decopple old widget
147  if (this->shieldWidget != NULL)
148  {
149    this->shieldWidget->hide();
150  }
151
152  this->shieldWidget = widget;
153  if (this->shieldWidget != NULL)
154  {
155    //this->shieldWidget->shiftDir2D(270);
156    //this->shipValuesBox->pack(this->shieldWidget);
157    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->shieldWidget)->setStandardSettings();
158    this->shieldWidget->setParent2D(this->leftRect);
159    this->shieldWidget->show();
160    /*    this->shieldWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
161        this->shieldWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
162  }
163  else
164    printf("schild im hud nicht uebergeben!!!!!!!!!!!!!!!!!!!!!!!!!");
165
166  this->updateResolution();
167}
168
169void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget)
170{
171  /*
172  if (this->shipValuesBox == NULL)
173    this->createShipValuesBox();
174  */
175
176// decopple old widget
177  if (this->armorWidget != NULL)
178  {
179    this->armorWidget->hide();
180  }
181
182  this->armorWidget = widget;
183  if (this->armorWidget != NULL)
184  {
185    //this->armorWidget->shiftDir2D(270);
186    //this->shipValuesBox->pack(this->armorWidget);
187    //dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->armorWidget)->setStandardSettings();
188    this->armorWidget->setParent2D(this->leftRect);
189    this->armorWidget->show();
190    /*    this->armorWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
191        this->armorWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
192  }
193
194  this->updateResolution();
195}
196
197void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec)
198{
199  if (this->weaponManager != NULL)
200  {
201    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
202    {
203      Weapon* weapon = this->weaponManager->getWeapon(i);
204      if (weapon != NULL)
205      {
206        weapon->getEnergyWidget()->hide();
207        this->weaponsWidgetsPrim.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
208      }
209    }
210  }
211
212  if (this->weaponManagerSecondary != NULL)
213  {
214    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
215    {
216      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
217      if (weapon != NULL)
218      {
219        weapon->getEnergyWidget()->hide();
220        this->weaponsWidgetsSec.remove(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
221      }
222    }
223  }
224
225  this->weaponManager = weaponMan;
226  this->weaponManagerSecondary = weaponManSec;
227
228  this->updateWeaponManager();
229  //  this->updateResolution();
230}
231
232void Hud::updateWeaponManager()
233{
234  // hide all the Widgets
235  std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget;
236  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
237  {
238    (*weaponWidget)->hide();
239  }
240  this->weaponsWidgetsPrim.clear();
241
242  for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++)
243  {
244    (*weaponWidget)->hide();
245  }
246  this->weaponsWidgetsSec.clear();
247
248  // add all that we need again.
249  if (this->weaponManager != NULL)
250    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
251    {
252      Weapon* weapon = this->weaponManager->getWeapon(i);
253      if (weapon != NULL)
254      {
255        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
256        weapon->getEnergyWidget()->setParent2D(this->rightRect);
257        weapon->getEnergyWidget()->show();
258        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
259        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
260        weapon->getEnergyWidget()->setWidgetSize(120,30);
261        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
262        this->weaponsWidgetsPrim.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
263      }
264    }
265
266  if (this->weaponManagerSecondary != NULL)
267    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
268    {
269      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
270      if (weapon != NULL)
271      {
272        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
273        weapon->getEnergyWidget()->setParent2D(this->rightRect);
274        weapon->getEnergyWidget()->show();
275        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
276        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
277        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
278        this->weaponsWidgetsSec.push_back(dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (weapon->getEnergyWidget()));
279      }
280    }
281
282  this->updateResolution();
283
284}
285
286void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget)
287{}
288
289void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget)
290{}
291
292void Hud::updateResolution()
293{
294  this->resX = State::getResX();
295  this->resY = State::getResY();
296
297  this->setSize2D(.2 * this->resX, this->resY);
298  this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY);
299  this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY);
300
301  int overlayWidth = this->resX * (overlayPercentage)/(200);
302  this->rightRect->hide();
303  this->leftRect->hide();
304
305  this->leftRect->setParent2D(this);
306  this->leftRect->setWidgetSize(float(overlayWidth), float(this->resY));
307  this->leftRect->setAbsCoor2D(0,0);
308  this->leftRect->setBackgroundTexture(Texture());
309  this->leftRect->setBackgroundColor(Color(0,0,0.7,0.2));
310  this->leftRect->setForegroundTexture(Texture());
311  this->leftRect->setForegroundColor(Color(0,0,0,0));
312
313  this->rightRect->setParent2D(this);
314  this->rightRect->setWidgetSize(float(overlayWidth), float(this->resY));
315  this->rightRect->setAbsCoor2D(this->resX - overlayWidth,0);
316  this->rightRect->setBackgroundTexture(Texture());
317  this->rightRect->setBackgroundColor(Color(0,0,0.7,0.2));
318  this->rightRect->setForegroundTexture(Texture());
319  this->rightRect->setForegroundColor(Color(0,0,0,0));
320
321
322  if (this->overlayActive == true)
323  {
324    this->rightRect->show();
325    this->leftRect->show();
326  }
327
328
329  if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager())
330  {
331    PRINTF(4)("UPDATING RADAR\n");
332    this->_radar->setParent2D(this->leftRect);
333    if (radarCenterNode == NULL)
334      this->_radar->setCenterNode(State::getPlayer()->getPlayable());
335    else
336      this->_radar->setCenterNode(this->radarCenterNode);
337
338    //this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0));
339    this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_00), Color(1, 0, 0));
340    this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_01), Color(0, 0, 1));
341    this->_radar->setAbsCoor2D(0, 0.01 * this->resY);
342    this->_radar->setWidgetSize(0.18 * this->resX, 0.2 * this->resY);
343    this->_radar->setRange(300);
344    this->_radar->show();
345
346    if (this->armorWidget != NULL)
347      this->armorWidget->setRelCoor2D(100,0.2*this->resY + this->armorWidget->getSizeX2D());
348    if (this->shieldWidget != NULL)
349      this->shieldWidget->setRelCoor2D(60,0.2*this->resY + this->armorWidget->getSizeX2D());
350    if (this->energyWidget != NULL)
351      this->energyWidget->setRelCoor2D(20,0.2*this->resY + this->armorWidget->getSizeX2D());
352    //this->shieldWidget->setRelCoor2D(0.1*this->resX + this->armorWidget->getSizeX2D(),0);
353    //this->energyWidget->setRelCoor2D(0.1*this->resX + this->armorWidget->getSizeX2D() + this->shieldWidget->getSizeX2D(),0);
354  }
355
356  /*
357  if (this->shipValuesBox != NULL)
358  {
359    this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY);
360    this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY);
361  }
362  else
363    createShipValuesBox();
364  */
365
366  std::list<OrxGui::GLGuiEnergyWidgetVertical*>::iterator weaponWidget;
367  Vector2D pos(overlayWidth, 0.5*this->resY);
368
369  // out of reasons i can't get behind, this version is segfaulting when calling getSizeX2D or getSizeY2D. the other
370  // element2D- related function works tough.. :s
371
372  for (weaponWidget = this->weaponsWidgetsPrim.begin(); weaponWidget != this->weaponsWidgetsPrim.end(); weaponWidget++)
373  {
374    if (pos.x < overlayWidth*0.2)
375    {
376      pos.x = overlayWidth;
377      pos.y += (*weaponWidget)->getSizeX2D();
378    }
379    pos.x -= (*weaponWidget)->getSizeY2D();
380    (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);
381    //(*weaponWidget)->setAbsCoor2D(0,100);
382    (*weaponWidget)->show();
383    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
384  }
385
386  pos.y += 160;
387  pos.x = overlayWidth;
388  for (weaponWidget = this->weaponsWidgetsSec.begin(); weaponWidget != this->weaponsWidgetsSec.end(); weaponWidget++)
389  {
390    if (pos.x < overlayWidth*0.2)
391    {
392      pos.x = overlayWidth;
393      pos.y += (*weaponWidget)->getSizeX2D();
394    }
395    pos.x -= (*weaponWidget)->getSizeY2D();
396    (*weaponWidget)->setAbsCoor2D(pos.x, pos.y);
397    (*weaponWidget)->show();
398    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
399  }
400
401}
402
403void Hud::draw() const
404{
405  //  GLGuiWidget::draw();
406}
407
408
409void Hud::process(const Event &event)
410{
411  if (event.type == EV_VIDEO_RESIZE)
412    this->updateResolution();
413  else if (event.type == SDLK_TAB)
414  {
415    /// TODO SHOW THE INPUT-LINE
416  //  this->inputLine->select();
417  }
418}
419
420/*
421void Hud::createShipValuesBox()
422{
423  this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Vertical);
424  //this->shipValuesBox->setWidgetSize(1000,500);
425  //this->shipValuesBox->setBackgroundTexture("maps/gui_container_background.png");
426  this->shipValuesBox->setBackgroundTexture(Texture());
427  this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5));
428  this->shipValuesBox->setVisibility(true);
429}
430*/
431
432
Note: See TracBrowser for help on using the repository browser.