Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutoriallevel2/data/gui/scripts/NotificationLayer.lua @ 8377

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

Text coloring in notification queue now working.

  • Property svn:eol-style set to native
File size: 26.8 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', 'ARGB 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        cout(0, "tl:[" .. queue.fontColor .. "] tr:[" .. queue.fontColor .. "] bl:[" .. queue.fontColor .. "] br:[" .. queue.fontColor .. "]")
231    end
232end
233
234-- Enter the edit mode of the notification layer.
235function P.enterEditMode()
236    P.editMode = true
237
238    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
239
240    --Add control frame window.
241    local window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/ControlWindow")
242    local frame = tolua.cast(window, "CEGUI::FrameWindow")
243    frame:setCloseButtonEnabled(false)
244    frame:setText("NotificationLayer Control Window")
245    frame:setSize(CEGUI.UVector2(CEGUI.UDim(0.7, 0), CEGUI.UDim(0.2, 0)))
246    root:addChildWindow(window)
247    local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/ScrollingPane")
248    pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30)))
249    pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26)))
250    window:addChildWindow(pane)
251
252    vertOffset = 0
253    horzOffset = 0
254    -- Line to be able to create a new queue.
255    local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle")
256    newQueueTitle:setText("Create a new NotificationQueue:")
257    local size = getMinTextSize(newQueueTitle)
258    local textHeight = size[1]
259    newQueueTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
260    newQueueTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
261    pane:addChildWindow(newQueueTitle)
262    horzOffset = horzOffset + size[2] + 5
263    local newQueueName = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName")
264    newQueueName:setProperty("ReadOnly", "set:False")
265    newQueueName:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
266    newQueueName:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
267    horzOffset = horzOffset + size[2] + 5
268    pane:addChildWindow(newQueueName)
269    local create = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/CreateNewQueue")
270    create:setText("create")
271    P.sampleWindow:setText("create")
272    size = getMinTextSize(P.sampleWindow)
273    create:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight)))
274    create:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
275    orxonox.GUIManager:subscribeEventHelper(create, "Clicked", P.name .. ".createNewQueue_clicked")
276    pane:addChildWindow(create)
277    horzOffset = horzOffset + size[2]+20 + 5
278    vertOffset = vertOffset + textHeight + 5
279
280    horzOffset = 0
281    -- Button to leave the edit mode.
282    local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton")
283    leave:setText("leave Edit Mode")
284    P.sampleWindow:setText("leave Edit Mode")
285    size = getMinTextSize(P.sampleWindow)
286    leave:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight)))
287    leave:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
288    orxonox.GUIManager:subscribeEventHelper(leave, "Clicked", P.name .. ".leaveEditMode_clicked")
289    pane:addChildWindow(leave)
290    horzOffset = horzOffset + size[2]+20 + 5
291    vertOffset = vertOffset + textHeight + 5
292
293    --Replace all queues with FrameWindows
294    for k,v in pairs(P.queueList) do
295        if v ~= nil then
296            local queue = P.queueList[k]
297            -- Remove the window that displays the queue from the root window such that it is no longer displayed.
298            root:removeChildWindow(v.window)
299
300            -- Create the frame window, with options to edit the queue, that is displayed instead of the queue.
301            local window = P.createQueueEditFrame(v.name)
302            window:setArea(v.window:getArea()) -- Set the frame window size and position to the same as the queue.
303
304            v.edit = window
305        end
306    end
307end
308
309-- Helper function. Creates a frame for the input queue.
310function P.createQueueEditFrame(queueName)
311    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
312
313    window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. queueName)
314    local frame = tolua.cast(window, "CEGUI::FrameWindow")
315    frame:setCloseButtonEnabled(true)
316    orxonox.GUIManager:subscribeEventHelper(frame, "CloseClicked", P.name .. ".closeQueue_clicked")
317    frame:setText("NotificationQueue \"" .. queueName .. "\"")
318    root:addChildWindow(window)
319    local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/ScrollingPane")
320    pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30)))
321    pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26)))
322    window:addChildWindow(pane)
323
324    local horzOffset = 0
325    local vertOffset = 0
326
327    -- The line that lets you edit the targets of the queue.
328    local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/TargetsTitle")
329    targetsTitle:setText("Targets:")
330    local size = getMinTextSize(targetsTitle)
331    local textHeight = size[1]
332    targetsTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
333    targetsTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
334    pane:addChildWindow(targetsTitle)
335    horzOffset = horzOffset + size[2] + 5
336    local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets")
337    targets:setProperty("ReadOnly", "set:False")
338    local targetsText = orxonox.NotificationManager:getInstance():getQueue(queueName):getTargets()
339    targets:setText(targetsText)
340    P.sampleWindow:setText(targetsText)
341    size = getMinTextSize(P.sampleWindow)
342    targets:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight)))
343    targets:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
344    horzOffset = horzOffset + size[2]*2+20 + 5
345    pane:addChildWindow(targets)
346    local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save")
347    save:setText("save")
348    P.sampleWindow:setText("save")
349    size = getMinTextSize(P.sampleWindow)
350    local saveTextWidth = size[2]+20
351    save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight)))
352    save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
353    orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveTargets_clicked")
354    pane:addChildWindow(save)
355    horzOffset = horzOffset + saveTextWidth
356    vertOffset = vertOffset + textHeight + 5
357
358    horzOffset = 0
359    -- The line that lets you edit the size of the queue.
360    local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/SizeTitle")
361    sizeTitle:setText("Size:")
362    size = getMinTextSize(sizeTitle)
363    sizeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
364    sizeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
365    pane:addChildWindow(sizeTitle)
366    horzOffset = horzOffset + size[2] + 5
367    local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size")
368    queueSize:setProperty("ReadOnly", "set:False")
369    local maxSize = orxonox.NotificationManager:getInstance():getQueue(queueName):getMaxSize()
370    queueSize:setText(maxSize)
371    P.sampleWindow:setText(maxSize)
372    size = getMinTextSize(P.sampleWindow)
373    queueSize:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight)))
374    queueSize:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
375    horzOffset = horzOffset + size[2]*2+20 + 5
376    pane:addChildWindow(queueSize)
377    save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save")
378    save:setText("save")
379    P.sampleWindow:setText("save")
380    size = getMinTextSize(P.sampleWindow)
381    local saveTextWidth = size[2]+20
382    save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight)))
383    save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
384    orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveSize_clicked")
385    pane:addChildWindow(save)
386    horzOffset = horzOffset + saveTextWidth
387    vertOffset = vertOffset + textHeight + 5
388
389    horzOffset = 0
390    -- The line that lets you edit the display time of the queue.
391    local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTimeTitle")
392    displayTimeTitle:setText("Display time:")
393    size = getMinTextSize(displayTimeTitle)
394    displayTimeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))
395    displayTimeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
396    pane:addChildWindow(displayTimeTitle)
397    horzOffset = horzOffset + size[2] + 5
398    local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime")
399    displayTime:setProperty("ReadOnly", "set:False")
400    local time = orxonox.NotificationManager:getInstance():getQueue(queueName):getDisplayTime()
401    displayTime:setText(time)
402    P.sampleWindow:setText(time)
403    size = getMinTextSize(P.sampleWindow)
404    displayTime:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight)))
405    displayTime:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
406    horzOffset = horzOffset + size[2]*2+20 + 5
407    pane:addChildWindow(displayTime)
408    save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save")
409    save:setText("save")
410    P.sampleWindow:setText("save")
411    size = getMinTextSize(P.sampleWindow)
412    local saveTextWidth = size[2]+20
413    save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight)))
414    save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))
415    orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveDisplayTime_clicked")
416    pane:addChildWindow(save)
417    horzOffset = horzOffset + saveTextWidth
418    vertOffset = vertOffset + textHeight + 5
419
420    return window
421end
422
423-- Leave the edit mode.
424function P.leaveEditMode()
425    P.editMode = false
426
427    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
428    --Replace all queues with FrameWindows
429    for k,v in pairs(P.queueList) do
430        if v ~= nil then
431            -- Add the queue window to the root window to have it displayed again.
432            root:addChildWindow(v.window)
433            -- Set the size and position of the queue window to the size and position of the queue edit frame.
434            v.window:setArea(v.edit:getArea())
435            -- Destroy the edit frame.
436            winMgr:destroyWindow(v.edit)
437            v.edit = nil
438        end
439    end
440
441    --Remove control window
442    winMgr:destroyWindow(winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow"))
443end
444
445-- Is called after the sheet has been hidden.
446function P.afterHide()
447    -- If we leave the edit mode we show the sheet again.
448    if P.editMode then
449        P.leaveEditMode()
450        showMenuSheet(P.name, false, true)
451    end
452end
453
454-- If the button to save the targets of a queue has been clicked.
455function P.saveTargets_clicked(e)
456    local we = CEGUI.toWindowEventArgs(e)
457    local name = we.window:getName()
458
459    local match = string.gmatch(name, "EditMode/.*/Targets/Save")
460    local nameStr = match()
461    local queueName = string.sub(nameStr, 10, string.len(nameStr)-13)
462
463    local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets")
464    local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save")
465    local width = window:getWidth():asAbsolute(1)
466
467    local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
468    -- Set the new targets.
469    queue:setTargets(window:getText())
470    local targets = queue:getTargets()
471
472    window:setText(targets)
473    P.sampleWindow:setText(targets)
474    local size = getMinTextSize(P.sampleWindow)
475    -- Adjust the width of the targets field.
476    window:setWidth(CEGUI.UDim(0, size[2]*2+20))
477    -- Adjust the position of the save button after the targets field.
478    save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
479end
480
481-- If the button to save the size if a queue has been clicked.
482function P.saveSize_clicked(e)
483    local we = CEGUI.toWindowEventArgs(e)
484    local name = we.window:getName()
485
486    local match = string.gmatch(name, "EditMode/.*/Size/Save")
487    local nameStr = match()
488    local queueName = string.sub(nameStr, 10, string.len(nameStr)-10)
489
490    local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size")
491    local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save")
492    local width = window:getWidth():asAbsolute(1)
493
494    local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
495    -- Set the new size.
496    queue:setMaxSize(tonumber(window:getText()))
497    local maxSize = queue:getMaxSize()
498
499    window:setText(maxSize)
500    P.sampleWindow:setText(maxSize)
501    local size = getMinTextSize(P.sampleWindow)
502    -- Adjust the width of the size field.
503    window:setWidth(CEGUI.UDim(0, size[2]*2+20))
504    -- Adjust the position of the save button after the size field.
505    save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
506end
507
508-- If the button to save the display time if a queue has been clicked.
509function P.saveDisplayTime_clicked(e)
510    local we = CEGUI.toWindowEventArgs(e)
511    local name = we.window:getName()
512
513    local match = string.gmatch(name, "EditMode/.*/DisplayTime/Save")
514    local nameStr = match()
515    local queueName = string.sub(nameStr, 10, string.len(nameStr)-17)
516
517    local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime")
518    local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save")
519    local width = window:getWidth():asAbsolute(1)
520
521    local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
522    -- Set the new display time.
523    queue:setDisplayTime(tonumber(window:getText()))
524    local time = queue:getDisplayTime()
525
526    window:setText(time)
527    P.sampleWindow:setText(time)
528    local size = getMinTextSize(P.sampleWindow)
529    -- Adjust the width of the display time field.
530    window:setWidth(CEGUI.UDim(0, size[2]*2+20))
531    -- Adjust the position of the save button after the display time field.
532    save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
533end
534
535-- if the button to create a new queue has been clicked.
536function P.createNewQueue_clicked(e)
537    local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName")
538    local name = window:getText()
539
540    local queue = P.queueList[name]
541    -- Test if a queue with that name already exists.
542    if queue ~= nil then
543        window:setText("Queue with that name already exists.")
544        return
545    end
546
547    -- Creates the new queue.
548    orxonox.NotificationManager:getInstance():createQueue(name)
549
550    queue = P.queueList[name]
551    if queue == nil then
552        return
553    end
554
555    -- Create the frame that represents the queue in edit mode, since that's what we're in.
556    local frame = P.createQueueEditFrame(name)
557    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
558    -- Remove the queue window from the root window, since we're in edit mode.
559    root:removeChildWindow(queue.window)
560    -- Set the frame window size and position to that of the queue window.
561    frame:setArea(queue.window:getArea())
562    queue.edit = frame
563
564    -- Reset the text to create a new queue.
565    window:setText("")
566end
567
568-- If the button to leave the edit mode has been clicked.
569function P.leaveEditMode_clicked(e)
570    hideMenuSheet(P.name)
571end
572
573-- If the button to close the queue has been clicked.
574function P.closeQueue_clicked(e)
575    local we = CEGUI.toWindowEventArgs(e)
576    local name = we.window:getName()
577
578    local match = string.gmatch(name, "EditMode/.*")
579    local nameStr = match()
580    local queueName = string.sub(nameStr, 10, string.len(nameStr))
581
582    -- Destroy the frame window,
583    winMgr:destroyWindow(P.queueList[queueName].edit)
584    P.queueList[queueName].edit = nil
585    -- Destroy the queue.
586    orxonox.NotificationManager:getInstance():getQueue(queueName):destroy()
587end
588
589-- Helper function. Returns height a queue needs to have to display 'size' items.
590function P.queueHeightHelper(queue, size)
591    --local listbox = CEGUI.toListbox(queue.window)
592    --local item = CEGUI.createListboxTextItem("Text")
593    --P.setItemFontHelper(item, queue, false)
594    --listbox:addItem(item)
595    --local singleItemHeight = listbox:getTotalItemsHeight()
596    local singleItemHeight = P.itemHeightHelper(queue)
597    --local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel())
598    --local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window)
599    --local frameHeight = queue.window:getUnclippedOuterRect():getHeight() - formattedArea:getHeight()
600    --listbox:removeItem(item)
601    --return frameHeight + singleItemHeight*size
602    return singleItemHeight*size + 1
603end
604
605function P.itemHeightHelper(queue)
606    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Test/")
607    item:setText("text")
608    P.setItemFontHelper(item, queue, true)
609    queue.window:addChildWindow(item)
610    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
611    item:setProperty("FrameEnabled", "false")
612    local height = getStaticTextWindowHeight(item)
613    queue.window:removeChildWindow(item)
614    winMgr:destroyWindow(item)
615    return height
616end
617
618return P
Note: See TracBrowser for help on using the repository browser.