Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: notifier notifies

File size: 4.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"
28
[3245]29/**
[4838]30 * standard constructor
31 * @todo this constructor is not jet implemented - do it
[3245]32*/
[6437]33Hud::Hud ()
[3365]34{
[6438]35  this->setClassID(CL_HUD, "Hud");
[4320]36
[6441]37  //this->setSize2D(
[6442]38  this->weaponManager = NULL;
[6440]39  this->energyWidget = NULL;
40  this->shieldWidget = NULL;
41  this->armorWidget = NULL;
[6441]42  this->resX = 1;
43  this->resY = 1;
[6442]44
[8518]45  this->inputLine = new OrxGui::GLGuiInputLine();
46  this->inputLine->setParent2D(this);
47  this->notifier = new OrxGui::GLGuiNotifier();
48  this->notifier->setParent2D(this);
49  notifier->setAbsCoor2D(100,100);
50
51
52
[3365]53}
[1853]54
55
[3245]56/**
[4838]57 * standard deconstructor
[3245]58*/
[6437]59Hud::~Hud ()
[3543]60{
[8518]61  delete this->inputLine;
62  delete this->notifier;
[3543]63  // delete what has to be deleted here
64}
[6438]65
66
67void Hud::loadParams(const TiXmlElement* root)
68{
[6512]69  Element2D::loadParams(root);
[6438]70}
71
[8518]72void Hud::notifyUser(const std::string& message)
[6438]73{
[8518]74  this->notifier->pushNotifyMessage(message);
[6438]75}
76
[8518]77void Hud::setBackGround()
78{}
79
[8145]80void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget)
[6438]81{
[6440]82  // decopple old widget
83  if (this->energyWidget != NULL)
84  {
85    this->energyWidget->hide();
86  }
[6438]87
[6440]88  this->energyWidget = widget;
89  if (this->energyWidget != NULL)
90  {
91    this->energyWidget->show();
[8619]92    this->energyWidget->setBackgroundTexture( "hud_energy_background.png");
[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();
[8976]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      {
[8976]144        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassName(), weapon->getName());
[8518]145        weapon->getEnergyWidget()->show();
[8619]146        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.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();
[8976]165
166  this->setSize2D(.2 * this->resX, this->resY);
[8989]167  this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY);
168  this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY);
[8976]169
[6441]170  if (this->energyWidget != NULL)
171  {
[8986]172    this->energyWidget->setAbsCoor2D(0.0 * this->resX, 0.85 * this->resY);
[8975]173    this->energyWidget->setWidgetSize(.25 * this->resX, 0.1 * this->resY);
[6441]174  }
[6442]175
176
[8145]177  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[8988]178  Vector2D pos(0.3, .9);
[8987]179  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos.x+=.2)
[6442]180  {
[8987]181    if (pos.x > .8)
182    {
183      pos.x = 0.3;
184      pos.y -= .1;
185
186    }
187    (*weaponWidget)->setAbsCoor2D(pos.x*this->resX, pos.y*this->resY);
[8976]188    (*weaponWidget)->setWidgetSize(.02*this->resX, .1 *this->resY);
189    (*weaponWidget)->show();
190    //printf("update thing %s::%s\n", (*weaponWidget)->getClassName(), (*weaponWidget)->getName());
[6442]191  }
[6441]192}
193
194
195void Hud::tick(float dt)
196{
[8518]197  if (this->resY != State::getResY() || this->resX != State::getResX())
198  {
[6441]199    this->updateResolution();
[8518]200  }
201
[6441]202}
203
204void Hud::draw() const
205{
[8518]206  //  GLGuiWidget::draw();
[6441]207}
208
209
Note: See TracBrowser for help on using the repository browser.