Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sagerjFS16/src/modules/overlays/hud/HUDChargeBar.cc @ 11189

Last change on this file since 11189 was 11189, checked in by sagerj, 8 years ago

done/fixed everything, weaponmode/discharger fully commented only hudchargebar left

File size: 3.5 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                    this->setVisible(true);
63                }
64                else
65                {
66                    this->setVisible(false);
67                }
68            }
69        }
70        else
71        {
72            this->setValue(0);
73        }
74
75    }
76
77    void HUDChargeBar::changedOwner()
78    {
79        SUPER(HUDChargeBar, changedOwner);
80
81        this->setVisible(false);
82        this->correspondingMode_ = nullptr;
83
84        this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
85        if(this->owner_ == nullptr){
86            return;
87        }
88
89        const WeaponSystem* weaponsystem = owner_->getWeaponSystem();
90        if(weaponsystem == nullptr){
91            return;
92        }
93
94        const std::vector<WeaponPack*> weaponpacklist = weaponsystem->getAllWeaponPacks();
95        for(WeaponPack* weaponpack : weaponpacklist){
96            const std::vector<Weapon*> weaponlist = weaponpack->getAllWeapons();
97            for(Weapon* weapon : weaponlist){
98                const std::multimap<unsigned int, WeaponMode*> weaponmodelist = weapon->getAllWeaponmodes();
99                for(std::multimap<unsigned int, WeaponMode*>::const_iterator it = weaponmodelist.begin(); it != weaponmodelist.end(); ++it){
100                    if(it->second->isChargeable()){
101                        this->correspondingMode_ = it->second;
102                        return;
103                    }
104                }
105            }
106        }
107    }
108}
Note: See TracBrowser for help on using the repository browser.