Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/notifications/data/gui/scripts/NotificationLayer.lua @ 7349

Last change on this file since 7349 was 7349, checked in by dafrick, 14 years ago

Making the background of the NotificationQueue transparent. (Had to change/update TaharezLook look'n'feel file, so don't forget to update data_extern as well…)
Removing some obsolete includes and a warning.

File size: 3.6 KB
Line 
1-- NotificationLayer.lua
2
3local P = createMenuSheet("NotificationLayer")
4
5P.queueList = {}
6P.nameList = {}
7
8function P.createQueue(name, size)
9    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
10    local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
11    queue:setProperty("BackgroundColor", "00FFFFFF")
12    root:addChildWindow(queue)
13
14    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
15    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))
16
17    table.insert(P.queueList, queue)
18    table.insert(P.nameList, name)
19    --TODO: Check name for uniqueness.
20end
21
22function P.removeQueue(name)
23    local queue = nil
24
25    for k,v in pairs(P.nameList) do
26        if v == name then
27            P.nameList[k] = nil
28            queue = P.queueList[k]
29            P.queueList[k] = nil
30            break
31        end
32    end
33
34    if queue ~= nil then
35        winMgr:destroyWindow(queue)
36    end
37end
38
39function P.pushNotification(queueName, notification)
40    local queue = P.nameToQueueHelper(queueName)
41    if queue == nil then
42        cout(0, "Queue is nil!")
43        return
44    end
45    item = CEGUI.createListboxTextItem(notification)
46    local listbox = CEGUI.toListbox(queue)
47    if listbox:getItemCount() == 0 then
48        listbox:addItem(item)
49    else
50        listbox:insertItem(item, listbox:getListboxItemFromIndex(0))
51    end
52end
53
54function P.popNotification(queueName)
55    local queue = P.nameToQueueHelper(queueName)
56    if queue == nil then
57        cout(0, "Queue is nil!")
58        return
59    end
60    local listbox = CEGUI.toListbox(queue)
61    listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1))
62end
63
64function P.removeNotification(queueName, index)
65    local queue = P.nameToQueueHelper(queueName)
66    if queue == nil then
67        cout(0, "Queue is nil!")
68        return
69    end
70    local listbox = CEGUI.toListbox(queue)
71    listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index)))
72end
73
74function P.clearQueue(name)
75    local queue = P.nameToQueueHelper(name)
76    if queue == nil then
77        cout(0, "Queue is nil!")
78        return
79    end
80    local listbox = CEGUI.toListbox(queue)
81    CEGUI.toListbox(queue):resetList()
82end
83
84function P.changePosition(name, xPos, yPos)
85    local queue = P.nameToQueueHelper(name)
86    if queue == nil then
87        cout(0, "Queue is nil!")
88        return
89    end
90    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0)))
91    queue:setWidth(CEGUI.UDim(1.0, -xPos))
92end
93
94function P.changeSize(name, size)
95    local queue = P.nameToQueueHelper(name)
96    if queue == nil then
97        cout(0, "Queue is nil!")
98        return
99    end
100    queue:setHeight(CEGUI.UDim(0, P.queueHeightHelper(queue, size)))
101end
102
103function P.nameToQueueHelper(name)
104    local queue = nil
105    for k,v in pairs(P.nameList) do
106        if v == name then
107            queue = P.queueList[k]
108            break
109        end
110    end
111    return queue
112end
113
114function P.queueHeightHelper(queue, size)
115    local listbox = CEGUI.toListbox(queue)
116    local item = CEGUI.createListboxTextItem("Text")
117    listbox:addItem(item)
118    local singleItemHeight = listbox:getTotalItemsHeight()
119    local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel())
120    local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue)
121    local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
122    listbox:removeItem(item)
123    return frameHeight + singleItemHeight*size
124end
125
126return P
127
Note: See TracBrowser for help on using the repository browser.