Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/overlays/hud/HUDPickupSystem.cc @ 11705

Last change on this file since 11705 was 11705, checked in by landauf, 7 years ago

[HUD_HS16] removed HUDPickupItem as it is not really necessary (it's just an ogre overlay). also fixed several memory-leaks and some issues with positioning and visibility of the pickup items

File size: 3.9 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 <OgreOverlayManager.h>
33#include <OgreOverlayElement.h>
34#include <OgrePanelOverlayElement.h>
35
36#include "core/CoreIncludes.h"
37#include "core/class/Super.h"
38#include "util/Convert.h"
39#include "HUDPickupSystem.h"
40#include "pickup/PickupManager.h"
41
42namespace orxonox
43{
44    RegisterClass(HUDPickupSystem);
45
46    HUDPickupSystem::HUDPickupSystem(Context* context) : OrxonoxOverlay(context)
47    {
48        RegisterObject(HUDPickupSystem);
49
50        const float offsetX = 0.02f;
51        const float offsetY = 0.05f;
52        const float x = 0.2;
53        const float y = 0.5f;
54
55        for (int index = 0; index < 10; ++index)
56        {
57            int row = index / 5;
58            int column = index % 5;
59
60            std::string name = "HUDPickupItem" + multi_cast<std::string>(index);
61            Ogre::OverlayElement* item = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", name);
62
63            item->setDimensions(0.16, 0.4);
64            item->setPosition(offsetX + column*x, offsetY + row*y);
65            this->items_.push_back(item);
66        }
67    }
68
69    HUDPickupSystem::~HUDPickupSystem()
70    {
71        for (Ogre::OverlayElement* item : items_)
72            Ogre::OverlayManager::getSingleton().destroyOverlayElement(item);
73    }
74
75    void HUDPickupSystem::sizeChanged()
76    {
77        OrxonoxOverlay::sizeChanged();
78
79    }
80   
81    void HUDPickupSystem::tick(float dt)
82    {
83        SUPER(HUDPickupSystem, tick, dt);
84
85        int numPickups = PickupManager::getInstance().getNumPickups();
86        for (size_t index = 0; index < this->items_.size(); ++index)
87        {
88            Ogre::OverlayElement* item = this->items_[index];
89
90            if (static_cast<int>(index) < numPickups)
91            {
92                const PickupInventoryContainer* container = PickupManager::getInstance().popPickup();
93                item->setMaterialName(this->getIcon(container->representationName));
94                if (!item->getParent())
95                    this->background_->addChild(item);
96            }
97            else
98            {
99                if (item->getParent())
100                    this->background_->removeChild(item->getName());
101            }
102        }
103    }
104
105    std::string HUDPickupSystem::getIcon(std::string repName)
106    {
107        if(repName.find("invisible", 0)!=std::string::npos) return "Eye";
108        else if(repName.find("tri", 0)!=std::string::npos) return "Asterisk";
109        else if(repName.find("health", 0)!=std::string::npos || repName.find("Health", 0)!=std::string::npos) return "Cross";
110        else if(repName.find("shield", 0)!=std::string::npos) return "Shield";
111        else if(repName.find("munition", 0)!=std::string::npos) return "Munition";
112        else if(repName.find("shrink", 0)!=std::string::npos) return "Shrink";
113        else if(repName.find("boost", 0)!=std::string::npos) return "Flash";
114        else if(repName.find("speed", 0)!=std::string::npos) return "3arrowsup";
115        else if(repName.find("drone", 0)!=std::string::npos) return "Damage";
116        else return "Unknown";
117    }
118}
Note: See TracBrowser for help on using the repository browser.