Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/hud.cc @ 9503

Last change on this file since 9503 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 5.9 KB
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[6437]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[6437]18#include "hud.h"
[1853]19
[6441]20#include "state.h"
[8976]21#include "debug.h"
[6441]22
[6442]23#include "world_entities/weapons/weapon_manager.h"
[8448]24#include "glgui_widget.h"
[6442]25
[8518]26#include "glgui_inputline.h"
27#include "specials/glgui_notifier.h"
[8994]28#include "elements/glgui_radar.h"
[8518]29
[8996]30
31
32/// HACK
33#include "player.h"
34#include "playable.h"
35
[3245]36/**
[4838]37 * standard constructor
38 * @todo this constructor is not jet implemented - do it
[3245]39*/
[6437]40Hud::Hud ()
[3365]41{
[6438]42  this->setClassID(CL_HUD, "Hud");
[4320]43
[6441]44  //this->setSize2D(
[6442]45  this->weaponManager = NULL;
[6440]46  this->energyWidget = NULL;
47  this->shieldWidget = NULL;
48  this->armorWidget = NULL;
[6441]49  this->resX = 1;
50  this->resY = 1;
[6442]51
[8518]52  this->inputLine = new OrxGui::GLGuiInputLine();
53  this->inputLine->setParent2D(this);
54  this->notifier = new OrxGui::GLGuiNotifier();
55  this->notifier->setParent2D(this);
56  notifier->setAbsCoor2D(100,100);
57
[8995]58  this->_radar = new OrxGui::GLGuiRadar();
[8994]59
[8990]60  this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE);
[9003]61  this->subscribeEvent(ES_ALL, SDLK_TAB);
[8518]62
63
[3365]64}
[1853]65
66
[3245]67/**
[4838]68 * standard deconstructor
[3245]69*/
[6437]70Hud::~Hud ()
[3543]71{
[8518]72  delete this->inputLine;
73  delete this->notifier;
[8994]74
[8995]75  delete this->_radar;
[3543]76  // delete what has to be deleted here
77}
[6438]78
79
80void Hud::loadParams(const TiXmlElement* root)
81{
[6512]82  Element2D::loadParams(root);
[6438]83}
84
[8518]85void Hud::notifyUser(const std::string& message)
[6438]86{
[8518]87  this->notifier->pushNotifyMessage(message);
[6438]88}
89
[8518]90void Hud::setBackGround()
91{}
92
[8145]93void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget)
[6438]94{
[6440]95  // decopple old widget
96  if (this->energyWidget != NULL)
97  {
98    this->energyWidget->hide();
99  }
[6438]100
[6440]101  this->energyWidget = widget;
102  if (this->energyWidget != NULL)
103  {
104    this->energyWidget->show();
[8619]105    this->energyWidget->setBackgroundTexture( "hud_energy_background.png");
[8518]106    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
107        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
[6440]108  }
109
[6441]110  this->updateResolution();
[6438]111}
112
[8145]113void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget)
[8518]114{}
[6438]115
[8145]116void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget)
[8518]117{}
[6438]118
[6442]119void Hud::setWeaponManager(WeaponManager* weaponMan)
120{
121  if (this->weaponManager != NULL)
122  {
123    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
124    {
125      Weapon* weapon = this->weaponManager->getWeapon(i);
126      if (weapon != NULL)
127      {
128        weapon->getEnergyWidget()->hide();
129        this->weaponsWidgets.remove(weapon->getEnergyWidget());
130      }
131    }
132  }
133
134  this->weaponManager = weaponMan;
135
[6445]136  this->updateWeaponManager();
[8996]137  //  this->updateResolution();
[6438]138}
139
[6443]140void Hud::updateWeaponManager()
141{
142  // hide all the Widgets
[8145]143  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[6443]144  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++)
145  {
146    (*weaponWidget)->hide();
147  }
148  this->weaponsWidgets.clear();
[6442]149
[6443]150  // add all that we need again.
151  if (this->weaponManager != NULL)
152    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
153    {
[8518]154      Weapon* weapon = this->weaponManager->getWeapon(i);
155      if (weapon != NULL)
156      {
[9406]157        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
[8518]158        weapon->getEnergyWidget()->show();
[8619]159        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
[8518]160        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
161        //      weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
162        this->weaponsWidgets.push_back(weapon->getEnergyWidget());
163      }
[6443]164    }
165  this->updateResolution();
166}
167
[8145]168void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]169{}
[6438]170
[8145]171void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]172{}
[6438]173
[6441]174void Hud::updateResolution()
175{
[6498]176  this->resX = State::getResX();
177  this->resY = State::getResY();
[8976]178
179  this->setSize2D(.2 * this->resX, this->resY);
[8989]180  this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY);
181  this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY);
[8976]182
[8995]183
[8996]184  if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager())
185  {
186    printf("UPDATING RADAR\n");
187    this->_radar->setCenterNode(State::getPlayer()->getPlayable());
[9000]188    this->_radar->addEntityList(&State::getObjectManager()->getObjectList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0));
[9235]189    this->_radar->addEntityList(&State::getObjectManager()->getObjectList(OM_GROUP_02), Color(1.0, .2, .2));
[9001]190    this->_radar->setAbsCoor2D(0.8 * this->resX, 0.01 * this->resY);
[8996]191    this->_radar->setWidgetSize(0.2 * this->resX, 0.2 * this->resY);
[9014]192    this->_radar->setRange(300);
[8996]193    this->_radar->show();
194  }
195
196
[6441]197  if (this->energyWidget != NULL)
198  {
[8986]199    this->energyWidget->setAbsCoor2D(0.0 * this->resX, 0.85 * this->resY);
[8975]200    this->energyWidget->setWidgetSize(.25 * this->resX, 0.1 * this->resY);
[6441]201  }
[6442]202
203
[8145]204  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[8988]205  Vector2D pos(0.3, .9);
[8987]206  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos.x+=.2)
[6442]207  {
[8987]208    if (pos.x > .8)
209    {
210      pos.x = 0.3;
211      pos.y -= .1;
212
213    }
214    (*weaponWidget)->setAbsCoor2D(pos.x*this->resX, pos.y*this->resY);
[8976]215    (*weaponWidget)->setWidgetSize(.02*this->resX, .1 *this->resY);
216    (*weaponWidget)->show();
[9406]217    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
[6442]218  }
[6441]219}
220
[8990]221void Hud::draw() const
[6441]222{
[8990]223  //  GLGuiWidget::draw();
[6441]224}
225
[8990]226
227void Hud::process(const Event &event)
[6441]228{
[8990]229  if (event.type == EV_VIDEO_RESIZE)
230    this->updateResolution();
[9003]231  else if (event.type == SDLK_TAB)
232  {
233    /// TODO SHOW THE INPUT-LINE
234  //  this->inputLine->select();
235  }
236
237
[6441]238}
239
240
Note: See TracBrowser for help on using the repository browser.