Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10250 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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