Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Dialogue_FS17/data/gui/scripts/Dialogue.lua @ 11401

Last change on this file since 11401 was 11401, checked in by rrogge, 7 years ago

zeigt PickupInventory an

File size: 13.7 KB
Line 
1--[[local P = createMenuSheet("Dialogue Window")
2
3function P.onLoad()
4        P.createWindow()
5        P.showing = true   
6end
7 function function_name( ... )
8        -- body
9 end
10
11
12
13
14function P.createWindow()
15   
16    local question = orxonox.DialogueManager:getInstance():getquestion()
17    local default = (winMgr:createWindow("DefaultWindow"))
18    default:setText(question)
19    default:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}")
20    default:setProperty("UnifiedAreaRect", "{{0,0},{0,0},{1,0},{1,0}}")
21   
22   
23
24
25   
26end
27local numOptions = DialogueManager:getnumOptions()
28    local counter = 1
29    local offset = 0
30    --create and name buttons while there are still options
31    while counter <= numOptions do
32       
33       
34    end]]
35-- Dialogue.lua
36
37local P = createMenuSheet("PickupInventory")
38
39P.wrapper = nil
40P.detailsWindows = {}
41P.detailPickups = {}
42P.pickupsList = {}
43
44P.showing = false
45
46-- Design parameters
47P.imageHeight = 50
48P.detailImageSize = 100
49P.textHeight = 30
50P.buttonWidth = 85
51
52function P.onLoad()
53        orxout("loading")
54    P.wrapper = nil
55    P.detailsWindows = {}
56    P.detailPickups = {}
57    P.pickupsList = {}
58end
59
60function P.onShow()
61        orxout("showing")
62    P.createInventory()
63    P.showing = true
64end
65
66function P.onHide()
67    P.showing = false
68    P.cleanup(true)
69end
70
71function P.update()
72    if P.showing == false then
73        return
74    end
75
76    -- Update opened detail windows.
77    for k,v in pairs(P.detailsWindows) do
78        if v ~= nil then
79            local pickup = P.detailPickups[k]
80            if pickup ~= nil and pickup ~= 0 then
81                local useButton = winMgr:getWindow("orxonox/PickupInventory/Details" .. k .. "/UseButton")
82                local dropButton = winMgr:getWindow("orxonox/PickupInventory/Details" .. k .. "/DropButton")
83                if orxonox.PickupManager:getInstance():isValidPickup(pickup.pickup) == false then
84                    useButton:setEnabled(false)
85                    dropButton:setEnabled(false)
86                    P.detailPickups[k] = nil
87                else
88                    useButton:setEnabled(true)
89                    if pickup.inUse == true then
90                        useButton:setText("unuse")
91                        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked")
92                        if pickup.usable == false then
93                            useButton:setEnabled(false)
94                        end
95                    else
96                        useButton:setText("use")
97                        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked")
98                        if pickup.unusable == false then
99                            useButton:setEnabled(false)
100                        end
101                    end
102
103                    if pickup.pickedUp == false then
104                        useButton:setEnabled(false)
105                        dropButton:setEnabled(false)
106                        P.detailPickups[k] = nil
107                    end
108                end
109            end
110        end
111    end
112
113    -- Update main inventory.
114    P.cleanup(false)
115    P.createInventory()
116    -- TODO: Recover scrolling position
117   
118end
119
120function P.createInventory()
121    local pickupManager = orxonox.PickupManager:getInstance()
122   
123    local root = winMgr:getWindow("orxonox/PickupInventory/Inventory")
124    P.wrapper = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/PickupInventory/Inventory/Wrapper")
125    P.wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1,0),CEGUI.UDim(1,0)))
126    root:addChildWindow(P.wrapper)
127   
128    P.pickupsList = {}
129
130    local numPickups = pickupManager:getNumPickups()
131    local counter = 1
132    local offset = 0
133    while counter <= numPickups do
134        local pickup = pickupManager:popPickup()
135        table.insert(P.pickupsList, pickup)
136        local window = P.createPickupEntry(counter, pickup)
137        window:setYPosition(CEGUI.UDim(0,offset))
138        offset = offset + window:getHeight():asAbsolute(1)
139        P.wrapper:addChildWindow(window)
140        counter = counter + 1
141    end
142
143end
144
145function P.createPickupEntry(index, pickup)
146    local representation = orxonox.PickupManager:getInstance():getRepresentation(pickup.representationName)
147
148    local name = "orxonox/PickupInventory/Box/Pickup" .. index
149
150    local item = winMgr:createWindow("MenuWidgets/StaticText", name)
151    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, P.imageHeight)))
152    item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
153
154    local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Image")
155    image:setProperty("Image", "set:PickupInventory image:" .. representation:getInventoryRepresentation())
156    image:setProperty("BackgroundEnabled", "set:False")
157    image:setProperty("FrameEnabled", "set:True")
158    image:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.imageHeight), CEGUI.UDim(0, P.imageHeight)))
159    item:addChildWindow(image)
160
161    local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title")
162    title:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.imageHeight+5), CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
163    title:setSize(CEGUI.UVector2(CEGUI.UDim(0.3, 0), CEGUI.UDim(0, P.textHeight)))
164    title:setText(representation:getPickupName())
165    title:setProperty("FrameEnabled", "set:False")
166    item:addChildWindow(title)
167
168    local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/UseButton")
169    useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+10),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
170    useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
171    if pickup.inUse == false then
172        useButton:setText("use")
173        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked")
174        if pickup.usable == false then
175            useButton:setEnabled(false)
176        end
177    else
178        useButton:setText("unuse")
179        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseButton_clicked")
180        if pickup.unusable == false then
181            useButton:setEnabled(false)
182        end
183    end
184    item:addChildWindow(useButton)
185
186    local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DropButton")
187    dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+15+P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
188    dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
189    dropButton:setText("drop")
190    orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropButton_clicked")
191    item:addChildWindow(dropButton)
192
193    local detailsButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DetailsButton")
194    detailsButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0.3, P.imageHeight+20+2*P.buttonWidth),CEGUI.UDim(0, (P.imageHeight-P.textHeight)/2)))
195    detailsButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
196    detailsButton:setText("details")
197    orxonox.GUIManager:subscribeEventHelper(detailsButton, "Clicked", P.name .. ".InventoryDetailsButton_clicked")
198    item:addChildWindow(detailsButton)
199
200    return item
201end
202
203function P.cleanup(destroyDetails)
204    if P.wrapper ~= nil then
205        winMgr:destroyWindow(P.wrapper)
206    end
207   
208    --Destroy details windows.
209    if destroyDetails == false then
210        return
211    end
212    for k,v in pairs(P.detailsWindows) do
213        if v ~= nil then
214            P.destroyDetailWindow(k)
215        end
216    end
217end
218
219function P.windowToPickupHelper(e)
220    local we = CEGUI.toWindowEventArgs(e)
221    local name = we.window:getName()
222
223    local match = string.gmatch(name, "%d+")
224    local pickupIndex = tonumber(match())
225
226    return pickupIndex
227end
228
229function P.createDetailsWindow(pickupIndex)
230    local pickup = P.pickupsList[pickupIndex]
231    local representation = orxonox.PickupManager:getInstance():getRepresentation(pickup.representationName)
232
233    local index = P.getNewDetailNumber()
234    local name = "orxonox/PickupInventory/Details" .. index
235   
236    local window = winMgr:createWindow("MenuWidgets/FrameWindow", name)
237    window:setSize(CEGUI.UVector2(CEGUI.UDim(0.5,0),CEGUI.UDim(0.4,0)))
238    orxonox.GUIManager:subscribeEventHelper(window, "CloseClicked", P.name .. ".closeDetailWindow")
239   
240    local root = winMgr:getWindow("orxonox/PickupInventory/Background")
241    root:addChildWindow(window)
242   
243    local wrapper = winMgr:createWindow("DefaultWindow", name .. "/Wrapper")
244    wrapper:setSize(CEGUI.UVector2(CEGUI.UDim(1, -20),CEGUI.UDim(1, -50)))
245    wrapper:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10),CEGUI.UDim(0, 40)))
246    window:addChildWindow(wrapper)
247   
248    local title = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Title")
249    title:setText(representation:getPickupName())
250    title:setHeight(CEGUI.UDim(0, P.textHeight))
251    title:setProperty("FrameEnabled", "set:False")
252    title:setProperty("BackgroundEnabled", "set:False")
253    wrapper:addChildWindow(title)
254   
255    local image = winMgr:createWindow("MenuWidgets/StaticImage", name .. "/Image")
256    image:setProperty("Image", "set:PickupInventory image:" .. representation:getInventoryRepresentation())
257    image:setProperty("BackgroundEnabled", "set:False")
258    image:setProperty("FrameEnabled", "set:True")
259    image:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize), CEGUI.UDim(0, P.detailImageSize)))
260    image:setYPosition(CEGUI.UDim(0, P.textHeight + 5))
261    wrapper:addChildWindow(image)
262   
263    local box = winMgr:createWindow("MenuWidgets/ScrollablePane", name .. "/Description")
264    box:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -1*(P.detailImageSize + 10)),CEGUI.UDim(1, -(P.textHeight + 5 + P.textHeight + 20))))
265    box:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize + 10),CEGUI.UDim(0, P.textHeight + 5)))
266    local description = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Description/Text")
267    description:setText(representation:getPickupDescription())
268    description:setProperty("HorzFormatting", "WordWrapLeftAligned")
269    description:setProperty("VertFormatting", "TopAligned")
270    box:addChildWindow(description)
271    wrapper:addChildWindow(box)
272
273    local useButton = winMgr:createWindow("MenuWidgets/Button", name .. "/UseButton")
274    useButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize+10),CEGUI.UDim(1, -40)))
275    useButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
276    if pickup.inUse == false then
277        useButton:setText("use")
278        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked")
279        if pickup.usable == false then
280            useButton:setEnabled(false)
281        end
282    else
283        useButton:setText("unuse")
284        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked")
285        if pickup.unusable == false then
286            useButton:setEnabled(false)
287        end
288    end
289    wrapper:addChildWindow(useButton)
290   
291    local dropButton = winMgr:createWindow("MenuWidgets/Button", name .. "/DropButton")
292    dropButton:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.detailImageSize+10+P.buttonWidth+10),CEGUI.UDim(1, -40)))
293    dropButton:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.buttonWidth), CEGUI.UDim(0, P.textHeight)))
294    dropButton:setText("drop")
295    orxonox.GUIManager:subscribeEventHelper(dropButton, "Clicked", P.name .. ".InventoryDropDetailButton_clicked")
296    wrapper:addChildWindow(dropButton)
297
298    P.detailsWindows[index] = window
299    P.detailPickups[index] = pickup
300   
301end
302
303function P.getNewDetailNumber()
304    local number = table.getn(P.detailsWindows)
305    for k,v in pairs(P.detailsWindows) do
306        if v == nil then
307            number = k-1
308        end
309    end
310    return number+1
311end
312
313function P.InventoryUseButton_clicked(e)
314    local pickupIndex = P.windowToPickupHelper(e)
315    local pickup = P.pickupsList[pickupIndex]
316    orxonox.PickupManager:getInstance():usePickup(pickup.pickup, true)
317end
318
319function P.InventoryUnuseButton_clicked(e)
320    local pickupIndex = P.windowToPickupHelper(e)
321    local pickup = P.pickupsList[pickupIndex]
322    orxonox.PickupManager:getInstance():usePickup(pickup.pickup, false)
323end
324
325function P.InventoryDropButton_clicked(e)
326    local pickupIndex = P.windowToPickupHelper(e)
327    local pickup = P.pickupsList[pickupIndex]
328    orxonox.PickupManager:getInstance():dropPickup(pickup.pickup)
329end
330
331function P.InventoryDetailsButton_clicked(e)
332    local pickupIndex = P.windowToPickupHelper(e)
333    P.createDetailsWindow(pickupIndex)
334end
335
336function P.InventoryUseDetailButton_clicked(e)
337    local pickupIndex = P.windowToPickupHelper(e)
338    local pickup = P.detailPickups[pickupIndex]
339    orxonox.PickupManager:getInstance():usePickup(pickup.pickup, true)
340end
341
342function P.InventoryUnuseDetailButton_clicked(e)
343    local pickupIndex = P.windowToPickupHelper(e)
344    local pickup = P.detailPickups[pickupIndex]
345    orxonox.PickupManager:getInstance():usePickup(pickup.pickup, false)
346end
347
348function P.InventoryDropDetailButton_clicked(e)
349    local pickupIndex = P.windowToPickupHelper(e)
350    local pickup = P.detailPickups[pickupIndex]
351    orxonox.PickupManager:getInstance():dropPickup(pickup.pickup)
352end
353
354function P.closeDetailWindow(e)
355    --Get some numbers from the window
356    local we = CEGUI.toWindowEventArgs(e)
357    local name = we.window:getName()
358    local match = string.gmatch(name, "%d+")
359    local detailNr = tonumber(match())
360   
361    P.destroyDetailWindow(detailNr)
362end
363
364function P.destroyDetailWindow(detailNr)
365    local window = P.detailsWindows[detailNr]
366    winMgr:destroyWindow(window)
367    P.detailsWindows[detailNr] = nil
368    P.detailPickups[detailNr] = nil
369end
370
371function P.InventoryBackButton_clicked(e)
372    orxonox.CommandExecutor:execute("OrxonoxOverlay toggleVisibility PickupInventory")
373end
374
375return P
Note: See TracBrowser for help on using the repository browser.