Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Started work on edit mode. ConsoleCommand is not yet working.
Some additional cleanup. All the NotificationQueues generated by the NotificationManager now are destroyed upon destruction of the NotificationManager.
Removed NotificationQueue from level files.

File size: 5.0 KB
Line 
1-- NotificationLayer.lua
2
3local P = createMenuSheet("NotificationLayer")
4
5P.queueList = {}
6P.nameList = {}
7P.visible = nil
8P.editMode = false
9P.editList = {}
10
11function P.createQueue(name, size)
12    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
13    local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
14    queue:setProperty("BackgroundColor", "00FFFFFF")
15    root:addChildWindow(queue)
16
17    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
18    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))
19
20    P.setVisible(queue, false)
21
22    table.insert(P.queueList, queue)
23    table.insert(P.nameList, name)
24    --TODO: Check name for uniqueness.
25end
26
27function P.removeQueue(name)
28    local queue = nil
29
30    for k,v in pairs(P.nameList) do
31        if v == name then
32            P.nameList[k] = nil
33            queue = P.queueList[k]
34            P.queueList[k] = nil
35            break
36        end
37    end
38
39    if queue ~= nil then
40        winMgr:destroyWindow(queue)
41    end
42end
43
44function P.pushNotification(queueName, notification)
45    local queue = P.nameToQueueHelper(queueName)
46    if queue == nil then
47        cout(0, "Queue is nil!")
48        return
49    end
50    item = CEGUI.createListboxTextItem(notification)
51    local listbox = CEGUI.toListbox(queue)
52    if listbox:getItemCount() == 0 then
53        listbox:addItem(item)
54    else
55        listbox:insertItem(item, listbox:getListboxItemFromIndex(0))
56    end
57
58    if P.visible == false then
59        P.setVisible(queue, true)
60    end
61end
62
63function P.popNotification(queueName)
64    local queue = P.nameToQueueHelper(queueName)
65    if queue == nil then
66        cout(0, "Queue is nil!")
67        return
68    end
69    local listbox = CEGUI.toListbox(queue)
70    listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1))
71
72    if listbox:getItemCount() == 0 then
73        P.setVisible(queue, false)
74    end
75end
76
77function P.removeNotification(queueName, index)
78    local queue = P.nameToQueueHelper(queueName)
79    if queue == nil then
80        cout(0, "Queue is nil!")
81        return
82    end
83    local listbox = CEGUI.toListbox(queue)
84    listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index)))
85
86    if listbox:getItemCount() == 0 then
87        P.setVisible(queue, false)
88    end
89end
90
91function P.clearQueue(name)
92    local queue = P.nameToQueueHelper(name)
93    if queue == nil then
94        cout(0, "Queue is nil!")
95        return
96    end
97    local listbox = CEGUI.toListbox(queue)
98    CEGUI.toListbox(queue):resetList()
99
100    P.setVisible(queue, false)
101end
102
103function P.changePosition(name, xPos, yPos)
104    local queue = P.nameToQueueHelper(name)
105    if queue == nil then
106        cout(0, "Queue is nil!")
107        return
108    end
109    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0)))
110    queue:setWidth(CEGUI.UDim(1.0, -xPos))
111end
112
113function P.changeSize(name, size)
114    local queue = P.nameToQueueHelper(name)
115    if queue == nil then
116        cout(0, "Queue is nil!")
117        return
118    end
119    queue:setHeight(CEGUI.UDim(0, P.queueHeightHelper(queue, size)))
120end
121
122function P.setVisible(queue, visible)
123    queue:setVisible(visible)
124    P.visible = visible
125end
126
127function P.enterEditMode()
128    P.editMode = true
129
130    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
131    --Replace all queues with FrameWindows
132    for k,v in pairs(P.queueList) do
133        if v ~= nil then
134            root:removeChildWindow(v)
135            local frame = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. P.nameList(k))
136            frame:setArea(v:getArea())
137            P.editList[k] = frame
138        end
139    end
140end
141
142function P.leaveEditMode()
143    P.editMode = false
144
145    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
146    --Replace all queues with FrameWindows
147    for k,v in pairs(P.queueList) do
148        if v ~= nil then
149            root:addChildWindow(v)
150            v:setArea(P.editList[k]:getArea())
151            winMgr:destroyWindow(P.editList[k])
152            P.editList[k] = nil
153        end
154    end
155end
156
157function P.onHide()
158    if P.editMode then
159        P.leaveEditMode()
160    end
161end
162
163function P.nameToQueueHelper(name)
164    local queue = nil
165    for k,v in pairs(P.nameList) do
166        if v == name then
167            queue = P.queueList[k]
168            break
169        end
170    end
171    return queue
172end
173
174function P.queueHeightHelper(queue, size)
175    local listbox = CEGUI.toListbox(queue)
176    local item = CEGUI.createListboxTextItem("Text")
177    listbox:addItem(item)
178    local singleItemHeight = listbox:getTotalItemsHeight()
179    local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel())
180    local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue)
181    local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
182    listbox:removeItem(item)
183    return frameHeight + singleItemHeight*size
184end
185
186return P
187
Note: See TracBrowser for help on using the repository browser.