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