Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trying to adjust interface

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