Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/fabienHS15/src/modules/overlays/hud/HUDWeaponSystem.cc @ 10688

Last change on this file since 10688 was 10688, checked in by fvultier, 9 years ago

There is now a HUD that shows the status of the weapon system: all weapons, weapon modes and their munition. Progress bars show the progress of replenishing munition.

File size: 5.1 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 "HUDWeaponSystem.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 "weaponsystem/WeaponSystem.h"
40#include "weaponsystem/WeaponPack.h"
41#include "weaponsystem/Weapon.h"
42#include "util/Convert.h"
43#include "core/class/Super.h"
44
45namespace orxonox
46{
47    RegisterClass(HUDWeaponSystem);
48
49    HUDWeaponSystem::HUDWeaponSystem(Context* context) : OrxonoxOverlay(context)
50    {
51        RegisterObject(HUDWeaponSystem);
52
53        weapons_.clear();
54        hudWeapons_.clear();
55    }
56
57    HUDWeaponSystem::~HUDWeaponSystem()
58    {
59        if (this->isInitialized())
60        {
61            destroyHUDChilds();
62        }
63    }
64
65    void HUDWeaponSystem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
66    {
67        SUPER(HUDWeaponSystem, XMLPort, xmlelement, mode);
68
69        /*XMLPortParam(HUDWeaponSystem, "sensitivity", setRadarSensitivity, getRadarSensitivity, xmlelement, mode);
70        XMLPortParam(HUDWeaponSystem, "halfDotSizeDistance", setHalfDotSizeDistance, getHalfDotSizeDistance, xmlelement, mode);*/
71    }
72
73    void HUDWeaponSystem::tick(float dt)
74    {
75        SUPER(HUDWeaponSystem, tick, dt);
76
77        if (this->owner_)
78        {
79
80        }
81    } 
82
83    void HUDWeaponSystem::positionChanged()
84    {
85        OrxonoxOverlay::positionChanged();
86
87        positionHUDChilds();
88    } 
89
90    void HUDWeaponSystem::changedOwner()
91    {
92        SUPER(HUDWeaponSystem, changedOwner);
93
94        this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
95
96        updateWeaponList();
97    }
98
99    void HUDWeaponSystem::changedOverlayGroup()
100    {
101        SUPER(HUDWeaponSystem, changedOverlayGroup);
102
103        //this->getOverlayGroup()->addElement(this->textOverlay_.get());
104    }   
105
106    void HUDWeaponSystem::changedVisibility()
107    {
108        SUPER(HUDWeaponSystem, changedVisibility);
109
110        //this->textOverlay_->setVisible(this->isVisible());
111    }
112
113    void HUDWeaponSystem::changedName()
114    {
115        SUPER(HUDWeaponSystem, changedName);
116
117        //this->textOverlay_->setName(this->getName() + "text");
118    } 
119
120    void HUDWeaponSystem::updateWeaponList()
121    {
122        if (owner_ == NULL)
123        {
124            return;
125        }
126
127        weapons_.clear();
128
129        destroyHUDChilds();
130
131        std::vector<WeaponPack*>* weaponPacks = owner_->getAllWeaponPacks();
132
133        for (std::vector<WeaponPack*>::const_iterator itPacks = weaponPacks->begin(); itPacks != weaponPacks->end(); ++itPacks)
134        {
135            std::vector<Weapon*>* weapons = (*itPacks)->getAllWeapons();
136
137            for (std::vector<Weapon*>::const_iterator itWeapons = weapons->begin(); itWeapons != weapons->end(); ++itWeapons)
138            {
139                this->weapons_.push_back(*itWeapons);
140            }
141        }
142
143        createHUDChilds();
144        positionHUDChilds();       
145    }
146
147    void HUDWeaponSystem::createHUDChilds()
148    {
149        for (std::vector<WeakPtr<Weapon> >::iterator it = weapons_.begin(); it != weapons_.end(); ++it)
150        {
151            HUDWeapon* hudWeapon = new HUDWeapon(this->getContext());           
152            hudWeapon->setOwner(owner_);
153            hudWeapon->setWeapon(*it);
154            hudWeapons_.push_back(hudWeapon);
155        }       
156    }     
157
158    void HUDWeaponSystem::positionHUDChilds()
159    {
160        int positionIndex = 0;
161
162        for (std::vector<WeakPtr<HUDWeapon> >::iterator it = hudWeapons_.begin(); it != hudWeapons_.end(); ++it)
163        {
164            (*it)->setOverlayGroup(this->getOverlayGroup());           
165            (*it)->setAspectCorrection(this->getAspectCorrection());
166            (*it)->setPosition(this->getPosition() + Vector2(0.15f*positionIndex,0.0f));           
167            (*it)->setSize(Vector2(0.15f,0.10f));
168            (*it)->setPickPoint(Vector2(0.0f,0.0f));
169
170            ++ positionIndex;
171        }       
172    } 
173
174    void HUDWeaponSystem::destroyHUDChilds()
175    {
176        for (std::vector<WeakPtr<HUDWeapon> >::iterator it = hudWeapons_.begin(); it != hudWeapons_.end(); ++it)
177        {
178            (*it)->destroy();
179        } 
180
181        hudWeapons_.clear();     
182    }     
183}
Note: See TracBrowser for help on using the repository browser.