Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8116 was 7894, checked in by dafrick, 14 years ago

Some extension of NotificationQueue, font size and color can now be specified.

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