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 | queue:setProperty("BackgroundColor", "00FFFFFF") |
---|
12 | root:addChildWindow(queue) |
---|
13 | |
---|
14 | queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) |
---|
15 | queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size)))) |
---|
16 | |
---|
17 | table.insert(P.queueList, queue) |
---|
18 | table.insert(P.nameList, name) |
---|
19 | --TODO: Check name for uniqueness. |
---|
20 | end |
---|
21 | |
---|
22 | function P.removeQueue(name) |
---|
23 | local queue = nil |
---|
24 | |
---|
25 | for k,v in pairs(P.nameList) do |
---|
26 | if v == name then |
---|
27 | P.nameList[k] = nil |
---|
28 | queue = P.queueList[k] |
---|
29 | P.queueList[k] = nil |
---|
30 | break |
---|
31 | end |
---|
32 | end |
---|
33 | |
---|
34 | if queue ~= nil then |
---|
35 | winMgr:destroyWindow(queue) |
---|
36 | end |
---|
37 | end |
---|
38 | |
---|
39 | function P.pushNotification(queueName, notification) |
---|
40 | local queue = P.nameToQueueHelper(queueName) |
---|
41 | if queue == nil then |
---|
42 | cout(0, "Queue is nil!") |
---|
43 | return |
---|
44 | end |
---|
45 | item = CEGUI.createListboxTextItem(notification) |
---|
46 | local listbox = CEGUI.toListbox(queue) |
---|
47 | if listbox:getItemCount() == 0 then |
---|
48 | listbox:addItem(item) |
---|
49 | else |
---|
50 | listbox:insertItem(item, listbox:getListboxItemFromIndex(0)) |
---|
51 | end |
---|
52 | end |
---|
53 | |
---|
54 | function P.popNotification(queueName) |
---|
55 | local queue = P.nameToQueueHelper(queueName) |
---|
56 | if queue == nil then |
---|
57 | cout(0, "Queue is nil!") |
---|
58 | return |
---|
59 | end |
---|
60 | local listbox = CEGUI.toListbox(queue) |
---|
61 | listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1)) |
---|
62 | end |
---|
63 | |
---|
64 | function P.removeNotification(queueName, index) |
---|
65 | local queue = P.nameToQueueHelper(queueName) |
---|
66 | if queue == nil then |
---|
67 | cout(0, "Queue is nil!") |
---|
68 | return |
---|
69 | end |
---|
70 | local listbox = CEGUI.toListbox(queue) |
---|
71 | listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index))) |
---|
72 | end |
---|
73 | |
---|
74 | function P.clearQueue(name) |
---|
75 | local queue = P.nameToQueueHelper(name) |
---|
76 | if queue == nil then |
---|
77 | cout(0, "Queue is nil!") |
---|
78 | return |
---|
79 | end |
---|
80 | local listbox = CEGUI.toListbox(queue) |
---|
81 | CEGUI.toListbox(queue):resetList() |
---|
82 | end |
---|
83 | |
---|
84 | function P.changePosition(name, xPos, yPos) |
---|
85 | local queue = P.nameToQueueHelper(name) |
---|
86 | if queue == nil then |
---|
87 | cout(0, "Queue is nil!") |
---|
88 | return |
---|
89 | end |
---|
90 | queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0))) |
---|
91 | queue:setWidth(CEGUI.UDim(1.0, -xPos)) |
---|
92 | end |
---|
93 | |
---|
94 | function P.changeSize(name, size) |
---|
95 | local queue = P.nameToQueueHelper(name) |
---|
96 | if queue == nil then |
---|
97 | cout(0, "Queue is nil!") |
---|
98 | return |
---|
99 | end |
---|
100 | queue:setHeight(CEGUI.UDim(0, P.queueHeightHelper(queue, size))) |
---|
101 | end |
---|
102 | |
---|
103 | function P.nameToQueueHelper(name) |
---|
104 | local queue = nil |
---|
105 | for k,v in pairs(P.nameList) do |
---|
106 | if v == name then |
---|
107 | queue = P.queueList[k] |
---|
108 | break |
---|
109 | end |
---|
110 | end |
---|
111 | return queue |
---|
112 | end |
---|
113 | |
---|
114 | function P.queueHeightHelper(queue, size) |
---|
115 | local listbox = CEGUI.toListbox(queue) |
---|
116 | local item = CEGUI.createListboxTextItem("Text") |
---|
117 | listbox:addItem(item) |
---|
118 | local singleItemHeight = listbox:getTotalItemsHeight() |
---|
119 | local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel()) |
---|
120 | local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue) |
---|
121 | local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight() |
---|
122 | listbox:removeItem(item) |
---|
123 | return frameHeight + singleItemHeight*size |
---|
124 | end |
---|
125 | |
---|
126 | return P |
---|
127 | |
---|