Changeset 7399 for code/branches/notifications/data/gui/scripts
- Timestamp:
- Sep 10, 2010, 11:17:02 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/notifications/data/gui/scripts/NotificationLayer.lua
r7398 r7399 8 8 P.sampleWindow = nil 9 9 10 -- Loads the queues from the NotificationManager and creates the sample window, that is used to measure the width various strings need. 10 11 function P.onLoad() 11 12 orxonox.NotificationManager:getInstance():loadQueues() … … 13 14 end 14 15 16 -- Creates a queue in the GUI. 15 17 function P.createQueue(name, size) 16 18 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 17 19 local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name) 18 queue:setProperty("BackgroundColor", "00FFFFFF") 20 queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent. 19 21 root:addChildWindow(queue) 20 22 … … 31 33 32 34 P.queueList[name] = queueTuple -- name access 33 P.setVisible(queueTuple, false) 34 end 35 36 function P.removeQueue(name) 37 local queue = P.queueList[name] 35 P.setVisible(queueTuple, false) -- Set the queue to invisible as long as there are no notifications in it. 36 end 37 38 -- Removes a queue from the GUI. 39 function P.removeQueue(queueName) 40 local queue = P.queueList[queueName] 38 41 39 42 if queue ~= nil then 40 43 winMgr:destroyWindow(queue.window) 41 44 end 42 P.queueList[name] = nil 43 end 44 45 P.queueList[queueName] = nil 46 end 47 48 -- Pushes an input notification to the input queue. 45 49 function P.pushNotification(queueName, notification) 46 50 local queue = P.queueList[queueName] 47 51 if queue == nil then 48 cout(0, "0Queue is nil! " .. queueName)49 52 return 50 53 end 51 54 item = CEGUI.createListboxTextItem(notification) 52 55 local listbox = CEGUI.toListbox(queue.window) 56 -- Add the item to the top of the listbox. 53 57 if listbox:getItemCount() == 0 then 54 58 listbox:addItem(item) … … 57 61 end 58 62 63 -- If the queue has been invisible, set it to visible. 59 64 if queue.visible == false then 60 65 P.setVisible(queue, true) … … 62 67 end 63 68 69 -- Pops the least recently added notification from the queue. 64 70 function P.popNotification(queueName) 65 71 local queue = P.queueList[queueName] 66 72 if queue == nil then 67 cout(0, "1Queue is nil! " .. queueName)68 73 return 69 74 end 70 75 local listbox = CEGUI.toListbox(queue.window) 76 -- Removes the item from the bottom of the listbox. 71 77 listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1)) 72 78 79 -- Sets the queue to invisible if there are no more notifications in it. 73 80 if listbox:getItemCount() == 0 then 74 81 P.setVisible(queue, false) … … 76 83 end 77 84 85 -- Removes a notification at a given index from the queue. 78 86 function P.removeNotification(queueName, index) 79 87 local queue = P.queueList[queueName] 80 88 if queue == nil then 81 cout(0, "2Queue is nil! " .. queueName)82 89 return 83 90 end 84 91 local listbox = CEGUI.toListbox(queue.window) 92 -- Removes the item. 85 93 listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index))) 86 94 95 -- Sets the queue to invisible if there are no more notifications in it. 87 96 if listbox:getItemCount() == 0 then 88 97 P.setVisible(queue, false) … … 90 99 end 91 100 92 function P.clearQueue(name) 93 local queue = P.queueList[name] 94 if queue == nil then95 cout(0, "3Queue is nil! " .. name)101 -- Clears the queue. Removes all notifications from it. 102 function P.clearQueue(queueName) 103 local queue = P.queueList[queueName] 104 if queue == nil then 96 105 return 97 106 end … … 99 108 CEGUI.toListbox(queue.window):resetList() 100 109 110 -- Sets the queue to invisible. 101 111 P.setVisible(queue, false) 102 112 end 103 113 104 function P.changeSize(name, size) 105 local queue = P.queueList[name] 106 if queue == nil then 107 cout(0, "5Queue is nil! " .. name) 108 return 109 end 110 queue.window:setHeight(CEGUI.UDim(0, P.queueHeightHelper(queue.window, size))) 111 end 112 114 -- Sets the visibility of the queue. 113 115 function P.setVisible(queue, visible) 114 116 if queue == nil then 115 cout(0, "6Queue is nil! " .. queue.name)116 117 return 117 118 end … … 120 121 end 121 122 123 -- Enter the edit mode of the notification layer. 122 124 function P.enterEditMode() 123 125 P.editMode = true … … 139 141 vertOffset = 0 140 142 horzOffset = 0 143 -- Line to be able to create a new queue. 141 144 local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle") 142 145 newQueueTitle:setText("Create a new NotificationQueue:") … … 165 168 166 169 horzOffset = 0 170 -- Button to leave the edit mode. 167 171 local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton") 168 172 leave:setText("leave Edit Mode") … … 180 184 if v ~= nil then 181 185 local queue = P.queueList[k] 182 root:removeChildWindow(queue.window) 183 184 local window = P.createQueueEditFrame(queue.name) 185 window:setArea(queue.window:getArea()) 186 187 queue.edit = window 186 -- Remove the window that displays the queue from the root window such that it is no longer displayed. 187 root:removeChildWindow(v.window) 188 189 -- Create the frame window, with options to edit the queue, that is displayed instead of the queue. 190 local window = P.createQueueEditFrame(v.name) 191 window:setArea(v.window:getArea()) -- Set the frame window size and position to the same as the queue. 192 193 v.edit = window 188 194 end 189 195 end 190 196 end 191 197 192 function P.createQueueEditFrame(name) 198 -- Helper function. Creates a frame for the input queue. 199 function P.createQueueEditFrame(queueName) 193 200 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 194 window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. name) 201 202 window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. queueName) 195 203 local frame = tolua.cast(window, "CEGUI::FrameWindow") 196 204 frame:setCloseButtonEnabled(true) 197 205 orxonox.GUIManager:subscribeEventHelper(frame, "CloseClicked", P.name .. ".closeQueue_clicked") 198 frame:setText("NotificationQueue \"" .. name .. "\"")206 frame:setText("NotificationQueue \"" .. queueName .. "\"") 199 207 root:addChildWindow(window) 200 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/ScrollingPane")208 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/ScrollingPane") 201 209 pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30))) 202 210 pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26))) … … 206 214 local vertOffset = 0 207 215 208 local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/TargetsTitle") 216 -- The line that lets you edit the targets of the queue. 217 local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/TargetsTitle") 209 218 targetsTitle:setText("Targets:") 210 219 local size = getMinTextSize(targetsTitle) … … 214 223 pane:addChildWindow(targetsTitle) 215 224 horzOffset = horzOffset + size[2] + 5 216 local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Targets")225 local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets") 217 226 targets:setProperty("ReadOnly", "set:False") 218 local targetsText = orxonox.NotificationManager:getInstance():getQueue( name):getTargets()227 local targetsText = orxonox.NotificationManager:getInstance():getQueue(queueName):getTargets() 219 228 targets:setText(targetsText) 220 229 P.sampleWindow:setText(targetsText) … … 224 233 horzOffset = horzOffset + size[2]*2+20 + 5 225 234 pane:addChildWindow(targets) 226 local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Targets/Save")235 local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save") 227 236 save:setText("save") 228 237 P.sampleWindow:setText("save") … … 237 246 238 247 horzOffset = 0 239 local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/SizeTitle") 248 -- The line that lets you edit the size of the queue. 249 local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/SizeTitle") 240 250 sizeTitle:setText("Size:") 241 251 size = getMinTextSize(sizeTitle) … … 244 254 pane:addChildWindow(sizeTitle) 245 255 horzOffset = horzOffset + size[2] + 5 246 local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Size")256 local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size") 247 257 queueSize:setProperty("ReadOnly", "set:False") 248 local maxSize = orxonox.NotificationManager:getInstance():getQueue( name):getMaxSize()258 local maxSize = orxonox.NotificationManager:getInstance():getQueue(queueName):getMaxSize() 249 259 queueSize:setText(maxSize) 250 260 P.sampleWindow:setText(maxSize) … … 254 264 horzOffset = horzOffset + size[2]*2+20 + 5 255 265 pane:addChildWindow(queueSize) 256 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Size/Save")266 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save") 257 267 save:setText("save") 258 268 P.sampleWindow:setText("save") … … 267 277 268 278 horzOffset = 0 269 local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTimeTitle") 279 -- The line that lets you edit the display time of the queue. 280 local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTimeTitle") 270 281 displayTimeTitle:setText("Display time:") 271 282 size = getMinTextSize(displayTimeTitle) … … 274 285 pane:addChildWindow(displayTimeTitle) 275 286 horzOffset = horzOffset + size[2] + 5 276 local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTime")287 local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime") 277 288 displayTime:setProperty("ReadOnly", "set:False") 278 local time = orxonox.NotificationManager:getInstance():getQueue( name):getDisplayTime()289 local time = orxonox.NotificationManager:getInstance():getQueue(queueName):getDisplayTime() 279 290 displayTime:setText(time) 280 291 P.sampleWindow:setText(time) … … 284 295 horzOffset = horzOffset + size[2]*2+20 + 5 285 296 pane:addChildWindow(displayTime) 286 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTime/Save")297 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save") 287 298 save:setText("save") 288 299 P.sampleWindow:setText("save") … … 299 310 end 300 311 312 -- Leave the edit mode. 301 313 function P.leaveEditMode() 302 314 P.editMode = false … … 306 318 for k,v in pairs(P.queueList) do 307 319 if v ~= nil then 320 -- Add the queue window to the root window to have it displayed again. 308 321 root:addChildWindow(v.window) 322 -- Set the size and position of the queue window to the size and position of the queue edit frame. 309 323 v.window:setArea(v.edit:getArea()) 324 -- Destroy the edit frame. 310 325 winMgr:destroyWindow(v.edit) 311 326 v.edit = nil … … 317 332 end 318 333 334 -- Is called after the sheet has been hidden. 319 335 function P.afterHide() 336 -- If we leave the edit mode we show the sheet again. 320 337 if P.editMode then 321 338 P.leaveEditMode() … … 324 341 end 325 342 343 -- If the button to save the targets of a queue has been clicked. 326 344 function P. saveTargets_clicked(e) 327 345 local we = CEGUI.toWindowEventArgs(e) … … 337 355 338 356 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 357 -- Set the new targets. 339 358 queue:setTargets(window:getText()) 340 359 local targets = queue:getTargets() … … 343 362 P.sampleWindow:setText(targets) 344 363 local size = getMinTextSize(P.sampleWindow) 364 -- Adjust the width of the targets field. 345 365 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 366 -- Adjust the position of the save button after the targets field. 346 367 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 347 368 end 348 369 370 -- If the button to save the size if a queue has been clicked. 349 371 function P. saveSize_clicked(e) 350 372 local we = CEGUI.toWindowEventArgs(e) … … 360 382 361 383 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 384 -- Set the new size. 362 385 queue:setMaxSize(tonumber(window:getText())) 363 386 local maxSize = queue:getMaxSize() … … 366 389 P.sampleWindow:setText(maxSize) 367 390 local size = getMinTextSize(P.sampleWindow) 391 -- Adjust the width of the size field. 368 392 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 393 -- Adjust the position of the save button after the size field. 369 394 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 370 395 end 371 396 397 -- If the button to save the display time if a queue has been clicked. 372 398 function P. saveDisplayTime_clicked(e) 373 399 local we = CEGUI.toWindowEventArgs(e) … … 383 409 384 410 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 411 -- Set the new display time. 385 412 queue:setDisplayTime(tonumber(window:getText())) 386 413 local time = queue:getDisplayTime() … … 389 416 P.sampleWindow:setText(time) 390 417 local size = getMinTextSize(P.sampleWindow) 418 -- Adjust the width of the display time field. 391 419 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 420 -- Adjust the position of the save button after the display time field. 392 421 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 393 422 end 394 423 424 -- if the button to create a new queue has been clicked. 395 425 function P.createNewQueue_clicked(e) 396 426 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName") 397 427 local name = window:getText() 428 -- Creates the new queue. 398 429 orxonox.NotificationManager:getInstance():createQueue(name) 399 430 400 431 local queue = P.queueList[name] 401 432 if queue == nil then 402 cout(0, "7Queue is nil! " .. name)403 return404 end 405 433 return 434 end 435 436 -- Create the frame that represents the queue in edit mode, since that's what we're in. 406 437 local frame = P.createQueueEditFrame(name) 407 438 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 439 -- Remove the queue window from the root window, since we're in edit mode. 408 440 root:removeChildWindow(queue.window) 441 -- Set the frame window size and position to that of the queue window. 409 442 frame:setArea(queue.window:getArea()) 410 443 queue.edit = frame 411 444 445 -- Reset the text to create a new queue. 412 446 window:setText("") 413 447 end 414 448 449 -- If the button to leave the edit mode has been clicked. 415 450 function P.leaveEditMode_clicked(e) 416 451 hideMenuSheet(P.name) 417 452 end 418 453 454 -- If the button to close the queue has been clicked. 419 455 function P.closeQueue_clicked(e) 420 456 local we = CEGUI.toWindowEventArgs(e) … … 425 461 local queueName = string.sub(nameStr, 10, string.len(nameStr)) 426 462 463 -- Destroy the frame window, 427 464 winMgr:destroyWindow(P.queueList[queueName].edit) 428 465 P.queueList[queueName].edit = nil 466 -- Destroy the queue. 429 467 orxonox.NotificationManager:getInstance():getQueue(queueName):destroy() 430 468 end 431 469 470 -- Helper function. Returns height a queue needs to have to display 'size' items. 432 471 function P.queueHeightHelper(queue, size) 433 472 local listbox = CEGUI.toListbox(queue)
Note: See TracChangeset
for help on using the changeset viewer.