Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/src/modules/overlays/hud/HUDPickupSystem.cc @ 12119

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

fixed build

  • Property svn:eol-style set to native
File size: 4.6 KB
RevLine 
[11263]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
[11277]29#include <vector>
30#include <string>
31
[11796]32#if OGRE_VERSION >= 0x010900
33#   include <Overlay/OgreOverlayManager.h>
34#   include <Overlay/OgrePanelOverlayElement.h>
35#else
36#   include <OgreOverlayManager.h>
37#   include <OgrePanelOverlayElement.h>
38#endif
[11702]39
[11708]40#include "HUDPickupSystem.h"
41
[11263]42#include "core/CoreIncludes.h"
43#include "core/class/Super.h"
[11705]44#include "util/Convert.h"
[11305]45#include "pickup/PickupManager.h"
[11708]46#include "worldentities/pawns/Pawn.h"
[11263]47
48namespace orxonox
49{
50    RegisterClass(HUDPickupSystem);
51
52    HUDPickupSystem::HUDPickupSystem(Context* context) : OrxonoxOverlay(context)
53    {
54        RegisterObject(HUDPickupSystem);
55
[11705]56        const float offsetX = 0.02f;
57        const float offsetY = 0.05f;
58        const float x = 0.2;
59        const float y = 0.5f;
60
61        for (int index = 0; index < 10; ++index)
62        {
63            int row = index / 5;
64            int column = index % 5;
65
66            std::string name = "HUDPickupItem" + multi_cast<std::string>(index);
67            Ogre::OverlayElement* item = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", name);
68
69            item->setDimensions(0.16, 0.4);
70            item->setPosition(offsetX + column*x, offsetY + row*y);
71            this->items_.push_back(item);
72        }
[11263]73    }
74
75    HUDPickupSystem::~HUDPickupSystem()
76    {
[11705]77        for (Ogre::OverlayElement* item : items_)
78            Ogre::OverlayManager::getSingleton().destroyOverlayElement(item);
[11263]79    }
80
[11708]81    void HUDPickupSystem::changedOwner()
82    {
83        SUPER(HUDPickupSystem, changedOwner);
84
85        this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
86    }
87
[11704]88    void HUDPickupSystem::tick(float dt)
[11700]89    {
[11704]90        SUPER(HUDPickupSystem, tick, dt);
91
[11708]92        std::vector<const PickupInventoryContainer*> containers = this->getPickupsForOwner();
93
[11705]94        for (size_t index = 0; index < this->items_.size(); ++index)
[11277]95        {
[11705]96            Ogre::OverlayElement* item = this->items_[index];
[11336]97
[11708]98            if (index < containers.size())
[11705]99            {
[11708]100                item->setMaterialName(this->getIcon(containers[index]->representationName));
[11705]101                if (!item->getParent())
102                    this->background_->addChild(item);
103            }
104            else
105            {
106                if (item->getParent())
107                    this->background_->removeChild(item->getName());
108            }
[11277]109        }
[11263]110    }
111
[11708]112    std::vector<const PickupInventoryContainer*> HUDPickupSystem::getPickupsForOwner() const
[11325]113    {
[11708]114        std::vector<const PickupInventoryContainer*> containers;
115
116        int numPickups = PickupManager::getInstance().getNumPickups();
117        for (int i = 0; i < numPickups; ++i)
118        {
119            const PickupInventoryContainer* container = PickupManager::getInstance().popPickup();
120            if (this->owner_ && this->owner_->getObjectID() == container->carrierPawnId)
121                containers.push_back(container);
122        }
123
124        return containers;
125    }
126
127    std::string HUDPickupSystem::getIcon(const std::string& repName) const
128    {
[11325]129        if(repName.find("invisible", 0)!=std::string::npos) return "Eye";
[11336]130        else if(repName.find("tri", 0)!=std::string::npos) return "Asterisk";
[11325]131        else if(repName.find("health", 0)!=std::string::npos || repName.find("Health", 0)!=std::string::npos) return "Cross";
132        else if(repName.find("shield", 0)!=std::string::npos) return "Shield";
133        else if(repName.find("munition", 0)!=std::string::npos) return "Munition";
134        else if(repName.find("shrink", 0)!=std::string::npos) return "Shrink";
135        else if(repName.find("boost", 0)!=std::string::npos) return "Flash";
136        else if(repName.find("speed", 0)!=std::string::npos) return "3arrowsup";
137        else if(repName.find("drone", 0)!=std::string::npos) return "Damage";
138        else return "Unknown";
139    }
[11263]140}
Note: See TracBrowser for help on using the repository browser.