Changeset 11708 for code/trunk
- Timestamp:
- Jan 6, 2018, 6:07:53 PM (7 years ago)
- Location:
- code/trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/overlays/hud/HUDPickupSystem.cc
r11705 r11708 34 34 #include <OgrePanelOverlayElement.h> 35 35 36 #include "HUDPickupSystem.h" 37 36 38 #include "core/CoreIncludes.h" 37 39 #include "core/class/Super.h" 38 40 #include "util/Convert.h" 39 #include "HUDPickupSystem.h"40 41 #include "pickup/PickupManager.h" 42 #include "worldentities/pawns/Pawn.h" 41 43 42 44 namespace orxonox … … 78 80 79 81 } 80 82 83 void HUDPickupSystem::changedOwner() 84 { 85 SUPER(HUDPickupSystem, changedOwner); 86 87 this->owner_ = orxonox_cast<Pawn*>(this->getOwner()); 88 } 89 81 90 void HUDPickupSystem::tick(float dt) 82 91 { 83 92 SUPER(HUDPickupSystem, tick, dt); 84 93 85 int numPickups = PickupManager::getInstance().getNumPickups(); 94 std::vector<const PickupInventoryContainer*> containers = this->getPickupsForOwner(); 95 86 96 for (size_t index = 0; index < this->items_.size(); ++index) 87 97 { 88 98 Ogre::OverlayElement* item = this->items_[index]; 89 99 90 if ( static_cast<int>(index) < numPickups)100 if (index < containers.size()) 91 101 { 92 const PickupInventoryContainer* container = PickupManager::getInstance().popPickup(); 93 item->setMaterialName(this->getIcon(container->representationName)); 102 item->setMaterialName(this->getIcon(containers[index]->representationName)); 94 103 if (!item->getParent()) 95 104 this->background_->addChild(item); … … 103 112 } 104 113 105 std::string HUDPickupSystem::getIcon(std::string repName) 114 std::vector<const PickupInventoryContainer*> HUDPickupSystem::getPickupsForOwner() const 115 { 116 std::vector<const PickupInventoryContainer*> containers; 117 118 int numPickups = PickupManager::getInstance().getNumPickups(); 119 for (int i = 0; i < numPickups; ++i) 120 { 121 const PickupInventoryContainer* container = PickupManager::getInstance().popPickup(); 122 if (this->owner_ && this->owner_->getObjectID() == container->carrierPawnId) 123 containers.push_back(container); 124 } 125 126 return containers; 127 } 128 129 std::string HUDPickupSystem::getIcon(const std::string& repName) const 106 130 { 107 131 if(repName.find("invisible", 0)!=std::string::npos) return "Eye"; -
code/trunk/src/modules/overlays/hud/HUDPickupSystem.h
r11705 r11708 32 32 33 33 #include "overlays/OverlaysPrereqs.h" 34 #include "pickup/PickupPrereqs.h" 34 35 35 36 #include <vector> … … 48 49 49 50 virtual void tick(float dt) override; 51 50 52 virtual void sizeChanged() override; 53 virtual void changedOwner() override; 51 54 52 55 private: 53 std::string getIcon(std::string repName); 56 std::vector<const PickupInventoryContainer*> getPickupsForOwner() const; 57 std::string getIcon(const std::string& repName) const; 54 58 55 59 std::vector<Ogre::OverlayElement*> items_; 60 WeakPtr<Pawn> owner_; 56 61 }; 57 62 } -
code/trunk/src/modules/pickup/PickupManager.cc
r11704 r11708 301 301 if(GameMode::isStandalone() || Host::getPlayerID() == clientId) 302 302 { 303 // If there is no PickupRepresentation registered the default representation is used. 304 if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end()) 305 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickup->getRepresentationName(), pickedUp); 306 else 307 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickup->getRepresentationName(), pickedUp); 303 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), pickup->getRepresentationName(), pickedUp, pawn->getObjectID()); 308 304 } 309 305 // If the concerned host is somewhere in the network, we call pickupChangedPickedUpNetwork() on its PickupManager. 310 306 else 311 307 { 312 // If there is no PickupRepresentation registered the default representation is used. 313 if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end()) 314 { 315 callStaticNetworkFunction(&PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp); 316 } 317 else 318 { 319 callStaticNetworkFunction(&PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickedUp); 320 } 308 callStaticNetworkFunction(&PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), pickedUp, pawn->getObjectID()); 321 309 } 322 310 … … 332 320 @param usable 333 321 Whether the Pickupable's used status can be changed to used in the PickupInventory. 334 @param representationObjectId335 The objectId identifying (over the network) the PickupRepresentation that represents this Pickupable.336 322 @param representationName 337 323 The name of the associated PickupRepresentation 338 324 @param pickedUp 339 325 The pickedUp status the Pickupable changed to. 340 */ 341 /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp) 326 @param carrierPawnId 327 The objectId identifier (over the network) the Pawn that carries this Pickupable 328 */ 329 /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, const std::string& representationName, bool pickedUp, uint32_t carrierPawnId) 342 330 { 343 331 PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host. … … 352 340 container->usable = usable; 353 341 container->unusable = false; 354 container->representationObjectId = representationObjectId;355 342 container->representationName = representationName; 343 container->carrierPawnId = carrierPawnId; 356 344 // Insert the container into the pickupInventoryContainers_ list. 357 345 manager.pickupInventoryContainers_.insert(std::pair<uint32_t, PickupInventoryContainer*>(pickup, container)); -
code/trunk/src/modules/pickup/PickupManager.h
r11704 r11708 64 64 bool usable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is usable. 65 65 bool unusable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is droppable. 66 uint32_t representationObjectId; //!< The objectId of the @ref orxonox::PickupRepresentation "PickupRepresentation" that represents the @ref orxonox::Pickupable "Pickupable".67 66 std::string representationName; //!< The name of the associated PickupRepresentation 67 uint32_t carrierPawnId; //!< The objectId of the @ref orxonox::Pawn "Pawn" that carries the @ref orxonox::Pickupable "Pickupable". 68 68 }; 69 69 // tolua_end … … 120 120 static void pickupChangedUsedNetwork(uint32_t pickup, bool inUse, bool usable, bool unusable); //!< Helper method to react to the change in the used status of a Pickupable. 121 121 virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp) override; //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state. 122 static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp); //!< Helper method to react to the change in the pickedUp status of a Pickupable.122 static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, const std::string& representationName, bool pickedUp, uint32_t carrierPawnId); //!< Helper method to react to the change in the pickedUp status of a Pickupable. 123 123 124 124 // Methods to be used by the PickupInventory. -
code/trunk/src/modules/pickup/PickupPrereqs.h
r11052 r11708 72 72 class Pickup; 73 73 class PickupCollection; 74 class PickupInventoryContainer; 74 75 class PickupManager; 75 76 class PickupRepresentation; -
code/trunk/src/orxonox/controllers/ActionpointController.h
r11112 r11708 33 33 #include "tools/Timer.h" 34 34 #include "tools/interfaces/Tickable.h" 35 #include "../modules/pickup/PickupSpawner.h"36 35 #include <map> 37 36
Note: See TracChangeset
for help on using the changeset viewer.