Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9981 was 9965, checked in by marcscha, 18 years ago

Modifications to ship, HUD,.. see changelog

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