Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Some documenting and adjustment.

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