[7338] | 1 | -- NotificationLayer.lua |
---|
| 2 | |
---|
| 3 | local P = createMenuSheet("NotificationLayer") |
---|
| 4 | |
---|
| 5 | P.queueList = {} |
---|
| 6 | P.nameList = {} |
---|
[7351] | 7 | P.visible = nil |
---|
[7338] | 8 | |
---|
| 9 | function P.createQueue(name, size) |
---|
| 10 | local root = winMgr:getWindow("orxonox/NotificationLayer/Root") |
---|
| 11 | local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name) |
---|
[7351] | 12 | queue:setProperty("BackgroundColor", "66FFFFFF") |
---|
[7342] | 13 | root:addChildWindow(queue) |
---|
| 14 | |
---|
[7338] | 15 | queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) |
---|
[7342] | 16 | queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size)))) |
---|
| 17 | |
---|
[7351] | 18 | P.setVisible(queue, false) |
---|
| 19 | |
---|
[7338] | 20 | table.insert(P.queueList, queue) |
---|
| 21 | table.insert(P.nameList, name) |
---|
| 22 | --TODO: Check name for uniqueness. |
---|
| 23 | end |
---|
| 24 | |
---|
| 25 | function P.removeQueue(name) |
---|
| 26 | local queue = nil |
---|
| 27 | |
---|
| 28 | for k,v in pairs(P.nameList) do |
---|
| 29 | if v == name then |
---|
| 30 | P.nameList[k] = nil |
---|
| 31 | queue = P.queueList[k] |
---|
| 32 | P.queueList[k] = nil |
---|
| 33 | break |
---|
| 34 | end |
---|
| 35 | end |
---|
| 36 | |
---|
| 37 | if queue ~= nil then |
---|
| 38 | winMgr:destroyWindow(queue) |
---|
| 39 | end |
---|
| 40 | end |
---|
| 41 | |
---|
| 42 | function P.pushNotification(queueName, notification) |
---|
[7342] | 43 | local queue = P.nameToQueueHelper(queueName) |
---|
[7338] | 44 | if queue == nil then |
---|
| 45 | cout(0, "Queue is nil!") |
---|
| 46 | return |
---|
| 47 | end |
---|
| 48 | item = CEGUI.createListboxTextItem(notification) |
---|
| 49 | local listbox = CEGUI.toListbox(queue) |
---|
| 50 | if listbox:getItemCount() == 0 then |
---|
| 51 | listbox:addItem(item) |
---|
| 52 | else |
---|
| 53 | listbox:insertItem(item, listbox:getListboxItemFromIndex(0)) |
---|
| 54 | end |
---|
[7351] | 55 | |
---|
| 56 | if P.visible == false then |
---|
| 57 | P.setVisible(queue, true) |
---|
| 58 | end |
---|
[7338] | 59 | end |
---|
| 60 | |
---|
| 61 | function P.popNotification(queueName) |
---|
[7342] | 62 | local queue = P.nameToQueueHelper(queueName) |
---|
[7338] | 63 | if queue == nil then |
---|
| 64 | cout(0, "Queue is nil!") |
---|
| 65 | return |
---|
| 66 | end |
---|
| 67 | local listbox = CEGUI.toListbox(queue) |
---|
| 68 | listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1)) |
---|
[7351] | 69 | |
---|
| 70 | if listbox:getItemCount() == 0 then |
---|
| 71 | P.setVisible(queue, false) |
---|
| 72 | end |
---|
[7338] | 73 | end |
---|
| 74 | |
---|
| 75 | function P.removeNotification(queueName, index) |
---|
[7342] | 76 | local queue = P.nameToQueueHelper(queueName) |
---|
[7338] | 77 | if queue == nil then |
---|
| 78 | cout(0, "Queue is nil!") |
---|
| 79 | return |
---|
| 80 | end |
---|
| 81 | local listbox = CEGUI.toListbox(queue) |
---|
| 82 | listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index))) |
---|
[7351] | 83 | |
---|
| 84 | if listbox:getItemCount() == 0 then |
---|
| 85 | P.setVisible(queue, false) |
---|
| 86 | end |
---|
[7338] | 87 | end |
---|
| 88 | |
---|
| 89 | function P.clearQueue(name) |
---|
[7342] | 90 | local queue = P.nameToQueueHelper(name) |
---|
[7338] | 91 | if queue == nil then |
---|
| 92 | cout(0, "Queue is nil!") |
---|
| 93 | return |
---|
| 94 | end |
---|
| 95 | local listbox = CEGUI.toListbox(queue) |
---|
| 96 | CEGUI.toListbox(queue):resetList() |
---|
[7351] | 97 | |
---|
| 98 | P.setVisible(queue, false) |
---|
[7338] | 99 | end |
---|
| 100 | |
---|
[7343] | 101 | function P.changePosition(name, xPos, yPos) |
---|
| 102 | local queue = P.nameToQueueHelper(name) |
---|
| 103 | if queue == nil then |
---|
| 104 | cout(0, "Queue is nil!") |
---|
| 105 | return |
---|
| 106 | end |
---|
| 107 | queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0))) |
---|
| 108 | queue:setWidth(CEGUI.UDim(1.0, -xPos)) |
---|
| 109 | end |
---|
| 110 | |
---|
| 111 | function P.changeSize(name, size) |
---|
| 112 | local queue = P.nameToQueueHelper(name) |
---|
| 113 | if queue == nil then |
---|
| 114 | cout(0, "Queue is nil!") |
---|
| 115 | return |
---|
| 116 | end |
---|
| 117 | queue:setHeight(CEGUI.UDim(0, P.queueHeightHelper(queue, size))) |
---|
| 118 | end |
---|
| 119 | |
---|
[7351] | 120 | function P.setVisible(queue, visible) |
---|
| 121 | queue:setVisible(visible) |
---|
| 122 | P.visible = visible |
---|
| 123 | end |
---|
| 124 | |
---|
[7342] | 125 | function P.nameToQueueHelper(name) |
---|
[7338] | 126 | local queue = nil |
---|
| 127 | for k,v in pairs(P.nameList) do |
---|
| 128 | if v == name then |
---|
| 129 | queue = P.queueList[k] |
---|
| 130 | break |
---|
| 131 | end |
---|
| 132 | end |
---|
| 133 | return queue |
---|
| 134 | end |
---|
| 135 | |
---|
[7342] | 136 | function P.queueHeightHelper(queue, size) |
---|
| 137 | local listbox = CEGUI.toListbox(queue) |
---|
| 138 | local item = CEGUI.createListboxTextItem("Text") |
---|
| 139 | listbox:addItem(item) |
---|
| 140 | local singleItemHeight = listbox:getTotalItemsHeight() |
---|
| 141 | local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel()) |
---|
| 142 | local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue) |
---|
| 143 | local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight() |
---|
| 144 | listbox:removeItem(item) |
---|
| 145 | return frameHeight + singleItemHeight*size |
---|
| 146 | end |
---|
| 147 | |
---|
[7338] | 148 | return P |
---|
| 149 | |
---|