Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/kicklib/data/gui/scripts/NotificationLayer.lua @ 8501

Last change on this file since 8501 was 7961, checked in by rgrieder, 14 years ago

Restored compatibility of our Lua code with CEGUI:
Some functions were renamed. I've done so too and added an alias at initialisation for older versions.
Caution: Credits and Quest menu don't yet work because CEGUI 0.7 has less Font functionality.

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