1 | -- NotificationLayer.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("NotificationLayer") |
---|
4 | |
---|
5 | P.queueList = {} |
---|
6 | P.nameList = {} |
---|
7 | |
---|
8 | function 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. |
---|
19 | end |
---|
20 | |
---|
21 | function 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 |
---|
36 | end |
---|
37 | |
---|
38 | function 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))) |
---|
45 | end |
---|
46 | |
---|
47 | function 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 |
---|
60 | end |
---|
61 | |
---|
62 | function 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)) |
---|
70 | end |
---|
71 | |
---|
72 | function 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))) |
---|
80 | end |
---|
81 | |
---|
82 | function 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() |
---|
90 | end |
---|
91 | |
---|
92 | function 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 |
---|
101 | end |
---|
102 | |
---|
103 | function 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 |
---|
113 | end |
---|
114 | |
---|
115 | return P |
---|
116 | |
---|