| [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) |
|---|
| 135 | local frame = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. P.nameList(k)) |
|---|
| 136 | frame:setArea(v:getArea()) |
|---|
| 137 | P.editList[k] = frame |
|---|
| 138 | end |
|---|
| 139 | end |
|---|
| 140 | end |
|---|
| 141 | |
|---|
| 142 | function P.leaveEditMode() |
|---|
| 143 | P.editMode = false |
|---|
| 144 | |
|---|
| 145 | local root = winMgr:getWindow("orxonox/NotificationLayer/Root") |
|---|
| 146 | --Replace all queues with FrameWindows |
|---|
| 147 | for k,v in pairs(P.queueList) do |
|---|
| 148 | if v ~= nil then |
|---|
| 149 | root:addChildWindow(v) |
|---|
| 150 | v:setArea(P.editList[k]:getArea()) |
|---|
| 151 | winMgr:destroyWindow(P.editList[k]) |
|---|
| 152 | P.editList[k] = nil |
|---|
| 153 | end |
|---|
| 154 | end |
|---|
| 155 | end |
|---|
| 156 | |
|---|
| 157 | function P.onHide() |
|---|
| 158 | if P.editMode then |
|---|
| 159 | P.leaveEditMode() |
|---|
| 160 | end |
|---|
| 161 | end |
|---|
| 162 | |
|---|
| [7342] | 163 | function P.nameToQueueHelper(name) |
|---|
| [7338] | 164 | local queue = nil |
|---|
| 165 | for k,v in pairs(P.nameList) do |
|---|
| 166 | if v == name then |
|---|
| 167 | queue = P.queueList[k] |
|---|
| 168 | break |
|---|
| 169 | end |
|---|
| 170 | end |
|---|
| 171 | return queue |
|---|
| 172 | end |
|---|
| 173 | |
|---|
| [7342] | 174 | function P.queueHeightHelper(queue, size) |
|---|
| 175 | local listbox = CEGUI.toListbox(queue) |
|---|
| 176 | local item = CEGUI.createListboxTextItem("Text") |
|---|
| 177 | listbox:addItem(item) |
|---|
| 178 | local singleItemHeight = listbox:getTotalItemsHeight() |
|---|
| 179 | local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel()) |
|---|
| 180 | local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue) |
|---|
| 181 | local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight() |
|---|
| 182 | listbox:removeItem(item) |
|---|
| 183 | return frameHeight + singleItemHeight*size |
|---|
| 184 | end |
|---|
| 185 | |
|---|
| [7338] | 186 | return P |
|---|
| 187 | |
|---|