Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Changing from OrxonoxOverlays to CEGUI as means of displaying Notifications.
Still messy and not working completely but it's a start.

File size: 2.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:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
12    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0.2, 0)))
13    root:addChildWindow(queue)
14    table.insert(P.queueList, queue)
15    table.insert(P.nameList, name)
16    --TODO: Check name for uniqueness.
17end
18
19function P.removeQueue(name)
20    local queue = nil
21
22    for k,v in pairs(P.nameList) do
23        if v == name then
24            P.nameList[k] = nil
25            queue = P.queueList[k]
26            P.queueList[k] = nil
27            break
28        end
29    end
30
31    if queue ~= nil then
32        winMgr:destroyWindow(queue)
33    end
34end
35
36function P.changePosition(name, xPos, yPos)
37    local queue = P.nameToQueue(name)
38    if queue == nil then
39        cout(0, "Queue is nil!")
40        return
41    end
42    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0)))
43end
44
45function P.pushNotification(queueName, notification)
46    local queue = P.nameToQueue(queueName)
47    if queue == nil then
48        cout(0, "Queue is nil!")
49        return
50    end
51    item = CEGUI.createListboxTextItem(notification)
52    local listbox = CEGUI.toListbox(queue)
53    if listbox:getItemCount() == 0 then
54        listbox:addItem(item)
55    else
56        listbox:insertItem(item, listbox:getListboxItemFromIndex(0))
57    end
58end
59
60function P.popNotification(queueName)
61    local queue = P.nameToQueue(queueName)
62    if queue == nil then
63        cout(0, "Queue is nil!")
64        return
65    end
66    local listbox = CEGUI.toListbox(queue)
67    listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1))
68end
69
70function P.removeNotification(queueName, index)
71    local queue = P.nameToQueue(queueName)
72    if queue == nil then
73        cout(0, "Queue is nil!")
74        return
75    end
76    local listbox = CEGUI.toListbox(queue)
77    listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index)))
78end
79
80function P.clearQueue(name)
81    local queue = P.nameToQueue(name)
82    if queue == nil then
83        cout(0, "Queue is nil!")
84        return
85    end
86    local listbox = CEGUI.toListbox(queue)
87    CEGUI.toListbox(queue):resetList()
88end
89
90function P.nameToQueue(name)
91    local queue = nil
92    for k,v in pairs(P.nameList) do
93        if v == name then
94            queue = P.queueList[k]
95            break
96        end
97    end
98    return queue
99end
100
101return P
102
Note: See TracBrowser for help on using the repository browser.