Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6442 in orxonox.OLD for trunk


Ignore:
Timestamp:
Jan 8, 2006, 5:19:39 PM (19 years ago)
Author:
bensch
Message:

Gui Shows weapons (simple)

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/util/hud.cc

    r6441 r6442  
    2020#include "state.h"
    2121
     22#include "world_entities/weapons/weapon_manager.h"
     23
    2224using namespace std;
    2325
     
    3234
    3335  //this->setSize2D(
     36  this->weaponManager = NULL;
    3437  this->energyWidget = NULL;
    3538  this->shieldWidget = NULL;
     
    3740  this->resX = 1;
    3841  this->resY = 1;
     42
    3943}
    4044
     
    5155void Hud::loadParams(const TiXmlElement* root)
    5256{
    53 
    5457}
    5558
    5659void Hud::setBackGround()
    5760{
    58 
    5961}
    6062
     
    7880void Hud::setShiledWidget(GLGuiWidget* widget)
    7981{
    80 
    8182}
    8283
    8384void Hud::setArmorWidget(GLGuiWidget* widget)
    8485{
     86}
    8587
     88void Hud::setWeaponManager(WeaponManager* weaponMan)
     89{
     90  if (this->weaponManager != NULL)
     91  {
     92    for (unsigned int i = 0; i < this->weaponManager->getSlotCount(); i++)
     93    {
     94      Weapon* weapon = this->weaponManager->getWeapon(i);
     95      if (weapon != NULL)
     96      {
     97        weapon->getEnergyWidget()->hide();
     98        this->weaponsWidgets.remove(weapon->getEnergyWidget());
     99      }
     100    }
     101  }
     102
     103  this->weaponManager = weaponMan;
     104
     105  if (weaponManager != NULL)
     106    for (unsigned int i = 0; i < weaponMan->getSlotCount(); i++)
     107    {
     108      Weapon* weapon = weaponMan->getWeapon(i);
     109      if (weapon != NULL)
     110      {
     111        weapon->getEnergyWidget()->show();
     112        this->weaponsWidgets.push_back(weapon->getEnergyWidget());
     113
     114      }
     115    }
     116
     117    this->updateResolution();
    86118}
     119
    87120
    88121void Hud::addWeaponWidget(GLGuiWidget* widget)
    89122{
    90 
    91123}
    92124
    93125void Hud::removeWeaponWidget(GLGuiWidget* widget)
    94126{
    95 
    96127}
    97128
     
    105136    this->energyWidget->setSize2D(.05 * this->resX, .55 * this->resY);
    106137  }
     138
     139  this->setSize2D(.2 * this->resX, this->resY);
     140
     141  std::list<GLGuiWidget*>::iterator weaponWidget;
     142  float pos = .2;
     143  for (weaponWidget = this->weaponsWidgets.begin(); weaponWidget != this->weaponsWidgets.end(); weaponWidget++, pos+=.03)
     144  {
     145    (*weaponWidget)->setSize2D(.02*this->resX, .2 *this->resY);
     146    (*weaponWidget)->setAbsCoor2D(pos*this->resX, .75*this->resY);
     147  }
     148
    107149}
    108150
  • trunk/src/util/hud.h

    r6441 r6442  
    1212// FORWARD DECLARATION
    1313class TiXmlElement;
    14 
     14class WeaponManager;
    1515
    1616//! A class that renders a HUD.
     
    2929  void setShiledWidget(GLGuiWidget* widget);
    3030  void setArmorWidget(GLGuiWidget* widget);
     31  void setWeaponManager(WeaponManager* weaponMan);
    3132
    3233  void addWeaponWidget(GLGuiWidget* widget);
     
    4647  GLGuiWidget*             armorWidget;
    4748
     49  WeaponManager*           weaponManager;
     50
    4851  std::list<GLGuiWidget*>  weaponsWidgets; //!< WeaponWidgets will be displayed one after another
    4952};
  • trunk/src/world_entities/playable.cc

    r6436 r6442  
    2525Playable::Playable()
    2626{
    27   this->init();
     27  this->setClassID(CL_PLAYABLE, "Playable");
     28  PRINTF(4)("PLAYABLE INIT\n");
     29
     30  this->toList(OM_GROUP_01);
     31  this->weaponMan = new WeaponManager(this);
     32
     33  // the reference to the Current Player is NULL, because we dont have one at the beginning.
     34  this->currentPlayer = NULL;
    2835}
    2936
     
    3946}
    4047
    41 /**
    42  * initializes this Playable
    43  */
    44 void Playable::init()
    45 {
    46   this->setClassID(CL_PLAYABLE, "Playable");
    47   PRINTF(4)("PLAYABLE INIT\n");
    48 
    49   this->toList(OM_GROUP_01);
    50   this->weaponMan = new WeaponManager(this);
    51 
    52   // the reference to the Current Player is NULL, because we dont have one at the beginning.
    53   this->currentPlayer = NULL;
    54 }
    5548
    5649/**
  • trunk/src/world_entities/playable.h

    r6436 r6442  
    1010#include "event.h"
    1111#include <list>
     12
    1213
    1314class Weapon;
     
    5152
    5253  private:
    53     void init();
    54 
    55   private:
    5654    WeaponManager*        weaponMan;          //!< the weapon manager: managing a list of weapon to wepaon-slot mapping
    5755    std::list<int>        events;             //!< A list of Events, that are captured for this playable
  • trunk/src/world_entities/player.cc

    r6441 r6442  
    5959      this->controllable = controllable;
    6060      this->hud.setEnergyWidget(this->controllable->getEnergyWidget());
     61      this->hud.setWeaponManager(this->controllable->getWeaponManager());
    6162      return true;
    6263  }
     
    7374     this->controllable = NULL;
    7475     this->hud.setEnergyWidget(NULL);
     76     this->hud.setWeaponManager(NULL);
    7577     return true;
    7678   }
  • trunk/src/world_entities/weapons/weapon_manager.h

    r6142 r6442  
    5454
    5555    void setSlotCount(unsigned int slotCount);
     56    unsigned int getSlotCount() const { return this->slotCount; };
    5657    // setting up the WeaponManager with the following functions
    5758    void setSlotPosition(int slot, const Vector& position);
     
    6970    void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
    7071    void removeWeapon(Weapon* weapon, int configID = -1);
     72    Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].currentWeapon: NULL; };
    7173
    7274    // FIXME ::
Note: See TracChangeset for help on using the changeset viewer.