Changeset 8706 for code/trunk/data/gui/scripts/NotificationLayer.lua
- Timestamp:
- Jun 14, 2011, 8:53:28 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/data/gui/scripts/NotificationLayer.lua
r8351 r8706 4 4 5 5 P.queueList = {} 6 P.editMode = false7 6 8 7 P.sampleWindow = nil … … 17 16 function P.createQueue(name, size) 18 17 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 19 local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name) 20 queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent. 18 --local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name) 19 --queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent. 20 local queue = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/Queue/" .. name) 21 queue:setProperty("Alpha", 0.0) 22 --queue:setProperty("FrameEnabled", "false") 21 23 root:addChildWindow(queue) 22 23 queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))24 queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))25 24 26 25 local queueTuple = 27 26 { 28 ["window"] = queue, 29 ["name"] = name, 30 ["edit"] = nil, 31 ["visible"] = false 27 ["window"] = queue, 28 ["name"] = name, 29 ["maxSize"] = size, 30 ["visible"] = false, 31 ["fontSize"] = 12, 32 ["fontColor"] = "FFFFFFFF", 33 ["alignment"] = "LeftAligned", 34 ["items"] = {}, 35 ["first"] = 1, 36 ["last"] = 1 32 37 } 38 39 queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) 40 queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queueTuple, size)))) 33 41 34 42 P.queueList[name] = queueTuple -- name access … … 41 49 42 50 if queue ~= nil then 51 queue.window:getParent():removeChildWindow(queue.window) 43 52 winMgr:destroyWindow(queue.window) 44 53 end … … 52 61 return 53 62 end 54 item = CEGUI.createListboxTextItem(notification) 55 local listbox = CEGUI.toListbox(queue.window) 56 -- Add the item to the top of the listbox. 57 if listbox:getItemCount() == 0 then 58 listbox:addItem(item) 59 else 60 listbox:insertItem(item, listbox:getListboxItemFromIndex(0)) 61 end 63 64 if not guiMgr:usingOldCEGUI() then 65 notification = string.gsub(notification, "%[", "\\%[") -- escape '[' which is used to format text since cegui 0.7 66 end 67 68 local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Queue/" .. queueName .. "/" .. queue.last) 69 item:setText(notification) 70 P.setItemFontHelper(item, queue, true) 71 -- Add the item to the top of the queue. 72 local itemHeight = P.itemHeightHelper(queue) 73 if queue.last-queue.first > 0 then -- If the queue is not empty move all items down 74 for i=queue.first,queue.last-1 do 75 local item = queue.items[i] 76 item:setYPosition(CEGUI.UDim(0, itemHeight*(queue.last-i))) 77 end 78 end 79 queue.window:addChildWindow(item) 80 item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, itemHeight))) 81 item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) 82 item:setProperty("Alpha", 1.0) 83 item:setProperty("InheritsAlpha", "false") 84 item:setProperty("BackgroundEnabled", "false") 85 item:setProperty("FrameEnabled", "false") 86 item:setProperty("HorzFormatting", queue.alignment) 87 queue.items[queue.last] = item 88 queue.last = queue.last+1 62 89 63 90 -- If the queue has been invisible, set it to visible. … … 73 100 return 74 101 end 75 local listbox = CEGUI.toListbox(queue.window) 76 -- Removes the item from the bottom of the listbox. 77 listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1)) 102 local item = queue.items[queue.first] 103 -- Removes the item from the bottom of the queue. 104 queue.window:removeChildWindow(item) 105 winMgr:destroyWindow(item) 106 queue.first = queue.first+1 78 107 79 108 -- Sets the queue to invisible if there are no more notifications in it. 80 if listbox:getItemCount()== 0 then109 if queue.last-queue.first == 0 then 81 110 P.setVisible(queue, false) 82 111 end 83 112 end 84 113 85 -- Removes a notification at a given index from the queue. 114 -- Removes a notification at a given index from the queue. Where the 0th item is the newest and the nth the (n+1)th newest. 86 115 function P.removeNotification(queueName, index) 87 116 local queue = P.queueList[queueName] … … 89 118 return 90 119 end 91 local listbox = CEGUI.toListbox(queue.window) 120 121 index = queue.last-tonumber(index)-1 122 --if index == queue.first then -- If we want to remove the oldest notification, we can just use pop. 123 -- P.popNotification(queueName) 124 -- return 125 --end 126 92 127 -- Removes the item. 93 listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index))) 128 local item = queue.items[index] 129 queue.window:removeChildWindow(item) 130 winMgr:destroyWindow(item) 131 queue.items[index] = nil 132 133 -- Move the items below, up. 134 local itemHeight = P.itemHeightHelper(queue) 135 local moved = false 136 if index > queue.first then -- Move all older notifications up in the list. 137 for i=index-1,-1,queue.first do 138 cout(0, i) 139 item = queue.items[i] 140 item:setYposition(CEGUI.UDim(0, itemHeight*(queue.last-i-1))) 141 queue.items[i+1] = item 142 end 143 end 144 queue.items[queue.first] = nil 145 queue.first = queue.first+1 94 146 95 147 -- Sets the queue to invisible if there are no more notifications in it. 96 if listbox:getItemCount()== 0 then148 if queue.last-queue.first == 0 then 97 149 P.setVisible(queue, false) 98 150 end … … 105 157 return 106 158 end 107 local listbox = CEGUI.toListbox(queue.window) 108 CEGUI.toListbox(queue.window):resetList() 159 for i=queue.first,queue.last-1 do 160 local item = queue.items[i] 161 queue.window:removeChildWindow(item) 162 winMgr:destroyWindow(item) 163 end 164 queue.items = {} 165 queue.first = 1 166 queue.last = 1 109 167 110 168 -- Sets the queue to invisible. … … 121 179 end 122 180 123 -- Enter the edit mode of the notification layer. 124 function P.enterEditMode() 125 P.editMode = true 126 127 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 128 129 --Add control frame window. 130 local window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/ControlWindow") 131 local frame = tolua.cast(window, "CEGUI::FrameWindow") 132 frame:setCloseButtonEnabled(false) 133 frame:setText("NotificationLayer Control Window") 134 frame:setSize(CEGUI.UVector2(CEGUI.UDim(0.7, 0), CEGUI.UDim(0.2, 0))) 135 root:addChildWindow(window) 136 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/ScrollingPane") 137 pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30))) 138 pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26))) 139 window:addChildWindow(pane) 140 141 vertOffset = 0 142 horzOffset = 0 143 -- Line to be able to create a new queue. 144 local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle") 145 newQueueTitle:setText("Create a new NotificationQueue:") 146 local size = getMinTextSize(newQueueTitle) 147 local textHeight = size[1] 148 newQueueTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 149 newQueueTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 150 pane:addChildWindow(newQueueTitle) 151 horzOffset = horzOffset + size[2] + 5 152 local newQueueName = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName") 153 newQueueName:setProperty("ReadOnly", "set:False") 154 newQueueName:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 155 newQueueName:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 156 horzOffset = horzOffset + size[2] + 5 157 pane:addChildWindow(newQueueName) 158 local create = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/CreateNewQueue") 159 create:setText("create") 160 P.sampleWindow:setText("create") 161 size = getMinTextSize(P.sampleWindow) 162 create:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight))) 163 create:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 164 orxonox.GUIManager:subscribeEventHelper(create, "Clicked", P.name .. ".createNewQueue_clicked") 165 pane:addChildWindow(create) 166 horzOffset = horzOffset + size[2]+20 + 5 167 vertOffset = vertOffset + textHeight + 5 168 169 horzOffset = 0 170 -- Button to leave the edit mode. 171 local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton") 172 leave:setText("leave Edit Mode") 173 P.sampleWindow:setText("leave Edit Mode") 174 size = getMinTextSize(P.sampleWindow) 175 leave:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight))) 176 leave:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 177 orxonox.GUIManager:subscribeEventHelper(leave, "Clicked", P.name .. ".leaveEditMode_clicked") 178 pane:addChildWindow(leave) 179 horzOffset = horzOffset + size[2]+20 + 5 180 vertOffset = vertOffset + textHeight + 5 181 182 --Replace all queues with FrameWindows 183 for k,v in pairs(P.queueList) do 184 if v ~= nil then 185 local queue = P.queueList[k] 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 194 end 195 end 196 end 197 198 -- Helper function. Creates a frame for the input queue. 199 function P.createQueueEditFrame(queueName) 200 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 201 202 window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. queueName) 203 local frame = tolua.cast(window, "CEGUI::FrameWindow") 204 frame:setCloseButtonEnabled(true) 205 orxonox.GUIManager:subscribeEventHelper(frame, "CloseClicked", P.name .. ".closeQueue_clicked") 206 frame:setText("NotificationQueue \"" .. queueName .. "\"") 207 root:addChildWindow(window) 208 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/ScrollingPane") 209 pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30))) 210 pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26))) 211 window:addChildWindow(pane) 212 213 local horzOffset = 0 214 local vertOffset = 0 215 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") 218 targetsTitle:setText("Targets:") 219 local size = getMinTextSize(targetsTitle) 220 local textHeight = size[1] 221 targetsTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 222 targetsTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 223 pane:addChildWindow(targetsTitle) 224 horzOffset = horzOffset + size[2] + 5 225 local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets") 226 targets:setProperty("ReadOnly", "set:False") 227 local targetsText = orxonox.NotificationManager:getInstance():getQueue(queueName):getTargets() 228 targets:setText(targetsText) 229 P.sampleWindow:setText(targetsText) 230 size = getMinTextSize(P.sampleWindow) 231 targets:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) 232 targets:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 233 horzOffset = horzOffset + size[2]*2+20 + 5 234 pane:addChildWindow(targets) 235 local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save") 236 save:setText("save") 237 P.sampleWindow:setText("save") 238 size = getMinTextSize(P.sampleWindow) 239 local saveTextWidth = size[2]+20 240 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) 241 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 242 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveTargets_clicked") 243 pane:addChildWindow(save) 244 horzOffset = horzOffset + saveTextWidth 245 vertOffset = vertOffset + textHeight + 5 246 247 horzOffset = 0 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") 250 sizeTitle:setText("Size:") 251 size = getMinTextSize(sizeTitle) 252 sizeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 253 sizeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 254 pane:addChildWindow(sizeTitle) 255 horzOffset = horzOffset + size[2] + 5 256 local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size") 257 queueSize:setProperty("ReadOnly", "set:False") 258 local maxSize = orxonox.NotificationManager:getInstance():getQueue(queueName):getMaxSize() 259 queueSize:setText(maxSize) 260 P.sampleWindow:setText(maxSize) 261 size = getMinTextSize(P.sampleWindow) 262 queueSize:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) 263 queueSize:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 264 horzOffset = horzOffset + size[2]*2+20 + 5 265 pane:addChildWindow(queueSize) 266 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save") 267 save:setText("save") 268 P.sampleWindow:setText("save") 269 size = getMinTextSize(P.sampleWindow) 270 local saveTextWidth = size[2]+20 271 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) 272 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 273 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveSize_clicked") 274 pane:addChildWindow(save) 275 horzOffset = horzOffset + saveTextWidth 276 vertOffset = vertOffset + textHeight + 5 277 278 horzOffset = 0 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") 281 displayTimeTitle:setText("Display time:") 282 size = getMinTextSize(displayTimeTitle) 283 displayTimeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 284 displayTimeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 285 pane:addChildWindow(displayTimeTitle) 286 horzOffset = horzOffset + size[2] + 5 287 local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime") 288 displayTime:setProperty("ReadOnly", "set:False") 289 local time = orxonox.NotificationManager:getInstance():getQueue(queueName):getDisplayTime() 290 displayTime:setText(time) 291 P.sampleWindow:setText(time) 292 size = getMinTextSize(P.sampleWindow) 293 displayTime:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) 294 displayTime:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 295 horzOffset = horzOffset + size[2]*2+20 + 5 296 pane:addChildWindow(displayTime) 297 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save") 298 save:setText("save") 299 P.sampleWindow:setText("save") 300 size = getMinTextSize(P.sampleWindow) 301 local saveTextWidth = size[2]+20 302 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) 303 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 304 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveDisplayTime_clicked") 305 pane:addChildWindow(save) 306 horzOffset = horzOffset + saveTextWidth 307 vertOffset = vertOffset + textHeight + 5 308 309 return window 310 end 311 312 -- Leave the edit mode. 313 function P.leaveEditMode() 314 P.editMode = false 315 316 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 317 --Replace all queues with FrameWindows 318 for k,v in pairs(P.queueList) do 319 if v ~= nil then 320 -- Add the queue window to the root window to have it displayed again. 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. 323 v.window:setArea(v.edit:getArea()) 324 -- Destroy the edit frame. 325 winMgr:destroyWindow(v.edit) 326 v.edit = nil 327 end 328 end 329 330 --Remove control window 331 winMgr:destroyWindow(winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow")) 332 end 333 334 -- Is called after the sheet has been hidden. 335 function P.onQuit() 336 -- If we leave the edit mode we show the sheet again. 337 if P.editMode then 338 P.leaveEditMode() 339 showMenuSheet(P.name, false, true) 340 end 341 end 342 343 -- If the button to save the targets of a queue has been clicked. 344 function P. saveTargets_clicked(e) 345 local we = CEGUI.toWindowEventArgs(e) 346 local name = we.window:getName() 347 348 local match = string.gmatch(name, "EditMode/.*/Targets/Save") 349 local nameStr = match() 350 local queueName = string.sub(nameStr, 10, string.len(nameStr)-13) 351 352 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets") 353 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save") 354 local width = window:getWidth():asAbsolute(1) 355 356 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 357 -- Set the new targets. 358 queue:setTargets(window:getText()) 359 local targets = queue:getTargets() 360 361 window:setText(targets) 362 P.sampleWindow:setText(targets) 363 local size = getMinTextSize(P.sampleWindow) 364 -- Adjust the width of the targets field. 365 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 366 -- Adjust the position of the save button after the targets field. 367 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 368 end 369 370 -- If the button to save the size if a queue has been clicked. 371 function P. saveSize_clicked(e) 372 local we = CEGUI.toWindowEventArgs(e) 373 local name = we.window:getName() 374 375 local match = string.gmatch(name, "EditMode/.*/Size/Save") 376 local nameStr = match() 377 local queueName = string.sub(nameStr, 10, string.len(nameStr)-10) 378 379 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size") 380 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save") 381 local width = window:getWidth():asAbsolute(1) 382 383 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 384 -- Set the new size. 385 queue:setMaxSize(tonumber(window:getText())) 386 local maxSize = queue:getMaxSize() 387 388 window:setText(maxSize) 389 P.sampleWindow:setText(maxSize) 390 local size = getMinTextSize(P.sampleWindow) 391 -- Adjust the width of the size field. 392 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 393 -- Adjust the position of the save button after the size field. 394 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 395 end 396 397 -- If the button to save the display time if a queue has been clicked. 398 function P. saveDisplayTime_clicked(e) 399 local we = CEGUI.toWindowEventArgs(e) 400 local name = we.window:getName() 401 402 local match = string.gmatch(name, "EditMode/.*/DisplayTime/Save") 403 local nameStr = match() 404 local queueName = string.sub(nameStr, 10, string.len(nameStr)-17) 405 406 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime") 407 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save") 408 local width = window:getWidth():asAbsolute(1) 409 410 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 411 -- Set the new display time. 412 queue:setDisplayTime(tonumber(window:getText())) 413 local time = queue:getDisplayTime() 414 415 window:setText(time) 416 P.sampleWindow:setText(time) 417 local size = getMinTextSize(P.sampleWindow) 418 -- Adjust the width of the display time field. 419 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 420 -- Adjust the position of the save button after the display time field. 421 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 422 end 423 424 -- if the button to create a new queue has been clicked. 425 function P.createNewQueue_clicked(e) 426 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName") 427 local name = window:getText() 428 429 local queue = P.queueList[name] 430 -- Test if a queue with that name already exists. 431 if queue ~= nil then 432 window:setText("Queue with that name already exists.") 433 return 434 end 435 436 -- Creates the new queue. 437 orxonox.NotificationManager:getInstance():createQueue(name) 438 439 queue = P.queueList[name] 440 if queue == nil then 441 return 442 end 443 444 -- Create the frame that represents the queue in edit mode, since that's what we're in. 445 local frame = P.createQueueEditFrame(name) 446 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 447 -- Remove the queue window from the root window, since we're in edit mode. 448 root:removeChildWindow(queue.window) 449 -- Set the frame window size and position to that of the queue window. 450 frame:setArea(queue.window:getArea()) 451 queue.edit = frame 452 453 -- Reset the text to create a new queue. 454 window:setText("") 455 end 456 457 -- If the button to leave the edit mode has been clicked. 458 function P.leaveEditMode_clicked(e) 459 hideMenuSheet(P.name) 460 end 461 462 -- If the button to close the queue has been clicked. 463 function P.closeQueue_clicked(e) 464 local we = CEGUI.toWindowEventArgs(e) 465 local name = we.window:getName() 466 467 local match = string.gmatch(name, "EditMode/.*") 468 local nameStr = match() 469 local queueName = string.sub(nameStr, 10, string.len(nameStr)) 470 471 -- Destroy the frame window, 472 winMgr:destroyWindow(P.queueList[queueName].edit) 473 P.queueList[queueName].edit = nil 474 -- Destroy the queue. 475 orxonox.NotificationManager:getInstance():getQueue(queueName):destroy() 181 -- Change the position of the queue. 182 -- 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'. 183 function P.moveQueue(queueName, relativeXPos, absoluteXPos, relativeYpos, absoluteYPos) 184 local queueWindow = P.queueList[queueName].window 185 queueWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(relativeXPos, absoluteXPos), CEGUI.UDim(relativeYpos, absoluteYPos))) 186 end 187 188 -- Change the size of the queue. 189 -- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'. 190 -- Additionally the last two parameters can be ommitted, which leads to the height being set such that all notifications can be displayed. using the size of the queue. 191 function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth) 192 local queue = P.queueList[queueName] 193 local queueWindow = queue.window 194 if queueWindow == nil then 195 return 196 end 197 if absoluteHeigth == nil then 198 absoluteHeigth = P.queueHeightHelper(queue, queue.maxSize) 199 relativeHeight = 0 200 end 201 queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth))) 202 end 203 204 -- Change the horizontal alignment of the displayed notifications. 205 -- The parameters are the name of the queue and the alignment parameter, 206 function P.changeQueueAlignment(queueName, alignment) 207 local queue = P.queueList[queueName] 208 local queueWindow = queue.window 209 if queueWindow == nil then 210 return 211 end 212 213 queue.alignment = alignment 214 local item = nil 215 for i=queue.first,queue.last-1 do 216 item = queue.items[i] 217 item:setProperty("HorzFormatting", queue.alignment) 218 end 219 end 220 221 -- Change the font size of all notifications in a queue. 222 -- The parameters are (in order) 'name of the queue', 'font size'. 223 function P.changeQueueFontSize(queueName, size) 224 local queue = P.queueList[queueName] 225 local queueWindow = queue.window 226 if queueWindow == nil then 227 return 228 end 229 230 queue.fontSize = size 231 for i=queue.first,queue.last-1 do 232 P.setItemFontHelper(queue.items[i], queue, false) 233 end 234 end 235 236 -- Change the font color of all notifications in a queue. 237 -- The parameters are (in order) 'name of the queue', 'ARGB of the font color in hex notation'. 238 function P.changeQueueFontColor(queueName, color) 239 local queue = P.queueList[queueName] 240 local queueWindow = queue.window 241 if queueWindow == nil then 242 return 243 end 244 245 queue.fontColor = color 246 for i=queue.first,queue.last-1 do 247 P.setItemFontHelper(queue.items[i], queue, true) 248 end 249 end 250 251 -- Helper function to set the font size and color of a item of a queue. 252 -- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well' 253 function P.setItemFontHelper(item, queue, changeColor) 254 --local item = tolua.cast(item, "CEGUI::ListboxTextItem") 255 local fontMgr = CEGUI.FontManager:getSingleton() 256 if (fontMgr["isFontPresent"] and fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize)) or -- cegui 0.6 257 (fontMgr["isDefined"] and fontMgr:isDefined("BlueHighway-" .. queue.fontSize)) then -- cegui 0.7 258 item:setFont("BlueHighway-" .. queue.fontSize) 259 else 260 orxonox.GUIManager:addFontHelper("BlueHighway-" .. queue.fontSize, queue.fontSize, "bluehigh.ttf") 261 item:setFont("BlueHighway-" .. queue.fontSize) 262 end 263 if changeColor then 264 item:setProperty("TextColours", "tl:" .. queue.fontColor .. " tr:" .. queue.fontColor .. " bl:" .. queue.fontColor .. " br:" .. queue.fontColor .. "") 265 end 476 266 end 477 267 478 268 -- Helper function. Returns height a queue needs to have to display 'size' items. 479 269 function P.queueHeightHelper(queue, size) 480 local listbox = CEGUI.toListbox(queue) 481 local item = CEGUI.createListboxTextItem("Text") 482 listbox:addItem(item) 483 local singleItemHeight = listbox:getTotalItemsHeight() 484 local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel()) 485 local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue) 486 local frameHeight = queue:getUnclippedOuterRect():getHeight() - formattedArea:getHeight() 487 listbox:removeItem(item) 488 return frameHeight + singleItemHeight*size 270 --local listbox = CEGUI.toListbox(queue.window) 271 --local item = CEGUI.createListboxTextItem("Text") 272 --P.setItemFontHelper(item, queue, false) 273 --listbox:addItem(item) 274 --local singleItemHeight = listbox:getTotalItemsHeight() 275 local singleItemHeight = P.itemHeightHelper(queue) 276 --local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel()) 277 --local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window) 278 --local frameHeight = queue.window:getUnclippedOuterRect():getHeight() - formattedArea:getHeight() 279 --listbox:removeItem(item) 280 --return frameHeight + singleItemHeight*size 281 return singleItemHeight*size + 1 282 end 283 284 function P.itemHeightHelper(queue) 285 local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Test/") 286 item:setText("text") 287 P.setItemFontHelper(item, queue, true) 288 queue.window:addChildWindow(item) 289 item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0))) 290 item:setProperty("FrameEnabled", "false") 291 local height = getStaticTextWindowHeight(item) 292 queue.window:removeChildWindow(item) 293 winMgr:destroyWindow(item) 294 return height 489 295 end 490 296
Note: See TracChangeset
for help on using the changeset viewer.