Changeset 7395
- Timestamp:
- Sep 9, 2010, 10:59:01 PM (14 years ago)
- Location:
- code/branches/notifications
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/notifications/data/gui/scripts/GUISheet.lua
r6748 r7395 40 40 end 41 41 42 -- Override this function if you need to do work just after the sheet has been hidden 43 function P:afterHide() 44 end 45 42 46 function P:load() 43 47 -- Load the layout that describes the sheet -
code/branches/notifications/data/gui/scripts/MiscConfigMenu.lua
r7284 r7395 51 51 table.insert(P.nameList, "Number of Bots") 52 52 table.insert(P.nameList, "UnderAttack: game time") 53 table.insert(P.nameList, "TeamDeathmatch: Num er of teams")53 table.insert(P.nameList, "TeamDeathmatch: Number of teams") 54 54 table.insert(P.nameList, "Playername") 55 55 table.insert(P.nameList, "Chat: display time") -
code/branches/notifications/data/gui/scripts/NotificationLayer.lua
r7362 r7395 1 1 -- NotificationLayer.lua 2 2 3 local P = createMenuSheet("NotificationLayer" )3 local P = createMenuSheet("NotificationLayer", true, TriBool.True, TriBool.True) 4 4 5 5 P.queueList = {} 6 P.nameList = {}7 P.visible = nil8 6 P.editMode = false 9 P.editList = {} 7 8 P.sampleWindow = nil 9 10 function P.onLoad() 11 orxonox.NotificationManager:getInstance():loadQueues() 12 P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/SampleWindow") 13 end 10 14 11 15 function P.createQueue(name, size) … … 18 22 queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size)))) 19 23 20 P.setVisible(queue, false) 21 22 table.insert(P.queueList, queue) 23 table.insert(P.nameList, name) 24 --TODO: Check name for uniqueness. 24 local queueTuple = 25 { 26 ["window"] = queue, 27 ["name"] = name, 28 ["edit"] = nil, 29 ["visible"] = false 30 } 31 32 P.queueList[name] = queueTuple -- name access 33 P.setVisible(queueTuple, false) 25 34 end 26 35 27 36 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 37 local queue = P.queueList[name] 38 38 39 39 if queue ~= nil then 40 winMgr:destroyWindow(queue) 41 end 40 winMgr:destroyWindow(queue.window) 41 end 42 queue = nil 42 43 end 43 44 44 45 function P.pushNotification(queueName, notification) 45 local queue = P. nameToQueueHelper(queueName)46 if queue == nil then 47 cout(0, " Queue is nil!")46 local queue = P.queueList[queueName] 47 if queue == nil then 48 cout(0, "0Queue is nil! " .. queueName) 48 49 return 49 50 end 50 51 item = CEGUI.createListboxTextItem(notification) 51 local listbox = CEGUI.toListbox(queue )52 local listbox = CEGUI.toListbox(queue.window) 52 53 if listbox:getItemCount() == 0 then 53 54 listbox:addItem(item) … … 56 57 end 57 58 58 if P.visible == false then59 if queue.visible == false then 59 60 P.setVisible(queue, true) 60 61 end … … 62 63 63 64 function P.popNotification(queueName) 64 local queue = P. nameToQueueHelper(queueName)65 if queue == nil then 66 cout(0, " Queue is nil!")67 return 68 end 69 local listbox = CEGUI.toListbox(queue )65 local queue = P.queueList[queueName] 66 if queue == nil then 67 cout(0, "1Queue is nil! " .. queueName) 68 return 69 end 70 local listbox = CEGUI.toListbox(queue.window) 70 71 listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1)) 71 72 … … 76 77 77 78 function P.removeNotification(queueName, index) 78 local queue = P. nameToQueueHelper(queueName)79 if queue == nil then 80 cout(0, " Queue is nil!")81 return 82 end 83 local listbox = CEGUI.toListbox(queue )79 local queue = P.queueList[queueName] 80 if queue == nil then 81 cout(0, "2Queue is nil! " .. queueName) 82 return 83 end 84 local listbox = CEGUI.toListbox(queue.window) 84 85 listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index))) 85 86 … … 90 91 91 92 function P.clearQueue(name) 92 local queue = P. nameToQueueHelper(name)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()93 local queue = P.queueList[name] 94 if queue == nil then 95 cout(0, "3Queue is nil! " .. name) 96 return 97 end 98 local listbox = CEGUI.toListbox(queue.window) 99 CEGUI.toListbox(queue.window):resetList() 99 100 100 101 P.setVisible(queue, false) 101 102 end 102 103 103 function P.changePosition(name, xPos, yPos)104 local queue = P.nameToQueueHelper(name)105 if queue == nil then106 cout(0, "Queue is nil!")107 return108 end109 queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0)))110 queue:setWidth(CEGUI.UDim(1.0, -xPos))111 end112 113 104 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)))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))) 120 111 end 121 112 122 113 function P.setVisible(queue, visible) 123 queue:setVisible(visible) 124 P.visible = visible 114 if queue == nil then 115 cout(0, "6Queue is nil! " .. queue.name) 116 return 117 end 118 queue.window:setVisible(visible) 119 queue.visible = visible 125 120 end 126 121 127 122 function P.enterEditMode() 128 123 P.editMode = true 124 125 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 126 127 --Add control frame window. 128 local window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/ControlWindow") 129 local frame = tolua.cast(window, "CEGUI::FrameWindow") 130 frame:setCloseButtonEnabled(false) 131 frame:setText("NotificationLayer Control Window") 132 frame:setSize(CEGUI.UVector2(CEGUI.UDim(0.7, 0), CEGUI.UDim(0.2, 0))) 133 root:addChildWindow(window) 134 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/ScrollingPane") 135 pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30))) 136 pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26))) 137 window:addChildWindow(pane) 138 139 vertOffset = 0 140 horzOffset = 0 141 local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle") 142 newQueueTitle:setText("Create a new NotificationQueue:") 143 local size = getMinTextSize(newQueueTitle) 144 local textHeight = size[1] 145 newQueueTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 146 newQueueTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 147 pane:addChildWindow(newQueueTitle) 148 horzOffset = horzOffset + size[2] + 5 149 local newQueueName = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName") 150 newQueueName:setProperty("ReadOnly", "set:False") 151 newQueueName:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 152 newQueueName:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 153 horzOffset = horzOffset + size[2] + 5 154 pane:addChildWindow(newQueueName) 155 local create = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/CreateNewQueue") 156 create:setText("create") 157 P.sampleWindow:setText("create") 158 size = getMinTextSize(P.sampleWindow) 159 create:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight))) 160 create:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 161 orxonox.GUIManager:subscribeEventHelper(create, "Clicked", P.name .. ".createNewQueue_clicked") 162 pane:addChildWindow(create) 163 horzOffset = horzOffset + size[2]+20 + 5 164 vertOffset = vertOffset + textHeight + 5 165 166 horzOffset = 0 167 local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton") 168 leave:setText("leave Edit Mode") 169 P.sampleWindow:setText("leave Edit Mode") 170 size = getMinTextSize(P.sampleWindow) 171 leave:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight))) 172 leave:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 173 orxonox.GUIManager:subscribeEventHelper(leave, "Clicked", P.name .. ".leaveEditMode_clicked") 174 pane:addChildWindow(leave) 175 horzOffset = horzOffset + size[2]+20 + 5 176 vertOffset = vertOffset + textHeight + 5 177 178 --Replace all queues with FrameWindows 179 for k,v in pairs(P.queueList) do 180 if v ~= nil then 181 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 188 end 189 end 190 end 191 192 function P.createQueueEditFrame(name) 193 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 194 window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. name) 195 local frame = tolua.cast(window, "CEGUI::FrameWindow") 196 frame:setCloseButtonEnabled(false) 197 frame:setText("NotificationQueue \"" .. name .. "\"") 198 root:addChildWindow(window) 199 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/ScrollingPane") 200 pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30))) 201 pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26))) 202 window:addChildWindow(pane) 203 204 local horzOffset = 0 205 local vertOffset = 0 206 207 local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/TargetsTitle") 208 targetsTitle:setText("Targets:") 209 local size = getMinTextSize(targetsTitle) 210 local textHeight = size[1] 211 targetsTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 212 targetsTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 213 pane:addChildWindow(targetsTitle) 214 horzOffset = horzOffset + size[2] + 5 215 local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Targets") 216 targets:setProperty("ReadOnly", "set:False") 217 local targetsText = orxonox.NotificationManager:getInstance():getQueue(name):getTargets() 218 targets:setText(targetsText) 219 P.sampleWindow:setText(targetsText) 220 size = getMinTextSize(P.sampleWindow) 221 targets:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) 222 targets:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 223 cout(0, horzOffset .. "|" .. targets:getXPosition():asAbsolute(1) .. "|" .. size[2]*2+20) 224 horzOffset = horzOffset + size[2]*2+20 + 5 225 pane:addChildWindow(targets) 226 local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Targets/Save") 227 save:setText("save") 228 P.sampleWindow:setText("save") 229 size = getMinTextSize(P.sampleWindow) 230 local saveTextWidth = size[2]+20 231 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) 232 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 233 cout(0, horzOffset .. "|" .. save:getXPosition():asAbsolute(1)) 234 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveTargets_clicked") 235 pane:addChildWindow(save) 236 horzOffset = horzOffset + saveTextWidth 237 vertOffset = vertOffset + textHeight + 5 238 239 horzOffset = 0 240 local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/SizeTitle") 241 sizeTitle:setText("Size:") 242 size = getMinTextSize(sizeTitle) 243 sizeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 244 sizeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 245 pane:addChildWindow(sizeTitle) 246 horzOffset = horzOffset + size[2] + 5 247 local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Size") 248 queueSize:setProperty("ReadOnly", "set:False") 249 local maxSize = orxonox.NotificationManager:getInstance():getQueue(name):getMaxSize() 250 queueSize:setText(maxSize) 251 P.sampleWindow:setText(maxSize) 252 size = getMinTextSize(P.sampleWindow) 253 queueSize:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) 254 queueSize:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 255 horzOffset = horzOffset + size[2]*2+20 + 5 256 pane:addChildWindow(queueSize) 257 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Size/Save") 258 save:setText("save") 259 P.sampleWindow:setText("save") 260 size = getMinTextSize(P.sampleWindow) 261 local saveTextWidth = size[2]+20 262 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) 263 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 264 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveSize_clicked") 265 pane:addChildWindow(save) 266 horzOffset = horzOffset + saveTextWidth 267 vertOffset = vertOffset + textHeight + 5 268 269 horzOffset = 0 270 local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTimeTitle") 271 displayTimeTitle:setText("Display time:") 272 size = getMinTextSize(displayTimeTitle) 273 displayTimeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 274 displayTimeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 275 pane:addChildWindow(displayTimeTitle) 276 horzOffset = horzOffset + size[2] + 5 277 local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTime") 278 displayTime:setProperty("ReadOnly", "set:False") 279 local time = orxonox.NotificationManager:getInstance():getQueue(name):getDisplayTime() 280 displayTime:setText(time) 281 P.sampleWindow:setText(time) 282 size = getMinTextSize(P.sampleWindow) 283 displayTime:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) 284 displayTime:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 285 horzOffset = horzOffset + size[2]*2+20 + 5 286 pane:addChildWindow(displayTime) 287 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTime/Save") 288 save:setText("save") 289 P.sampleWindow:setText("save") 290 size = getMinTextSize(P.sampleWindow) 291 local saveTextWidth = size[2]+20 292 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) 293 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 294 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveDisplayTime_clicked") 295 pane:addChildWindow(save) 296 horzOffset = horzOffset + saveTextWidth 297 vertOffset = vertOffset + textHeight + 5 298 299 return window 300 end 301 302 function P.leaveEditMode() 303 P.editMode = false 129 304 130 305 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") … … 132 307 for k,v in pairs(P.queueList) do 133 308 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 root:addChildWindow(frame) 138 P.editList[k] = frame 309 root:addChildWindow(v.window) 310 v.window:setArea(v.edit:getArea()) 311 winMgr:destroyWindow(v.edit) 312 v.edit = nil 139 313 end 140 314 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 156 157 showMenuSheet(P.name, false, true) 158 end 159 160 function P.onHide() 315 316 --Remove control window 317 winMgr:destroyWindow(winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow")) 318 end 319 320 function P.afterHide() 161 321 if P.editMode then 162 322 P.leaveEditMode() 163 end 164 end 165 166 function P.nameToQueueHelper(name) 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 323 showMenuSheet(P.name, false, true) 324 end 325 end 326 327 function P. saveTargets_clicked(e) 328 local we = CEGUI.toWindowEventArgs(e) 329 local name = we.window:getName() 330 331 local match = string.gmatch(name, "EditMode/.*/Targets/Save") 332 local nameStr = match() 333 local queueName = string.sub(nameStr, 10, string.len(nameStr)-13) 334 335 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets") 336 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save") 337 local width = window:getXPosition():asAbsolute(1) 338 339 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 340 queue:setTargets(window:getText()) 341 local targets = queue:getTargets() 342 343 window:setText(targets) 344 P.sampleWindow:setText(targets) 345 local size = getMinTextSize(P.sampleWindow) 346 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 347 cout(0, width .. "|" .. size[2]*2+20 .. "|" .. window:getWidth():asAbsolute(1) .. "|" .. save:getXPosition():asAbsolute(1)) 348 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 349 end 350 351 function P. saveSize_clicked(e) 352 local we = CEGUI.toWindowEventArgs(e) 353 local name = we.window:getName() 354 355 local match = string.gmatch(name, "EditMode/.*/Size/Save") 356 local nameStr = match() 357 local queueName = string.sub(nameStr, 10, string.len(nameStr)-10) 358 359 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size") 360 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save") 361 local width = window:getXPosition():asAbsolute(1) 362 363 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 364 queue:setMaxSize(tonumber(window:getText())) 365 local maxSize = queue:getMaxSize() 366 367 window:setText(maxSize) 368 P.sampleWindow:setText(maxSize) 369 local size = getMinTextSize(P.sampleWindow) 370 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 371 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 372 end 373 374 function P. saveDisplayTime_clicked(e) 375 local we = CEGUI.toWindowEventArgs(e) 376 local name = we.window:getName() 377 378 local match = string.gmatch(name, "EditMode/.*/DisplayTime/Save") 379 local nameStr = match() 380 local queueName = string.sub(nameStr, 10, string.len(nameStr)-17) 381 382 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime") 383 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save") 384 local width = window:getXPosition():asAbsolute(1) 385 386 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 387 queue:setDisplayTime(tonumber(window:getText())) 388 local time = queue:getDisplayTime() 389 390 window:setText(time) 391 P.sampleWindow:setText(time) 392 local size = getMinTextSize(P.sampleWindow) 393 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 394 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 395 end 396 397 function P.createNewQueue_clicked(e) 398 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName") 399 local name = window:getText() 400 orxonox.NotificationManager:getInstance():createQueue(name) 401 402 local queue = P.queueList[name] 403 if queue == nil then 404 cout(0, "7Queue is nil! " .. name) 405 return 406 end 407 408 local frame = P.createQueueEditFrame(name) 409 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 410 root:removeChildWindow(queue.window) 411 frame:setArea(queue.window:getArea()) 412 queue.edit = frame 413 414 window:setText("") 415 end 416 417 function P.leaveEditMode_clicked(e) 418 hideMenuSheet(P.name) 175 419 end 176 420 … … 188 432 189 433 return P 190 -
code/branches/notifications/data/gui/scripts/SheetManager.lua
r7342 r7395 185 185 hideCursor() 186 186 end 187 188 sheetTuple.sheet:afterHide() 187 189 end 188 190 -
code/branches/notifications/src/modules/notifications/CMakeLists.txt
r7354 r7395 13 13 TOLUA_FILES 14 14 NotificationManager.h 15 NotificationQueue.h 15 16 PCH_FILE 16 17 NotificationsPrecompiledHeaders.h -
code/branches/notifications/src/modules/notifications/NotificationManager.cc
r7362 r7395 28 28 29 29 /** 30 @file 30 @file NotificationManager.cc 31 31 @brief Implementation of the NotificationManager class. 32 32 */ … … 43 43 #include "NotificationQueue.h" 44 44 45 #include "ToluaBindNotifications.h" 46 45 47 namespace orxonox 46 48 { … … 49 51 const std::string NotificationManager::NONE("none"); 50 52 53 // Register tolua_open function when loading the library. 54 DeclareToluaInterface(Notifications); 55 51 56 ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false); 52 57 … … 65 70 66 71 ModifyConsoleCommand("enterEditMode").setObject(this); 67 68 if(GameMode::showsGraphics()) 69 { 70 GUIManager::getInstance().loadGUI("NotificationLayer"); 71 72 // Create first queue: 73 this->queues_.push_back(new NotificationQueue("all")); 74 } 72 73 COUT(3) << "NotificatioManager created." << std::endl; 75 74 } 76 75 … … 82 81 { 83 82 ModifyConsoleCommand("enterEditMode").setObject(NULL); 83 84 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 85 it->second->destroy(); 86 87 COUT(3) << "NotificationManager destroyed." << std::endl; 84 88 } 85 89 86 90 void NotificationManager::preDestroy(void) 87 91 { 88 for(std::vector<NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) 89 (*it)->destroy(); 92 for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); ) 93 { 94 NotificationQueue* queue = (*it).second; 95 it++; 96 queue->destroy(); 97 } 90 98 this->queues_.clear(); 91 99 } … … 101 109 bool NotificationManager::registerNotification(Notification* notification) 102 110 { 103 104 if(notification == NULL) //!< A NULL-Notification cannot be registered. 111 if(notification == NULL) // A NULL-Notification cannot be registered. 105 112 return false; 106 113 107 114 std::time_t time = std::time(0); //TODO: Doesn't this expire? //!< Get current time. 108 115 109 this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time,notification));110 111 if(notification->getSender() == N ONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.116 this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification)); 117 118 if(notification->getSender() == NotificationManager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications. 112 119 return true; 113 120 114 121 bool all = false; 115 if(notification->getSender() == ALL) // If all are the sender, then the Notifications is added to every NotificationListener.122 if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener. 116 123 all = true; 117 124 … … 119 126 for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all listeners. 120 127 { 121 std::set<std::string> set = it->first->getTargetsSet(); 122 if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TODO: Make sure this works. 128 std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet(); 129 bool bAll = set.find(NotificationManager::ALL) != set.end(); 130 if(all || bAll || set.find(notification->getSender()) != set.end()) //TODO: Make sure this works. 123 131 { 124 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); // Insert the Notification in the Notifications list of the current NotificationListener. 132 if(!bAll) 133 { 134 this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the Notifications list of the current NotificationListener. 135 } 125 136 it->first->update(notification, time); // Update the listener. 126 137 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification); … … 132 143 } 133 144 134 COUT(4) << "Notification registered with the NotificationManager." << std::endl;145 COUT(4) << "Notification (&" << notification << ") registered with the NotificationManager." << std::endl; 135 146 136 147 return true; … … 154 165 this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1; 155 166 156 // If the Notification is no longer present in any of the NotificationListeners it can be removed from the map of all Notifications and be destroyed. 157 if(this->listenerCounter_[notification] == (unsigned int) 0) 158 { 159 this->removeNotification(notification, this->allNotificationsList_); 160 this->listenerCounter_.erase(notification); 161 notification->destroy(); 162 } 163 164 COUT(4) << "Notification unregistered with the NotificationManager." << std::endl; 167 COUT(4) << "Notification (&" << notification << ")unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl; 165 168 } 166 169 … … 175 178 Returns true if successful. 176 179 */ 177 //TODO: Needed?178 180 bool NotificationManager::removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map) 179 181 { … … 206 208 this->listenerList_[listener] = index; // Add the NotificationListener to the list of listeners. 207 209 208 std::set<std::string > set = listener->getTargetsSet(); //TODO: Does this work?210 std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet(); 209 211 210 212 // If all senders are the target of the listener, then the list of notification for that specific listener is te same as the list of all Notifications. 211 if(set.find(ALL) != set.end()) 212 { 213 bool bAll = set.find(NotificationManager::ALL) != set.end(); 214 std::multimap<std::time_t, Notification*> map; 215 if(bAll) 213 216 this->notificationLists_[index] = &this->allNotificationsList_; 214 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 215 return true; 216 } 217 218 this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>; 219 std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index]; 217 else 218 { 219 this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>; 220 map = *this->notificationLists_[index]; 221 } 220 222 221 223 // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener. 222 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)223 { 224 if( set.find(it->second->getSender()) != set.end()) // Checks whether the overlayhas the sender of the current notification as target.224 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 225 { 226 if(bAll || set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current notification as target. 225 227 { 226 map.insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 228 if(!bAll) 229 map.insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 227 230 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second); 228 231 if(counterIt == this->listenerCounter_.end()) … … 288 291 return false; 289 292 290 std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener.291 292 if(notifications == NULL) // Returns NULL, if there are no Notifications.293 return true;293 std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener. 294 295 if(notifications == NULL) // Returns false, if there are no Notifications. 296 return false; 294 297 295 298 std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest; 296 299 itLowest = notifications->lower_bound(timeFrameStart); 297 itHighest = notifications->upper_bound(timeFrame Start);300 itHighest = notifications->upper_bound(timeFrameEnd); 298 301 299 302 for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time Frame to the end of it. 300 { 301 map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); // Add the found Notifications to the map. 302 } 303 map->insert(std::pair<std::time_t, Notification*>(it->first,it->second)); // Add the found Notifications to the map. 303 304 304 305 return true; 305 306 } 306 307 307 void NotificationManager::createQueue(const std::string& name, const std::string& targets, unsigned int size, unsigned int displayTime) 308 { 309 this->queues_.push_back(new NotificationQueue(name, targets, size, displayTime)); 308 void NotificationManager::loadQueues(void) 309 { 310 new NotificationQueue("all"); 311 } 312 313 void NotificationManager::createQueue(const std::string& name) 314 { 315 new NotificationQueue(name); 316 } 317 318 NotificationQueue* NotificationManager::getQueue(const std::string & name) 319 { 320 std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name); 321 if(it == this->queues_.end()) 322 return NULL; 323 324 return (*it).second; 325 } 326 327 bool NotificationManager::registerQueue(NotificationQueue* queue) 328 { 329 return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second; 330 } 331 332 void NotificationManager::unregisterQueue(NotificationQueue* queue) 333 { 334 this->queues_.erase(queue->getName()); 310 335 } 311 336 -
code/branches/notifications/src/modules/notifications/NotificationManager.h
r7354 r7395 28 28 29 29 /** 30 @file 30 @file NotificationManager.h 31 31 @brief Definition of the NotificationManager class. 32 32 */ … … 40 40 #include <map> 41 41 #include <string> 42 #include <vector>43 42 44 43 #include "util/Singleton.h" … … 55 54 Damian 'Mozork' Frick 56 55 */ 57 class _NotificationsExport NotificationManager 56 class _NotificationsExport NotificationManager // tolua_export 58 57 : public Singleton<NotificationManager>, public OrxonoxClass 59 58 { // tolua_export … … 75 74 void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager. 76 75 77 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe.76 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe. 78 77 79 78 /** … … 84 83 @return Returns true if successful. 85 84 */ 86 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)85 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay) 87 86 { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); } 88 87 89 88 void enterEditMode(void); 90 89 91 void createQueue(const std::string& name, const std::string& targets, unsigned int size, unsigned int displayTime); // tolua_export 90 // tolua_begin 91 void loadQueues(void); 92 93 void createQueue(const std::string& name); 94 orxonox::NotificationQueue* getQueue(const std::string & name); 95 // tolua_end 96 97 bool registerQueue(NotificationQueue* queue); 98 void unregisterQueue(NotificationQueue* queue); 92 99 93 100 private: 94 101 static NotificationManager* singletonPtr_s; 95 102 96 std:: vector<NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.103 std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager. 97 104 98 105 int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. 99 106 100 std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all notifications are stored.101 std::map<NotificationListener*, int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.102 std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.107 std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all notifications are stored. 108 std::map<NotificationListener*, int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. 109 std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. 103 110 std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with. 104 111 -
code/branches/notifications/src/modules/notifications/NotificationQueue.cc
r7354 r7395 35 35 36 36 #include <map> 37 #include <sstream> 37 38 38 39 #include "core/CoreIncludes.h" … … 62 63 this->setDisplayTime(displayTime); 63 64 65 bool queueRegistered = NotificationManager::getInstance().registerQueue(this); 66 this->registered_ = true; 67 if(!queueRegistered) 68 { 69 this->registered_ = false; 70 COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl; 71 return; 72 } 73 64 74 this->create(); 65 66 NotificationManager::getInstance().registerListener(this); 67 this->registered_ = true; 75 76 bool listenerRegistered = NotificationManager::getInstance().registerListener(this); 77 if(!listenerRegistered) 78 { 79 this->registered_ = false; 80 NotificationManager::getInstance().unregisterQueue(this); 81 COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl; 82 return; 83 } 68 84 69 85 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; … … 77 93 { 78 94 this->targets_.clear(); 79 this->clear();80 95 81 96 if(this->registered_) 97 { 98 this->clear(); 99 82 100 NotificationManager::getInstance().unregisterListener(this); 101 NotificationManager::getInstance().unregisterQueue(this); 102 } 83 103 } 84 104 … … 100 120 void NotificationQueue::create(void) 101 121 { 102 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");122 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")"); 103 123 } 104 124 … … 144 164 } 145 165 146 if(notifications->empty()) 147 return; 148 149 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications. 150 this->push(it->second, it->first); 166 if(!notifications->empty()) 167 { 168 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications. 169 { 170 this->push(it->second, it->first); 171 } 172 } 151 173 152 174 delete notifications; 153 175 154 COUT( 4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl;176 COUT(3) << "NotificationQueue '" << this->getName() << "' updated." << std::endl; //TODO: Level 4. 155 177 } 156 178 … … 167 189 this->push(notification, time); 168 190 169 COUT( 4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl;191 COUT(3) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; //TODO: Level 4. 170 192 } 171 193 … … 253 275 bool NotificationQueue::setName(const std::string& name) 254 276 { 255 //TODO: Test uniqueness of name.256 277 this->name_ = name; 257 278 return true; … … 268 289 void NotificationQueue::setMaxSize(unsigned int size) 269 290 { 291 if(this->maxSize_ == size) 292 return; 293 270 294 this->maxSize_ = size; 271 295 this->sizeChanged(); … … 292 316 void NotificationQueue::setDisplayTime(unsigned int time) 293 317 { 318 if(this->displayTime_ == time) 319 return; 320 294 321 this->displayTime_ = time; 295 this->update(); 322 323 if(this->registered_) 324 this->update(); 296 325 } 297 326 … … 299 328 @brief 300 329 Produces all targets concatinated as string, with kommas (',') as seperators. 301 @param string 302 Pointer to a string which will be used by the method to fill with the concatination of the targets. 303 @return 304 Returns true if successful. 305 */ 306 bool NotificationQueue::getTargets(std::string* string) const 307 { 308 if(string == NULL) 309 { 310 COUT(4) << "Input string must have memory allocated." << std::endl; 311 return false; 312 } 313 string->clear(); 330 @return 331 Returns the targets as a string. 332 */ 333 const std::string& NotificationQueue::getTargets(void) const 334 { 335 std::stringstream stream; 314 336 bool first = true; 315 for(std::set<std::string >::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets.337 for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets. 316 338 { 317 339 if(!first) 318 *string +=',';340 stream << ','; 319 341 else 320 342 first = false; 321 *string +=*it;322 } 323 324 return true;343 stream << *it; 344 } 345 346 return *(new std::string(stream.str())); 325 347 } 326 348 … … 352 374 } 353 375 376 if(this->registered_) 377 { 378 NotificationManager::getInstance().unregisterListener(this); 379 NotificationManager::getInstance().registerListener(this); 380 } 381 354 382 return true; 355 383 } -
code/branches/notifications/src/modules/notifications/NotificationQueue.h
r7354 r7395 46 46 #include "NotificationManager.h" 47 47 48 namespace orxonox 49 { 48 namespace orxonox // tolua_export 49 { // tolua_export 50 50 51 51 //! Container to allow easy handling. … … 68 68 Damian 'Mozork' Frick 69 69 */ 70 class _NotificationsExport NotificationQueue : public Tickable, public NotificationListener 71 { 70 class _NotificationsExport NotificationQueue // tolua_export 71 : public Tickable, public NotificationListener 72 { // tolua_export 72 73 73 74 public: … … 80 81 void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue. 81 82 83 // tolua_begin 82 84 /** 83 85 @brief Get the name of the NotificationQueue. … … 87 89 { return this->name_; } 88 90 91 void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications. 89 92 /** 90 93 @brief Returns the maximum number of Notifications displayed. … … 93 96 inline unsigned int getMaxSize() const 94 97 { return this->maxSize_; } 98 99 void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed. 100 /** 101 @brief Returns the time interval the Notification is displayed. 102 @return Returns the display time. 103 */ 104 inline float getDisplayTime() const 105 { return this->displayTime_; } 106 // tolua_end 107 95 108 /** 96 109 @brief Returns the current number of Notifications displayed. … … 99 112 inline unsigned int getSize() const 100 113 { return this->size_; } 101 /**102 @brief Returns the time interval the Notification is displayed.103 @return Returns the display time.104 */105 inline float getDisplayTime() const106 { return this->displayTime_; }107 114 108 115 /** … … 110 117 @return Retuns a set of string holding the different targets. 111 118 */ 112 inline const std::set<std::string > & getTargetsSet()119 inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet() 113 120 { return this->targets_; } 114 bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets. 121 122 // tolua_begin 123 bool setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue. 124 const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets. 125 // tolua_end 115 126 116 127 private: … … 124 135 unsigned int displayTime_; //!< The time a Notification is displayed. 125 136 126 std::set<std::string > targets_; //!< The targets the Queue displays Notifications of.137 std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the Queue displays Notifications of. 127 138 128 139 std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. //TODO: Would set work as well? … … 139 150 bool setName(const std::string& name); //!< Sets the name of the NotificationQueue. 140 151 141 void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.142 void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.143 144 bool setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.145 146 152 void sizeChanged(void); //!< Adjusts the NotificationQueue, when the maximum size has changed. 147 153 … … 152 158 void clear(void); //!< Clears the queue by removing all Notifications. 153 159 154 }; 160 }; // tolua_export 155 161 156 } 162 } // tolua_export 157 163 158 164 #endif /* _NotificationOverlay_H__ */ -
code/branches/notifications/src/orxonox/interfaces/NotificationListener.h
r7163 r7395 49 49 /** 50 50 @brief 51 Struct that overloads the compare operation between two PickupIdentifier pointers. 52 */ 53 //TODO: 54 struct NotificationListenerStringCompare 55 { 56 bool operator() (const std::string& lhs, const std::string& rhs) const 57 { return lhs.compare(rhs) < 0; } 58 }; 59 60 /** 61 @brief 51 62 NotificationListener interface. 52 63 @author … … 59 70 virtual ~NotificationListener() {} 60 71 61 virtual const std::set<std::string > & getTargetsSet() = 0;72 virtual const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet() = 0; 62 73 virtual void update(void) = 0; 63 74 virtual void update(Notification* notification, const std::time_t & time) = 0;
Note: See TracChangeset
for help on using the changeset viewer.