Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/Presentation_FS16/src/modules/overlays/hud/HUDChargeBar.cc @ 12373

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

merged discharger, thats the last one

File size: 3.6 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "HUDChargeBar.h"
30
31#include "util/Convert.h"
32#include "core/CoreIncludes.h"
33#include "worldentities/pawns/Pawn.h"
34#include "overlays/OverlayGroup.h"
35
36
37namespace orxonox
38{
39    RegisterClass(HUDChargeBar);
40
41    HUDChargeBar::HUDChargeBar(Context* context) : HUDBar(context)
42    {
43        RegisterObject(HUDChargeBar);
44
45        this->owner_ = nullptr;
46        this->correspondingMode_ = nullptr;             // usually no chargeable weapon equipped
47    }
48
49    HUDChargeBar::~HUDChargeBar() { }
50
51    void HUDChargeBar::tick(float dt)
52    {
53        SUPER(HUDChargeBar, tick, dt);
54
55        if (this->owner_)
56        {
57            if(correspondingMode_ != nullptr)                                                                       // if there is a chargeable weapon equipped we want to show the charged amount with a HUDBar
58            {
59                this->setValue( correspondingMode_->getCharges() * 1.0f / correspondingMode_->getMaxCharges() );    // The Value of the HUDBar is the ratio of current Charges and the maximum Charges possible
60               
61                if(this->correspondingMode_->getCharges() > 0)                                                      // The HUDBar should only be visible when we are charging up
62                {
63                    this->setVisible(true);
64                }
65                else
66                {
67                    this->setVisible(false);
68                }
69            }
70        }
71        else
72        {
73            this->setValue(0);
74        }
75
76    }
77
78    void HUDChargeBar::changedOwner()
79    {
80        SUPER(HUDChargeBar, changedOwner);
81
82        this->setVisible(false);
83        this->correspondingMode_ = nullptr;
84
85        this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
86        if(this->owner_ == nullptr){
87            return;
88        }
89
90        const WeaponSystem* weaponsystem = owner_->getWeaponSystem();
91        if(weaponsystem == nullptr){
92            return;
93        }
94
95        const std::vector<WeaponPack*> weaponpacklist = weaponsystem->getAllWeaponPacks();
96        for(WeaponPack* weaponpack : weaponpacklist){
97            const std::vector<Weapon*> weaponlist = weaponpack->getAllWeapons();
98            for(Weapon* weapon : weaponlist){
99                const std::multimap<unsigned int, WeaponMode*> weaponmodelist = weapon->getAllWeaponmodes();
100                for(std::multimap<unsigned int, WeaponMode*>::const_iterator it = weaponmodelist.begin(); it != weaponmodelist.end(); ++it){
101                    if(it->second->isChargeable()){
102                        this->correspondingMode_ = it->second;
103                        return;
104                    }
105                }
106            }
107        }
108    }
109}
Note: See TracBrowser for help on using the repository browser.