Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 1, 2011, 2:43:33 PM (13 years ago)
Author:
dafrick
Message:

Merging tutoriallevel branch into tutoriallevel2 branch.

Location:
code/branches/tutoriallevel2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel2

  • code/branches/tutoriallevel2/data/gui/scripts/NotificationLayer.lua

    r8351 r8371  
    1717function P.createQueue(name, size)
    1818    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
    19     local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
    20     queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent.
     19    --local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
     20    --queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent.
     21    local queue = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/Queue/" .. name)
     22    queue:setProperty("Alpha", 0.0)
     23    --queue:setProperty("FrameEnabled", "false")
    2124    root:addChildWindow(queue)
    22 
    23     queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
    24     queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))
    2525
    2626    local queueTuple =
    2727    {
    28         ["window"]  = queue,
    29         ["name"]    = name,
    30         ["edit"]    = nil,
    31         ["visible"] = false
     28        ["window"]    = queue,
     29        ["name"]      = name,
     30        ["edit"]      = nil,
     31        ["visible"]   = false,
     32        ["fontSize"]  = 12,
     33        ["fontColor"] = "#FFFFFFFF",
     34        ["items"]     = {},
     35        ["first"]     = 1,
     36        ["last"]      = 1
    3237    }
     38   
     39    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
     40    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queueTuple, size))))
    3341
    3442    P.queueList[name] = queueTuple -- name access
     
    5260        return
    5361    end
    54     item = CEGUI.createListboxTextItem(notification)
    55     local listbox = CEGUI.toListbox(queue.window)
    56     -- Add the item to the top of the listbox.
    57     if listbox:getItemCount() == 0 then
    58         listbox:addItem(item)
    59     else
    60         listbox:insertItem(item, listbox:getListboxItemFromIndex(0))
    61     end
     62
     63    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Queue/" .. queueName .. "/" .. queue.last)
     64    item:setText(notification)
     65    P.setItemFontHelper(item, queue, true)
     66    -- Add the item to the top of the queue.
     67    local itemHeight = P.itemHeightHelper(queue)
     68    if queue.last-queue.first > 0 then -- If the queue is not empty move all items down
     69        for i=queue.first,queue.last-1 do
     70            local item = queue.items[i]
     71            item:setYPosition(CEGUI.UDim(0, itemHeight*(queue.last-i)))
     72        end
     73    end
     74    queue.window:addChildWindow(item)
     75    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, itemHeight)))
     76    item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
     77    item:setProperty("Alpha", 1.0)
     78    item:setProperty("InheritsAlpha", "false")
     79    item:setProperty("BackgroundEnabled", "false")
     80    item:setProperty("FrameEnabled", "false")
     81    queue.items[queue.last] = item
     82    queue.last = queue.last+1
    6283
    6384    -- If the queue has been invisible, set it to visible.
     
    7394        return
    7495    end
    75     local listbox = CEGUI.toListbox(queue.window)
    76     -- Removes the item from the bottom of the listbox.
    77     listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1))
     96    local item = queue.items[queue.first]
     97    -- Removes the item from the bottom of the queue.
     98    queue.window:removeChildWindow(item)
     99    winMgr:destroyWindow(item)
     100    queue.first = queue.first+1
    78101
    79102    -- Sets the queue to invisible if there are no more notifications in it.
    80     if listbox:getItemCount() == 0 then
     103    if queue.last-queue.first == 0 then
    81104        P.setVisible(queue, false)
    82105    end
    83106end
    84107
    85 -- Removes a notification at a given index from the queue.
     108-- Removes a notification at a given index from the queue. Where the 0th item is the newest and the nth the (n+1)th newest.
    86109function P.removeNotification(queueName, index)
    87110    local queue = P.queueList[queueName]
     
    89112        return
    90113    end
    91     local listbox = CEGUI.toListbox(queue.window)
     114
     115    index = queue.last-tonumber(index)-1
     116    --if index == queue.first then -- If we want to remove the oldest notification, we can just use pop.
     117    --    P.popNotification(queueName)
     118    --    return
     119    --end
     120
    92121    -- Removes the item.
    93     listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index)))
     122    local item = queue.items[index]
     123    queue.window:removeChildWindow(item)
     124    winMgr:destroyWindow(item)
     125    queue.items[index] = nil
     126
     127    -- Move the items below, up.
     128    local itemHeight = P.itemHeightHelper(queue)
     129    local moved = false
     130    if index > queue.first then -- Move all older notifications up in the list.
     131        for i=index-1,-1,queue.first do
     132            cout(0, i)
     133            item = queue.items[i]
     134            item:setYposition(CEGUI.UDim(0, itemHeight*(queue.last-i-1)))
     135            queue.items[i+1] = item
     136        end
     137    end
     138    queue.items[queue.first] = nil
     139    queue.first = queue.first+1
    94140
    95141    -- Sets the queue to invisible if there are no more notifications in it.
    96     if listbox:getItemCount() == 0 then
     142    if queue.last-queue.first == 0 then
    97143        P.setVisible(queue, false)
    98144    end
     
    105151        return
    106152    end
    107     local listbox = CEGUI.toListbox(queue.window)
    108     CEGUI.toListbox(queue.window):resetList()
     153    for i=queue.first,queue.last-1 do
     154        local item = queue.items[i]
     155        queue.window:removeChildWindow(item)
     156        winMgr:destroyWindow(item)
     157    end
     158    queue.items = {}
     159    queue.first = 1
     160    queue.last = 1
    109161
    110162    -- Sets the queue to invisible.
     
    119171    queue.window:setVisible(visible)
    120172    queue.visible = visible
     173end
     174
     175-- Change the position of the queue.
     176-- The parameters are (in order) 'name of the queue', 'relative x-position', 'absolute x-position in pixel', 'relative y-position', 'absolute y-position in pixel'.
     177function P.moveQueue(queueName, relativeXPos, absoluteXPos, relativeYpos, absoluteYPos)
     178    local queueWindow = P.queueList[queueName].window
     179    queueWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(relativeXPos, absoluteXPos), CEGUI.UDim(relativeYpos, absoluteYPos)))
     180end
     181
     182-- Change the size of the queue.
     183-- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'.
     184-- Additionally the last parameter can be ommitted and relativeHeight can be set to the size (i.e. the maximal number of notifications displayed) of the queue, which leads to the height being set such that all notifications can be displayed.
     185function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth)
     186    local queueWindow = P.queueList[queueName].window
     187    if queueWindow == nil then
     188        return
     189    end
     190    if absoluteHeigth == nil then
     191        absoluteHeigth = P.queueHeightHelper(P.queueList[queueName], relativeHeight)
     192        relativeHeight = 0
     193    end
     194    queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth)))
     195end
     196
     197-- Change the font size and font color of all notifications in a queueHeightHelper
     198-- The parameters are (in order) 'name of the queue', 'font size', 'RGBA of the font color in hex notation'.
     199function P.changeQueueFont(queueName, size, color)
     200    local queue = P.queueList[queueName]
     201    local queueWindow = queue.window
     202    if queueWindow == nil then
     203        return
     204    end
     205
     206    queue.fontSize = size
     207    local changeColor = false
     208    if color ~= nil then
     209        queue.fontColor = color
     210        changeColor = true
     211    end
     212    for i=queue.first,queue.last-1 do
     213        P.setItemFontHelper(queue.items[i], queue, changeColor)
     214    end
     215end
     216
     217-- Helper function to set the font size and color of a item of a queue.
     218-- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well'
     219function P.setItemFontHelper(item, queue, changeColor)
     220    --local item = tolua.cast(item, "CEGUI::ListboxTextItem")
     221    local fontMgr = CEGUI.FontManager:getSingleton()
     222    if fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize) then
     223        item:setFont("BlueHighway-" .. queue.fontSize)
     224    else
     225        orxonox.GUIManager:addFontHelper("BlueHighway-" .. queue.fontSize, queue.fontSize, "bluehigh.ttf")
     226        item:setFont("BlueHighway-" .. queue.fontSize)
     227    end
     228    if changeColor then
     229        --item:setProperty("TextColours", "tl:[" .. queue.fontColor .. "] tr:[" .. queue.fontColor .. "] bl:[" .. queue.fontColor .. "] br:[" .. queue.fontColor .. "]")
     230    end
    121231end
    122232
     
    333443
    334444-- Is called after the sheet has been hidden.
    335 function P.onQuit()
     445function P.afterHide()
    336446    -- If we leave the edit mode we show the sheet again.
    337447    if P.editMode then
     
    342452
    343453-- If the button to save the targets of a queue has been clicked.
    344 function P. saveTargets_clicked(e)
     454function P.saveTargets_clicked(e)
    345455    local we = CEGUI.toWindowEventArgs(e)
    346456    local name = we.window:getName()
     
    369479
    370480-- If the button to save the size if a queue has been clicked.
    371 function P. saveSize_clicked(e)
     481function P.saveSize_clicked(e)
    372482    local we = CEGUI.toWindowEventArgs(e)
    373483    local name = we.window:getName()
     
    396506
    397507-- If the button to save the display time if a queue has been clicked.
    398 function P. saveDisplayTime_clicked(e)
     508function P.saveDisplayTime_clicked(e)
    399509    local we = CEGUI.toWindowEventArgs(e)
    400510    local name = we.window:getName()
     
    478588-- Helper function. Returns height a queue needs to have to display 'size' items.
    479589function P.queueHeightHelper(queue, size)
    480     local listbox = CEGUI.toListbox(queue)
    481     local item = CEGUI.createListboxTextItem("Text")
    482     listbox:addItem(item)
    483     local singleItemHeight = listbox:getTotalItemsHeight()
    484     local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel())
    485     local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue)
    486     local frameHeight = queue:getUnclippedOuterRect():getHeight() - formattedArea:getHeight()
    487     listbox:removeItem(item)
    488     return frameHeight + singleItemHeight*size
     590    --local listbox = CEGUI.toListbox(queue.window)
     591    --local item = CEGUI.createListboxTextItem("Text")
     592    --P.setItemFontHelper(item, queue, false)
     593    --listbox:addItem(item)
     594    --local singleItemHeight = listbox:getTotalItemsHeight()
     595    local singleItemHeight = P.itemHeightHelper(queue)
     596    --local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel())
     597    --local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window)
     598    --local frameHeight = queue.window:getUnclippedOuterRect():getHeight() - formattedArea:getHeight()
     599    --listbox:removeItem(item)
     600    --return frameHeight + singleItemHeight*size
     601    return singleItemHeight*size + 1
     602end
     603
     604function P.itemHeightHelper(queue)
     605    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Test/")
     606    item:setText("text")
     607    P.setItemFontHelper(item, queue, true)
     608    queue.window:addChildWindow(item)
     609    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
     610    item:setProperty("FrameEnabled", "false")
     611    local height = getStaticTextWindowHeight(item)
     612    queue.window:removeChildWindow(item)
     613    winMgr:destroyWindow(item)
     614    return height
    489615end
    490616
Note: See TracChangeset for help on using the changeset viewer.