Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: new Functionality to widget, so one can set a foreground texture, for Widgets requesting it.

File size: 5.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"
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
[8990]51  this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE);
[8518]52
53
[3365]54}
[1853]55
56
[3245]57/**
[4838]58 * standard deconstructor
[3245]59*/
[6437]60Hud::~Hud ()
[3543]61{
[8518]62  delete this->inputLine;
63  delete this->notifier;
[3543]64  // delete what has to be deleted here
65}
[6438]66
67
68void Hud::loadParams(const TiXmlElement* root)
69{
[6512]70  Element2D::loadParams(root);
[6438]71}
72
[8518]73void Hud::notifyUser(const std::string& message)
[6438]74{
[8518]75  this->notifier->pushNotifyMessage(message);
[6438]76}
77
[8518]78void Hud::setBackGround()
79{}
80
[8145]81void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget)
[6438]82{
[6440]83  // decopple old widget
84  if (this->energyWidget != NULL)
85  {
86    this->energyWidget->hide();
87  }
[6438]88
[6440]89  this->energyWidget = widget;
90  if (this->energyWidget != NULL)
91  {
92    this->energyWidget->show();
[8619]93    this->energyWidget->setBackgroundTexture( "hud_energy_background.png");
[8518]94    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
95        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
[6440]96  }
97
[6441]98  this->updateResolution();
[6438]99}
100
[8145]101void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget)
[8518]102{}
[6438]103
[8145]104void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget)
[8518]105{}
[6438]106
[6442]107void Hud::setWeaponManager(WeaponManager* weaponMan)
108{
109  if (this->weaponManager != NULL)
110  {
111    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
112    {
113      Weapon* weapon = this->weaponManager->getWeapon(i);
114      if (weapon != NULL)
115      {
116        weapon->getEnergyWidget()->hide();
117        this->weaponsWidgets.remove(weapon->getEnergyWidget());
118      }
119    }
120  }
121
122  this->weaponManager = weaponMan;
123
[6445]124  this->updateWeaponManager();
[8976]125//  this->updateResolution();
[6438]126}
127
[6443]128void Hud::updateWeaponManager()
129{
130  // hide all the Widgets
[8145]131  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[6443]132  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++)
133  {
134    (*weaponWidget)->hide();
135  }
136  this->weaponsWidgets.clear();
[6442]137
[6443]138  // add all that we need again.
139  if (this->weaponManager != NULL)
140    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
141    {
[8518]142      Weapon* weapon = this->weaponManager->getWeapon(i);
143      if (weapon != NULL)
144      {
[8976]145        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassName(), weapon->getName());
[8518]146        weapon->getEnergyWidget()->show();
[8619]147        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
[8518]148        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
149        //      weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
150        this->weaponsWidgets.push_back(weapon->getEnergyWidget());
151      }
[6443]152    }
153  this->updateResolution();
154}
155
[8145]156void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]157{}
[6438]158
[8145]159void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]160{}
[6438]161
[6441]162void Hud::updateResolution()
163{
[6498]164  this->resX = State::getResX();
165  this->resY = State::getResY();
[8976]166
167  this->setSize2D(.2 * this->resX, this->resY);
[8989]168  this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY);
169  this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY);
[8976]170
[6441]171  if (this->energyWidget != NULL)
172  {
[8986]173    this->energyWidget->setAbsCoor2D(0.0 * this->resX, 0.85 * this->resY);
[8975]174    this->energyWidget->setWidgetSize(.25 * this->resX, 0.1 * this->resY);
[6441]175  }
[6442]176
177
[8145]178  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[8988]179  Vector2D pos(0.3, .9);
[8987]180  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos.x+=.2)
[6442]181  {
[8987]182    if (pos.x > .8)
183    {
184      pos.x = 0.3;
185      pos.y -= .1;
186
187    }
188    (*weaponWidget)->setAbsCoor2D(pos.x*this->resX, pos.y*this->resY);
[8976]189    (*weaponWidget)->setWidgetSize(.02*this->resX, .1 *this->resY);
190    (*weaponWidget)->show();
191    //printf("update thing %s::%s\n", (*weaponWidget)->getClassName(), (*weaponWidget)->getName());
[6442]192  }
[6441]193}
194
[8990]195void Hud::draw() const
[6441]196{
[8990]197  //  GLGuiWidget::draw();
[6441]198}
199
[8990]200
201void Hud::process(const Event &event)
[6441]202{
[8990]203  if (event.type == EV_VIDEO_RESIZE)
204    this->updateResolution();
[6441]205}
206
207
Note: See TracBrowser for help on using the repository browser.