Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/util/hud.cc @ 8598

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

style enbedded into gui, as it was redundant

File size: 4.6 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"
21
[6442]22#include "world_entities/weapons/weapon_manager.h"
[8448]23#include "glgui_widget.h"
[6442]24
[8518]25#include "glgui_inputline.h"
26#include "specials/glgui_notifier.h"
27
[3245]28/**
[4838]29 * standard constructor
30 * @todo this constructor is not jet implemented - do it
[3245]31*/
[6437]32Hud::Hud ()
[3365]33{
[6438]34  this->setClassID(CL_HUD, "Hud");
[4320]35
[6441]36  //this->setSize2D(
[6442]37  this->weaponManager = NULL;
[6440]38  this->energyWidget = NULL;
39  this->shieldWidget = NULL;
40  this->armorWidget = NULL;
[6441]41  this->resX = 1;
42  this->resY = 1;
[6442]43
[8518]44  this->inputLine = new OrxGui::GLGuiInputLine();
45  this->inputLine->setParent2D(this);
46  this->notifier = new OrxGui::GLGuiNotifier();
47  this->notifier->setParent2D(this);
48  notifier->setAbsCoor2D(100,100);
49
50
51
[3365]52}
[1853]53
54
[3245]55/**
[4838]56 * standard deconstructor
[3245]57*/
[6437]58Hud::~Hud ()
[3543]59{
[8518]60  delete this->inputLine;
61  delete this->notifier;
[3543]62  // delete what has to be deleted here
63}
[6438]64
65
66void Hud::loadParams(const TiXmlElement* root)
67{
[6512]68  Element2D::loadParams(root);
[6438]69}
70
[8518]71void Hud::notifyUser(const std::string& message)
[6438]72{
[8518]73  this->notifier->pushNotifyMessage(message);
[6438]74}
75
[8518]76void Hud::setBackGround()
77{}
78
[8145]79void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget)
[6438]80{
[6440]81  // decopple old widget
82  if (this->energyWidget != NULL)
83  {
84    this->energyWidget->hide();
85  }
[6438]86
[6440]87  this->energyWidget = widget;
88  if (this->energyWidget != NULL)
89  {
90    this->energyWidget->show();
[8598]91    this->energyWidget->background().setDiffuseMap("hud_energy_background.png");
92    this->energyWidget->background().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
[8518]93    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
94        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
[6440]95  }
96
[6441]97  this->updateResolution();
[6438]98}
99
[8145]100void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget)
[8518]101{}
[6438]102
[8145]103void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget)
[8518]104{}
[6438]105
[6442]106void Hud::setWeaponManager(WeaponManager* weaponMan)
107{
108  if (this->weaponManager != NULL)
109  {
110    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
111    {
112      Weapon* weapon = this->weaponManager->getWeapon(i);
113      if (weapon != NULL)
114      {
115        weapon->getEnergyWidget()->hide();
116        this->weaponsWidgets.remove(weapon->getEnergyWidget());
117      }
118    }
119  }
120
121  this->weaponManager = weaponMan;
122
[6445]123  this->updateWeaponManager();
124  this->updateResolution();
[6438]125}
126
[6443]127void Hud::updateWeaponManager()
128{
129  // hide all the Widgets
[8145]130  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[6443]131  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++)
132  {
133    (*weaponWidget)->hide();
134  }
135  this->weaponsWidgets.clear();
[6442]136
[6443]137  // add all that we need again.
138  if (this->weaponManager != NULL)
139    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
140    {
[8518]141      Weapon* weapon = this->weaponManager->getWeapon(i);
142      if (weapon != NULL)
143      {
144        weapon->getEnergyWidget()->show();
[8598]145        weapon->getEnergyWidget()->background().setDiffuse( .8,.2,.11);
146        weapon->getEnergyWidget()->background().setTransparency(.1);
[8518]147        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
148        //      weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
149        this->weaponsWidgets.push_back(weapon->getEnergyWidget());
150      }
[6443]151    }
152  this->updateResolution();
153}
154
[8145]155void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]156{}
[6438]157
[8145]158void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]159{}
[6438]160
[6441]161void Hud::updateResolution()
162{
[6498]163  this->resX = State::getResX();
164  this->resY = State::getResY();
[6441]165  if (this->energyWidget != NULL)
166  {
[7062]167    this->energyWidget->setAbsCoor2D(0 * this->resX, 0 * this->resY);
[7064]168    this->energyWidget->setSize2D(.25 * this->resX, 1 * this->resY);
[6441]169  }
[6442]170
171  this->setSize2D(.2 * this->resX, this->resY);
172
[8145]173  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[7064]174  float pos = .3;
[6756]175  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos+=.03)
[6442]176  {
[8518]177    (*weaponWidget)->setSize2D(.02*this->resX, .2 *this->resY);
178    (*weaponWidget)->setAbsCoor2D(pos*this->resX, .75*this->resY);
[6756]179
[6442]180  }
[6441]181}
182
183
184void Hud::tick(float dt)
185{
[8518]186  if (this->resY != State::getResY() || this->resX != State::getResX())
187  {
[6441]188    this->updateResolution();
[8518]189  }
190
[6441]191}
192
193void Hud::draw() const
194{
[8518]195  //  GLGuiWidget::draw();
[6441]196}
197
198
Note: See TracBrowser for help on using the repository browser.