Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/util/hud.cc @ 10182

Last change on this file since 10182 was 10139, checked in by muellmic, 18 years ago

trying to adjust interface

File size: 9.1 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"
[10111]25#include "glgui_box.h"
[10120]26#include "elements/glgui_energywidgetvertical.h"
[6442]27
[8518]28#include "glgui_inputline.h"
29#include "specials/glgui_notifier.h"
[8994]30#include "elements/glgui_radar.h"
[8518]31
[8996]32
33
34/// HACK
35#include "player.h"
36#include "playable.h"
37
[9869]38ObjectListDefinition(Hud);
[3245]39/**
[4838]40 * standard constructor
41 * @todo this constructor is not jet implemented - do it
[3245]42*/
[6437]43Hud::Hud ()
[3365]44{
[9869]45  this->registerObject(this, Hud::_objectList);
[4320]46
[6441]47  //this->setSize2D(
[6442]48  this->weaponManager = NULL;
[9965]49  this->weaponManagerSecondary = NULL;
[6440]50  this->energyWidget = NULL;
51  this->shieldWidget = NULL;
52  this->armorWidget = NULL;
[6441]53  this->resX = 1;
54  this->resY = 1;
[6442]55
[8518]56  this->inputLine = new OrxGui::GLGuiInputLine();
57  this->inputLine->setParent2D(this);
58  this->notifier = new OrxGui::GLGuiNotifier();
59  this->notifier->setParent2D(this);
60  notifier->setAbsCoor2D(100,100);
61
[8995]62  this->_radar = new OrxGui::GLGuiRadar();
[8994]63
[8990]64  this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE);
[9003]65  this->subscribeEvent(ES_ALL, SDLK_TAB);
[8518]66
[10139]67  this->shipValuesBox = NULL;
[3365]68}
[1853]69
70
[3245]71/**
[4838]72 * standard deconstructor
[3245]73*/
[6437]74Hud::~Hud ()
[3543]75{
[8518]76  delete this->inputLine;
77  delete this->notifier;
[8994]78
[8995]79  delete this->_radar;
[10139]80  delete this->shipValuesBox;
81
[3543]82  // delete what has to be deleted here
83}
[6438]84
85
86void Hud::loadParams(const TiXmlElement* root)
87{
[6512]88  Element2D::loadParams(root);
[6438]89}
90
[8518]91void Hud::notifyUser(const std::string& message)
[6438]92{
[8518]93  this->notifier->pushNotifyMessage(message);
[6438]94}
95
[8518]96void Hud::setBackGround()
97{}
98
[8145]99void Hud::setEnergyWidget(OrxGui::GLGuiWidget* widget)
[6438]100{
[10139]101  if (this->shipValuesBox == NULL)
102    this->createShipValuesBox();
[6440]103  // decopple old widget
104  if (this->energyWidget != NULL)
105  {
106    this->energyWidget->hide();
107  }
[6438]108
[6440]109  this->energyWidget = widget;
110  if (this->energyWidget != NULL)
111  {
[10139]112    //this->energyWidget->shiftDir2D(270);
[10120]113    dynamic_cast<OrxGui::GLGuiEnergyWidgetVertical*> (this->energyWidget)->setDisplayedName("Electronics");
[10111]114    this->shipValuesBox->pack(this->energyWidget);
[10139]115    this->energyWidget->show();
[8518]116    /*    this->energyWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
117        this->energyWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
[6440]118  }
119
[6441]120  this->updateResolution();
[6438]121}
122
[8145]123void Hud::setShiledWidget(OrxGui::GLGuiWidget* widget)
[10120]124{
[10139]125  if (this->shipValuesBox == NULL)
126    this->createShipValuesBox();
[10120]127  // decopple old widget
128  if (this->shieldWidget != NULL)
129  {
130    this->shieldWidget->hide();
131  }
[6438]132
[10120]133  this->shieldWidget = widget;
134  if (this->shieldWidget != NULL)
135  {
[10139]136    //this->shieldWidget->shiftDir2D(270);
137    this->shipValuesBox->pack(this->shieldWidget);
[10120]138    this->shieldWidget->show();
139    /*    this->shieldWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
140        this->shieldWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
141  }
[10139]142  else
143    printf("schild im hud nicht uebergeben!!!!!!!!!!!!!!!!!!!!!!!!!");
[10120]144
145  this->updateResolution();
146}
147
[8145]148void Hud::setArmorWidget(OrxGui::GLGuiWidget* widget)
[10120]149{
[10139]150  if (this->shipValuesBox == NULL)
151    this->createShipValuesBox();
152
[10120]153// decopple old widget
154  if (this->armorWidget != NULL)
155  {
156    this->armorWidget->hide();
157  }
[6438]158
[10120]159  this->armorWidget = widget;
160  if (this->armorWidget != NULL)
161  {
[10139]162    //this->armorWidget->shiftDir2D(270);
163    this->shipValuesBox->pack(this->armorWidget);
[10120]164    this->armorWidget->show();
165    /*    this->armorWidget->frontMaterial().setDiffuseMap("hud_energy_bar.png");
166        this->armorWidget->frontMaterial().setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
167  }
168
169  this->updateResolution();
170}
171
[9965]172void Hud::setWeaponManager(WeaponManager* weaponMan, WeaponManager* weaponManSec)
[6442]173{
174  if (this->weaponManager != NULL)
175  {
176    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
177    {
178      Weapon* weapon = this->weaponManager->getWeapon(i);
179      if (weapon != NULL)
180      {
181        weapon->getEnergyWidget()->hide();
182        this->weaponsWidgets.remove(weapon->getEnergyWidget());
183      }
184    }
185  }
186
[9965]187  if (this->weaponManagerSecondary != NULL)
188  {
189    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
190    {
191      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
192      if (weapon != NULL)
193      {
194        weapon->getEnergyWidget()->hide();
195        this->weaponsWidgets.remove(weapon->getEnergyWidget());
196      }
197    }
198  }
199
[6442]200  this->weaponManager = weaponMan;
[9965]201  this->weaponManagerSecondary = weaponManSec;
[6442]202
[6445]203  this->updateWeaponManager();
[8996]204  //  this->updateResolution();
[6438]205}
206
[6443]207void Hud::updateWeaponManager()
208{
209  // hide all the Widgets
[8145]210  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[6443]211  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++)
212  {
213    (*weaponWidget)->hide();
214  }
215  this->weaponsWidgets.clear();
[6442]216
[6443]217  // add all that we need again.
218  if (this->weaponManager != NULL)
219    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
220    {
[8518]221      Weapon* weapon = this->weaponManager->getWeapon(i);
222      if (weapon != NULL)
223      {
[9406]224        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
[8518]225        weapon->getEnergyWidget()->show();
[8619]226        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
[8518]227        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
[10023]228        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
[8518]229        this->weaponsWidgets.push_back(weapon->getEnergyWidget());
230      }
[6443]231    }
[9965]232
233  if (this->weaponManagerSecondary != NULL)
234    for (unsigned int i = 0; i < this->weaponManagerSecondary->getSlotCount(); i++)
235    {
236      Weapon* weapon = this->weaponManagerSecondary->getWeapon(i);
237      if (weapon != NULL)
238      {
239        //PRINTF(0)("WEAPON %s::%s in Slots\n", weapon->getClassCName(), weapon->getName());
240        weapon->getEnergyWidget()->show();
241        weapon->getEnergyWidget()->setBackgroundColor(Color(.8,.2,.11, 0.1));
242        weapon->getEnergyWidget()->setFrontColor(Color( .2,.5,.7,.6));
[10023]243        //weapon->getEnergyWidget()->frontMaterial().setTransparency(.6);
[9965]244        this->weaponsWidgets.push_back(weapon->getEnergyWidget());
245      }
246    }
247
[6443]248  this->updateResolution();
[9965]249
[6443]250}
251
[8145]252void Hud::addWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]253{}
[6438]254
[8145]255void Hud::removeWeaponWidget(OrxGui::GLGuiWidget* widget)
[8518]256{}
[6438]257
[6441]258void Hud::updateResolution()
259{
[6498]260  this->resX = State::getResX();
261  this->resY = State::getResY();
[8976]262
263  this->setSize2D(.2 * this->resX, this->resY);
[8989]264  this->notifier->setAbsCoor2D(0.7 * this->resX, 0.3 * this->resY);
265  this->notifier->setWidgetSize(0.25 * this->resX, 0.6 * this->resY);
[8976]266
[8995]267
[8996]268  if (State::getPlayer() && State::getPlayer()->getPlayable() && State::getObjectManager())
269  {
[9869]270    PRINTF(4)("UPDATING RADAR\n");
[8996]271    this->_radar->setCenterNode(State::getPlayer()->getPlayable());
[10092]272    //this->_radar->addEntityList(&State::getObjectManager()->getEntityList((OM_LIST)(State::getPlayer()->getPlayable()->getOMListNumber()+1)), Color(.4, .4, 1.0));
273    this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_00), Color(1, 0, 0));
274    this->_radar->addEntityList(&State::getObjectManager()->getEntityList(OM_GROUP_01), Color(0, 0, 1));
[9001]275    this->_radar->setAbsCoor2D(0.8 * this->resX, 0.01 * this->resY);
[8996]276    this->_radar->setWidgetSize(0.2 * this->resX, 0.2 * this->resY);
[9014]277    this->_radar->setRange(300);
[8996]278    this->_radar->show();
279  }
280
[10111]281 
282  if (this->shipValuesBox != NULL)
[6441]283  {
[10139]284    this->shipValuesBox->setAbsCoor2D(0.2 * this->resX, 0.4 * this->resY);
[10111]285    this->shipValuesBox->setWidgetSize(.4 * this->resX, 0.1 * this->resY);
[6441]286  }
[10139]287  else
288    createShipValuesBox();
[6442]289
290
[8145]291  std::list<OrxGui::GLGuiWidget*>::iterator weaponWidget;
[10030]292  Vector2D pos(0.3, .9);
[10042]293  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos.x+=.1)
[6442]294  {
[8987]295    if (pos.x > .8)
296    {
297      pos.x = 0.3;
298      pos.y -= .1;
299
300    }
301    (*weaponWidget)->setAbsCoor2D(pos.x*this->resX, pos.y*this->resY);
[8976]302    (*weaponWidget)->setWidgetSize(.02*this->resX, .1 *this->resY);
303    (*weaponWidget)->show();
[9406]304    //printf("update thing %s::%s\n", (*weaponWidget)->getClassCName(), (*weaponWidget)->getName());
[6442]305  }
[6441]306}
307
[8990]308void Hud::draw() const
[6441]309{
[8990]310  //  GLGuiWidget::draw();
[6441]311}
312
[8990]313
314void Hud::process(const Event &event)
[6441]315{
[8990]316  if (event.type == EV_VIDEO_RESIZE)
317    this->updateResolution();
[9003]318  else if (event.type == SDLK_TAB)
319  {
320    /// TODO SHOW THE INPUT-LINE
321  //  this->inputLine->select();
322  }
[10139]323}
[9003]324
[10139]325void Hud::createShipValuesBox()
326{
327  this->shipValuesBox = new OrxGui::GLGuiBox(OrxGui::Horizontal);
328  //this->shipValuesBox->setWidgetSize(1000,500);
329  //this->shipValuesBox->setBackgroundTexture("maps/gui_container_background.png");
330  this->shipValuesBox->setBackgroundTexture(Texture());
331  this->shipValuesBox->setBackgroundColor(Color(0,0,1,0.5));
332  this->shipValuesBox->setVisibility(true);
[6441]333}
334
335
Note: See TracBrowser for help on using the repository browser.