Changeset 8446 for code/branches
- Timestamp:
- May 11, 2011, 12:21:32 PM (14 years ago)
- Location:
- code/branches/tutoriallevel2
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/tutoriallevel2/data/gui/scripts/NotificationLayer.lua
r8378 r8446 4 4 5 5 P.queueList = {} 6 P.editMode = false7 6 8 7 P.sampleWindow = nil … … 248 247 end 249 248 250 -- Enter the edit mode of the notification layer.251 function P.enterEditMode()252 P.editMode = true253 254 local root = winMgr:getWindow("orxonox/NotificationLayer/Root")255 256 --Add control frame window.257 local window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/ControlWindow")258 local frame = tolua.cast(window, "CEGUI::FrameWindow")259 frame:setCloseButtonEnabled(false)260 frame:setText("NotificationLayer Control Window")261 frame:setSize(CEGUI.UVector2(CEGUI.UDim(0.7, 0), CEGUI.UDim(0.2, 0)))262 root:addChildWindow(window)263 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/ScrollingPane")264 pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30)))265 pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26)))266 window:addChildWindow(pane)267 268 vertOffset = 0269 horzOffset = 0270 -- Line to be able to create a new queue.271 local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle")272 newQueueTitle:setText("Create a new NotificationQueue:")273 local size = getMinTextSize(newQueueTitle)274 local textHeight = size[1]275 newQueueTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))276 newQueueTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))277 pane:addChildWindow(newQueueTitle)278 horzOffset = horzOffset + size[2] + 5279 local newQueueName = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName")280 newQueueName:setProperty("ReadOnly", "set:False")281 newQueueName:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))282 newQueueName:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))283 horzOffset = horzOffset + size[2] + 5284 pane:addChildWindow(newQueueName)285 local create = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/CreateNewQueue")286 create:setText("create")287 P.sampleWindow:setText("create")288 size = getMinTextSize(P.sampleWindow)289 create:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight)))290 create:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))291 orxonox.GUIManager:subscribeEventHelper(create, "Clicked", P.name .. ".createNewQueue_clicked")292 pane:addChildWindow(create)293 horzOffset = horzOffset + size[2]+20 + 5294 vertOffset = vertOffset + textHeight + 5295 296 horzOffset = 0297 -- Button to leave the edit mode.298 local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton")299 leave:setText("leave Edit Mode")300 P.sampleWindow:setText("leave Edit Mode")301 size = getMinTextSize(P.sampleWindow)302 leave:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight)))303 leave:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))304 orxonox.GUIManager:subscribeEventHelper(leave, "Clicked", P.name .. ".leaveEditMode_clicked")305 pane:addChildWindow(leave)306 horzOffset = horzOffset + size[2]+20 + 5307 vertOffset = vertOffset + textHeight + 5308 309 --Replace all queues with FrameWindows310 for k,v in pairs(P.queueList) do311 if v ~= nil then312 local queue = P.queueList[k]313 -- Remove the window that displays the queue from the root window such that it is no longer displayed.314 root:removeChildWindow(v.window)315 316 -- Create the frame window, with options to edit the queue, that is displayed instead of the queue.317 local window = P.createQueueEditFrame(v.name)318 window:setArea(v.window:getArea()) -- Set the frame window size and position to the same as the queue.319 320 v.edit = window321 end322 end323 end324 325 -- Helper function. Creates a frame for the input queue.326 function P.createQueueEditFrame(queueName)327 local root = winMgr:getWindow("orxonox/NotificationLayer/Root")328 329 window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. queueName)330 local frame = tolua.cast(window, "CEGUI::FrameWindow")331 frame:setCloseButtonEnabled(true)332 orxonox.GUIManager:subscribeEventHelper(frame, "CloseClicked", P.name .. ".closeQueue_clicked")333 frame:setText("NotificationQueue \"" .. queueName .. "\"")334 root:addChildWindow(window)335 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/ScrollingPane")336 pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30)))337 pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26)))338 window:addChildWindow(pane)339 340 local horzOffset = 0341 local vertOffset = 0342 343 -- The line that lets you edit the targets of the queue.344 local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/TargetsTitle")345 targetsTitle:setText("Targets:")346 local size = getMinTextSize(targetsTitle)347 local textHeight = size[1]348 targetsTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))349 targetsTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))350 pane:addChildWindow(targetsTitle)351 horzOffset = horzOffset + size[2] + 5352 local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets")353 targets:setProperty("ReadOnly", "set:False")354 local targetsText = orxonox.NotificationManager:getInstance():getQueue(queueName):getTargets()355 targets:setText(targetsText)356 P.sampleWindow:setText(targetsText)357 size = getMinTextSize(P.sampleWindow)358 targets:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight)))359 targets:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))360 horzOffset = horzOffset + size[2]*2+20 + 5361 pane:addChildWindow(targets)362 local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save")363 save:setText("save")364 P.sampleWindow:setText("save")365 size = getMinTextSize(P.sampleWindow)366 local saveTextWidth = size[2]+20367 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight)))368 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))369 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveTargets_clicked")370 pane:addChildWindow(save)371 horzOffset = horzOffset + saveTextWidth372 vertOffset = vertOffset + textHeight + 5373 374 horzOffset = 0375 -- The line that lets you edit the size of the queue.376 local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/SizeTitle")377 sizeTitle:setText("Size:")378 size = getMinTextSize(sizeTitle)379 sizeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))380 sizeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))381 pane:addChildWindow(sizeTitle)382 horzOffset = horzOffset + size[2] + 5383 local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size")384 queueSize:setProperty("ReadOnly", "set:False")385 local maxSize = orxonox.NotificationManager:getInstance():getQueue(queueName):getMaxSize()386 queueSize:setText(maxSize)387 P.sampleWindow:setText(maxSize)388 size = getMinTextSize(P.sampleWindow)389 queueSize:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight)))390 queueSize:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))391 horzOffset = horzOffset + size[2]*2+20 + 5392 pane:addChildWindow(queueSize)393 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save")394 save:setText("save")395 P.sampleWindow:setText("save")396 size = getMinTextSize(P.sampleWindow)397 local saveTextWidth = size[2]+20398 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight)))399 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))400 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveSize_clicked")401 pane:addChildWindow(save)402 horzOffset = horzOffset + saveTextWidth403 vertOffset = vertOffset + textHeight + 5404 405 horzOffset = 0406 -- The line that lets you edit the display time of the queue.407 local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTimeTitle")408 displayTimeTitle:setText("Display time:")409 size = getMinTextSize(displayTimeTitle)410 displayTimeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight)))411 displayTimeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))412 pane:addChildWindow(displayTimeTitle)413 horzOffset = horzOffset + size[2] + 5414 local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime")415 displayTime:setProperty("ReadOnly", "set:False")416 local time = orxonox.NotificationManager:getInstance():getQueue(queueName):getDisplayTime()417 displayTime:setText(time)418 P.sampleWindow:setText(time)419 size = getMinTextSize(P.sampleWindow)420 displayTime:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight)))421 displayTime:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))422 horzOffset = horzOffset + size[2]*2+20 + 5423 pane:addChildWindow(displayTime)424 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save")425 save:setText("save")426 P.sampleWindow:setText("save")427 size = getMinTextSize(P.sampleWindow)428 local saveTextWidth = size[2]+20429 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight)))430 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset)))431 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveDisplayTime_clicked")432 pane:addChildWindow(save)433 horzOffset = horzOffset + saveTextWidth434 vertOffset = vertOffset + textHeight + 5435 436 return window437 end438 439 -- Leave the edit mode.440 function P.leaveEditMode()441 P.editMode = false442 443 local root = winMgr:getWindow("orxonox/NotificationLayer/Root")444 --Replace all queues with FrameWindows445 for k,v in pairs(P.queueList) do446 if v ~= nil then447 -- Add the queue window to the root window to have it displayed again.448 root:addChildWindow(v.window)449 -- Set the size and position of the queue window to the size and position of the queue edit frame.450 v.window:setArea(v.edit:getArea())451 -- Destroy the edit frame.452 winMgr:destroyWindow(v.edit)453 v.edit = nil454 end455 end456 457 --Remove control window458 winMgr:destroyWindow(winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow"))459 end460 461 -- Is called after the sheet has been hidden.462 function P.afterHide()463 -- If we leave the edit mode we show the sheet again.464 if P.editMode then465 P.leaveEditMode()466 showMenuSheet(P.name, false, true)467 end468 end469 470 -- If the button to save the targets of a queue has been clicked.471 function P.saveTargets_clicked(e)472 local we = CEGUI.toWindowEventArgs(e)473 local name = we.window:getName()474 475 local match = string.gmatch(name, "EditMode/.*/Targets/Save")476 local nameStr = match()477 local queueName = string.sub(nameStr, 10, string.len(nameStr)-13)478 479 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets")480 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save")481 local width = window:getWidth():asAbsolute(1)482 483 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)484 -- Set the new targets.485 queue:setTargets(window:getText())486 local targets = queue:getTargets()487 488 window:setText(targets)489 P.sampleWindow:setText(targets)490 local size = getMinTextSize(P.sampleWindow)491 -- Adjust the width of the targets field.492 window:setWidth(CEGUI.UDim(0, size[2]*2+20))493 -- Adjust the position of the save button after the targets field.494 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))495 end496 497 -- If the button to save the size if a queue has been clicked.498 function P.saveSize_clicked(e)499 local we = CEGUI.toWindowEventArgs(e)500 local name = we.window:getName()501 502 local match = string.gmatch(name, "EditMode/.*/Size/Save")503 local nameStr = match()504 local queueName = string.sub(nameStr, 10, string.len(nameStr)-10)505 506 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size")507 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save")508 local width = window:getWidth():asAbsolute(1)509 510 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)511 -- Set the new size.512 queue:setMaxSize(tonumber(window:getText()))513 local maxSize = queue:getMaxSize()514 515 window:setText(maxSize)516 P.sampleWindow:setText(maxSize)517 local size = getMinTextSize(P.sampleWindow)518 -- Adjust the width of the size field.519 window:setWidth(CEGUI.UDim(0, size[2]*2+20))520 -- Adjust the position of the save button after the size field.521 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))522 end523 524 -- If the button to save the display time if a queue has been clicked.525 function P.saveDisplayTime_clicked(e)526 local we = CEGUI.toWindowEventArgs(e)527 local name = we.window:getName()528 529 local match = string.gmatch(name, "EditMode/.*/DisplayTime/Save")530 local nameStr = match()531 local queueName = string.sub(nameStr, 10, string.len(nameStr)-17)532 533 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime")534 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save")535 local width = window:getWidth():asAbsolute(1)536 537 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)538 -- Set the new display time.539 queue:setDisplayTime(tonumber(window:getText()))540 local time = queue:getDisplayTime()541 542 window:setText(time)543 P.sampleWindow:setText(time)544 local size = getMinTextSize(P.sampleWindow)545 -- Adjust the width of the display time field.546 window:setWidth(CEGUI.UDim(0, size[2]*2+20))547 -- Adjust the position of the save button after the display time field.548 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))549 end550 551 -- if the button to create a new queue has been clicked.552 function P.createNewQueue_clicked(e)553 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName")554 local name = window:getText()555 556 local queue = P.queueList[name]557 -- Test if a queue with that name already exists.558 if queue ~= nil then559 window:setText("Queue with that name already exists.")560 return561 end562 563 -- Creates the new queue.564 orxonox.NotificationManager:getInstance():createQueue(name)565 566 queue = P.queueList[name]567 if queue == nil then568 return569 end570 571 -- Create the frame that represents the queue in edit mode, since that's what we're in.572 local frame = P.createQueueEditFrame(name)573 local root = winMgr:getWindow("orxonox/NotificationLayer/Root")574 -- Remove the queue window from the root window, since we're in edit mode.575 root:removeChildWindow(queue.window)576 -- Set the frame window size and position to that of the queue window.577 frame:setArea(queue.window:getArea())578 queue.edit = frame579 580 -- Reset the text to create a new queue.581 window:setText("")582 end583 584 -- If the button to leave the edit mode has been clicked.585 function P.leaveEditMode_clicked(e)586 hideMenuSheet(P.name)587 end588 589 -- If the button to close the queue has been clicked.590 function P.closeQueue_clicked(e)591 local we = CEGUI.toWindowEventArgs(e)592 local name = we.window:getName()593 594 local match = string.gmatch(name, "EditMode/.*")595 local nameStr = match()596 local queueName = string.sub(nameStr, 10, string.len(nameStr))597 598 -- Destroy the frame window,599 winMgr:destroyWindow(P.queueList[queueName].edit)600 P.queueList[queueName].edit = nil601 -- Destroy the queue.602 orxonox.NotificationManager:getInstance():getQueue(queueName):destroy()603 end604 605 249 -- Helper function. Returns height a queue needs to have to display 'size' items. 606 250 function P.queueHeightHelper(queue, size) -
code/branches/tutoriallevel2/src/modules/notifications/CMakeLists.txt
r7403 r8446 4 4 NotificationManager.cc 5 5 NotificationQueue.cc 6 NotificationQueueCEGUI.cc 6 7 ) 7 8 … … 13 14 TOLUA_FILES 14 15 NotificationManager.h 15 NotificationQueue .h16 NotificationQueueCEGUI.h 16 17 PCH_FILE 17 18 NotificationsPrecompiledHeaders.h -
code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc
r8445 r8446 46 46 #include "Notification.h" 47 47 #include "NotificationQueue.h" 48 #include "NotificationQueueCEGUI.h" 48 49 49 50 #include "ToluaBindNotifications.h" … … 57 58 ManageScopedSingleton(NotificationManager, ScopeID::Root, false); 58 59 59 // Setting console command to enter the edit mode.60 SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);61 62 60 /** 63 61 @brief … … 68 66 RegisterRootObject(NotificationManager); 69 67 70 ModifyConsoleCommand("enterEditMode").setObject(this);71 72 68 COUT(3) << "NotificatioManager created." << std::endl; 73 69 } … … 79 75 NotificationManager::~NotificationManager() 80 76 { 81 ModifyConsoleCommand("enterEditMode").setObject(NULL);82 83 77 // Destroys all Notifications. 84 78 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it!= this->allNotificationsList_.end(); it++) … … 99 93 while(it != this->queues_.end()) 100 94 { 101 it->second->destroy( true);95 it->second->destroy(); 102 96 it = this->queues_.begin(); 103 97 } … … 313 307 /** 314 308 @brief 315 Enters the edit mode of the NotificationLayer.316 */317 void NotificationManager::enterEditMode(void)318 {319 if(GameMode::showsGraphics())320 {321 GUIManager::getInstance().hideGUI("NotificationLayer");322 GUIManager::getInstance().showGUI("NotificationLayer", false, false);323 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.enterEditMode()");324 }325 }326 327 /**328 @brief329 309 Registers a NotificationQueue. 330 310 This makes sure that the NotificationQueue can be accessed through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager. … … 409 389 void NotificationManager::loadQueues(void) 410 390 { 411 NotificationQueue* allQueue = new NotificationQueue ("all");391 NotificationQueue* allQueue = new NotificationQueueCEGUI("all"); 412 392 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"all\", 0.5, 0, " + multi_cast<std::string>(allQueue->getMaxSize()) + ")"); 413 393 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"all\", 0, 10, 0.3, 0)"); 414 394 415 NotificationQueue* infoQueue = new NotificationQueue ("info", NotificationListener::ALL, 1, -1);395 NotificationQueue* infoQueue = new NotificationQueueCEGUI("info", NotificationListener::ALL, 1, -1); 416 396 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"CCFFFF00\")"); 417 397 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")"); -
code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h
r8445 r8446 50 50 /** 51 51 @brief 52 The Singleton NotificationManager functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationListener "NotificationListeners".53 It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationL istener "NotificationListeners".54 It also provides a static function to send @ref orxonox::Notification "Notifications" andworks as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer.52 The Singleton NotificationManager is a NotificationListener and functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationQueues "NotificationQueues". 53 It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationLQueue "NotificationQueues". 54 It also works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer. 55 55 56 56 @author … … 95 95 void getNewestNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications); // Fetches the newest Notifications for a specific NotificationQueue and stores them in the input map. 96 96 97 void enterEditMode(void); // Enters the edit mode of the NotificationLayer.98 99 97 bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue. 100 98 void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue. -
code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc
r8445 r8446 38 38 39 39 #include "core/CoreIncludes.h" 40 #include "core/GameMode.h"41 #include "core/GUIManager.h"42 #include "core/LuaState.h"43 #include "util/Convert.h"44 40 #include "util/SubString.h" 45 41 … … 88 84 } 89 85 90 this->create(); // Creates the NotificationQueue in lua.91 92 86 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; 93 87 } … … 108 102 NotificationManager::getInstance().unregisterQueue(this); 109 103 } 110 } 111 112 /** 113 @brief 114 Destroys the NotificationQueue. 115 Used in lua and NotificationManager. 116 @param noGraphics 117 If this is set to true (false is default), then the queue is not removed in lua. This is used to destroy the queue, after the GUIManager has been destroyed. 118 */ 119 void NotificationQueue::destroy(bool noGraphics) 120 { 121 // Remove the NotificationQueue in lua. 122 if(GameMode::showsGraphics() && !noGraphics) 123 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")"); 124 104 125 105 COUT(3) << "NotificationQueue '" << this->getName() << "' destroyed." << std::endl; 126 127 this->OrxonoxClass::destroy();128 }129 130 /**131 @brief132 Creates the NotificationQueue in lua.133 */134 void NotificationQueue::create(void)135 {136 if(GameMode::showsGraphics())137 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");138 106 } 139 107 … … 236 204 this->notifications_.insert(this->notifications_.begin(), container); 237 205 238 // Push the Notification to the GUI. 239 if(GameMode::showsGraphics()) 240 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); 206 // Inform that a Notification was pushed. 207 this->notificationPushed(notification); 241 208 242 209 COUT(5) << "Notification \"" << notification->getMessage() << "\" pushed to NotificationQueue '" << this->getName() << "'" << endl; … … 269 236 delete container; 270 237 271 // Pops the Notification from the GUI. 272 if(GameMode::showsGraphics()) 273 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")"); 238 // Inform that a Notification was popped. 239 this->notificationPopped(); 274 240 } 275 241 … … 295 261 delete *containerIterator; 296 262 297 // Removes the Notification from the GUI.298 if(GameMode::showsGraphics())299 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");263 // TODO: index automatically cast? 264 // Inform that a Notification was removed. 265 this->notificationRemoved(index); 300 266 } 301 267 … … 316 282 this->notifications_.clear(); 317 283 this->size_ = 0; 318 319 // Clear the NotificationQueue in the GUI.320 if(GameMode::showsGraphics() && !noGraphics)321 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");322 284 } 323 285 -
code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h
r8445 r8446 47 47 #include "tools/interfaces/Tickable.h" 48 48 49 namespace orxonox // tolua_export50 { // tolua_export49 namespace orxonox 50 { 51 51 52 52 /** … … 88 88 @ingroup Notifications 89 89 */ 90 class _NotificationsExport NotificationQueue // tolua_export 91 : public Tickable 92 { // tolua_export 90 class _NotificationsExport NotificationQueue : public Tickable 91 { 93 92 94 93 public: 95 NotificationQueue(const std::string& name, const std::string& senders = Notification Manager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);94 NotificationQueue(const std::string& name, const std::string& senders = NotificationListener::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); 96 95 virtual ~NotificationQueue(); 97 98 //! Destroys the NotificationQueue.99 void destroy(bool noGraphics = false); // tolua_export100 96 101 97 virtual void tick(float dt); //!< To update from time to time. … … 143 139 { return this->targets_; } 144 140 145 // tolua_begin146 141 void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue. 147 142 const std::string& getTargets(void) const; //!< Returns a string consisting of the concatenation of the targets. 148 // tolua_end149 143 150 144 void tidy(void); 151 152 pr ivate:145 146 protected: 153 147 static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. 154 148 static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 155 149 static const int INF = -1; //!< Constant denoting infinity. 150 151 /** 152 @brief Is called when a notification was pushed. 153 @param notification The Notification that was pushed. 154 */ 155 virtual void notificationPushed(Notification* notification) {} 156 /** 157 @brief Is called when a notification was popped. 158 */ 159 virtual void notificationPopped(void) {} 160 /** 161 @brief Is called when a notification was removed. 162 @param index The index the removed notification was at. 163 */ 164 virtual void notificationRemoved(unsigned int index) {} 165 166 virtual void clear(bool noGraphics = false); //!< Clears the NotificationQueue by removing all NotificationContainers. 156 167 168 169 private: 157 170 std::string name_; //!< The name of the NotificationQueue. 158 171 … … 171 184 NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 172 185 173 void create(void); //!< Creates the NotificationQueue in lua.174 175 186 void setName(const std::string& name); //!< Sets the name of the NotificationQueue. 176 187 … … 179 190 void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); //!< Removes the Notification that is stored in the input NotificationContainer. 180 191 181 void clear(bool noGraphics = false); //!< Clears the NotificationQueue by removing all NotificationContainers.192 }; 182 193 183 }; // tolua_export 194 } 184 195 185 } // tolua_export 186 187 #endif /* _NotificationOverlay_H__ */ 196 #endif /* _NotificationQueue_H__ */
Note: See TracChangeset
for help on using the changeset viewer.