Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/fabienHS15/src/modules/overlays/hud/HUDWeapon.cc @ 10715

Last change on this file since 10715 was 10715, checked in by fvultier, 9 years ago
File size: 4.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Yuning Chai
24 *      Felix Schulthess
25 *   Co-authors:
26 *      Reto Grieder
27 *      Wolfgang Roenninger
28 *
29 */
30
31#include "HUDWeapon.h"
32
33#include <OgreOverlayManager.h>
34#include <OgrePanelOverlayElement.h>
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "tools/TextureGenerator.h"
39#include "util/Convert.h"
40#include "core/class/Super.h"
41
42namespace orxonox
43{
44    RegisterClass(HUDWeapon);
45
46    HUDWeapon::HUDWeapon(Context* context) : OrxonoxOverlay(context)
47    {
48        RegisterObject(HUDWeapon);
49
50        overlayElement_ = static_cast<Ogre::PanelOverlayElement* >(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDWeapon" + getUniqueNumberString()));
51        overlayElement_->setMaterialName("Orxonox/WSHUD_Weapon");
52        overlayElement_->setPosition(0.0f,0.0f);
53        overlayElement_->setDimensions(1.0f,1.0f);
54        this->background_->addChild(overlayElement_);
55    }
56
57    HUDWeapon::~HUDWeapon()
58    {
59        if (this->isInitialized())
60        {
61            destroyHUDChilds();
62            //this->overlayElement_->destroy();           
63        }
64    }
65
66    void HUDWeapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
67    {
68        SUPER(HUDWeapon, XMLPort, xmlelement, mode);
69
70        /*XMLPortParam(HUDWeapons, "sensitivity", setRadarSensitivity, getRadarSensitivity, xmlelement, mode);
71        XMLPortParam(HUDWeapons, "halfDotSizeDistance", setHalfDotSizeDistance, getHalfDotSizeDistance, xmlelement, mode);*/
72    }
73
74    void HUDWeapon::tick(float dt)
75    {
76        SUPER(HUDWeapon, tick, dt);
77    }   
78
79    void HUDWeapon::positionChanged()
80    {
81        OrxonoxOverlay::positionChanged();
82
83        positionHUDChilds();
84    }     
85
86    void HUDWeapon::changedOwner()
87    {
88        SUPER(HUDWeapon, changedOwner);
89
90        this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
91
92        updateWeaponModeList();
93    }
94
95    void HUDWeapon::changedOverlayGroup()
96    {
97        SUPER(HUDWeapon, changedOverlayGroup);
98    }   
99
100    void HUDWeapon::changedVisibility()
101    {
102        SUPER(HUDWeapon, changedVisibility);
103    }
104
105    void HUDWeapon::changedName()
106    {
107        SUPER(HUDWeapon, changedName);
108    }
109
110    void HUDWeapon::setWeapon(Weapon* weapon)
111    {
112        weapon_ = weapon;
113
114        if (!weapon_)
115        {
116            return;
117        }
118
119        updateWeaponModeList();
120    }
121
122    void HUDWeapon::updateWeaponModeList()
123    {
124        if (owner_ == NULL || weapon_ == NULL)
125        {
126            return;
127        }
128           
129        destroyHUDChilds();
130
131        weaponModes_ = weapon_->getAllWeaponmodes();
132
133        createHUDChilds();
134        positionHUDChilds();       
135    } 
136
137    void HUDWeapon::createHUDChilds()
138    {
139        for (std::multimap<unsigned int, WeaponMode*>::iterator it = weaponModes_->begin(); it != weaponModes_->end(); ++it)
140        {
141            HUDWeaponMode* hudWeaponMode = new HUDWeaponMode(this->getContext());
142            hudWeaponMode->setOwner(owner_);
143            hudWeaponMode->setWeaponMode(it->second);
144            hudWeaponModes_.push_back(hudWeaponMode);
145        }   
146    }     
147
148    void HUDWeapon::positionHUDChilds()
149    {
150        int positionIndex = 0;
151
152        for (std::vector<WeakPtr<HUDWeaponMode> >::iterator it = hudWeaponModes_.begin(); it != hudWeaponModes_.end(); ++it)
153        {
154            (*it)->setOverlayGroup(this->getOverlayGroup());           
155            (*it)->setAspectCorrection(this->getAspectCorrection());
156            (*it)->setPosition(this->getPosition() + Vector2(0.0f,0.025f*positionIndex));
157            (*it)->setSize(Vector2(0.15f,0.025f));
158            (*it)->setPickPoint(Vector2(0.0f,0.0f));
159
160            ++ positionIndex;       
161        }
162
163        overlayElement_->setDimensions(1.0f,0.25f*hudWeaponModes_.size());
164    } 
165
166    void HUDWeapon::destroyHUDChilds()
167    {
168        for (std::vector<WeakPtr<HUDWeaponMode> >::iterator it = hudWeaponModes_.begin(); it != hudWeaponModes_.end(); ++it)
169        {
170            (*it)->destroy();
171        } 
172
173        hudWeaponModes_.clear();
174    }
175}
Note: See TracBrowser for help on using the repository browser.