[Orxonox-commit 2249] r6965 - in code/branches/presentation3: data/gui/scripts src/modules/pickup src/orxonox src/orxonox/interfaces

dafrick at orxonox.net dafrick at orxonox.net
Mon May 24 16:59:23 CEST 2010


Author: dafrick
Date: 2010-05-24 16:59:23 +0200 (Mon, 24 May 2010)
New Revision: 6965

Modified:
   code/branches/presentation3/data/gui/scripts/PickupInventory.lua
   code/branches/presentation3/src/modules/pickup/PickupManager.cc
   code/branches/presentation3/src/modules/pickup/PickupManager.h
   code/branches/presentation3/src/orxonox/CMakeLists.txt
   code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h
   code/branches/presentation3/src/orxonox/interfaces/Pickupable.h
Log:
Cleaned up in PickupInventory, to be able to improve it at a later stage.


Modified: code/branches/presentation3/data/gui/scripts/PickupInventory.lua
===================================================================
--- code/branches/presentation3/data/gui/scripts/PickupInventory.lua	2010-05-22 18:43:39 UTC (rev 6964)
+++ code/branches/presentation3/data/gui/scripts/PickupInventory.lua	2010-05-24 14:59:23 UTC (rev 6965)
@@ -5,20 +5,35 @@
 P.carrierList = {}
 P.wrapper = nil
 P.detailsWindows = {}
+P.pickupsList = {}
 
+P.showing = false
+
+-- Design parameters
+P.imageHeight = 50
+P.detailImageSize = 100
+P.textHeight = 30
+P.buttonWidth = 85
+
 function P.onLoad()
     carrierList = {}
 end
 
 function P.onShow()
     P.createInventory()
+    P.showing = true
 end
 
 function P.onHide()
+    P.showing = false
     P.cleanup()
 end
 
 function P.update()
+    if P.showing == false then
+        return
+    end
+    
     P.cleanup()
     
     P.createInventory()
@@ -26,115 +41,79 @@
 
 function P.createInventory()
     local pickupManager = orxonox.PickupManager:getInstance()
-    local carrier = pickupManager:getPawn()
     
     local root = winMgr:getWindow("orxonox/PickupInventory/Inventory")
     P.wrapper = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/PickupInventory/Inventory/Wrapper")
     P.wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1,0),CEGUI.UDim(1,0)))
     root:addChildWindow(P.wrapper)
     
-    P.carrierList = {}
-    
-    --Design parameters:
-    local space = 15
-    
-    P.getCarrierList(carrier)
+    P.pickupsList = {}
+
+    local numPickups = pickupManager:getNumPickups()
+    local counter = 1
     local offset = 0
-    for k,v in pairs(P.carrierList) do
-        local window = P.createCarrierBox(v,k)
+    while counter <= numPickups do
+        local pickup = pickupManager:popPickup()
+        table.insert(P.pickupsList, pickup)
+        local window = P.createPickupEntry(counter, pickup)
         window:setYPosition(CEGUI.UDim(0,offset))
-        offset = offset + window:getHeight():asAbsolute(1) + space
+        offset = offset + window:getHeight():asAbsolute(1)
         P.wrapper:addChildWindow(window)
+        counter = counter + 1
     end
+
 end
 
-function P.getCarrierList(carrier)
+function P.createPickupEntry(index, pickup)
+    local representation = orxonox.PickupManager:getInstance():getPickupRepresentation(pickup)
 
-    -- TODO: Test for nil or 0?
-    if carrier == nil then
-        return
-    end
-    
-    table.insert(P.carrierList, carrier)
-    
-    local numCarriers = orxonox.PickupManager:getInstance():getNumCarrierChildren(carrier)
-    if numCarriers == 0 then
-        return
-    end
-    
-    for i=0,numCarriers-1,1 do
-        local child = orxonox.PickupManager:getInstance():getCarrierChild(i, carrier)
-        if child ~= nil then
-            P.getCarrierList(child)
-        end
-    end
-end
+    local name = "orxonox/PickupInventory/Box/Pickup" .. index
 
-function P.createCarrierBox(carrier, index)
+    local item = winMgr:createWindow("MenuWidgets/StaticText", name)
+    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, P.imageHeight)))
+    item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
 
-    local name = "orxonox/PickupInventory/Carrier" .. index
-    
-    --Design parameters:
-    local imageHeight = 50
-    local textHeight = 30
-    local horizontalOffset = 20
-    local buttonWidth = 85
-    
-    local offset = 0
+    local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Image")
+    image:setProperty("Image", "set:PickupInventory image:" .. representation:getInventoryRepresentation())
+    image:setProperty("BackgroundEnabled", "set:False")
+    image:setProperty("FrameEnabled", "set:True")
+    image:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.imageHeight), CEGUI.UDim(0, P.imageHeight)))
+    item:addChildWindow(image)
 
-    local box = winMgr:createWindow("MenuWidgets/ScrollablePane", name .. "/Box")
-    box:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horizontalOffset), CEGUI.UDim(0, 0)))
-    box:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -horizontalOffset), CEGUI.UDim(1, 0)))
-    
-    local numPickups = orxonox.PickupManager:getInstance():getNumPickups(carrier)
-    for i=0,numPickups-1,1 do
-        local pickup = orxonox.PickupManager:getInstance():getPickupRepresentation(i, carrier)
-        
-        local item = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Box/Pickup" .. i)
-        item:setSize(CEGUI.UVector2(CEGUI.UDim(1, -horizontalOffset), CEGUI.UDim(0, imageHeight)))
-        item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horizontalOffset), CEGUI.UDim(0, offset)))
-        box:addChildWindow(item)
-        offset = offset + imageHeight+5
-        
-        local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Box/Pickup" .. i .. "/Image")
-        image:setProperty("Image", "set:PickupInventory image:" .. pickup:getInventoryRepresentation())
-        image:setProperty("BackgroundEnabled", "set:False")
-        image:setProperty("FrameEnabled", "set:True")
-        image:setSize(CEGUI.UVector2(CEGUI.UDim(0, imageHeight), CEGUI.UDim(0, imageHeight)))
-        item:addChildWindow(image)
-        
-        local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Box/Pickup" .. i .. "/Title")
-        title:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageHeight+5), CEGUI.UDim(0, (imageHeight-textHeight)/2)))
-        title:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(0, textHeight)))
-        title:setText(pickup:getPickupName())
-        title:setProperty("FrameEnabled", "set:False")
-        item:addChildWindow(title)
-        
-        local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/Box/Pickup" .. i .. "/UseButton")
-        useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+10),CEGUI.UDim(0, (imageHeight-textHeight)/2)))
-        useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, textHeight)))
+    local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title")
+    title:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.imageHeight+5), CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
+    title:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(0, P.textHeight)))
+    title:setText(representation:getPickupName())
+    title:setProperty("FrameEnabled", "set:False")
+    item:addChildWindow(title)
+
+    local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/UseButton")
+    useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, P.imageHeight+10),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
+    useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
+    if pickup:isUsed() == false then
         useButton:setText("use")
         orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked")
-        item:addChildWindow(useButton)
-        
-        local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/Box/Pickup" .. i .. "/DropButton")
-        dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+15+buttonWidth),CEGUI.UDim(0, (imageHeight-textHeight)/2)))
-        dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, textHeight)))
-        dropButton:setText("drop")
-        orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked")
-        item:addChildWindow(dropButton)
-        
-        local detailsButton = winMgr:createWindow("MenuWidgets/Button", name .. "/Box/Pickup" .. i .. "/DetailsButton")
-        detailsButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+20+2*buttonWidth),CEGUI.UDim(0, (imageHeight-textHeight)/2)))
-        detailsButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, textHeight)))
-        detailsButton:setText("details")
-        orxonox.GUIManager:subscribeEventHelper(detailsButton, "Clicked", P.name .. ".InventoryDetailsButton_clicked")
-        item:addChildWindow(detailsButton)
+    else
+        useButton:setText("unuse")
+        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseButton_clicked")
     end
-    
-    box:setHeight(CEGUI.UDim(0,offset))
-    
-    return box
+    item:addChildWindow(useButton)
+
+    local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DropButton")
+    dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, P.imageHeight+15+P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
+    dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
+    dropButton:setText("drop")
+    orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked")
+    item:addChildWindow(dropButton)
+
+    local detailsButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DetailsButton")
+    detailsButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, P.imageHeight+20+2*P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
+    detailsButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
+    detailsButton:setText("details")
+    orxonox.GUIManager:subscribeEventHelper(detailsButton, "Clicked", P.name .. ".InventoryDetailsButton_clicked")
+    item:addChildWindow(detailsButton)
+
+    return item
 end
 
 function P.cleanup()
@@ -150,31 +129,25 @@
     end
 end
 
-function P.windowToCarrierHelper(e)
+function P.windowToPickupHelper(e)
     local we = CEGUI.toWindowEventArgs(e)
     local name = we.window:getName()
 
     local match = string.gmatch(name, "%d+")
-    local carrierNr = tonumber(match())
-    local pickupNr = tonumber(match())
+    local pickupIndex = tonumber(match())
 
-    local arguments = {}
-    arguments[1] = carrierNr
-    arguments[2] = pickupNr
-    return arguments
+    return pickupIndex
 end
 
-function P.createDetailsWindow(pickupIndex, carrierIndex)
-    local carrier = P.carrierList[carrierIndex]
-    local pickup = orxonox.PickupManager:getInstance():getPickupRepresentation(pickupIndex, carrier)
+function P.createDetailsWindow(pickupIndex)
+    local pickup = P.pickupsList[pickupIndex]
+    local representation = orxonox.PickupManager:getInstance():getPickupRepresentation(pickup)
     
     local headerOffset = 35
     --Design parameters
-    local titleHeight = 30
     local imageSize = 100
-    local buttonWidth = 85
     
-    local name = "orxonox/PickupInventory/Carrier" .. carrierIndex .. "/Pickup" .. pickupIndex .. "/Details" .. P.getNewDetailNumber()
+    local name = "orxonox/PickupInventory/Pickup" .. pickupIndex .. "/Details" .. P.getNewDetailNumber()
     
     local window = winMgr:createWindow("MenuWidgets/FrameWindow", name)
     window:setSize(CEGUI.UVector2(CEGUI.UDim(0.5,0),CEGUI.UDim(0.4,0)))
@@ -189,40 +162,45 @@
     window:addChildWindow(wrapper)
     
     local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title")
-    title:setText(pickup:getPickupName())
-    title:setHeight(CEGUI.UDim(0, titleHeight))
+    title:setText(representation:getPickupName())
+    title:setHeight(CEGUI.UDim(0, P.textHeight))
     title:setProperty("FrameEnabled", "set:False")
     title:setProperty("BackgroundEnabled", "set:False")
     wrapper:addChildWindow(title)
     
     local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Image")
-    image:setProperty("Image", "set:PickupInventory image:" .. pickup:getInventoryRepresentation())
+    image:setProperty("Image", "set:PickupInventory image:" .. representation:getInventoryRepresentation())
     image:setProperty("BackgroundEnabled", "set:False")
     image:setProperty("FrameEnabled", "set:True")
-    image:setSize(CEGUI.UVector2(CEGUI.UDim(0, imageSize), CEGUI.UDim(0, imageSize)))
-    image:setYPosition(CEGUI.UDim(0, titleHeight + 5))
+    image:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize), CEGUI.UDim(0, P.detailImageSize)))
+    image:setYPosition(CEGUI.UDim(0, P.textHeight + 5))
     wrapper:addChildWindow(image)
     
     local box = winMgr:createWindow("MenuWidgets/ScrollablePane", name .. "/Description")
-    box:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -1*(imageSize + 10)),CEGUI.UDim(1, -(titleHeight + 5 + titleHeight + 20))))
-    box:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageSize + 10),CEGUI.UDim(0, titleHeight + 5)))
-    local description = winMgr:createWindow("TaharezLook/StaticText", name .. "/Description/Text")
-    description:setText(pickup:getPickupDescription())
+    box:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -1*(P.detailImageSize + 10)),CEGUI.UDim(1, -(P.textHeight + 5 + P.textHeight + 20))))
+    box:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize + 10),CEGUI.UDim(0, P.textHeight + 5)))
+    local description = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Description/Text")
+    description:setText(representation:getPickupDescription())
     description:setProperty("HorzFormatting", "WordWrapLeftAligned")
     description:setProperty("VertFormatting", "TopAligned")
     box:addChildWindow(description)
     wrapper:addChildWindow(box)
-    
+
     local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/UseButton")
-    useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageSize+10),CEGUI.UDim(1, -40)))
-    useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, titleHeight)))
-    useButton:setText("use")
-    orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked")
+    useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize+10),CEGUI.UDim(1, -40)))
+    useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
+    if pickup:isUsed() == false then
+        useButton:setText("use")
+        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked")
+    else
+        useButton:setText("unuse")
+        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseButton_clicked")
+    end
     wrapper:addChildWindow(useButton)
     
     local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DropButton")
-    dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageSize+10+buttonWidth+10),CEGUI.UDim(1, -40)))
-    dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, titleHeight)))
+    dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize+10+P.buttonWidth+10),CEGUI.UDim(1, -40)))
+    dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
     dropButton:setText("drop")
     orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked")
     wrapper:addChildWindow(dropButton)
@@ -242,18 +220,23 @@
 end
 
 function P.InventoryUseButton_clicked(e)
-    local arguments = P.windowToCarrierHelper(e)
-    orxonox.PickupManager:getInstance():usePickup(arguments[2], P.carrierList[arguments[1]], true)
+    local pickupIndex = P.windowToPickupHelper(e)
+    orxonox.PickupManager:getInstance():usePickup(P.pickupsList[pickupIndex], true)
 end
 
+function P.InventoryUnuseButton_clicked(e)
+    local pickupIndex = P.windowToPickupHelper(e)
+    orxonox.PickupManager:getInstance():usePickup(P.pickupsList[pickupIndex], false)
+end
+
 function P.InventoryDropButton_clicked(e)
-    local arguments = P.windowToCarrierHelper(e)
-    orxonox.PickupManager:getInstance():dropPickup(arguments[2], P.carrierList[arguments[1]])
+    local pickupIndex = P.windowToPickupHelper(e)
+    orxonox.PickupManager:getInstance():dropPickup(P.pickupsList[pickupIndex])
 end
 
 function P.InventoryDetailsButton_clicked(e)
-    local arguments = P.windowToCarrierHelper(e)
-    P.createDetailsWindow(arguments[2], arguments[1])
+    local pickupIndex = P.windowToPickupHelper(e)
+    P.createDetailsWindow(pickupIndex)
 end
 
 function P.closeDetailWindow(e)
@@ -261,7 +244,6 @@
     local we = CEGUI.toWindowEventArgs(e)
     local name = we.window:getName()
     local match = string.gmatch(name, "%d+")
-    local carrierNr = tonumber(match())
     local pickupNr = tonumber(match())
     local detailNr = tonumber(match())
     

Modified: code/branches/presentation3/src/modules/pickup/PickupManager.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupManager.cc	2010-05-22 18:43:39 UTC (rev 6964)
+++ code/branches/presentation3/src/modules/pickup/PickupManager.cc	2010-05-24 14:59:23 UTC (rev 6965)
@@ -63,6 +63,7 @@
         RegisterRootObject(PickupManager);
         
         this->defaultRepresentation_ = new PickupRepresentation();
+        this->pickupsIndex_ = 0;
         
         COUT(3) << "PickupManager created." << std::endl;
     }
@@ -148,64 +149,70 @@
         
         return it->second;
     }
-    
-    PickupCarrier* PickupManager::getPawn(void)
+
+    int PickupManager::getNumPickups(void)
     {
+        this->pickupsList_.clear();
+        this->pickupsIndex_ = 0;
+        
         PlayerInfo* player = GUIManager::getInstance().getPlayer(PickupManager::guiName_s);
+        PickupCarrier* carrier = NULL;
         if (player != NULL)
-            return dynamic_cast<PickupCarrier*>(player->getControllableEntity());
+            carrier =  dynamic_cast<PickupCarrier*>(player->getControllableEntity());
         else
-            return NULL;
-    }
-    
-    int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)
-    {
-        if(carrier == NULL)
             return 0;
-        return carrier->getNumCarrierChildren();
+
+        std::vector<PickupCarrier*>* carriers = this->getAllCarriers(carrier);
+        for(std::vector<PickupCarrier*>::iterator it = carriers->begin(); it != carriers->end(); it++)
+        {
+            std::set<Pickupable*> pickups = (*it)->getPickups();
+            for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++)
+            {
+                this->pickupsList_.insert(*pickup);
+            }
+        }
+        delete carriers;
+
+        this->pickupsIterator_ = this->pickupsList_.begin();
+        return this->pickupsList_.size();
     }
-            
-    PickupCarrier* PickupManager::getCarrierChild(int index, PickupCarrier* carrier)
+
+    std::vector<PickupCarrier*>* PickupManager::getAllCarriers(PickupCarrier* carrier)
     {
-        if(carrier == NULL)
-            return NULL;
-        return carrier->getCarrierChild(index);
+        //TODO: More efficiently.
+        std::vector<PickupCarrier*>* carriers = new std::vector<PickupCarrier*>();
+        carriers->insert(carriers->end(), carrier);
+        std::vector<PickupCarrier*>* children = carrier->getCarrierChildren();
+        for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
+        {
+            std::vector<PickupCarrier*>* childrensChildren = this->getAllCarriers(*it);
+            for(std::vector<PickupCarrier*>::iterator it2 = childrensChildren->begin(); it2 != childrensChildren->end(); it2++)
+            {
+                carriers->insert(carriers->end(), *it2);
+            }
+            delete childrensChildren;
+        }
+        delete children;
+        return carriers;
     }
-    
-    const std::string& PickupManager::getCarrierName(orxonox::PickupCarrier* carrier)
+
+    void PickupManager::dropPickup(orxonox::Pickupable* pickup)
     {
-        if(carrier == NULL)
-            return BLANKSTRING;
-        return carrier->getCarrierName();
-    }
-    
-    PickupRepresentation* PickupManager::getPickupRepresentation(int index, PickupCarrier* carrier)
-    {
-        Pickupable* pickup = carrier->getPickup(index);
-        if(pickup == NULL)
-            return NULL;
+        if(!pickup->isPickedUp())
+            return;
         
-        return this->getRepresentation(pickup->getPickupIdentifier());
-    }
-    
-    int PickupManager::getNumPickups(PickupCarrier* carrier)
-    {
-        if(carrier == NULL)
-            return 0;
-        return carrier->getNumPickups();
-    }
-    
-    void PickupManager::dropPickup(int index, PickupCarrier* carrier)
-    {
-        Pickupable* pickup = carrier->getPickup(index);
-        if(pickup != NULL)
+        PickupCarrier* carrier = pickup->getCarrier();
+        if(pickup != NULL && carrier != NULL)
             carrier->drop(pickup);
     }
-    
-    void PickupManager::usePickup(int index, PickupCarrier* carrier, bool use)
+
+    void PickupManager::usePickup(orxonox::Pickupable* pickup, bool use)
     {
-        Pickupable* pickup = carrier->getPickup(index);
-        if(pickup != NULL)
+        if(!pickup->isPickedUp())
+            return;
+
+        PickupCarrier* carrier = pickup->getCarrier();
+        if(pickup != NULL && carrier != NULL)
             pickup->setUsed(use);
     }
     

Modified: code/branches/presentation3/src/modules/pickup/PickupManager.h
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupManager.h	2010-05-22 18:43:39 UTC (rev 6964)
+++ code/branches/presentation3/src/modules/pickup/PickupManager.h	2010-05-24 14:59:23 UTC (rev 6965)
@@ -70,17 +70,13 @@
             PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
             
             // tolua_begin
-            orxonox::PickupCarrier* getPawn(void);
-            
-            int getNumCarrierChildren(orxonox::PickupCarrier* carrier);
-            orxonox::PickupCarrier* getCarrierChild(int index, orxonox::PickupCarrier* carrier);
-            
-            const std::string& getCarrierName(orxonox::PickupCarrier* carrier);
-            
-            int getNumPickups(orxonox::PickupCarrier* carrier);
-            PickupRepresentation* getPickupRepresentation(int index, orxonox::PickupCarrier* carrier);
-            void dropPickup(int index, orxonox::PickupCarrier* carrier);
-            void usePickup(int index, orxonox::PickupCarrier* carrier, bool use);
+            int getNumPickups(void);
+            orxonox::Pickupable* popPickup(void) { this->pickupsIndex_++; return *(this->pickupsIterator_++); }
+            int getPickupIndex(void) { return this->pickupsIndex_-1; }
+            orxonox::PickupRepresentation* getPickupRepresentation(orxonox::Pickupable* pickup) { if(pickup != NULL) return this->getRepresentation(pickup->getPickupIdentifier()); return NULL; }
+
+            void dropPickup(orxonox::Pickupable* pickup);
+            void usePickup(orxonox::Pickupable* pickup, bool use);
             // tolua_end
             
         private:
@@ -89,6 +85,12 @@
             
             PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
             std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
+
+            std::set<Pickupable*> pickupsList_;
+            std::set<Pickupable*>::iterator pickupsIterator_;
+            int pickupsIndex_;
+
+            std::vector<PickupCarrier*>* getAllCarriers(PickupCarrier* carrier);
         
     }; // tolua_export
     

Modified: code/branches/presentation3/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/presentation3/src/orxonox/CMakeLists.txt	2010-05-22 18:43:39 UTC (rev 6964)
+++ code/branches/presentation3/src/orxonox/CMakeLists.txt	2010-05-24 14:59:23 UTC (rev 6965)
@@ -59,7 +59,7 @@
     LevelManager.h
     MoodManager.h
     controllers/HumanController.h
-    interfaces/PickupCarrier.h
+    interfaces/Pickupable.h
     sound/SoundManager.h
   DEFINE_SYMBOL
     "ORXONOX_SHARED_BUILD"

Modified: code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h
===================================================================
--- code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h	2010-05-22 18:43:39 UTC (rev 6964)
+++ code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h	2010-05-24 14:59:23 UTC (rev 6965)
@@ -44,8 +44,8 @@
 
 #include "core/OrxonoxClass.h"
 
-namespace orxonox // tolua_export
-{ // tolua_export
+namespace orxonox
+{
 
     //! Forward-declarations.
     class PickupManager;
@@ -61,9 +61,8 @@
     @author
         Damian 'Mozork' Frick
     */
-    class _OrxonoxExport PickupCarrier  // tolua_export
-        : virtual public OrxonoxClass
-    { // tolua_export
+    class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
+    {
         //! So that the different Pickupables have full access to their PickupCarrier.
         friend class Pickupable;
         friend class PickupManager;
@@ -258,7 +257,7 @@
                     return *it;
                 }
             
-    }; // tolua_export
-} // tolua_export
+    };
+}
 
 #endif /* _PickupCarrier_H__ */

Modified: code/branches/presentation3/src/orxonox/interfaces/Pickupable.h
===================================================================
--- code/branches/presentation3/src/orxonox/interfaces/Pickupable.h	2010-05-22 18:43:39 UTC (rev 6964)
+++ code/branches/presentation3/src/orxonox/interfaces/Pickupable.h	2010-05-24 14:59:23 UTC (rev 6965)
@@ -41,8 +41,8 @@
 
 #include "core/OrxonoxClass.h"
 
-namespace orxonox
-{
+namespace orxonox // tolua_export
+{ // tolua_export
     
     /**
     @brief
@@ -50,8 +50,9 @@
     @author
         Damian 'Mozork' Frick
     */
-    class _OrxonoxExport Pickupable : virtual public OrxonoxClass
-    {
+    class _OrxonoxExport Pickupable  // tolua_export
+        : virtual public OrxonoxClass
+    {  // tolua_export
         protected:
             Pickupable(); //!< Default constructor.
         
@@ -62,8 +63,7 @@
             @brief Get whether the pickup is currently in use or not.
             @return Returns true if the pickup is currently in use.
             */
-            inline bool isUsed(void)
-                { return this->used_; }
+            inline bool isUsed(void) { return this->used_; }  // tolua_export
             /**
             @brief  Should be called when the pickup has transited from used to unused or the other way around.
                     Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method.
@@ -86,8 +86,7 @@
             @brief Returns whether the Pickupable is currently picked up.
             @return Returns true if the Pickupable is currently picked up, false if not.
             */
-            inline bool isPickedUp(void)
-                { return this->pickedUp_; }
+            inline bool isPickedUp(void) { return this->pickedUp_; }  // tolua_export
             /**
             @brief  Should be called when the pickup has transited from picked up to dropped or the other way around.
                     Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
@@ -141,11 +140,11 @@
             PickupCarrier* carrier_; //!< The carrier of the pickup.
             std::list<Identifier*> targets_; //!< The possible targets of this pickup.
 
-    };
+    };  // tolua_export
     
     SUPER_FUNCTION(10, Pickupable, changedUsed, false);
     SUPER_FUNCTION(12, Pickupable, changedCarrier, false);
     SUPER_FUNCTION(13, Pickupable, changedPickedUp, false);
-}
+}  // tolua_export
 
 #endif /* _Pickupable_H__ */




More information about the Orxonox-commit mailing list