Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Notification text alignment can be set per queue.

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