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