Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/notifications/data/gui/scripts/NotificationLayer.lua @ 7342

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

Some documenting, cleaning up. Also: Now the NotificationQueue has a height corresponding to its input size.

File size: 3.3 KB
Line 
1-- NotificationLayer.lua
2
3local P = createMenuSheet("NotificationLayer")
4
5P.queueList = {}
6P.nameList = {}
7
8function P.createQueue(name, size)
9    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
10    local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
11    root:addChildWindow(queue)
12
13    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
14    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))
15
16    table.insert(P.queueList, queue)
17    table.insert(P.nameList, name)
18    --TODO: Check name for uniqueness.
19end
20
21function P.removeQueue(name)
22    local queue = nil
23
24    for k,v in pairs(P.nameList) do
25        if v == name then
26            P.nameList[k] = nil
27            queue = P.queueList[k]
28            P.queueList[k] = nil
29            break
30        end
31    end
32
33    if queue ~= nil then
34        winMgr:destroyWindow(queue)
35    end
36end
37
38function P.changePosition(name, xPos, yPos)
39    local queue = P.nameToQueueHelper(name)
40    if queue == nil then
41        cout(0, "Queue is nil!")
42        return
43    end
44    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0)))
45end
46
47function P.pushNotification(queueName, notification)
48    local queue = P.nameToQueueHelper(queueName)
49    if queue == nil then
50        cout(0, "Queue is nil!")
51        return
52    end
53    item = CEGUI.createListboxTextItem(notification)
54    local listbox = CEGUI.toListbox(queue)
55    if listbox:getItemCount() == 0 then
56        listbox:addItem(item)
57    else
58        listbox:insertItem(item, listbox:getListboxItemFromIndex(0))
59    end
60end
61
62function P.popNotification(queueName)
63    local queue = P.nameToQueueHelper(queueName)
64    if queue == nil then
65        cout(0, "Queue is nil!")
66        return
67    end
68    local listbox = CEGUI.toListbox(queue)
69    listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1))
70end
71
72function P.removeNotification(queueName, index)
73    local queue = P.nameToQueueHelper(queueName)
74    if queue == nil then
75        cout(0, "Queue is nil!")
76        return
77    end
78    local listbox = CEGUI.toListbox(queue)
79    listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index)))
80end
81
82function P.clearQueue(name)
83    local queue = P.nameToQueueHelper(name)
84    if queue == nil then
85        cout(0, "Queue is nil!")
86        return
87    end
88    local listbox = CEGUI.toListbox(queue)
89    CEGUI.toListbox(queue):resetList()
90end
91
92function P.nameToQueueHelper(name)
93    local queue = nil
94    for k,v in pairs(P.nameList) do
95        if v == name then
96            queue = P.queueList[k]
97            break
98        end
99    end
100    return queue
101end
102
103function P.queueHeightHelper(queue, size)
104    local listbox = CEGUI.toListbox(queue)
105    local item = CEGUI.createListboxTextItem("Text")
106    listbox:addItem(item)
107    local singleItemHeight = listbox:getTotalItemsHeight()
108    local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel())
109    local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue)
110    local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
111    listbox:removeItem(item)
112    return frameHeight + singleItemHeight*size
113end
114
115return P
116
Note: See TracBrowser for help on using the repository browser.