Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc @ 11283

Last change on this file since 11283 was 11277, checked in by patricwi, 8 years ago

visualization of pickup system initiated. next steps: add pickup icons when picked up

  • Property svn:eol-style set to native
File size: 24.3 KB
RevLine 
[6474]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:
[7494]23 *      Damian 'Mozork' Frick
[6474]24 *   Co-authors:
25 *      ...
26 *
27*/
28
29/**
[6540]30    @file PickupManager.cc
[6474]31    @brief Implementation of the PickupManager class.
32*/
33
34#include "PickupManager.h"
35
36#include "core/CoreIncludes.h"
[6711]37#include "core/LuaState.h"
38#include "core/GUIManager.h"
[9667]39#include "core/class/Identifier.h"
[10624]40#include "core/singleton/ScopedSingletonIncludes.h"
[7504]41#include "network/Host.h"
[10624]42#include "network/NetworkFunctionIncludes.h"
[11240]43#include "core/input/KeyBinderManager.h"    //for keybinding
44#include "core/input/KeyBinder.h"           //for keybinding
[11252]45#include "core/command/ConsoleCommandIncludes.h"
[7533]46
[7539]47#include "infos/PlayerInfo.h"
[6474]48#include "interfaces/PickupCarrier.h"
49#include "worldentities/pawns/Pawn.h"
[7533]50
[7163]51#include "CollectiblePickup.h"
[6474]52#include "PickupRepresentation.h"
[11277]53// #include "overlays/hud/HUDPickupSystem.h"
[6474]54
55namespace orxonox
56{
[10624]57    ManageScopedSingleton(PickupManager, ScopeID::ROOT, false);
[7163]58
[7533]59    // Initialization of the name of the PickupInventory GUI.
[6711]60    /*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
[7163]61
[7801]62    // Register static network functions that are used to communicate changes to pickups over the network, such that the PickupInventory can display the information about the pickups properly.
[7504]63    registerStaticNetworkFunction(PickupManager::pickupChangedUsedNetwork);
64    registerStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork);
65    registerStaticNetworkFunction(PickupManager::dropPickupNetworked);
66    registerStaticNetworkFunction(PickupManager::usePickupNetworked);
67
[10624]68    RegisterAbstractClass(PickupManager).inheritsFrom<PickupListener>();
69
[11253]70    SetConsoleCommand("useUnusePickup", &PickupManager::useUnusePickup).addShortcut().setActive(true);
[11252]71
72   // SetConsoleCommand("HumanController", "fire",           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
[6474]73    /**
74    @brief
75        Constructor. Registers the PickupManager and creates the default PickupRepresentation.
76    */
[11071]77    PickupManager::PickupManager() : guiLoaded_(false), pickupHighestIndex_(0), defaultRepresentation_(nullptr)
[6474]78    {
[7504]79        RegisterObject(PickupManager);
[7163]80
[6474]81        this->defaultRepresentation_ = new PickupRepresentation();
[7163]82
[11241]83        orxout(internal_info, context::pickups) << "PickupManager created." << endl;
[6474]84    }
[7163]85
[6474]86    /**
87    @brief
88        Destructor.
[7533]89        Destroys the default PickupRepresentation and does some cleanup.
[6474]90    */
91    PickupManager::~PickupManager()
92    {
[7533]93        // Destroying the default representation.
[11071]94        if(this->defaultRepresentation_ != nullptr)
[6474]95            this->defaultRepresentation_->destroy();
[7163]96
[6725]97        this->representations_.clear();
[7163]98
[7533]99        // Destroying all the PickupInventoryContainers that are still there.
[11071]100        for(const auto& mapEntry : this->pickupInventoryContainers_)
101            delete mapEntry.second;
[7533]102        this->pickupInventoryContainers_.clear();
[7504]103
[7533]104        // Destroying all the WeakPointers that are still there.
105        this->pickups_.clear();
106
107        this->indexes_.clear();
108
[8858]109        orxout(internal_info, context::pickups) << "PickupManager destroyed." << endl;
[6474]110    }
[7163]111
[6474]112    /**
113    @brief
[9348]114        Registers a PickupRepresentation.
115    @param name
116        The representation's name.
[6474]117    @param representation
118        A pointer to the PickupRepresentation.
119    @return
120        Returns true if successful and false if not.
121    */
[9348]122    bool PickupManager::registerRepresentation(const std::string& name, PickupRepresentation* representation)
[7163]123    {
[7494]124        assert(representation);
125
[7533]126        // If the list is not empty and Pickupable already has a Representation registered.
[9348]127        if(!this->representations_.empty() && this->representations_.find(name) != this->representations_.end())
[6474]128            return false;
[7163]129
[9348]130        this->representations_[name] = representation;
[7163]131
[8858]132        orxout(verbose, context::pickups) << "PickupRepresentation &" << representation << " registered with the PickupManager." << endl;
[6474]133        return true;
134    }
[7163]135
[6474]136    /**
137    @brief
[9348]138        Unegisters a PickupRepresentation.
139    @param name
140        The representation's name.
[6725]141    @return
142        Returns true if successful and false if not.
143    */
[9348]144    bool PickupManager::unregisterRepresentation(const std::string& name)
[7163]145    {
[9348]146        std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name);
[7533]147        if(it == this->representations_.end()) // If the Pickupable is not registered in the first place.
[6725]148            return false;
[7163]149
[6725]150        this->representations_.erase(it);
[7163]151
[9348]152        orxout(verbose, context::pickups) << "PickupRepresentation &" << name << " unregistered with the PickupManager." << endl;
[6725]153        return true;
154    }
[7163]155
[7533]156    /**
157    @brief
[9348]158        Get the PickupRepresentation with the given name.
159    @param name
160        The name of the PickupRepresentation.
[7533]161    @return
[6474]162        Returns a pointer to the PickupRepresentation.
163    */
[9348]164    PickupRepresentation* PickupManager::getRepresentation(const std::string& name)
[6474]165    {
[9348]166        std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name);
167        if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input name.
[6474]168        {
[8858]169            orxout(verbose, context::pickups) << "PickupManager::getRepresentation() returned default representation." << endl;
[6474]170            return this->defaultRepresentation_;
171        }
[7163]172
[6474]173        return it->second;
174    }
[7163]175
[7206]176    /**
177    @brief
[7533]178        Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state.
[7206]179    @param pickup
[7533]180        The Pickupable whose used status changed.
181    @param used
182        The used status the Pickupable changed to.
[7206]183    */
[7504]184    void PickupManager::pickupChangedUsed(Pickupable* pickup, bool used)
185    {
186        assert(pickup);
187
188        if(!GameMode::isMaster()) // If this is neither standalone nor the server.
189            return;
190
191        CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(pickup);
[7533]192        // If the Pickupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is.
[11071]193        if(collectible != nullptr && collectible->isInCollection())
[7504]194            return;
195
[7533]196        // Getting clientId of the host this change of the pickup's used status concerns.
[7504]197        PickupCarrier* carrier = pickup->getCarrier();
[11071]198        while(carrier->getCarrierParent() != nullptr)
[7504]199            carrier = carrier->getCarrierParent();
200        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
[11071]201        if(pawn == nullptr)
[7504]202            return;
203        PlayerInfo* info = pawn->getPlayer();
[11071]204        if(info == nullptr)
[7504]205            return;
206        unsigned int clientId = info->getClientID();
207
[7533]208        // Get the number identifying the pickup.
209        std::map<Pickupable*, uint32_t>::iterator it = this->indexes_.find(pickup);
[7504]210        assert(it != this->indexes_.end());
[7533]211        uint32_t index = it->second;
[7504]212
[7533]213        // If we're either in standalone mode or this is the host whom the change of the pickup's status concerns.
[7504]214        if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
215        {
216            PickupManager::pickupChangedUsedNetwork(index, used, pickup->isUsable(), pickup->isUnusable());
217        }
[7533]218        // If the concerned host is somewhere in the network, we call pickupChangedUsedNetwork() on its PickupManager.
[7504]219        else
220        {
[10624]221            callStaticNetworkFunction(&PickupManager::pickupChangedUsedNetwork, clientId, index, used, pickup->isUsable(), pickup->isUnusable());
[7504]222        }
223    }
224
[7533]225    /**
226    @brief
227        Helper method to react to the change in the used status of a Pickupable.
228        Static method that is used by the server to inform the client it concerns about the status change.
229        The parameters that are given are used to update the information (i.e. the PickupInventoryContainer) the concerning PickupManager has about the Pickupable that changed.
230    @param pickup
231        A number identifying the Pickupable that changed its used status.
232    @param inUse
233        The used status the Pickupable changed to. (i.e. whether the Pickupable is in use or not).
234    @param usable
235        Whether the Pickupable's used status can be changed used in the PickupInventory.
236    @param unusable
237        Whether the Pickupable's used status can be changed to unused in the PickupInventory.
238    */
239    /*static*/ void PickupManager::pickupChangedUsedNetwork(uint32_t pickup, bool inUse, bool usable, bool unusable)
[7504]240    {
[7533]241        PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host.
242        // If the input Pickupable (i.e its identifier) is not present in the list the PickupManager has.
[7504]243        if(manager.pickupInventoryContainers_.find(pickup) == manager.pickupInventoryContainers_.end())
244        {
[8858]245            orxout(internal_error, context::pickups) << "Pickupable &(" << pickup << ") was not registered with PickupManager for the PickupInventory, when it changed used." << endl;
[7504]246            return;
247        }
248
[7533]249        // Update the Pickupable's container with the information transferred.
[7504]250        manager.pickupInventoryContainers_[pickup]->inUse = inUse;
251        manager.pickupInventoryContainers_[pickup]->usable = usable;
252        manager.pickupInventoryContainers_[pickup]->unusable = unusable;
253
[7533]254        manager.updateGUI(); // Tell the PickupInventory that something has changed.
[7504]255    }
256
[7533]257    /**
258    @brief
259        Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state.
260    @param pickup
261        The Pickupable whose pickedUp status changed.
262    @param pickedUp
263        The pickedUp status the Pickupable changed to.
264    */
[7504]265    void PickupManager::pickupChangedPickedUp(Pickupable* pickup, bool pickedUp)
266    {
267        assert(pickup);
268
[7533]269        if(!GameMode::isMaster()) // If this is neither standalone nor the server.
[7504]270            return;
271
272        CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(pickup);
[7533]273        // If the Pickupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is.
[11071]274        if(collectible != nullptr && collectible->isInCollection())
[7504]275            return;
276
[7533]277        // Getting clientId of the host this change of the pickup's pickedUp status concerns.
[7504]278        PickupCarrier* carrier = pickup->getCarrier();
[11071]279        while(carrier->getCarrierParent() != nullptr)
[7504]280            carrier = carrier->getCarrierParent();
281        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
[11071]282        if(pawn == nullptr)
[7504]283            return;
[7533]284        PlayerInfo* info = pawn->getFormerPlayer();
[11071]285        if(info == nullptr)
[7504]286            return;
287        unsigned int clientId = info->getClientID();
288
[7533]289        uint32_t index = 0;
290        if(pickedUp) // If the Pickupable has changed to picked up, it is added to the required lists.
[7504]291        {
[11241]292            index = this->getPickupIndex(); // Get a new identifier (index) for the Pickupable.
[7533]293            // Add the Pickupable to the indexes_ and pickups_ lists.
[7504]294            this->indexes_[pickup] = index;
[10624]295            this->pickups_[index] = pickup;
[11241]296
[11252]297            //  //Add pickup keybinding
298            // if( KeyBinderManager::exists() )
299            //     addKeyBindingForNewPickup(pickup, index);
300            // else
301            //     orxout() << "Could not create new keybinding because KeyBinderManager doesn't exist." << endl;
[7504]302        }
[7533]303        else // If it was dropped, it is removed from the required lists.
[7504]304        {
[7533]305            // Get the indentifier (index) that identifies the input Pickupable.
306            std::map<Pickupable*, uint32_t>::iterator it = this->indexes_.find(pickup);
[7504]307            index = it->second;
[7533]308
[11252]309            // //Remove pickup keybinding
310            // if( KeyBinderManager::exists() )
311            //       removeKeyBindingForOldPickup(pickup, index);
312            // else
313            //     orxout() << "Could not delete old keybinding because KeyBinderManager doesn't exist." << endl;
[11241]314
315            // Remove the Pickupable from the indexes_ and pickups_ list.
316            this->indexes_.erase(pickup);
[11252]317            this->pickups_.find(index)->second=nullptr; //set to null, so that can be identified as free slot by getPickupIndex()
[7504]318        }
319
[7533]320        // If we're either in standalone mode or this is the host whom the change of the pickup's status concerns.
[7504]321        if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
322        {
[7533]323            // If there is no PickupRepresentation registered the default representation is used.
[9348]324            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
325                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickup->getRepresentationName(), pickedUp);
[7531]326            else
[9348]327                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickup->getRepresentationName(), pickedUp);
[7504]328        }
[7533]329        // If the concerned host is somewhere in the network, we call pickupChangedPickedUpNetwork() on its PickupManager.
[7504]330        else
331        {
[7533]332            // If there is no PickupRepresentation registered the default representation is used.
[9348]333            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
[7531]334            {
[10624]335                callStaticNetworkFunction(&PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp);
[7531]336            }
337            else
338            {
[10624]339                callStaticNetworkFunction(&PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickedUp);
[7531]340            }
[7504]341        }
342
343    }
344
[11241]345    //PRECONDITION: KeyBinderManager exists, pickup is not NULL, 0 < index < 9
[11252]346    //FUNCTION: Adds a keybinding for the new pickup using its index and sets a console command
347    // void PickupManager::addKeyBindingForNewPickup(Pickupable* pickup, uint32_t index)
348    // {
349    //     std::string name="Keys.KeyNumpad";
350    //     std::string binding="useOrUnusePickup";
[11241]351
[11252]352    //     name.append(std::to_string(index));
353    //     binding.append(std::to_string(index));
[11241]354
[11252]355    //     SetConsoleCommand(binding, &PickupManager::useUnusePickup(pickup, index));
356    //     KeyBinderManager::getInstance().getCurrent()->setBinding(binding, name, true);
[11241]357
[11252]358    //     orxout() << "Keybinding for item " << index << " has been added on keybinding " << name << endl;
[11241]359
360
[11252]361    // }
[11241]362
363    //PRECONDITION: KeyBinderManager exists, pickup is not NULL, 0 < index < 9
364    //FUNCTION: Removes the keybinding of the pickup using its index
[11252]365    // void PickupManager::removeKeyBindingForOldPickup(Pickupable* pickup, uint32_t index)
366    // {
367    //     std::string name="Keys.KeyNumpad";
368    //     std::string binding="";
[11241]369
[11252]370    //     name.append(std::to_string(index));
[11241]371
[11252]372    //     SetConsoleCommand(binding, nullptr);
373    //     KeyBinderManager::getInstance().getCurrent()->setBinding("", name, true);
[11241]374
[11252]375    //     orxout() << "Keybinding for item " << index << " has been removed on keybinding " << name << endl;
[11241]376
[11252]377    // }
378
379    //This function is called by the command line or by the key binding
380    //it uses or unuses the pickup, depending on its current state
[11277]381    void PickupManager::useUnusePickup(uint32_t index) 
[11252]382    {
[11253]383        orxout() << "Hello there I was here " << index << endl;
384
385        PickupManager& manager = PickupManager::getInstance();
386
387        Pickupable* pickup=manager.pickups_.find(index)->second;
388        if(pickup==nullptr)
389        {
390            orxout() << "The pickup does not exist." << endl;
391            return;                       //pickup does not exist
392        }
393
394        orxout() << "The pickup is being used: " << pickup->isUsed() << endl;
395
396        if(pickup->isUsed())
397            manager.usePickup(index, false);
398        else
399            manager.usePickup(index, true);
[11241]400    }
401
[11252]402
[7533]403    /**
404    @brief
405        Helper method to react to the change in the pickedUp status of a Pickupable.
406        Static method that is used by the server to inform the client it concerns about the status change.
407        The parameters that are given are used to update the information (i.e. the PickupInventoryContainer) the concerning PickupManager has about the Pickupable that changed.
408    @param pickup
409        A number identifying the Pickupable that changed its pickedUp status.
[7547]410    @param usable
411        Whether the Pickupable's used status can be changed to used in the PickupInventory.
[7533]412    @param representationObjectId
413        The objectId identifying (over the network) the PickupRepresentation that represents this Pickupable.
[11099]414    @param representationName
415        The name of the associated PickupRepresentation
[7533]416    @param pickedUp
417        The pickedUp status the Pickupable changed to.
418    */
[9348]419    /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp)
[7504]420    {
[7533]421        PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host.
422        // If the Pickupable has been picked up, we create a new PickupInventoryContainer for it.
[7504]423        if(pickedUp)
424        {
[7533]425            // Create a new PickupInventoryContainer for the Pickupable and set all the necessary information.
[7504]426            PickupInventoryContainer* container = new PickupInventoryContainer;
427            container->pickup = pickup;
428            container->inUse = false;
429            container->pickedUp = pickedUp;
430            container->usable = usable;
431            container->unusable = false;
432            container->representationObjectId = representationObjectId;
[9348]433            container->representationName = representationName;
[7533]434            // Insert the container into the pickupInventoryContainers_ list.
435            manager.pickupInventoryContainers_.insert(std::pair<uint32_t, PickupInventoryContainer*>(pickup, container));
[7504]436
[7533]437            manager.updateGUI(); // Tell the PickupInventory that something has changed.
[7504]438        }
[7533]439        // If the Pickupable has been dropped, we remove it from the pickupInventoryContainers_ list.
[7504]440        else
441        {
[7533]442            std::map<uint32_t, PickupInventoryContainer*>::iterator it = manager.pickupInventoryContainers_.find(pickup);
[7504]443            if(it != manager.pickupInventoryContainers_.end())
444                delete it->second;
445            manager.pickupInventoryContainers_.erase(pickup);
446
[7533]447            manager.updateGUI(); // Tell the PickupInventory that something has changed.
[7504]448        }
449    }
450
[7533]451    /**
452    @brief
453        Get the number of pickups currently picked up by the player.
454        This method is used in lua to populate the PickupInventory. The intended usage is to call this method to reset the iterator of the list of PickupInventoryContainers and then use popPickup() to get the individual PickupInventoryContainers.
455    @return
456        Returns the number of the players picked up Pickupables.
457    */
458    int PickupManager::getNumPickups(void)
459    {
460        this->pickupsIterator_ = this->pickupInventoryContainers_.begin(); // Reset iterator.
461
462        return this->pickupInventoryContainers_.size();
463    }
464
465    /**
466    @brief
467        Drop the input Pickupable.
468        This method checks whether the input Pickupable still exists and drops it, if so.
469    @param pickup
470        The identifier of the Pickupable to be dropped.
471    */
472    void PickupManager::dropPickup(uint32_t pickup)
473    {
474        // If we're either server or standalone and the list of pickups is not empty, we find and drop the input pickup.
[7539]475        if(GameMode::isMaster())
[7533]476        {
[7539]477            if(this->pickups_.empty())
478                return;
[10624]479            Pickupable* pickupable = this->pickups_.find(pickup)->second;
[11071]480            if(pickupable != nullptr)
[11241]481            {
[7533]482                pickupable->drop();
[11241]483
484            }
[7533]485        }
486        // If we're neither server nor standalone we drop the pickup by calling dropPickupNetworked() of the PickupManager on the server.
487        else
488        {
[10624]489            callStaticNetworkFunction(&PickupManager::dropPickupNetworked, 0, pickup);
[7533]490        }
491    }
492
493    /**
494    @brief
495        Helper method to drop the input pickup on the server.
496        Static method that is used by clients to instruct the server to drop the input pickup.
497    @param pickup
498        The identifier of the Pickupable to be dropped.
499    */
500    /*static*/ void PickupManager::dropPickupNetworked(uint32_t pickup)
501    {
502        if(GameMode::isServer()) // Obviously we only want to do this on the server.
503        {
504            PickupManager& manager = PickupManager::getInstance();
[7539]505            manager.dropPickup(pickup);
[7533]506        }
507    }
508
509    /**
510    @brief
511        Use (or unuse) the input Pickupable.
512        This method checks whether the input Pickupable still exists and uses (or unuses) it, if so,
513    @param pickup
514        The identifier of the Pickupable to be used (or unused).
515    @param use
516        If true the input Pickupable is used, if false it is unused.
517    */
518    void PickupManager::usePickup(uint32_t pickup, bool use)
519    {
520        // If we're either server or standalone and the list of pickups is not empty, we find and change the used status of the input pickup.
[7539]521        if(GameMode::isMaster())
[7533]522        {
[7539]523            if(this->pickups_.empty())
524                return;
[10624]525            Pickupable* pickupable = this->pickups_.find(pickup)->second;
[11071]526            if(pickupable != nullptr)
[7533]527                pickupable->setUsed(use);
528        }
529        // If we're neither server nor standalone we change the used status of the pickup by calling usePickupNetworked() of the PickupManager on the server.
530        else
531        {
[10624]532            callStaticNetworkFunction(&PickupManager::usePickupNetworked, 0, pickup, use);
[7533]533        }
534    }
535
536    /**
537    @brief
538        Helper method to use (or unuse) the input Pickupable on the server.
539        Static method that is used by clients to instruct the server to use (or unuse) the input pickup.
540    @param pickup
541        The identifier of the Pickupable to be used (or unused).
542    @param use
543        If true the input Pickupable is used, if false it is unused.
544    */
545    /*static*/ void PickupManager::usePickupNetworked(uint32_t pickup, bool use)
546    {
547        if(GameMode::isServer())
548        {
549            PickupManager& manager = PickupManager::getInstance();
[7539]550            manager.usePickup(pickup, use);
[7533]551        }
552    }
553
554    /**
555    @brief
556        Updates the PickupInventory GUI.
557        Also loads the PickupInventory GUI if is hasn't been done already.
558    */
[7504]559    inline void PickupManager::updateGUI(void)
560    {
[7533]561        // We only need to update (and load) the GUI if this host shows graphics.
[7504]562        if(GameMode::showsGraphics())
563        {
[7533]564            if(!this->guiLoaded_) // If the GUI hasn't been loaded, yet, we load it.
[7504]565            {
566                GUIManager::getInstance().loadGUI(PickupManager::guiName_s);
567                this->guiLoaded_ = true;
568            }
[7533]569
570            // Update the GUI.
[7504]571            GUIManager::getInstance().getLuaState()->doString(PickupManager::guiName_s + ".update()");
572        }
573    }
574
[7533]575    /**
576    @brief
[11241]577        Get a new index between 0 and 9 for a Pickupable.
578        If all slots are occupied, the Pickupable in the first slot will be dropped.
[7533]579    @return
580        Returns the new index.
581    */
582    uint32_t PickupManager::getPickupIndex(void)
[7504]583    {
[11241]584        //check if there are free slots available
585
586        for(uint32_t i=0; i<10; i++)
587        {
588            if(pickups_.find(i)->second==nullptr) return i;
589        }
590        //all slots are full and we have to drop sth
591        orxout() << "everything was full and we have now dropped the first element" << endl;
592        this->dropPickup(0);
593        return 0;
[7504]594    }
595
[6474]596}
Note: See TracBrowser for help on using the repository browser.