Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8370


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

Committing changes before merge.

Location:
code/branches/tutoriallevel
Files:
2 edited

Legend:

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

    r7894 r8370  
    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)
    2225
     
    2831        ["visible"]   = false,
    2932        ["fontSize"]  = 12,
    30         ["fontColor"] = CEGUI.colour(1.0, 1.0, 1.0, 1.0)
     33        ["fontColor"] = "#FFFFFFFF",
     34        ["items"]     = {},
     35        ["first"]     = 1,
     36        ["last"]      = 1
    3137    }
    3238   
     
    5460        return
    5561    end
    56     item = CEGUI.createListboxTextItem(notification)
     62
     63    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Queue/" .. queueName .. "/" .. queue.last)
     64    item:setText(notification)
    5765    P.setItemFontHelper(item, queue, true)
    58     local listbox = CEGUI.toListbox(queue.window)
    59     -- Add the item to the top of the listbox.
    60     if listbox:getItemCount() == 0 then
    61         listbox:addItem(item)
    62     else
    63         listbox:insertItem(item, listbox:getListboxItemFromIndex(0))
    64     end
     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
    6583
    6684    -- If the queue has been invisible, set it to visible.
     
    7694        return
    7795    end
    78     local listbox = CEGUI.toListbox(queue.window)
    79     -- Removes the item from the bottom of the listbox.
    80     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
    81101
    82102    -- Sets the queue to invisible if there are no more notifications in it.
    83     if listbox:getItemCount() == 0 then
     103    if queue.last-queue.first == 0 then
    84104        P.setVisible(queue, false)
    85105    end
    86106end
    87107
    88 -- 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.
    89109function P.removeNotification(queueName, index)
    90110    local queue = P.queueList[queueName]
     
    92112        return
    93113    end
    94     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
    95121    -- Removes the item.
    96     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
    97140
    98141    -- Sets the queue to invisible if there are no more notifications in it.
    99     if listbox:getItemCount() == 0 then
     142    if queue.last-queue.first == 0 then
    100143        P.setVisible(queue, false)
    101144    end
     
    108151        return
    109152    end
    110     local listbox = CEGUI.toListbox(queue.window)
    111     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
    112161
    113162    -- Sets the queue to invisible.
     
    147196
    148197-- Change the font size and font color of all notifications in a queueHeightHelper
    149 -- The parameters are (in order) 'name of the queue', 'font size', 'RGBA of the font color, with values from 0 to 1 each'.
    150 function P.changeQueueFont(queueName, size, colorRed, colorGreen, colorBlue, colorAlpha)
     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)
    151200    local queue = P.queueList[queueName]
    152201    local queueWindow = queue.window
     
    154203        return
    155204    end
    156     if colorAlpha == nil then
    157         colorAlpha = 1.0
    158     end
    159 
    160     local list = CEGUI.toListbox(queueWindow)
    161     local num = list:getItemCount()
     205
    162206    queue.fontSize = size
    163207    local changeColor = false
    164     if colorRed ~= nil and colorGreen ~= nil and colorBlue ~= nil then
    165         queue.fontColor:set(colorRed, colorGreen, colorBlue, colorAlpha)
     208    if color ~= nil then
     209        queue.fontColor = color
    166210        changeColor = true
    167211    end
    168     for i=0,num-1 do
    169         P.setItemFontHelper(item, queue, changeColor)
     212    for i=queue.first,queue.last-1 do
     213        P.setItemFontHelper(queue.items[i], queue, changeColor)
    170214    end
    171215end
     
    174218-- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well'
    175219function P.setItemFontHelper(item, queue, changeColor)
    176     local item = tolua.cast(item, "CEGUI::ListboxTextItem")
     220    --local item = tolua.cast(item, "CEGUI::ListboxTextItem")
    177221    local fontMgr = CEGUI.FontManager:getSingleton()
    178222    if fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize) then
     
    183227    end
    184228    if changeColor then
    185         item:setTextColours(queue.fontColor)
     229        --item:setProperty("TextColours", "tl:[" .. queue.fontColor .. "] tr:[" .. queue.fontColor .. "] bl:[" .. queue.fontColor .. "] br:[" .. queue.fontColor .. "]")
    186230    end
    187231end
     
    544588-- Helper function. Returns height a queue needs to have to display 'size' items.
    545589function P.queueHeightHelper(queue, size)
    546     local listbox = CEGUI.toListbox(queue.window)
    547     local item = CEGUI.createListboxTextItem("Text")
    548     P.setItemFontHelper(item, queue, false)
    549     listbox:addItem(item)
    550     local singleItemHeight = listbox:getTotalItemsHeight()
    551     local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel())
    552     local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window)
    553     local frameHeight = queue.window:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
    554     listbox:removeItem(item)
    555     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:getUnclippedPixelRect():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
    556615end
    557616
  • code/branches/tutoriallevel/src/modules/notifications/NotificationManager.cc

    r7894 r8370  
    419419
    420420        NotificationQueue* infoQueue = new NotificationQueue("info", NotificationManager::ALL, 1, -1);
    421         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, 1.0, 1.0, 0.0, 0.8)");
     421        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"FFFFFF00\")");
    422422        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")");
    423423        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");
Note: See TracChangeset for help on using the changeset viewer.