Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9198 was 9014, checked in by bensch, 18 years ago

orxonox/trunk: autoselect first entries in the Menu

File size: 5.8 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      {
[8976]157        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassName(), 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));
[9001]189    this->_radar->setAbsCoor2D(0.8 * this->resX, 0.01 * this->resY);
[8996]190    this->_radar->setWidgetSize(0.2 * this->resX, 0.2 * this->resY);
[9014]191    this->_radar->setRange(300);
[8996]192    this->_radar->show();
193  }
194
195
[6441]196  if (this->energyWidget != NULL)
197  {
[8986]198    this->energyWidget->setAbsCoor2D(0.0 * this->resX, 0.85 * this->resY);
[8975]199    this->energyWidget->setWidgetSize(.25 * this->resX, 0.1 * this->resY);
[6441]200  }
[6442]201
202
[8145]203  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[8988]204  Vector2D pos(0.3, .9);
[8987]205  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos.x+=.2)
[6442]206  {
[8987]207    if (pos.x > .8)
208    {
209      pos.x = 0.3;
210      pos.y -= .1;
211
212    }
213    (*weaponWidget)->setAbsCoor2D(pos.x*this->resX, pos.y*this->resY);
[8976]214    (*weaponWidget)->setWidgetSize(.02*this->resX, .1 *this->resY);
215    (*weaponWidget)->show();
216    //printf("update thing %s::%s\n", (*weaponWidget)->getClassName(), (*weaponWidget)->getName());
[6442]217  }
[6441]218}
219
[8990]220void Hud::draw() const
[6441]221{
[8990]222  //  GLGuiWidget::draw();
[6441]223}
224
[8990]225
226void Hud::process(const Event &event)
[6441]227{
[8990]228  if (event.type == EV_VIDEO_RESIZE)
229    this->updateResolution();
[9003]230  else if (event.type == SDLK_TAB)
231  {
232    /// TODO SHOW THE INPUT-LINE
233  //  this->inputLine->select();
234  }
235
236
[6441]237}
238
239
Note: See TracBrowser for help on using the repository browser.