[7338] | 1 | -- NotificationLayer.lua |
---|
| 2 | |
---|
[7395] | 3 | local P = createMenuSheet("NotificationLayer", true, TriBool.True, TriBool.True) |
---|
[7338] | 4 | |
---|
| 5 | P.queueList = {} |
---|
[7354] | 6 | P.editMode = false |
---|
[7338] | 7 | |
---|
[7395] | 8 | P.sampleWindow = nil |
---|
| 9 | |
---|
[7399] | 10 | -- Loads the queues from the NotificationManager and creates the sample window, that is used to measure the width various strings need. |
---|
[7395] | 11 | function P.onLoad() |
---|
| 12 | orxonox.NotificationManager:getInstance():loadQueues() |
---|
| 13 | P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/SampleWindow") |
---|
| 14 | end |
---|
| 15 | |
---|
[7399] | 16 | -- Creates a queue in the GUI. |
---|
[7338] | 17 | function P.createQueue(name, size) |
---|
| 18 | local root = winMgr:getWindow("orxonox/NotificationLayer/Root") |
---|
| 19 | local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name) |
---|
[7399] | 20 | queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent. |
---|
[7342] | 21 | root:addChildWindow(queue) |
---|
| 22 | |
---|
[7395] | 23 | local queueTuple = |
---|
| 24 | { |
---|
[7894] | 25 | ["window"] = queue, |
---|
| 26 | ["name"] = name, |
---|
| 27 | ["edit"] = nil, |
---|
| 28 | ["visible"] = false, |
---|
| 29 | ["fontSize"] = 12, |
---|
| 30 | ["fontColor"] = CEGUI.colour(1.0, 1.0, 1.0, 1.0) |
---|
[7395] | 31 | } |
---|
[7894] | 32 | |
---|
| 33 | queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) |
---|
| 34 | queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queueTuple, size)))) |
---|
[7351] | 35 | |
---|
[7395] | 36 | P.queueList[name] = queueTuple -- name access |
---|
[7399] | 37 | P.setVisible(queueTuple, false) -- Set the queue to invisible as long as there are no notifications in it. |
---|
[7338] | 38 | end |
---|
| 39 | |
---|
[7399] | 40 | -- Removes a queue from the GUI. |
---|
| 41 | function P.removeQueue(queueName) |
---|
| 42 | local queue = P.queueList[queueName] |
---|
[7338] | 43 | |
---|
| 44 | if queue ~= nil then |
---|
[7395] | 45 | winMgr:destroyWindow(queue.window) |
---|
[7338] | 46 | end |
---|
[7399] | 47 | P.queueList[queueName] = nil |
---|
[7338] | 48 | end |
---|
| 49 | |
---|
[7399] | 50 | -- Pushes an input notification to the input queue. |
---|
[7338] | 51 | function P.pushNotification(queueName, notification) |
---|
[7395] | 52 | local queue = P.queueList[queueName] |
---|
[7338] | 53 | if queue == nil then |
---|
| 54 | return |
---|
| 55 | end |
---|
| 56 | item = CEGUI.createListboxTextItem(notification) |
---|
[7894] | 57 | P.setItemFontHelper(item, queue, true) |
---|
[7395] | 58 | local listbox = CEGUI.toListbox(queue.window) |
---|
[7399] | 59 | -- Add the item to the top of the listbox. |
---|
[7338] | 60 | if listbox:getItemCount() == 0 then |
---|
| 61 | listbox:addItem(item) |
---|
| 62 | else |
---|
| 63 | listbox:insertItem(item, listbox:getListboxItemFromIndex(0)) |
---|
| 64 | end |
---|
[7351] | 65 | |
---|
[7399] | 66 | -- If the queue has been invisible, set it to visible. |
---|
[7395] | 67 | if queue.visible == false then |
---|
[7351] | 68 | P.setVisible(queue, true) |
---|
| 69 | end |
---|
[7338] | 70 | end |
---|
| 71 | |
---|
[7399] | 72 | -- Pops the least recently added notification from the queue. |
---|
[7338] | 73 | function P.popNotification(queueName) |
---|
[7395] | 74 | local queue = P.queueList[queueName] |
---|
[7338] | 75 | if queue == nil then |
---|
| 76 | return |
---|
| 77 | end |
---|
[7395] | 78 | local listbox = CEGUI.toListbox(queue.window) |
---|
[7399] | 79 | -- Removes the item from the bottom of the listbox. |
---|
[7338] | 80 | listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1)) |
---|
[7351] | 81 | |
---|
[7399] | 82 | -- Sets the queue to invisible if there are no more notifications in it. |
---|
[7351] | 83 | if listbox:getItemCount() == 0 then |
---|
| 84 | P.setVisible(queue, false) |
---|
| 85 | end |
---|
[7338] | 86 | end |
---|
| 87 | |
---|
[7399] | 88 | -- Removes a notification at a given index from the queue. |
---|
[7338] | 89 | function P.removeNotification(queueName, index) |
---|
[7395] | 90 | local queue = P.queueList[queueName] |
---|
[7338] | 91 | if queue == nil then |
---|
| 92 | return |
---|
| 93 | end |
---|
[7395] | 94 | local listbox = CEGUI.toListbox(queue.window) |
---|
[7399] | 95 | -- Removes the item. |
---|
[7338] | 96 | listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index))) |
---|
[7351] | 97 | |
---|
[7399] | 98 | -- Sets the queue to invisible if there are no more notifications in it. |
---|
[7351] | 99 | if listbox:getItemCount() == 0 then |
---|
| 100 | P.setVisible(queue, false) |
---|
| 101 | end |
---|
[7338] | 102 | end |
---|
| 103 | |
---|
[7399] | 104 | -- Clears the queue. Removes all notifications from it. |
---|
| 105 | function P.clearQueue(queueName) |
---|
| 106 | local queue = P.queueList[queueName] |
---|
[7338] | 107 | if queue == nil then |
---|
| 108 | return |
---|
| 109 | end |
---|
[7395] | 110 | local listbox = CEGUI.toListbox(queue.window) |
---|
| 111 | CEGUI.toListbox(queue.window):resetList() |
---|
[7351] | 112 | |
---|
[7399] | 113 | -- Sets the queue to invisible. |
---|
[7351] | 114 | P.setVisible(queue, false) |
---|
[7338] | 115 | end |
---|
| 116 | |
---|
[7399] | 117 | -- Sets the visibility of the queue. |
---|
[7395] | 118 | function P.setVisible(queue, visible) |
---|
[7343] | 119 | if queue == nil then |
---|
| 120 | return |
---|
| 121 | end |
---|
[7395] | 122 | queue.window:setVisible(visible) |
---|
| 123 | queue.visible = visible |
---|
[7343] | 124 | end |
---|
| 125 | |
---|
[7894] | 126 | -- Change the position of the queue. |
---|
| 127 | -- The parameters are (in order) 'name of the queue', 'relative x-position', 'absolute x-position in pixel', 'relative y-position', 'absolute y-position in pixel'. |
---|
| 128 | function P.moveQueue(queueName, relativeXPos, absoluteXPos, relativeYpos, absoluteYPos) |
---|
| 129 | local queueWindow = P.queueList[queueName].window |
---|
| 130 | queueWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(relativeXPos, absoluteXPos), CEGUI.UDim(relativeYpos, absoluteYPos))) |
---|
| 131 | end |
---|
| 132 | |
---|
| 133 | -- Change the size of the queue. |
---|
| 134 | -- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'. |
---|
| 135 | -- Additionally the last parameter can be ommitted and relativeHeight can be set to the size (i.e. the maximal number of notifications displayed) of the queue, which leads to the height being set such that all notifications can be displayed. |
---|
| 136 | function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth) |
---|
| 137 | local queueWindow = P.queueList[queueName].window |
---|
| 138 | if queueWindow == nil then |
---|
| 139 | return |
---|
| 140 | end |
---|
| 141 | if absoluteHeigth == nil then |
---|
| 142 | absoluteHeigth = P.queueHeightHelper(P.queueList[queueName], relativeHeight) |
---|
| 143 | relativeHeight = 0 |
---|
| 144 | end |
---|
| 145 | queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth))) |
---|
| 146 | end |
---|
| 147 | |
---|
| 148 | -- Change the font size and font color of all notifications in a queueHeightHelper |
---|
| 149 | -- The parameters are (in order) 'name of the queue', 'font size', 'RGBA of the font color, with values from 0 to 1 each'. |
---|
| 150 | function P.changeQueueFont(queueName, size, colorRed, colorGreen, colorBlue, colorAlpha) |
---|
| 151 | local queue = P.queueList[queueName] |
---|
| 152 | local queueWindow = queue.window |
---|
| 153 | if queueWindow == nil then |
---|
| 154 | return |
---|
| 155 | end |
---|
| 156 | if colorAlpha == nil then |
---|
| 157 | colorAlpha = 1.0 |
---|
| 158 | end |
---|
| 159 | |
---|
| 160 | local list = CEGUI.toListbox(queueWindow) |
---|
| 161 | local num = list:getItemCount() |
---|
| 162 | queue.fontSize = size |
---|
| 163 | local changeColor = false |
---|
| 164 | if colorRed ~= nil and colorGreen ~= nil and colorBlue ~= nil then |
---|
| 165 | queue.fontColor:set(colorRed, colorGreen, colorBlue, colorAlpha) |
---|
| 166 | changeColor = true |
---|
| 167 | end |
---|
| 168 | for i=0,num-1 do |
---|
| 169 | P.setItemFontHelper(item, queue, changeColor) |
---|
| 170 | end |
---|
| 171 | end |
---|
| 172 | |
---|
| 173 | -- Helper function to set the font size and color of a item of a queue. |
---|
| 174 | -- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well' |
---|
| 175 | function P.setItemFontHelper(item, queue, changeColor) |
---|
| 176 | local item = tolua.cast(item, "CEGUI::ListboxTextItem") |
---|
| 177 | local fontMgr = CEGUI.FontManager:getSingleton() |
---|
| 178 | if fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize) then |
---|
| 179 | item:setFont("BlueHighway-" .. queue.fontSize) |
---|
| 180 | else |
---|
| 181 | orxonox.GUIManager:addFontHelper("BlueHighway-" .. queue.fontSize, queue.fontSize, "bluehigh.ttf") |
---|
| 182 | item:setFont("BlueHighway-" .. queue.fontSize) |
---|
| 183 | end |
---|
| 184 | if changeColor then |
---|
| 185 | item:setTextColours(queue.fontColor) |
---|
| 186 | end |
---|
| 187 | end |
---|
| 188 | |
---|
[7399] | 189 | -- Enter the edit mode of the notification layer. |
---|
[7354] | 190 | function P.enterEditMode() |
---|
| 191 | P.editMode = true |
---|
| 192 | |
---|
| 193 | local root = winMgr:getWindow("orxonox/NotificationLayer/Root") |
---|
[7395] | 194 | |
---|
| 195 | --Add control frame window. |
---|
| 196 | local window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/ControlWindow") |
---|
| 197 | local frame = tolua.cast(window, "CEGUI::FrameWindow") |
---|
| 198 | frame:setCloseButtonEnabled(false) |
---|
| 199 | frame:setText("NotificationLayer Control Window") |
---|
| 200 | frame:setSize(CEGUI.UVector2(CEGUI.UDim(0.7, 0), CEGUI.UDim(0.2, 0))) |
---|
| 201 | root:addChildWindow(window) |
---|
| 202 | local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/ScrollingPane") |
---|
| 203 | pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30))) |
---|
| 204 | pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26))) |
---|
| 205 | window:addChildWindow(pane) |
---|
| 206 | |
---|
| 207 | vertOffset = 0 |
---|
| 208 | horzOffset = 0 |
---|
[7399] | 209 | -- Line to be able to create a new queue. |
---|
[7395] | 210 | local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle") |
---|
| 211 | newQueueTitle:setText("Create a new NotificationQueue:") |
---|
| 212 | local size = getMinTextSize(newQueueTitle) |
---|
| 213 | local textHeight = size[1] |
---|
| 214 | newQueueTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) |
---|
| 215 | newQueueTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 216 | pane:addChildWindow(newQueueTitle) |
---|
| 217 | horzOffset = horzOffset + size[2] + 5 |
---|
| 218 | local newQueueName = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName") |
---|
| 219 | newQueueName:setProperty("ReadOnly", "set:False") |
---|
| 220 | newQueueName:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) |
---|
| 221 | newQueueName:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 222 | horzOffset = horzOffset + size[2] + 5 |
---|
| 223 | pane:addChildWindow(newQueueName) |
---|
| 224 | local create = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/CreateNewQueue") |
---|
| 225 | create:setText("create") |
---|
| 226 | P.sampleWindow:setText("create") |
---|
| 227 | size = getMinTextSize(P.sampleWindow) |
---|
| 228 | create:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight))) |
---|
| 229 | create:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 230 | orxonox.GUIManager:subscribeEventHelper(create, "Clicked", P.name .. ".createNewQueue_clicked") |
---|
| 231 | pane:addChildWindow(create) |
---|
| 232 | horzOffset = horzOffset + size[2]+20 + 5 |
---|
| 233 | vertOffset = vertOffset + textHeight + 5 |
---|
| 234 | |
---|
| 235 | horzOffset = 0 |
---|
[7399] | 236 | -- Button to leave the edit mode. |
---|
[7395] | 237 | local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton") |
---|
| 238 | leave:setText("leave Edit Mode") |
---|
| 239 | P.sampleWindow:setText("leave Edit Mode") |
---|
| 240 | size = getMinTextSize(P.sampleWindow) |
---|
| 241 | leave:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight))) |
---|
| 242 | leave:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 243 | orxonox.GUIManager:subscribeEventHelper(leave, "Clicked", P.name .. ".leaveEditMode_clicked") |
---|
| 244 | pane:addChildWindow(leave) |
---|
| 245 | horzOffset = horzOffset + size[2]+20 + 5 |
---|
| 246 | vertOffset = vertOffset + textHeight + 5 |
---|
| 247 | |
---|
[7354] | 248 | --Replace all queues with FrameWindows |
---|
| 249 | for k,v in pairs(P.queueList) do |
---|
| 250 | if v ~= nil then |
---|
[7395] | 251 | local queue = P.queueList[k] |
---|
[7399] | 252 | -- Remove the window that displays the queue from the root window such that it is no longer displayed. |
---|
| 253 | root:removeChildWindow(v.window) |
---|
| 254 | |
---|
| 255 | -- Create the frame window, with options to edit the queue, that is displayed instead of the queue. |
---|
| 256 | local window = P.createQueueEditFrame(v.name) |
---|
| 257 | window:setArea(v.window:getArea()) -- Set the frame window size and position to the same as the queue. |
---|
| 258 | |
---|
| 259 | v.edit = window |
---|
[7354] | 260 | end |
---|
| 261 | end |
---|
| 262 | end |
---|
| 263 | |
---|
[7399] | 264 | -- Helper function. Creates a frame for the input queue. |
---|
| 265 | function P.createQueueEditFrame(queueName) |
---|
[7395] | 266 | local root = winMgr:getWindow("orxonox/NotificationLayer/Root") |
---|
[7399] | 267 | |
---|
| 268 | window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. queueName) |
---|
[7395] | 269 | local frame = tolua.cast(window, "CEGUI::FrameWindow") |
---|
[7398] | 270 | frame:setCloseButtonEnabled(true) |
---|
| 271 | orxonox.GUIManager:subscribeEventHelper(frame, "CloseClicked", P.name .. ".closeQueue_clicked") |
---|
[7399] | 272 | frame:setText("NotificationQueue \"" .. queueName .. "\"") |
---|
[7395] | 273 | root:addChildWindow(window) |
---|
[7399] | 274 | local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/ScrollingPane") |
---|
[7395] | 275 | pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30))) |
---|
| 276 | pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26))) |
---|
| 277 | window:addChildWindow(pane) |
---|
| 278 | |
---|
| 279 | local horzOffset = 0 |
---|
| 280 | local vertOffset = 0 |
---|
| 281 | |
---|
[7399] | 282 | -- The line that lets you edit the targets of the queue. |
---|
| 283 | local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/TargetsTitle") |
---|
[7395] | 284 | targetsTitle:setText("Targets:") |
---|
| 285 | local size = getMinTextSize(targetsTitle) |
---|
| 286 | local textHeight = size[1] |
---|
| 287 | targetsTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) |
---|
| 288 | targetsTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 289 | pane:addChildWindow(targetsTitle) |
---|
| 290 | horzOffset = horzOffset + size[2] + 5 |
---|
[7399] | 291 | local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets") |
---|
[7395] | 292 | targets:setProperty("ReadOnly", "set:False") |
---|
[7399] | 293 | local targetsText = orxonox.NotificationManager:getInstance():getQueue(queueName):getTargets() |
---|
[7395] | 294 | targets:setText(targetsText) |
---|
| 295 | P.sampleWindow:setText(targetsText) |
---|
| 296 | size = getMinTextSize(P.sampleWindow) |
---|
| 297 | targets:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) |
---|
| 298 | targets:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 299 | horzOffset = horzOffset + size[2]*2+20 + 5 |
---|
| 300 | pane:addChildWindow(targets) |
---|
[7399] | 301 | local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save") |
---|
[7395] | 302 | save:setText("save") |
---|
| 303 | P.sampleWindow:setText("save") |
---|
| 304 | size = getMinTextSize(P.sampleWindow) |
---|
| 305 | local saveTextWidth = size[2]+20 |
---|
| 306 | save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) |
---|
| 307 | save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 308 | orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveTargets_clicked") |
---|
| 309 | pane:addChildWindow(save) |
---|
| 310 | horzOffset = horzOffset + saveTextWidth |
---|
| 311 | vertOffset = vertOffset + textHeight + 5 |
---|
| 312 | |
---|
| 313 | horzOffset = 0 |
---|
[7399] | 314 | -- The line that lets you edit the size of the queue. |
---|
| 315 | local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/SizeTitle") |
---|
[7395] | 316 | sizeTitle:setText("Size:") |
---|
| 317 | size = getMinTextSize(sizeTitle) |
---|
| 318 | sizeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) |
---|
| 319 | sizeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 320 | pane:addChildWindow(sizeTitle) |
---|
| 321 | horzOffset = horzOffset + size[2] + 5 |
---|
[7399] | 322 | local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size") |
---|
[7395] | 323 | queueSize:setProperty("ReadOnly", "set:False") |
---|
[7399] | 324 | local maxSize = orxonox.NotificationManager:getInstance():getQueue(queueName):getMaxSize() |
---|
[7395] | 325 | queueSize:setText(maxSize) |
---|
| 326 | P.sampleWindow:setText(maxSize) |
---|
| 327 | size = getMinTextSize(P.sampleWindow) |
---|
| 328 | queueSize:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) |
---|
| 329 | queueSize:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 330 | horzOffset = horzOffset + size[2]*2+20 + 5 |
---|
| 331 | pane:addChildWindow(queueSize) |
---|
[7399] | 332 | save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save") |
---|
[7395] | 333 | save:setText("save") |
---|
| 334 | P.sampleWindow:setText("save") |
---|
| 335 | size = getMinTextSize(P.sampleWindow) |
---|
| 336 | local saveTextWidth = size[2]+20 |
---|
| 337 | save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) |
---|
| 338 | save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 339 | orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveSize_clicked") |
---|
| 340 | pane:addChildWindow(save) |
---|
| 341 | horzOffset = horzOffset + saveTextWidth |
---|
| 342 | vertOffset = vertOffset + textHeight + 5 |
---|
| 343 | |
---|
| 344 | horzOffset = 0 |
---|
[7399] | 345 | -- The line that lets you edit the display time of the queue. |
---|
| 346 | local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTimeTitle") |
---|
[7395] | 347 | displayTimeTitle:setText("Display time:") |
---|
| 348 | size = getMinTextSize(displayTimeTitle) |
---|
| 349 | displayTimeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) |
---|
| 350 | displayTimeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 351 | pane:addChildWindow(displayTimeTitle) |
---|
| 352 | horzOffset = horzOffset + size[2] + 5 |
---|
[7399] | 353 | local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime") |
---|
[7395] | 354 | displayTime:setProperty("ReadOnly", "set:False") |
---|
[7399] | 355 | local time = orxonox.NotificationManager:getInstance():getQueue(queueName):getDisplayTime() |
---|
[7395] | 356 | displayTime:setText(time) |
---|
| 357 | P.sampleWindow:setText(time) |
---|
| 358 | size = getMinTextSize(P.sampleWindow) |
---|
| 359 | displayTime:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) |
---|
| 360 | displayTime:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 361 | horzOffset = horzOffset + size[2]*2+20 + 5 |
---|
| 362 | pane:addChildWindow(displayTime) |
---|
[7399] | 363 | save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save") |
---|
[7395] | 364 | save:setText("save") |
---|
| 365 | P.sampleWindow:setText("save") |
---|
| 366 | size = getMinTextSize(P.sampleWindow) |
---|
| 367 | local saveTextWidth = size[2]+20 |
---|
| 368 | save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) |
---|
| 369 | save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) |
---|
| 370 | orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveDisplayTime_clicked") |
---|
| 371 | pane:addChildWindow(save) |
---|
| 372 | horzOffset = horzOffset + saveTextWidth |
---|
| 373 | vertOffset = vertOffset + textHeight + 5 |
---|
| 374 | |
---|
| 375 | return window |
---|
| 376 | end |
---|
| 377 | |
---|
[7399] | 378 | -- Leave the edit mode. |
---|
[7354] | 379 | function P.leaveEditMode() |
---|
| 380 | P.editMode = false |
---|
| 381 | |
---|
| 382 | local root = winMgr:getWindow("orxonox/NotificationLayer/Root") |
---|
| 383 | --Replace all queues with FrameWindows |
---|
| 384 | for k,v in pairs(P.queueList) do |
---|
| 385 | if v ~= nil then |
---|
[7399] | 386 | -- Add the queue window to the root window to have it displayed again. |
---|
[7395] | 387 | root:addChildWindow(v.window) |
---|
[7399] | 388 | -- Set the size and position of the queue window to the size and position of the queue edit frame. |
---|
[7395] | 389 | v.window:setArea(v.edit:getArea()) |
---|
[7399] | 390 | -- Destroy the edit frame. |
---|
[7395] | 391 | winMgr:destroyWindow(v.edit) |
---|
| 392 | v.edit = nil |
---|
[7354] | 393 | end |
---|
| 394 | end |
---|
[7362] | 395 | |
---|
[7395] | 396 | --Remove control window |
---|
| 397 | winMgr:destroyWindow(winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow")) |
---|
[7354] | 398 | end |
---|
| 399 | |
---|
[7399] | 400 | -- Is called after the sheet has been hidden. |
---|
[7395] | 401 | function P.afterHide() |
---|
[7399] | 402 | -- If we leave the edit mode we show the sheet again. |
---|
[7354] | 403 | if P.editMode then |
---|
| 404 | P.leaveEditMode() |
---|
[7395] | 405 | showMenuSheet(P.name, false, true) |
---|
[7354] | 406 | end |
---|
| 407 | end |
---|
| 408 | |
---|
[7399] | 409 | -- If the button to save the targets of a queue has been clicked. |
---|
[7894] | 410 | function P.saveTargets_clicked(e) |
---|
[7395] | 411 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 412 | local name = we.window:getName() |
---|
| 413 | |
---|
| 414 | local match = string.gmatch(name, "EditMode/.*/Targets/Save") |
---|
| 415 | local nameStr = match() |
---|
| 416 | local queueName = string.sub(nameStr, 10, string.len(nameStr)-13) |
---|
| 417 | |
---|
| 418 | local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets") |
---|
| 419 | local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save") |
---|
[7398] | 420 | local width = window:getWidth():asAbsolute(1) |
---|
[7395] | 421 | |
---|
| 422 | local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) |
---|
[7399] | 423 | -- Set the new targets. |
---|
[7395] | 424 | queue:setTargets(window:getText()) |
---|
| 425 | local targets = queue:getTargets() |
---|
| 426 | |
---|
| 427 | window:setText(targets) |
---|
| 428 | P.sampleWindow:setText(targets) |
---|
| 429 | local size = getMinTextSize(P.sampleWindow) |
---|
[7399] | 430 | -- Adjust the width of the targets field. |
---|
[7395] | 431 | window:setWidth(CEGUI.UDim(0, size[2]*2+20)) |
---|
[7399] | 432 | -- Adjust the position of the save button after the targets field. |
---|
[7395] | 433 | save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) |
---|
| 434 | end |
---|
| 435 | |
---|
[7399] | 436 | -- If the button to save the size if a queue has been clicked. |
---|
[7894] | 437 | function P.saveSize_clicked(e) |
---|
[7395] | 438 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 439 | local name = we.window:getName() |
---|
| 440 | |
---|
| 441 | local match = string.gmatch(name, "EditMode/.*/Size/Save") |
---|
| 442 | local nameStr = match() |
---|
| 443 | local queueName = string.sub(nameStr, 10, string.len(nameStr)-10) |
---|
| 444 | |
---|
| 445 | local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size") |
---|
| 446 | local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save") |
---|
[7398] | 447 | local width = window:getWidth():asAbsolute(1) |
---|
[7395] | 448 | |
---|
| 449 | local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) |
---|
[7399] | 450 | -- Set the new size. |
---|
[7395] | 451 | queue:setMaxSize(tonumber(window:getText())) |
---|
| 452 | local maxSize = queue:getMaxSize() |
---|
| 453 | |
---|
| 454 | window:setText(maxSize) |
---|
| 455 | P.sampleWindow:setText(maxSize) |
---|
| 456 | local size = getMinTextSize(P.sampleWindow) |
---|
[7399] | 457 | -- Adjust the width of the size field. |
---|
[7395] | 458 | window:setWidth(CEGUI.UDim(0, size[2]*2+20)) |
---|
[7399] | 459 | -- Adjust the position of the save button after the size field. |
---|
[7395] | 460 | save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) |
---|
| 461 | end |
---|
| 462 | |
---|
[7399] | 463 | -- If the button to save the display time if a queue has been clicked. |
---|
[7894] | 464 | function P.saveDisplayTime_clicked(e) |
---|
[7395] | 465 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 466 | local name = we.window:getName() |
---|
| 467 | |
---|
| 468 | local match = string.gmatch(name, "EditMode/.*/DisplayTime/Save") |
---|
| 469 | local nameStr = match() |
---|
| 470 | local queueName = string.sub(nameStr, 10, string.len(nameStr)-17) |
---|
| 471 | |
---|
| 472 | local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime") |
---|
| 473 | local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save") |
---|
[7398] | 474 | local width = window:getWidth():asAbsolute(1) |
---|
[7395] | 475 | |
---|
| 476 | local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) |
---|
[7399] | 477 | -- Set the new display time. |
---|
[7395] | 478 | queue:setDisplayTime(tonumber(window:getText())) |
---|
| 479 | local time = queue:getDisplayTime() |
---|
| 480 | |
---|
| 481 | window:setText(time) |
---|
| 482 | P.sampleWindow:setText(time) |
---|
| 483 | local size = getMinTextSize(P.sampleWindow) |
---|
[7399] | 484 | -- Adjust the width of the display time field. |
---|
[7395] | 485 | window:setWidth(CEGUI.UDim(0, size[2]*2+20)) |
---|
[7399] | 486 | -- Adjust the position of the save button after the display time field. |
---|
[7395] | 487 | save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) |
---|
| 488 | end |
---|
| 489 | |
---|
[7399] | 490 | -- if the button to create a new queue has been clicked. |
---|
[7395] | 491 | function P.createNewQueue_clicked(e) |
---|
| 492 | local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName") |
---|
| 493 | local name = window:getText() |
---|
[7413] | 494 | |
---|
| 495 | local queue = P.queueList[name] |
---|
| 496 | -- Test if a queue with that name already exists. |
---|
| 497 | if queue ~= nil then |
---|
| 498 | window:setText("Queue with that name already exists.") |
---|
| 499 | return |
---|
| 500 | end |
---|
| 501 | |
---|
[7399] | 502 | -- Creates the new queue. |
---|
[7395] | 503 | orxonox.NotificationManager:getInstance():createQueue(name) |
---|
| 504 | |
---|
[7413] | 505 | queue = P.queueList[name] |
---|
[7395] | 506 | if queue == nil then |
---|
| 507 | return |
---|
[7338] | 508 | end |
---|
[7399] | 509 | |
---|
| 510 | -- Create the frame that represents the queue in edit mode, since that's what we're in. |
---|
[7395] | 511 | local frame = P.createQueueEditFrame(name) |
---|
| 512 | local root = winMgr:getWindow("orxonox/NotificationLayer/Root") |
---|
[7399] | 513 | -- Remove the queue window from the root window, since we're in edit mode. |
---|
[7395] | 514 | root:removeChildWindow(queue.window) |
---|
[7399] | 515 | -- Set the frame window size and position to that of the queue window. |
---|
[7395] | 516 | frame:setArea(queue.window:getArea()) |
---|
| 517 | queue.edit = frame |
---|
[7399] | 518 | |
---|
| 519 | -- Reset the text to create a new queue. |
---|
[7395] | 520 | window:setText("") |
---|
[7338] | 521 | end |
---|
| 522 | |
---|
[7399] | 523 | -- If the button to leave the edit mode has been clicked. |
---|
[7395] | 524 | function P.leaveEditMode_clicked(e) |
---|
| 525 | hideMenuSheet(P.name) |
---|
| 526 | end |
---|
| 527 | |
---|
[7399] | 528 | -- If the button to close the queue has been clicked. |
---|
[7398] | 529 | function P.closeQueue_clicked(e) |
---|
| 530 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 531 | local name = we.window:getName() |
---|
| 532 | |
---|
| 533 | local match = string.gmatch(name, "EditMode/.*") |
---|
| 534 | local nameStr = match() |
---|
| 535 | local queueName = string.sub(nameStr, 10, string.len(nameStr)) |
---|
| 536 | |
---|
[7399] | 537 | -- Destroy the frame window, |
---|
[7398] | 538 | winMgr:destroyWindow(P.queueList[queueName].edit) |
---|
| 539 | P.queueList[queueName].edit = nil |
---|
[7399] | 540 | -- Destroy the queue. |
---|
[7398] | 541 | orxonox.NotificationManager:getInstance():getQueue(queueName):destroy() |
---|
| 542 | end |
---|
| 543 | |
---|
[7399] | 544 | -- Helper function. Returns height a queue needs to have to display 'size' items. |
---|
[7342] | 545 | function P.queueHeightHelper(queue, size) |
---|
[7894] | 546 | local listbox = CEGUI.toListbox(queue.window) |
---|
[7342] | 547 | local item = CEGUI.createListboxTextItem("Text") |
---|
[7894] | 548 | P.setItemFontHelper(item, queue, false) |
---|
[7342] | 549 | listbox:addItem(item) |
---|
| 550 | local singleItemHeight = listbox:getTotalItemsHeight() |
---|
[7894] | 551 | local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel()) |
---|
| 552 | local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window) |
---|
| 553 | local frameHeight = queue.window:getUnclippedPixelRect():getHeight() - formattedArea:getHeight() |
---|
[7342] | 554 | listbox:removeItem(item) |
---|
| 555 | return frameHeight + singleItemHeight*size |
---|
| 556 | end |
---|
| 557 | |
---|
[7338] | 558 | return P |
---|