Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10120 was 10120, checked in by muellmic, 17 years ago

some interface hacks

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