Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/PickupInventory.lua @ 6846

Last change on this file since 6846 was 6750, checked in by dafrick, 15 years ago

PickupInventory working again, just had to change TaharezLook to MenuWidget.
Also: made changes variable in SingleplayerMenu local.

  • Property svn:eol-style set to native
File size: 11.0 KB
RevLine 
[5661]1-- PickupInventory.lua
[5559]2
[6746]3local P = createMenuSheet("PickupInventory")
[6711]4
5P.carrierList = {}
6P.wrapper = nil
7P.detailsWindows = {}
[5587]8
[6746]9function P.onLoad()
[6711]10    carrierList = {}
11end
[6417]12
[6747]13function P.onShow()
[6711]14    P.createInventory()
[5559]15end
16
[6747]17function P.onHide()
[6711]18    P.cleanup()
[5559]19end
20
[6711]21function P.update()
22    P.cleanup()
23   
24    P.createInventory()
[5559]25end
26
[6711]27function P.createInventory()
28    local pickupManager = orxonox.PickupManager:getInstance()
29    local carrier = pickupManager:getPawn()
30   
31    local root = winMgr:getWindow("orxonox/PickupInventory/Inventory")
[6750]32    P.wrapper = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/PickupInventory/Inventory/Wrapper")
[6711]33    P.wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1,0),CEGUI.UDim(1,0)))
34    root:addChildWindow(P.wrapper)
35   
36    P.carrierList = {}
37   
38    --Design parameters:
39    local space = 15
40   
41    P.getCarrierList(carrier)
42    local offset = 0
43    for k,v in pairs(P.carrierList) do
44        local window = P.createCarrierBox(v,k)
45        window:setYPosition(CEGUI.UDim(0,offset))
46        offset = offset + window:getHeight():asAbsolute(1) + space
47        P.wrapper:addChildWindow(window)
48    end
49end
[6417]50
[6711]51function P.getCarrierList(carrier)
[6417]52
[6711]53    -- TODO: Test for nil or 0?
54    if carrier == nil then
55        return
[5587]56    end
[6711]57   
58    table.insert(P.carrierList, carrier)
59   
60    local numCarriers = orxonox.PickupManager:getInstance():getNumCarrierChildren(carrier)
61    if numCarriers == 0 then
62        return
63    end
64   
65    for i=0,numCarriers-1,1 do
66        local child = orxonox.PickupManager:getInstance():getCarrierChild(i, carrier)
67        if child ~= nil then
68            P.getCarrierList(child)
69        end
70    end
71end
[6417]72
[6711]73function P.createCarrierBox(carrier, index)
74
75    local name = "orxonox/PickupInventory/Carrier" .. index
76       
77    --Design parameters:
78    local imageHeight = 50
79    local textHeight = 30
80    local horizontalOffset = 20
81    local buttonWidth = 85
82   
83    local offset = 0
84
[6750]85    local box = winMgr:createWindow("MenuWidgets/ScrollablePane", name .. "/Box")
[6711]86    box:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horizontalOffset), CEGUI.UDim(0, 0)))
87    box:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -horizontalOffset), CEGUI.UDim(1, 0)))
88   
89    offset = offset+textHeight
[6750]90    local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title")
[6711]91    title:setText(carrier:getCarrierName())
92    title:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, offset)))
93    title:setProperty("FrameEnabled", "set:False")
94    box:addChildWindow(title)
95   
96    local numPickups = orxonox.PickupManager:getInstance():getNumPickups(carrier)
97    for i=0,numPickups-1,1 do
98        local pickup = orxonox.PickupManager:getInstance():getPickupRepresentation(i, carrier)
99       
[6750]100        local item = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Box/Pickup" .. i)
[6711]101        item:setSize(CEGUI.UVector2(CEGUI.UDim(1, -horizontalOffset), CEGUI.UDim(0, imageHeight)))
102        item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horizontalOffset), CEGUI.UDim(0, offset)))
103        box:addChildWindow(item)
104        offset = offset + imageHeight+5
105       
[6750]106        local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Box/Pickup" .. i .. "/Image")
[6711]107        image:setProperty("Image", "set:PickupInventory image:" .. pickup:getInventoryRepresentation())
108        image:setProperty("BackgroundEnabled", "set:False")
109        image:setProperty("FrameEnabled", "set:True")
110        image:setSize(CEGUI.UVector2(CEGUI.UDim(0, imageHeight), CEGUI.UDim(0, imageHeight)))
111        item:addChildWindow(image)
112       
[6750]113        local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Box/Pickup" .. i .. "/Title")
[6711]114        title:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageHeight+5), CEGUI.UDim(0, (imageHeight-textHeight)/2)))
115        title:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(0, textHeight)))
116        title:setText(pickup:getPickupName())
117        title:setProperty("FrameEnabled", "set:False")
118        item:addChildWindow(title)
119       
[6750]120        local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/Box/Pickup" .. i .. "/UseButton")
[6711]121        useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+10),CEGUI.UDim(0, (imageHeight-textHeight)/2)))
122        useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, textHeight)))
123        useButton:setText("use")
[6746]124        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked")
[6711]125        item:addChildWindow(useButton)
126       
[6750]127        local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/Box/Pickup" .. i .. "/DropButton")
[6711]128        dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+15+buttonWidth),CEGUI.UDim(0, (imageHeight-textHeight)/2)))
129        dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, textHeight)))
130        dropButton:setText("drop")
[6746]131        orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked")
[6711]132        item:addChildWindow(dropButton)
133       
[6750]134        local detailsButton = winMgr:createWindow("MenuWidgets/Button", name .. "/Box/Pickup" .. i .. "/DetailsButton")
[6711]135        detailsButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.4, imageHeight+20+2*buttonWidth),CEGUI.UDim(0, (imageHeight-textHeight)/2)))
136        detailsButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, textHeight)))
137        detailsButton:setText("details")
[6746]138        orxonox.GUIManager:subscribeEventHelper(detailsButton, "Clicked", P.name .. ".InventoryDetailsButton_clicked")
[6711]139        item:addChildWindow(detailsButton)
140    end
141   
142    box:setHeight(CEGUI.UDim(0,offset))
143   
144    return box
145end
146
147function P.cleanup()
148    if P.wrapper ~= nil then
149        winMgr:destroyWindow(P.wrapper)
150    end
151   
152    --Destroy details windows.
153    for k,v in pairs(P.detailsWindows) do
154        if v ~= nil then
155            winMgr:destroyWindow(v)
[5587]156        end
157    end
158end
159
[6711]160function P.windowToCarrierHelper(e)
161    local we = CEGUI.toWindowEventArgs(e)
162    local name = we.window:getName()
[6417]163
[6711]164    local match = string.gmatch(name, "%d+")
165    local carrierNr = tonumber(match())
166    local pickupNr = tonumber(match())
167
168    local arguments = {}
169    arguments[1] = carrierNr
170    arguments[2] = pickupNr
171    return arguments
[5587]172end
173
[6711]174function P.createDetailsWindow(pickupIndex, carrierIndex)
175    local carrier = P.carrierList[carrierIndex]
176    local pickup = orxonox.PickupManager:getInstance():getPickupRepresentation(pickupIndex, carrier)
177   
178    local headerOffset = 35
179    --Design parameters
180    local titleHeight = 30
181    local imageSize = 100
182    local buttonWidth = 85
183   
184    local name = "orxonox/PickupInventory/Carrier" .. carrierIndex .. "/Pickup" .. pickupIndex .. "/Details" .. P.getNewDetailNumber()
185   
[6750]186    local window = winMgr:createWindow("MenuWidgets/FrameWindow", name)
[6711]187    window:setSize(CEGUI.UVector2(CEGUI.UDim(0.5,0),CEGUI.UDim(0.4,0)))
[6746]188    orxonox.GUIManager:subscribeEventHelper(window, "CloseClicked", P.name .. ".closeDetailWindow")
[6711]189   
190    local root = winMgr:getWindow("orxonox/PickupInventory/Background")
191    root:addChildWindow(window)
192   
193    local wrapper = winMgr:createWindow("DefaultWindow", name .. "/Wrapper")
194    wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1, -20),CEGUI.UDim(1, -50)))
195    wrapper:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10),CEGUI.UDim(0, 40)))
196    window:addChildWindow(wrapper)
197   
[6750]198    local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title")
[6711]199    title:setText(pickup:getPickupName())
200    title:setHeight(CEGUI.UDim(0, titleHeight))
201    title:setProperty("FrameEnabled", "set:False")
202    title:setProperty("BackgroundEnabled", "set:False")
203    wrapper:addChildWindow(title)
204   
[6750]205    local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Image")
[6711]206    image:setProperty("Image", "set:PickupInventory image:" .. pickup:getInventoryRepresentation())
207    image:setProperty("BackgroundEnabled", "set:False")
208    image:setProperty("FrameEnabled", "set:True")
209    image:setSize(CEGUI.UVector2(CEGUI.UDim(0, imageSize), CEGUI.UDim(0, imageSize)))
210    image:setYPosition(CEGUI.UDim(0, titleHeight + 5))
211    wrapper:addChildWindow(image)
212   
[6750]213    local box = winMgr:createWindow("MenuWidgets/ScrollablePane", name .. "/Description")
[6711]214    box:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -1*(imageSize + 10)),CEGUI.UDim(1, -(titleHeight + 5 + titleHeight + 20))))
215    box:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageSize + 10),CEGUI.UDim(0, titleHeight + 5)))
216    local description = winMgr:createWindow("TaharezLook/StaticText", name .. "/Description/Text")
217    description:setText(pickup:getPickupDescription())
218    description:setProperty("HorzFormatting", "WordWrapLeftAligned")
219    description:setProperty("VertFormatting", "TopAligned")
220    box:addChildWindow(description)
221    wrapper:addChildWindow(box)
222   
[6750]223    local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/UseButton")
[6711]224    useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageSize+10),CEGUI.UDim(1, -40)))
225    useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, titleHeight)))
226    useButton:setText("use")
[6746]227    orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked")
[6711]228    wrapper:addChildWindow(useButton)
229   
[6750]230    local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DropButton")
[6711]231    dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, imageSize+10+buttonWidth+10),CEGUI.UDim(1, -40)))
232    dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0, titleHeight)))
233    dropButton:setText("drop")
[6746]234    orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked")
[6711]235    wrapper:addChildWindow(dropButton)
236   
237    table.insert(P.detailsWindows, window)
238   
239end
240
241function P.getNewDetailNumber()
242    local number = table.getn(P.detailsWindows)
243    for k,v in pairs(P.detailsWindows) do
244        if v == nil then
245            number = k-1
246        end
247    end
248    return number
249end
250
251function P.InventoryUseButton_clicked(e)
252    local arguments = P.windowToCarrierHelper(e)
253    orxonox.PickupManager:getInstance():usePickup(arguments[2], P.carrierList[arguments[1]], true)
254end
255
256function P.InventoryDropButton_clicked(e)
257    local arguments = P.windowToCarrierHelper(e)
258    orxonox.PickupManager:getInstance():dropPickup(arguments[2], P.carrierList[arguments[1]])
259end
260
261function P.InventoryDetailsButton_clicked(e)
262    local arguments = P.windowToCarrierHelper(e)
263    P.createDetailsWindow(arguments[2], arguments[1])
264end
265
266function P.closeDetailWindow(e)
267    --Get some numbers from the window
268    local we = CEGUI.toWindowEventArgs(e)
269    local name = we.window:getName()
270    local match = string.gmatch(name, "%d+")
271    local carrierNr = tonumber(match())
272    local pickupNr = tonumber(match())
273    local detailNr = tonumber(match())
274   
275    local window = P.detailsWindows[detailNr+1]
276    winMgr:destroyWindow(window)
277    P.detailsWindows[detailNr+1] = nil
278end
279
280function P.InventoryBackButton_clicked(e)
[6750]281    orxonox.CommandExecutor:execute("OrxonoxOverlay toggleVisibility PickupInventory")
[6711]282end
283
[5661]284return P
Note: See TracBrowser for help on using the repository browser.