Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutoriallevel/data/gui/scripts/NotificationLayer.lua @ 8474

Last change on this file since 8474 was 8370, checked in by dafrick, 14 years ago

Committing changes before merge.

File size: 26.6 KB
Line 
1-- NotificationLayer.lua
2
3local P = createMenuSheet("NotificationLayer", true, TriBool.True, TriBool.True)
4
5P.queueList = {}
6P.editMode = false
7
8P.sampleWindow = nil
9
10-- Loads the queues from the NotificationManager and creates the sample window, that is used to measure the width various strings need.
11function P.onLoad()
12    orxonox.NotificationManager:getInstance():loadQueues()
13    P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/SampleWindow")
14end
15
16-- Creates a queue in the GUI.
17function P.createQueue(name, size)
18    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
19    --local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
20    --queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent.
21    local queue = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/Queue/" .. name)
22    queue:setProperty("Alpha", 0.0)
23    --queue:setProperty("FrameEnabled", "false")
24    root:addChildWindow(queue)
25
26    local queueTuple =
27    {
28        ["window"]    = queue,
29        ["name"]      = name,
30        ["edit"]      = nil,
31        ["visible"]   = false,
32        ["fontSize"]  = 12,
33        ["fontColor"] = "#FFFFFFFF",
34        ["items"]     = {},
35        ["first"]     = 1,
36        ["last"]      = 1
37    }
38   
39    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
40    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queueTuple, size))))
41
42    P.queueList[name] = queueTuple -- name access
43    P.setVisible(queueTuple, false) -- Set the queue to invisible as long as there are no notifications in it.
44end
45
46-- Removes a queue from the GUI.
47function P.removeQueue(queueName)
48    local queue = P.queueList[queueName]
49
50    if queue ~= nil then
51        winMgr:destroyWindow(queue.window)
52    end
53    P.queueList[queueName] = nil
54end
55
56-- Pushes an input notification to the input queue.
57function P.pushNotification(queueName, notification)
58    local queue = P.queueList[queueName]
59    if queue == nil then
60        return
61    end
62
63    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Queue/" .. queueName .. "/" .. queue.last)
64    item:setText(notification)
65    P.setItemFontHelper(item, queue, true)
66    -- Add the item to the top of the queue.
67    local itemHeight = P.itemHeightHelper(queue)
68    if queue.last-queue.first > 0 then -- If the queue is not empty move all items down
69        for i=queue.first,queue.last-1 do
70            local item = queue.items[i]
71            item:setYPosition(CEGUI.UDim(0, itemHeight*(queue.last-i)))
72        end
73    end
74    queue.window:addChildWindow(item)
75    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, itemHeight)))
76    item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
77    item:setProperty("Alpha", 1.0)
78    item:setProperty("InheritsAlpha", "false")
79    item:setProperty("BackgroundEnabled", "false")
80    item:setProperty("FrameEnabled", "false")
81    queue.items[queue.last] = item
82    queue.last = queue.last+1
83
84    -- If the queue has been invisible, set it to visible.
85    if queue.visible == false then
86        P.setVisible(queue, true)
87    end
88end
89
90-- Pops the least recently added notification from the queue.
91function P.popNotification(queueName)
92    local queue = P.queueList[queueName]
93    if queue == nil then
94        return
95    end
96    local item = queue.items[queue.first]
97    -- Removes the item from the bottom of the queue.
98    queue.window:removeChildWindow(item)
99    winMgr:destroyWindow(item)
100    queue.first = queue.first+1
101
102    -- Sets the queue to invisible if there are no more notifications in it.
103    if queue.last-queue.first == 0 then
104        P.setVisible(queue, false)
105    end
106end
107
108-- Removes a notification at a given index from the queue. Where the 0th item is the newest and the nth the (n+1)th newest.
109function P.removeNotification(queueName, index)
110    local queue = P.queueList[queueName]
111    if queue == nil then
112        return
113    end
114
115    index = queue.last-tonumber(index)-1
116    --if index == queue.first then -- If we want to remove the oldest notification, we can just use pop.
117    --    P.popNotification(queueName)
118    --    return
119    --end
120
121    -- Removes the item.
122    local item = queue.items[index]
123    queue.window:removeChildWindow(item)
124    winMgr:destroyWindow(item)
125    queue.items[index] = nil
126
127    -- Move the items below, up.
128    local itemHeight = P.itemHeightHelper(queue)
129    local moved = false
130    if index > queue.first then -- Move all older notifications up in the list.
131        for i=index-1,-1,queue.first do
132            cout(0, i)
133            item = queue.items[i]
134            item:setYposition(CEGUI.UDim(0, itemHeight*(queue.last-i-1)))
135            queue.items[i+1] = item
136        end
137    end
138    queue.items[queue.first] = nil
139    queue.first = queue.first+1
140
141    -- Sets the queue to invisible if there are no more notifications in it.
142    if queue.last-queue.first == 0 then
143        P.setVisible(queue, false)
144    end
145end
146
147-- Clears the queue. Removes all notifications from it.
148function P.clearQueue(queueName)
149    local queue = P.queueList[queueName]
150    if queue == nil then
151        return
152    end
153    for i=queue.first,queue.last-1 do
154        local item = queue.items[i]
155        queue.window:removeChildWindow(item)
156        winMgr:destroyWindow(item)
157    end
158    queue.items = {}
159    queue.first = 1
160    queue.last = 1
161
162    -- Sets the queue to invisible.
163    P.setVisible(queue, false)
164end
165
166-- Sets the visibility of the queue.
167function P.setVisible(queue, visible)
168    if queue == nil then
169        return
170    end
171    queue.window:setVisible(visible)
172    queue.visible = visible
173end
174
175-- Change the position of the queue.
176-- The parameters are (in order) 'name of the queue', 'relative x-position', 'absolute x-position in pixel', 'relative y-position', 'absolute y-position in pixel'.
177function P.moveQueue(queueName, relativeXPos, absoluteXPos, relativeYpos, absoluteYPos)
178    local queueWindow = P.queueList[queueName].window
179    queueWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(relativeXPos, absoluteXPos), CEGUI.UDim(relativeYpos, absoluteYPos)))
180end
181
182-- Change the size of the queue.
183-- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'.
184-- Additionally the last parameter can be ommitted and relativeHeight can be set to the size (i.e. the maximal number of notifications displayed) of the queue, which leads to the height being set such that all notifications can be displayed.
185function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth)
186    local queueWindow = P.queueList[queueName].window
187    if queueWindow == nil then
188        return
189    end
190    if absoluteHeigth == nil then
191        absoluteHeigth = P.queueHeightHelper(P.queueList[queueName], relativeHeight)
192        relativeHeight = 0
193    end
194    queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth)))
195end
196
197-- Change the font size and font color of all notifications in a queueHeightHelper
198-- The parameters are (in order) 'name of the queue', 'font size', 'RGBA of the font color in hex notation'.
199function P.changeQueueFont(queueName, size, color)
200    local queue = P.queueList[queueName]
201    local queueWindow = queue.window
202    if queueWindow == nil then
203        return
204    end
205
206    queue.fontSize = size
207    local changeColor = false
208    if color ~= nil then
209        queue.fontColor = color
210        changeColor = true
211    end
212    for i=queue.first,queue.last-1 do
213        P.setItemFontHelper(queue.items[i], queue, changeColor)
214    end
215end
216
217-- Helper function to set the font size and color of a item of a queue.
218-- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well'
219function P.setItemFontHelper(item, queue, changeColor)
220    --local item = tolua.cast(item, "CEGUI::ListboxTextItem")
221    local fontMgr = CEGUI.FontManager:getSingleton()
222    if fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize) then
223        item:setFont("BlueHighway-" .. queue.fontSize)
224    else
225        orxonox.GUIManager:addFontHelper("BlueHighway-" .. queue.fontSize, queue.fontSize, "bluehigh.ttf")
226        item:setFont("BlueHighway-" .. queue.fontSize)
227    end
228    if changeColor then
229        --item:setProperty("TextColours", "tl:[" .. queue.fontColor .. "] tr:[" .. queue.fontColor .. "] bl:[" .. queue.fontColor .. "] br:[" .. queue.fontColor .. "]")
230    end
231end
232
233-- Enter the edit mode of the notification layer.
234function P.enterEditMode()
235    P.editMode = true
236
237    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
238
239    --Add control frame window.
240    local window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/ControlWindow")
241    local frame = tolua.cast(window, "CEGUI::FrameWindow")
242    frame:setCloseButtonEnabled(false)
243    frame:setText("NotificationLayer Control Window")
244    frame:setSize(CEGUI.UVector2(CEGUI.UDim(0.7, 0), CEGUI.UDim(0.2, 0)))
245    root:addChildWindow(window)
246    local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/ScrollingPane")
247    pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30)))
248    pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26)))
249    window:addChildWindow(pane)
250
251    vertOffset = 0
252    horzOffset = 0
253    -- Line to be able to create a new queue.
254    local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle")
255    newQueueTitle:setText("Create a new NotificationQueue:")
256    local size = getMinTextSize(newQueueTitle)
257    local textHeight = size[1]
258    newQueueTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
259    newQueueTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
260    pane:addChildWindow(newQueueTitle)
261    horzOffset = horzOffset + size[2] + 5
262    local newQueueName = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName")
263    newQueueName:setProperty("ReadOnly", "set:False")
264    newQueueName:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
265    newQueueName:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
266    horzOffset = horzOffset + size[2] + 5
267    pane:addChildWindow(newQueueName)
268    local create = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/CreateNewQueue")
269    create:setText("create")
270    P.sampleWindow:setText("create")
271    size = getMinTextSize(P.sampleWindow)
272    create:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight)))
273    create:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
274    orxonox.GUIManager:subscribeEventHelper(create, "Clicked", P.name .. ".createNewQueue_clicked")
275    pane:addChildWindow(create)
276    horzOffset = horzOffset + size[2]+20 + 5
277    vertOffset = vertOffset + textHeight + 5
278
279    horzOffset = 0
280    -- Button to leave the edit mode.
281    local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton")
282    leave:setText("leave Edit Mode")
283    P.sampleWindow:setText("leave Edit Mode")
284    size = getMinTextSize(P.sampleWindow)
285    leave:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight)))
286    leave:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
287    orxonox.GUIManager:subscribeEventHelper(leave, "Clicked", P.name .. ".leaveEditMode_clicked")
288    pane:addChildWindow(leave)
289    horzOffset = horzOffset + size[2]+20 + 5
290    vertOffset = vertOffset + textHeight + 5
291
292    --Replace all queues with FrameWindows
293    for k,v in pairs(P.queueList) do
294        if v ~= nil then
295            local queue = P.queueList[k]
296            -- Remove the window that displays the queue from the root window such that it is no longer displayed.
297            root:removeChildWindow(v.window)
298
299            -- Create the frame window, with options to edit the queue, that is displayed instead of the queue.
300            local window = P.createQueueEditFrame(v.name)
301            window:setArea(v.window:getArea()) -- Set the frame window size and position to the same as the queue.
302
303            v.edit = window
304        end
305    end
306end
307
308-- Helper function. Creates a frame for the input queue.
309function P.createQueueEditFrame(queueName)
310    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
311
312    window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. queueName)
313    local frame = tolua.cast(window, "CEGUI::FrameWindow")
314    frame:setCloseButtonEnabled(true)
315    orxonox.GUIManager:subscribeEventHelper(frame, "CloseClicked", P.name .. ".closeQueue_clicked")
316    frame:setText("NotificationQueue \"" .. queueName .. "\"")
317    root:addChildWindow(window)
318    local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/ScrollingPane")
319    pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30)))
320    pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26)))
321    window:addChildWindow(pane)
322
323    local horzOffset = 0
324    local vertOffset = 0
325
326    -- The line that lets you edit the targets of the queue.
327    local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/TargetsTitle")
328    targetsTitle:setText("Targets:")
329    local size = getMinTextSize(targetsTitle)
330    local textHeight = size[1]
331    targetsTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
332    targetsTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
333    pane:addChildWindow(targetsTitle)
334    horzOffset = horzOffset + size[2] + 5
335    local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets")
336    targets:setProperty("ReadOnly", "set:False")
337    local targetsText = orxonox.NotificationManager:getInstance():getQueue(queueName):getTargets()
338    targets:setText(targetsText)
339    P.sampleWindow:setText(targetsText)
340    size = getMinTextSize(P.sampleWindow)
341    targets:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight)))
342    targets:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
343    horzOffset = horzOffset + size[2]*2+20 + 5
344    pane:addChildWindow(targets)
345    local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save")
346    save:setText("save")
347    P.sampleWindow:setText("save")
348    size = getMinTextSize(P.sampleWindow)
349    local saveTextWidth = size[2]+20
350    save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight)))
351    save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
352    orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveTargets_clicked")
353    pane:addChildWindow(save)
354    horzOffset = horzOffset + saveTextWidth
355    vertOffset = vertOffset + textHeight + 5
356
357    horzOffset = 0
358    -- The line that lets you edit the size of the queue.
359    local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/SizeTitle")
360    sizeTitle:setText("Size:")
361    size = getMinTextSize(sizeTitle)
362    sizeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
363    sizeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
364    pane:addChildWindow(sizeTitle)
365    horzOffset = horzOffset + size[2] + 5
366    local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size")
367    queueSize:setProperty("ReadOnly", "set:False")
368    local maxSize = orxonox.NotificationManager:getInstance():getQueue(queueName):getMaxSize()
369    queueSize:setText(maxSize)
370    P.sampleWindow:setText(maxSize)
371    size = getMinTextSize(P.sampleWindow)
372    queueSize:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight)))
373    queueSize:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
374    horzOffset = horzOffset + size[2]*2+20 + 5
375    pane:addChildWindow(queueSize)
376    save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save")
377    save:setText("save")
378    P.sampleWindow:setText("save")
379    size = getMinTextSize(P.sampleWindow)
380    local saveTextWidth = size[2]+20
381    save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight)))
382    save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
383    orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveSize_clicked")
384    pane:addChildWindow(save)
385    horzOffset = horzOffset + saveTextWidth
386    vertOffset = vertOffset + textHeight + 5
387
388    horzOffset = 0
389    -- The line that lets you edit the display time of the queue.
390    local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTimeTitle")
391    displayTimeTitle:setText("Display time:")
392    size = getMinTextSize(displayTimeTitle)
393    displayTimeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
394    displayTimeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
395    pane:addChildWindow(displayTimeTitle)
396    horzOffset = horzOffset + size[2] + 5
397    local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime")
398    displayTime:setProperty("ReadOnly", "set:False")
399    local time = orxonox.NotificationManager:getInstance():getQueue(queueName):getDisplayTime()
400    displayTime:setText(time)
401    P.sampleWindow:setText(time)
402    size = getMinTextSize(P.sampleWindow)
403    displayTime:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight)))
404    displayTime:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
405    horzOffset = horzOffset + size[2]*2+20 + 5
406    pane:addChildWindow(displayTime)
407    save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save")
408    save:setText("save")
409    P.sampleWindow:setText("save")
410    size = getMinTextSize(P.sampleWindow)
411    local saveTextWidth = size[2]+20
412    save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight)))
413    save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
414    orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveDisplayTime_clicked")
415    pane:addChildWindow(save)
416    horzOffset = horzOffset + saveTextWidth
417    vertOffset = vertOffset + textHeight + 5
418
419    return window
420end
421
422-- Leave the edit mode.
423function P.leaveEditMode()
424    P.editMode = false
425
426    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
427    --Replace all queues with FrameWindows
428    for k,v in pairs(P.queueList) do
429        if v ~= nil then
430            -- Add the queue window to the root window to have it displayed again.
431            root:addChildWindow(v.window)
432            -- Set the size and position of the queue window to the size and position of the queue edit frame.
433            v.window:setArea(v.edit:getArea())
434            -- Destroy the edit frame.
435            winMgr:destroyWindow(v.edit)
436            v.edit = nil
437        end
438    end
439
440    --Remove control window
441    winMgr:destroyWindow(winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow"))
442end
443
444-- Is called after the sheet has been hidden.
445function P.afterHide()
446    -- If we leave the edit mode we show the sheet again.
447    if P.editMode then
448        P.leaveEditMode()
449        showMenuSheet(P.name, false, true)
450    end
451end
452
453-- If the button to save the targets of a queue has been clicked.
454function P.saveTargets_clicked(e)
455    local we = CEGUI.toWindowEventArgs(e)
456    local name = we.window:getName()
457
458    local match = string.gmatch(name, "EditMode/.*/Targets/Save")
459    local nameStr = match()
460    local queueName = string.sub(nameStr, 10, string.len(nameStr)-13)
461
462    local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets")
463    local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save")
464    local width = window:getWidth():asAbsolute(1)
465
466    local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
467    -- Set the new targets.
468    queue:setTargets(window:getText())
469    local targets = queue:getTargets()
470
471    window:setText(targets)
472    P.sampleWindow:setText(targets)
473    local size = getMinTextSize(P.sampleWindow)
474    -- Adjust the width of the targets field.
475    window:setWidth(CEGUI.UDim(0, size[2]*2+20))
476    -- Adjust the position of the save button after the targets field.
477    save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
478end
479
480-- If the button to save the size if a queue has been clicked.
481function P.saveSize_clicked(e)
482    local we = CEGUI.toWindowEventArgs(e)
483    local name = we.window:getName()
484
485    local match = string.gmatch(name, "EditMode/.*/Size/Save")
486    local nameStr = match()
487    local queueName = string.sub(nameStr, 10, string.len(nameStr)-10)
488
489    local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size")
490    local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save")
491    local width = window:getWidth():asAbsolute(1)
492
493    local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
494    -- Set the new size.
495    queue:setMaxSize(tonumber(window:getText()))
496    local maxSize = queue:getMaxSize()
497
498    window:setText(maxSize)
499    P.sampleWindow:setText(maxSize)
500    local size = getMinTextSize(P.sampleWindow)
501    -- Adjust the width of the size field.
502    window:setWidth(CEGUI.UDim(0, size[2]*2+20))
503    -- Adjust the position of the save button after the size field.
504    save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
505end
506
507-- If the button to save the display time if a queue has been clicked.
508function P.saveDisplayTime_clicked(e)
509    local we = CEGUI.toWindowEventArgs(e)
510    local name = we.window:getName()
511
512    local match = string.gmatch(name, "EditMode/.*/DisplayTime/Save")
513    local nameStr = match()
514    local queueName = string.sub(nameStr, 10, string.len(nameStr)-17)
515
516    local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime")
517    local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save")
518    local width = window:getWidth():asAbsolute(1)
519
520    local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
521    -- Set the new display time.
522    queue:setDisplayTime(tonumber(window:getText()))
523    local time = queue:getDisplayTime()
524
525    window:setText(time)
526    P.sampleWindow:setText(time)
527    local size = getMinTextSize(P.sampleWindow)
528    -- Adjust the width of the display time field.
529    window:setWidth(CEGUI.UDim(0, size[2]*2+20))
530    -- Adjust the position of the save button after the display time field.
531    save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
532end
533
534-- if the button to create a new queue has been clicked.
535function P.createNewQueue_clicked(e)
536    local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName")
537    local name = window:getText()
538
539    local queue = P.queueList[name]
540    -- Test if a queue with that name already exists.
541    if queue ~= nil then
542        window:setText("Queue with that name already exists.")
543        return
544    end
545
546    -- Creates the new queue.
547    orxonox.NotificationManager:getInstance():createQueue(name)
548
549    queue = P.queueList[name]
550    if queue == nil then
551        return
552    end
553
554    -- Create the frame that represents the queue in edit mode, since that's what we're in.
555    local frame = P.createQueueEditFrame(name)
556    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
557    -- Remove the queue window from the root window, since we're in edit mode.
558    root:removeChildWindow(queue.window)
559    -- Set the frame window size and position to that of the queue window.
560    frame:setArea(queue.window:getArea())
561    queue.edit = frame
562
563    -- Reset the text to create a new queue.
564    window:setText("")
565end
566
567-- If the button to leave the edit mode has been clicked.
568function P.leaveEditMode_clicked(e)
569    hideMenuSheet(P.name)
570end
571
572-- If the button to close the queue has been clicked.
573function P.closeQueue_clicked(e)
574    local we = CEGUI.toWindowEventArgs(e)
575    local name = we.window:getName()
576
577    local match = string.gmatch(name, "EditMode/.*")
578    local nameStr = match()
579    local queueName = string.sub(nameStr, 10, string.len(nameStr))
580
581    -- Destroy the frame window,
582    winMgr:destroyWindow(P.queueList[queueName].edit)
583    P.queueList[queueName].edit = nil
584    -- Destroy the queue.
585    orxonox.NotificationManager:getInstance():getQueue(queueName):destroy()
586end
587
588-- Helper function. Returns height a queue needs to have to display 'size' items.
589function P.queueHeightHelper(queue, size)
590    --local listbox = CEGUI.toListbox(queue.window)
591    --local item = CEGUI.createListboxTextItem("Text")
592    --P.setItemFontHelper(item, queue, false)
593    --listbox:addItem(item)
594    --local singleItemHeight = listbox:getTotalItemsHeight()
595    local singleItemHeight = P.itemHeightHelper(queue)
596    --local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel())
597    --local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window)
598    --local frameHeight = queue.window:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
599    --listbox:removeItem(item)
600    --return frameHeight + singleItemHeight*size
601    return singleItemHeight*size + 1
602end
603
604function P.itemHeightHelper(queue)
605    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Test/")
606    item:setText("text")
607    P.setItemFontHelper(item, queue, true)
608    queue.window:addChildWindow(item)
609    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
610    item:setProperty("FrameEnabled", "false")
611    local height = getStaticTextWindowHeight(item)
612    queue.window:removeChildWindow(item)
613    winMgr:destroyWindow(item)
614    return height
615end
616
617return P
Note: See TracBrowser for help on using the repository browser.