Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupItem.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: 7.2 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 "HUDPickupItem.h"
30
31#include <string>
32
33
34#include <OgreOverlayManager.h>
35#include <OgrePanelOverlayElement.h> 
36
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39#include "util/Convert.h"
40#include "core/class/Super.h"
41#include "HUDPickupItem.h"
42
43namespace orxonox
44{
45    RegisterClass(HUDPickupItem);
46
47    HUDPickupItem::HUDPickupItem(Context* context) : OrxonoxOverlay(context)
48    {
49        RegisterObject(HUDPickupItem);
50
51        std::string name = "HUDPickupItem" + getUniqueNumberString();
52
53        overlayElement_ = static_cast<Ogre::PanelOverlayElement* >(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", name ));
54        // overlayElement_->setName(name);
55
56        overlayElement_->setDimensions(0.1f,0.1f);
57       
58    }
59
60    HUDPickupItem::~HUDPickupItem()
61    {
62        if (this->isInitialized())
63        {
64            overlayElement_=nullptr;
65        }
66    }
67
68    void HUDPickupItem::initializeMaterial(const std::string& s, float x, float y)
69    {
70        orxout() << "material name is: " << s << endl;
71        overlayElement_->setMaterialName(s);
72        overlayElement_->setPosition(x, y);
73        overlayElement_->show();
74        this->background_->addChild(overlayElement_);
75    }
76
77    void HUDPickupItem::hideMe(Pickupable* p)
78    {
79        assert(overlayElement_);
80        assert(this->background_);
81        // if(p->isBeingDestroyed()) //if the pickup is being destroyed, we do nothing
82        // {
83        //     orxout() << "now i didnt repaint" << endl;
84        //     return;
85        // }
86        orxout() << "name overlay element: " << overlayElement_->getName() << endl;
87        // orxout() << this << " has called hide" << endl;
88        overlayElement_->hide();
89        this->background_->removeChild(overlayElement_->getName());
90        // this->background_->_update();
91        // orxout() << "after the call the element is visible: " << overlayElement_->isVisible() << endl;
92    }
93
94    // void HUDWeapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
95    // {
96    //     SUPER(HUDWeapon, XMLPort, xmlelement, mode);
97
98    //     XMLPortParam(HUDWeapons, "sensitivity", setRadarSensitivity, getRadarSensitivity, xmlelement, mode);
99    //     XMLPortParam(HUDWeapons, "halfDotSizeDistance", setHalfDotSizeDistance, getHalfDotSizeDistance, xmlelement, mode);
100    // }
101
102    // void HUDWeapon::tick(float dt)
103    // {
104    //     SUPER(HUDWeapon, tick, dt);
105
106    //     if (!weapon_)
107    //     {
108    //         // TODO: destroy this HUD id the Weapon does no more exist. (Wehen the weak pointer is null)
109    //     }
110    // }   
111
112    // void HUDWeapon::positionChanged()
113    // {
114    //     OrxonoxOverlay::positionChanged();
115
116    //     positionHUDChilds();
117    // }
118
119    // void HUDWeapon::sizeChanged()
120    // {
121    //     OrxonoxOverlay::sizeChanged();
122
123    //     positionHUDChilds();
124    // }
125
126    // void HUDWeapon::changedOwner()
127    // {
128    //     SUPER(HUDWeapon, changedOwner);
129
130    //     this->owner_ = orxonox_cast<Pawn*>(this->getOwner());
131
132    //     updateWeaponModeList();
133    // }
134
135    // void HUDWeapon::changedOverlayGroup()
136    // {
137    //     SUPER(HUDWeapon, changedOverlayGroup);
138    // }   
139
140    // void HUDWeapon::changedVisibility()
141    // {
142    //     SUPER(HUDWeapon, changedVisibility);
143
144    //     bool visible = this->isVisible();
145
146    //     for (HUDWeaponMode* hudWeaponMode : hudWeaponModes_)
147    //     {
148    //         hudWeaponMode->changedVisibility(); //inform all Child Overlays that our visibility has changed
149    //         hudWeaponMode->setVisible(visible);
150    //     }
151    // }
152
153    // void HUDWeapon::changedName()
154    // {
155    //     SUPER(HUDWeapon, changedName);
156    // }
157
158    // void HUDWeapon::setWeapon(Weapon* weapon)
159    // {
160    //     weapon_ = weapon;
161
162    //     if (!weapon_)
163    //     {
164    //         return;
165    //     }
166
167    //     updateWeaponModeList();
168    // }
169
170    // void HUDWeapon::updateWeaponModeList()
171    // {
172    //     if (owner_ == nullptr || weapon_ == nullptr)
173    //     {
174    //         return;
175    //     }
176           
177    //     destroyHUDChilds();
178
179    //     updateSize();
180    //     createHUDChilds();
181    //     positionHUDChilds();
182    // } 
183
184    // void HUDWeapon::createHUDChilds()
185    // {
186    //     if (weapon_ == nullptr)
187    //     {
188    //         return;
189    //     }
190
191    //     int positionIndex = 0;
192
193    //     for (const auto& mapEntry : weapon_->getAllWeaponmodes())
194    //     {
195    //         HUDWeaponMode* hudWeaponMode = new HUDWeaponMode(this->getContext());
196    //         hudWeaponMode->setOwner(owner_);
197    //         hudWeaponMode->setOverlayGroup(this->getOverlayGroup());
198    //         hudWeaponMode->setVisible(this->isVisible());
199    //         hudWeaponMode->setWeaponMode(mapEntry.second);
200    //         hudWeaponMode->setWeaponIndex(this->weaponIndex_);                   
201    //         hudWeaponMode->setAspectCorrection(false);
202    //         hudWeaponMode->setPickPoint(Vector2(0.0f,0.0f));
203
204    //         hudWeaponModes_.push_back(hudWeaponMode);
205
206    //         ++ positionIndex;
207    //     }
208    // }     
209
210    // void HUDWeapon::positionHUDChilds()
211    // {
212    //     int positionIndex = 0;
213
214    //     for (HUDWeaponMode* hudWeaponMode : hudWeaponModes_)
215    //     {
216    //         hudWeaponMode->setPositionOffset(this->positionOffset_);
217    //         hudWeaponMode->setWeaponModeIndex(positionIndex);
218    //         hudWeaponMode->setWeaponIndex(this->weaponIndex_);
219    //         hudWeaponMode->setWeaponModeHUDActualSize(this->weaponModeHUDActualSize_);
220
221    //         ++ positionIndex;
222    //     }
223    // } 
224
225    // void HUDWeapon::destroyHUDChilds()
226    // {
227    //     for (HUDWeaponMode* hudWeaponMode : hudWeaponModes_)
228    //     {
229    //         hudWeaponMode->destroy();
230    //     }
231
232    //     hudWeaponModes_.clear();
233    // }
234
235    // void HUDWeapon::updateSize()
236    // {
237    //     if (weapon_ != nullptr)
238    //     {
239    //         this->setSize(Vector2(weaponModeHUDActualSize_.x,weaponModeHUDActualSize_.y*weapon_->getAllWeaponmodes().size()));
240    //         updatePosition();
241    //     }       
242    // }
243
244    // void HUDWeapon::updatePosition()
245    // {
246    //     if (weapon_ != nullptr)
247    //     {
248    //         this->setPosition(Vector2(weaponModeHUDActualSize_.x*weaponIndex_,0.0f) + this->positionOffset_);
249    //     }       
250    // }       
251}
Note: See TracBrowser for help on using the repository browser.