Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 11, 2011, 12:21:32 PM (13 years ago)
Author:
dafrick
Message:

Removing editMode stuff, since that doesn't work anymore and that won't change for quite some time.
Seperating CEGUI from NotificationQueue stuff by introducing a new NotificationQueue called the NotificationQueueCEGUI.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel2/data/gui/scripts/NotificationLayer.lua

    r8378 r8446  
    44
    55P.queueList = {}
    6 P.editMode = false
    76
    87P.sampleWindow = nil
     
    248247end
    249248
    250 -- Enter the edit mode of the notification layer.
    251 function P.enterEditMode()
    252     P.editMode = true
    253 
    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 = 0
    269     horzOffset = 0
    270     -- 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] + 5
    279     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] + 5
    284     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 + 5
    294     vertOffset = vertOffset + textHeight + 5
    295 
    296     horzOffset = 0
    297     -- 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 + 5
    307     vertOffset = vertOffset + textHeight + 5
    308 
    309     --Replace all queues with FrameWindows
    310     for k,v in pairs(P.queueList) do
    311         if v ~= nil then
    312             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 = window
    321         end
    322     end
    323 end
    324 
    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 = 0
    341     local vertOffset = 0
    342 
    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] + 5
    352     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 + 5
    361     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]+20
    367     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 + saveTextWidth
    372     vertOffset = vertOffset + textHeight + 5
    373 
    374     horzOffset = 0
    375     -- 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] + 5
    383     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 + 5
    392     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]+20
    398     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 + saveTextWidth
    403     vertOffset = vertOffset + textHeight + 5
    404 
    405     horzOffset = 0
    406     -- 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] + 5
    414     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 + 5
    423     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]+20
    429     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 + saveTextWidth
    434     vertOffset = vertOffset + textHeight + 5
    435 
    436     return window
    437 end
    438 
    439 -- Leave the edit mode.
    440 function P.leaveEditMode()
    441     P.editMode = false
    442 
    443     local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
    444     --Replace all queues with FrameWindows
    445     for k,v in pairs(P.queueList) do
    446         if v ~= nil then
    447             -- 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 = nil
    454         end
    455     end
    456 
    457     --Remove control window
    458     winMgr:destroyWindow(winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow"))
    459 end
    460 
    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 then
    465         P.leaveEditMode()
    466         showMenuSheet(P.name, false, true)
    467     end
    468 end
    469 
    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 end
    496 
    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 end
    523 
    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 end
    550 
    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 then
    559         window:setText("Queue with that name already exists.")
    560         return
    561     end
    562 
    563     -- Creates the new queue.
    564     orxonox.NotificationManager:getInstance():createQueue(name)
    565 
    566     queue = P.queueList[name]
    567     if queue == nil then
    568         return
    569     end
    570 
    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 = frame
    579 
    580     -- Reset the text to create a new queue.
    581     window:setText("")
    582 end
    583 
    584 -- If the button to leave the edit mode has been clicked.
    585 function P.leaveEditMode_clicked(e)
    586     hideMenuSheet(P.name)
    587 end
    588 
    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 = nil
    601     -- Destroy the queue.
    602     orxonox.NotificationManager:getInstance():getQueue(queueName):destroy()
    603 end
    604 
    605249-- Helper function. Returns height a queue needs to have to display 'size' items.
    606250function P.queueHeightHelper(queue, size)
Note: See TracChangeset for help on using the changeset viewer.