Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10209 was 10194, checked in by muellmic, 18 years ago

implementing interface 'by hand' without still buggy packing-function. can't test with spaceship because of segfault

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