Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10261 was 10234, checked in by muellmic, 18 years ago

several interface changes and workarounds later… (yes there that crappy little flower at the op-left edge says hello again..)

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