Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

placed container for ship values into hud

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