Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

some interface hacks

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