Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 2, 2010, 5:35:14 PM (15 years ago)
Author:
dafrick
Message:

Lua bugs fixed.
Renamed name and description in PickupRepresentation to pickupName and pickupDescription to avoid problems.
More work on PickupInventory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup4/data/gui/scripts/PickupInventory.lua

    r6669 r6675  
    2323    P.visible = true
    2424   
    25     table.insert(P.carrierList, 4)
    26    
    2725    local pickupManager = orxonox.PickupManager:getInstance()
    2826    local carrier = pickupManager:getPawn()
    29     P.getCarrierList(carrier)
    3027   
     28    local root = winMgr:getWindow("orxonox/PickupInventory/Inventory")
     29   
     30    P.getCarrierList(carrier)   
    3131    for k,v in pairs(P.carrierList) do
    32         local args = {}
    33         table.insert(args, v)
    34         table.insert(args, k)
    35         local window = P.createCarrierBox(args)
     32        local window = P.createCarrierBox(v,k)
     33        root:addChildWindow(window);
    3634    end
     35
    3736end
    3837
     
    5958end
    6059
    61 function P.createCarrierBox(args)
    62     local carrier = args[1]
    63     local index = args[2]
    64    
     60function P.createCarrierBox(carrier, index)
     61
    6562    local name = "orxonox/PickupInventory/Carrier" .. index
    6663    local window = winMgr:createWindow("TaharezLook/StaticText", name .. "/Title")
     64    --TODO: Align text to the top
    6765    window:setText(carrier:getCarrierName())
    68     -- TODO: Does this exist?
    69     local height = window:getHeight()
    7066   
    7167    local box = winMgr:createWindow("TaharezLook/ScrollablePane", name .. "/Box")
    72     box:setPosition(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0, height)))
    73     box:setWidth(CEGUI.UDim(0.9, 0))
     68    box:setPosition(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0, 35)))
     69    box:setSize(CEGUI.UVector2(CEGUI.UDim(0.9, 0), CEGUI.UDim(1, 0)))
     70    window:addChildWindow(box)
    7471   
    75     local numPickups = orxonox.PickupManager.getInstance():getNumPickups(carrier)
     72    --Design parameters:
     73    imageHeight = 50
     74    textHeight = 30
     75   
     76    local numPickups = orxonox.PickupManager:getInstance():getNumPickups(carrier)
    7677    for i=0,numPickups-1,1 do
     78        local pickup = orxonox.PickupManager:getInstance():getPickupRepresentation(i, carrier)
    7779       
     80        local item = winMgr:createWindow("TaharezLook/StaticText", name .. "/Box/Pickup" .. i)
     81        item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, imageHeight)))
     82        item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, (imageHeight+5)*i)))
     83        box:addChildWindow(item)
     84       
     85        local image = winMgr:createWindow("TaharezLook/StaticImage", name .. "/Box/Pickup" .. i .. "/Image")
     86        image:setProperty("Image", "set:PickupInventory image:" .. pickup:getInventoryRepresentation())
     87        image:setProperty("BackgroundEnabled", "set:False")
     88        image:setProperty("FrameEnabled", "set:True")
     89        image:setSize(CEGUI.UVector2(CEGUI.UDim(0, imageHeight), CEGUI.UDim(0, imageHeight)))
     90        item:addChildWindow(image)
     91       
     92        local title = winMgr:createWindow("TaharezLook/StaticText", name .. "/Box/Pickup" .. i .. "/Title")
     93        title:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageHeight+5), CEGUI.UDim(0, (imageHeight-textHeight)/2)))
     94        title:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(0, textHeight)))
     95        title:setText(pickup:getPickupName())
     96        item:addChildWindow(title)
     97       
     98        local useButton = winMgr:createWindow("TaharezLook/Button", name .. "/Box/Pickup" .. i .. "/UseButton")
     99        useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+10),CEGUI.UDim(0, (imageHeight-textHeight)/2)))
     100        useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0.2, 0), CEGUI.UDim(0, textHeight)))
     101        useButton:setText("use")
     102        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.filename .. ".InventoryUseButton_clicked")
     103        item:addChildWindow(useButton)
     104       
     105        local dropButton = winMgr:createWindow("TaharezLook/Button", name .. "/Box/Pickup" .. i .. "/DropButton")
     106        dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, imageHeight+15),CEGUI.UDim(0, (imageHeight-textHeight)/2)))
     107        dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0.2, 0), CEGUI.UDim(0, textHeight)))
     108        dropButton:setText("drop")
     109        orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.filename .. ".InventoryDropButton_clicked")
     110        item:addChildWindow(dropButton)
    78111    end
    79112   
     
    81114end
    82115
     116function P.windowToCarrierHelper(e)
     117    local we = CEGUI.toWindowEventArgs(e)
     118    local name = we.window:getName()
     119    debug(0, "Name: " .. name)
     120
     121    local match = string.gmatch(name, "%d+")
     122    local carrierNr = tonumber(match())
     123    local pickupNr = tonumber(match())
     124
     125    local arguments = {}
     126    arguments[1] = carrierNr
     127    arguments[2] = pickupNr
     128    return arguments
     129end
     130
    83131function P.InventoryUseButton_clicked(e)
    84 
     132    local arguments = P.windowToCarrierHelper(e)
     133    debug(0, "(Buh: " .. arguments[1] .. "|" .. arguments[2] .. ")")
     134    orxonox.PickupManager:getInstance():usePickup(arguments[2], P.carrierList[arguments[1]], 1)
    85135end
    86136
    87137function P.InventoryDropButton_clicked(e)
    88 
     138    local arguments = P.windowToCarierHelper(e)
     139    orxonox.PickupManager:getInstance():dropPickup(arguments[2], P.carrierList[arguments[1]])
    89140end
    90141
Note: See TracChangeset for help on using the changeset viewer.