Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupSystem.cc @ 11323

Last change on this file since 11323 was 11323, checked in by patricwi, 7 years ago

bug when ending or restarting a game with non-empty inventory and size and address of pickups still has to be specified so that the item corresponds to the right pickup symbol

File size: 3.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 *      Patrick Wintermeyer
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include <vector>
30#include <string>
31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34#include "util/Convert.h"
35#include "core/class/Super.h"
36#include "HUDPickupSystem.h"
37#include "pickup/Pickup.h"
38#include "HUDPickupItem.h"
39#include "pickup/PickupManager.h"
40
41namespace orxonox
42{
43    RegisterClass(HUDPickupSystem);
44
45    HUDPickupSystem::HUDPickupSystem(Context* context) : OrxonoxOverlay(context)
46    {
47        RegisterObject(HUDPickupSystem);
48
49        overlayElement_ = static_cast<Ogre::PanelOverlayElement* >(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDPickupSystem" + getUniqueNumberString()));
50        overlayElement_->setMaterialName("PickupBar");
51        overlayElement_->setPosition(0.0f,0.0f);
52        overlayElement_->setDimensions(0.70f,0.15f);
53        orxout() << "hello here is the HUDPickupSystem" << endl;
54        this->background_->addChild(overlayElement_);
55    }
56
57    HUDPickupSystem::~HUDPickupSystem()
58    {
59        if (this->isInitialized())
60        {
61            this->picks.clear();
62        }
63    }
64
65   //TODO: XMLPort
66
67    void HUDPickupSystem::updatePickupList(std::vector<Pickupable*> picks)
68    {
69        int i=0;
70        const float offsetX = 0.32f;
71        float offsetY = 0.77f;
72        const float x = 0.1f;
73
74        orxout() << "size: " << picks.size() << endl;
75
76        if(picks.size()>0)
77        {
78
79            for(Pickupable* p : picks)
80            {
81                // orxout() << "actual pick is: " << p << endl;
82                if(i%5==0)
83                {
84                    offsetY+=0.04f;
85                    i=0;
86                }   
87                if(this->picks.count(p)==0)
88                {
89                    HUDPickupItem* item = new HUDPickupItem(this->getContext());
90                    // item->initializeMaterial(((Pickup*)p)->getRepresentationName(), offsetX+i*x, offsetY);
91                if(i%2==0)
92                    item->initializeMaterial("Shield", offsetX+i*x, offsetY);
93                else
94                    item->initializeMaterial("ArrowUp", offsetX+i*x, offsetY);
95                item->setOverlayGroup(this->getOverlayGroup());
96                this->picks[p] = item;
97                }
98               
99                ++i;
100            }
101        }
102    }
103
104    void HUDPickupSystem::createPickupList()
105    {
106    }     
107
108    void HUDPickupSystem::removePickup(Pickupable* pickup)
109    {
110        assert(pickup);
111        HUDPickupItem* item = this->picks.find(pickup)->second;
112        orxout() << "removePickup: pickup= " << pickup << " item= " << item << endl;
113        assert(item);
114        // item->setOverlayGroup(nullptr);
115        item->hideMe(pickup);
116        assert(overlayElement_);
117        // overlayElement_->_update();
118        assert(this->background_);
119        // this->background_->_update();
120        this->picks.erase(pickup);
121    }
122
123    void HUDPickupSystem::destroyAll()
124    {
125        this->background_->removeChild(overlayElement_->getName());
126    }
127}
Note: See TracBrowser for help on using the repository browser.