[Orxonox-commit 1958] r6675 - in code/branches/pickup4: data/gui/schemes data/gui/scripts data/levels data/levels/includes src/modules/pickup src/orxonox/worldentities/pawns

dafrick at orxonox.net dafrick at orxonox.net
Fri Apr 2 17:35:14 CEST 2010


Author: dafrick
Date: 2010-04-02 17:35:14 +0200 (Fri, 02 Apr 2010)
New Revision: 6675

Modified:
   code/branches/pickup4/data/gui/schemes/OrxonoxGUIScheme.scheme
   code/branches/pickup4/data/gui/scripts/InitialiseGUI.lua
   code/branches/pickup4/data/gui/scripts/PickupInventory.lua
   code/branches/pickup4/data/levels/includes/pickups.oxi
   code/branches/pickup4/data/levels/pickup.oxw
   code/branches/pickup4/src/modules/pickup/PickupManager.cc
   code/branches/pickup4/src/modules/pickup/PickupManager.h
   code/branches/pickup4/src/modules/pickup/PickupRepresentation.cc
   code/branches/pickup4/src/modules/pickup/PickupRepresentation.h
   code/branches/pickup4/src/orxonox/worldentities/pawns/Pawn.cc
Log:
Lua bugs fixed.
Renamed name and description in PickupRepresentation to pickupName and pickupDescription to avoid problems.
More work on PickupInventory.


Modified: code/branches/pickup4/data/gui/schemes/OrxonoxGUIScheme.scheme
===================================================================
--- code/branches/pickup4/data/gui/schemes/OrxonoxGUIScheme.scheme	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/data/gui/schemes/OrxonoxGUIScheme.scheme	2010-04-02 15:35:14 UTC (rev 6675)
@@ -1,4 +1,5 @@
 <?xml version="1.0" ?>
 <GUIScheme Name="OrxonoxGUI">
     <Imageset Name="MainMenuBackground" Filename="MainMenuBackground.imageset"/>
+    <Imageset Name="PickupInventory" Filename="PickupInventory.imageset"/>
 </GUIScheme>

Modified: code/branches/pickup4/data/gui/scripts/InitialiseGUI.lua
===================================================================
--- code/branches/pickup4/data/gui/scripts/InitialiseGUI.lua	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/data/gui/scripts/InitialiseGUI.lua	2010-04-02 15:35:14 UTC (rev 6675)
@@ -222,6 +222,7 @@
     return nil
 end
 
+--TODO: Needed?
 function test(e)
     debug(0, "Blubb")
 end

Modified: code/branches/pickup4/data/gui/scripts/PickupInventory.lua
===================================================================
--- code/branches/pickup4/data/gui/scripts/PickupInventory.lua	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/data/gui/scripts/PickupInventory.lua	2010-04-02 15:35:14 UTC (rev 6675)
@@ -22,18 +22,17 @@
     P.window:show() -- TODO: Do this through parent...
     P.visible = true
     
-    table.insert(P.carrierList, 4)
-    
     local pickupManager = orxonox.PickupManager:getInstance()
     local carrier = pickupManager:getPawn()
-    P.getCarrierList(carrier)
     
+    local root = winMgr:getWindow("orxonox/PickupInventory/Inventory")
+    
+    P.getCarrierList(carrier)    
     for k,v in pairs(P.carrierList) do
-        local args = {}
-        table.insert(args, v)
-        table.insert(args, k)
-        local window = P.createCarrierBox(args)
+        local window = P.createCarrierBox(v,k)
+        root:addChildWindow(window);
     end
+
 end
 
 function P.getCarrierList(carrier)
@@ -58,34 +57,86 @@
     end
 end
 
-function P.createCarrierBox(args)
-    local carrier = args[1]
-    local index = args[2]
-    
+function P.createCarrierBox(carrier, index)
+
     local name = "orxonox/PickupInventory/Carrier" .. index
     local window = winMgr:createWindow("TaharezLook/StaticText", name .. "/Title")
+    --TODO: Align text to the top
     window:setText(carrier:getCarrierName())
-    -- TODO: Does this exist?
-    local height = window:getHeight()
     
     local box = winMgr:createWindow("TaharezLook/ScrollablePane", name .. "/Box")
-    box:setPosition(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0, height)))
-    box:setWidth(CEGUI.UDim(0.9, 0))
+    box:setPosition(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0, 35)))
+    box:setSize(CEGUI.UVector2(CEGUI.UDim(0.9, 0), CEGUI.UDim(1, 0)))
+    window:addChildWindow(box)
     
-    local numPickups = orxonox.PickupManager.getInstance():getNumPickups(carrier)
+    --Design parameters:
+    imageHeight = 50
+    textHeight = 30
+    
+    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("TaharezLook/StaticText", name .. "/Box/Pickup" .. i)
+        item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, imageHeight)))
+        item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, (imageHeight+5)*i)))
+        box:addChildWindow(item)
+        
+        local image = winMgr:createWindow("TaharezLook/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("TaharezLook/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())
+        item:addChildWindow(title)
+        
+        local useButton = winMgr:createWindow("TaharezLook/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.2, 0), CEGUI.UDim(0, textHeight)))
+        useButton:setText("use")
+        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.filename .. ".InventoryUseButton_clicked")
+        item:addChildWindow(useButton)
+        
+        local dropButton = winMgr:createWindow("TaharezLook/Button", name .. "/Box/Pickup" .. i .. "/DropButton")
+        dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, imageHeight+15),CEGUI.UDim(0, (imageHeight-textHeight)/2)))
+        dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0.2, 0), CEGUI.UDim(0, textHeight)))
+        dropButton:setText("drop")
+        orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.filename .. ".InventoryDropButton_clicked")
+        item:addChildWindow(dropButton)
     end
     
     return window
 end
 
-function P.InventoryUseButton_clicked(e)
+function P.windowToCarrierHelper(e)
+    local we = CEGUI.toWindowEventArgs(e)
+    local name = we.window:getName()
+    debug(0, "Name: " .. name)
 
+    local match = string.gmatch(name, "%d+")
+    local carrierNr = tonumber(match())
+    local pickupNr = tonumber(match())
+
+    local arguments = {}
+    arguments[1] = carrierNr
+    arguments[2] = pickupNr
+    return arguments
 end
 
+function P.InventoryUseButton_clicked(e)
+    local arguments = P.windowToCarrierHelper(e)
+    debug(0, "(Buh: " .. arguments[1] .. "|" .. arguments[2] .. ")")
+    orxonox.PickupManager:getInstance():usePickup(arguments[2], P.carrierList[arguments[1]], 1)
+end
+
 function P.InventoryDropButton_clicked(e)
-
+    local arguments = P.windowToCarierHelper(e)
+    orxonox.PickupManager:getInstance():dropPickup(arguments[2], P.carrierList[arguments[1]])
 end
 
 function P.InventoryShowDetails_clicked(e)

Modified: code/branches/pickup4/data/levels/includes/pickups.oxi
===================================================================
--- code/branches/pickup4/data/levels/includes/pickups.oxi	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/data/levels/includes/pickups.oxi	2010-04-02 15:35:14 UTC (rev 6675)
@@ -1,6 +1,6 @@
 <PickupRepresentation
-    name = "Small Health Boost"
-    description = "Adds a small amout of health to the ship."
+    pickupName = "Small Health Boost"
+    pickupDescription = "Adds a small amout of health to the ship."
     spawnerTemplate = "smallhealthpickupRepresentation"
 >
     <pickup>
@@ -9,8 +9,8 @@
 </PickupRepresentation>
 
 <PickupRepresentation
-    name = "Medium Health Boost"
-    description = "Adds a medium amout of health to the ship."
+    pickupName = "Medium Health Boost"
+    pickupDescription = "Adds a medium amout of health to the ship."
     spawnerTemplate = "mediumhealthpickupRepresentation"
 >
     <pickup>
@@ -19,8 +19,8 @@
 </PickupRepresentation>
 
 <PickupRepresentation
-    name = "Huge Health Boost"
-    description = "Adds a huge amout of health to the ship."
+    pickupName = "Huge Health Boost"
+    pickupDescription = "Adds a huge amout of health to the ship."
     spawnerTemplate = "hugehealthpickupRepresentation"
 >
     <pickup>
@@ -29,8 +29,8 @@
 </PickupRepresentation>
 
 <PickupRepresentation
-    name = "Crazy Madness Health Boost"
-    description = "Adds a crazy amout of health to the ship."
+    pickupName = "Crazy Madness Health Boost"
+    pickupDescription = "Adds a crazy amout of health to the ship."
     spawnerTemplate = "crazyhealthpickupRepresentation"
 >
     <pickup>
@@ -39,8 +39,8 @@
 </PickupRepresentation>
 
 <PickupRepresentation
-    name = "Double Pickup"
-    description = "Does stuff."
+    pickupName = "Double Pickup"
+    pickupDescription = "Does stuff."
     spawnerTemplate = "crazyhealthpickupRepresentation"
 >
     <pickup>

Modified: code/branches/pickup4/data/levels/pickup.oxw
===================================================================
--- code/branches/pickup4/data/levels/pickup.oxw	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/data/levels/pickup.oxw	2010-04-02 15:35:14 UTC (rev 6675)
@@ -36,10 +36,16 @@
 
     <PickupSpawner position="-50,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
         <pickup>
-            <HealthPickup health=50 healthRate=5 durationType=continuous activationType=immediate healthType=permanent />
+            <HealthPickup health=50 healthRate=5 durationType=continuous activationType=onUse healthType=permanent />
         </pickup>
     </PickupSpawner>
     
+    <PickupSpawner position="-50,0,-125" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <HealthPickup health=50 healthRate=5 durationType=continuous activationType=onUse healthType=permanent />
+        </pickup>
+    </PickupSpawner>
+    
     <PickupSpawner position="-25,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
         <pickup>
             <HealthPickup template=smallhealthpickup />

Modified: code/branches/pickup4/src/modules/pickup/PickupManager.cc
===================================================================
--- code/branches/pickup4/src/modules/pickup/PickupManager.cc	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/src/modules/pickup/PickupManager.cc	2010-04-02 15:35:14 UTC (rev 6675)
@@ -126,20 +126,29 @@
         return dynamic_cast<PickupCarrier*>(pawn);
     }
     
-    unsigned int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)
+    int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)
     {
         if(carrier == NULL)
             return 0;
         return carrier->getNumCarrierChildren();
     }
             
-    PickupCarrier* PickupManager::getCarrierChild(unsigned int index, PickupCarrier* carrier)
+    PickupCarrier* PickupManager::getCarrierChild(int index, PickupCarrier* carrier)
     {
+        if(carrier == NULL)
+            return NULL;
         return carrier->getCarrierChild(index);
     }
     
-    PickupRepresentation* PickupManager::getPickupRepresentation(unsigned int index, PickupCarrier* carrier)
+    const std::string& PickupManager::getCarrierName(orxonox::PickupCarrier* carrier)
     {
+        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;
@@ -148,18 +157,20 @@
     }
     
 
-    unsigned int PickupManager::getNumPickups(PickupCarrier* carrier)
+    int PickupManager::getNumPickups(PickupCarrier* carrier)
     {
+        if(carrier == NULL)
+            return 0;
         return carrier->getNumPickups();
     }
     
-    void PickupManager::dropPickup(unsigned int index, PickupCarrier* carrier)
+    void PickupManager::dropPickup(int index, PickupCarrier* carrier)
     {
         Pickupable* pickup = carrier->getPickup(index);
         carrier->drop(pickup);
     }
     
-    void PickupManager::usePickup(unsigned int index, PickupCarrier* carrier, bool use)
+    void PickupManager::usePickup(int index, PickupCarrier* carrier, bool use)
     {
         Pickupable* pickup = carrier->getPickup(index);
         pickup->setUsed(use);

Modified: code/branches/pickup4/src/modules/pickup/PickupManager.h
===================================================================
--- code/branches/pickup4/src/modules/pickup/PickupManager.h	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/src/modules/pickup/PickupManager.h	2010-04-02 15:35:14 UTC (rev 6675)
@@ -71,13 +71,15 @@
             // tolua_begin
             orxonox::PickupCarrier* getPawn(void);
             
-            unsigned int getNumCarrierChildren(orxonox::PickupCarrier* carrier);
-            orxonox::PickupCarrier* getCarrierChild(unsigned int index, orxonox::PickupCarrier* carrier);
+            int getNumCarrierChildren(orxonox::PickupCarrier* carrier);
+            orxonox::PickupCarrier* getCarrierChild(int index, orxonox::PickupCarrier* carrier);
             
-            unsigned int getNumPickups(orxonox::PickupCarrier* carrier);
-            PickupRepresentation* getPickupRepresentation(unsigned int index, orxonox::PickupCarrier* carrier);
-            void dropPickup(unsigned int index, orxonox::PickupCarrier* carrier);
-            void usePickup(unsigned int index, orxonox::PickupCarrier* carrier, bool use);
+            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);
             // tolua_end
             
         private:

Modified: code/branches/pickup4/src/modules/pickup/PickupRepresentation.cc
===================================================================
--- code/branches/pickup4/src/modules/pickup/PickupRepresentation.cc	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/src/modules/pickup/PickupRepresentation.cc	2010-04-02 15:35:14 UTC (rev 6675)
@@ -85,7 +85,7 @@
         this->description_ = "This is a pickup.";
         this->name_ = "Pickup";
         this->spawnerTemplate_ = "";
-        this->inventoryRepresentation_ = "";
+        this->inventoryRepresentation_ = "Default";
         this->pickup_ = NULL;
     }
     
@@ -97,8 +97,8 @@
     {
         SUPER(PickupRepresentation, XMLPort, xmlelement, mode);
         
-        XMLPortParam(PickupRepresentation, "name", setName, getName, xmlelement, mode);
-        XMLPortParam(PickupRepresentation, "description", setDescription, getDescription, xmlelement, mode);
+        XMLPortParam(PickupRepresentation, "pickupName", setPickupName, getPickupName, xmlelement, mode);
+        XMLPortParam(PickupRepresentation, "pickupDescription", setPickupDescription, getPickupDescription, xmlelement, mode);
         XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode);
         XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode);
         XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);

Modified: code/branches/pickup4/src/modules/pickup/PickupRepresentation.h
===================================================================
--- code/branches/pickup4/src/modules/pickup/PickupRepresentation.h	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/src/modules/pickup/PickupRepresentation.h	2010-04-02 15:35:14 UTC (rev 6675)
@@ -67,13 +67,13 @@
             @brief Set the name of the Pickupable represented by this PickupRepresentation.
             @param name The name.
             */
-            inline void setName(const std::string& name)
+            inline void setPickupName(const std::string& name)
                 { this->name_ = name; }
             /**
             @brief Set the description of the Pickupable represented by this PickupRepresentation.
             @param description The Description.
             */
-            inline void setDescription(const std::string& description)
+            inline void setPickupDescription(const std::string& description)
                 { this->description_ = description; }
             /**
             @brief Set the spawnerTemplate of the Pickupable represented by this PickupRepresentation.
@@ -106,12 +106,12 @@
             @brief Get the name of the Pickupable represented by this PickupRepresentation.
             @return Returns the name.
             */
-            inline const std::string& getName(void) { return this->name_; } // tolua_export
+            inline const std::string& getPickupName(void) { return this->name_; } // tolua_export
             /**
             @brief Get the description of the Pickupable represented by this PickupRepresentation.
             @return Returns the description.
             */
-            inline const std::string& getDescription(void) { return this->description_; } // tolua_export
+            inline const std::string& getPickupDescription(void) { return this->description_; } // tolua_export
             /**
             @brief Get the name of spawnerTemplate the Pickupable represented by this PickupRepresentation.
             @return Returns the name of the spawnerTemplate.

Modified: code/branches/pickup4/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/pickup4/src/orxonox/worldentities/pawns/Pawn.cc	2010-04-01 14:24:59 UTC (rev 6674)
+++ code/branches/pickup4/src/orxonox/worldentities/pawns/Pawn.cc	2010-04-02 15:35:14 UTC (rev 6675)
@@ -77,6 +77,8 @@
         }
         else
             this->weaponSystem_ = 0;
+        
+        this->setCarrierName("Pawn");
 
         this->setRadarObjectColour(ColourValue::Red);
         this->setRadarObjectShape(RadarViewable::Dot);




More information about the Orxonox-commit mailing list