Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/NotificationLayer.lua @ 11592

Last change on this file since 11592 was 8858, checked in by landauf, 13 years ago

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

  • orxout levelname message
  • orxout_context levelname context message
  • shortcuts: log message, error message, warning message, status message, info message, debug message
  • Property svn:eol-style set to native
File size: 11.0 KB
RevLine 
[7338]1-- NotificationLayer.lua
2
[8729]3local P = createMenuSheet("NotificationLayer", true, tribool(true), tribool(true))
[7338]4
5P.queueList = {}
6
[7395]7P.sampleWindow = nil
8
[7399]9-- Loads the queues from the NotificationManager and creates the sample window, that is used to measure the width various strings need.
[7395]10function P.onLoad()
11    orxonox.NotificationManager:getInstance():loadQueues()
12    P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/SampleWindow")
13end
14
[7399]15-- Creates a queue in the GUI.
[7338]16function P.createQueue(name, size)
17    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
[8706]18    --local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
19    --queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent.
20    local queue = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/Queue/" .. name)
21    queue:setProperty("Alpha", 0.0)
22    --queue:setProperty("FrameEnabled", "false")
[7342]23    root:addChildWindow(queue)
24
[7395]25    local queueTuple =
26    {
[8706]27        ["window"]    = queue,
28        ["name"]      = name,
29        ["maxSize"]   = size,
30        ["visible"]   = false,
31        ["fontSize"]  = 12,
32        ["fontColor"] = "FFFFFFFF",
33        ["alignment"] = "LeftAligned",
34        ["items"]     = {},
35        ["first"]     = 1,
36        ["last"]      = 1
[7395]37    }
[8706]38   
39    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
40    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queueTuple, size))))
[7351]41
[7395]42    P.queueList[name] = queueTuple -- name access
[7399]43    P.setVisible(queueTuple, false) -- Set the queue to invisible as long as there are no notifications in it.
[7338]44end
45
[7399]46-- Removes a queue from the GUI.
47function P.removeQueue(queueName)
48    local queue = P.queueList[queueName]
[7338]49
50    if queue ~= nil then
[8706]51        queue.window:getParent():removeChildWindow(queue.window)
[7395]52        winMgr:destroyWindow(queue.window)
[7338]53    end
[7399]54    P.queueList[queueName] = nil
[7338]55end
56
[8079]57-- Pushes an input notification to the input queue.
[7338]58function P.pushNotification(queueName, notification)
[7395]59    local queue = P.queueList[queueName]
[7338]60    if queue == nil then
61        return
62    end
[8706]63
64    if not guiMgr:usingOldCEGUI() then
65        notification = string.gsub(notification, "%[", "\\%[") -- escape '[' which is used to format text since cegui 0.7
[7338]66    end
[7351]67
[8706]68    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Queue/" .. queueName .. "/" .. queue.last)
69    item:setText(notification)
70    P.setItemFontHelper(item, queue, true)
71    -- Add the item to the top of the queue.
72    local itemHeight = P.itemHeightHelper(queue)
73    if queue.last-queue.first > 0 then -- If the queue is not empty move all items down
74        for i=queue.first,queue.last-1 do
75            local item = queue.items[i]
76            item:setYPosition(CEGUI.UDim(0, itemHeight*(queue.last-i)))
77        end
78    end
79    queue.window:addChildWindow(item)
80    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, itemHeight)))
81    item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
82    item:setProperty("Alpha", 1.0)
83    item:setProperty("InheritsAlpha", "false")
84    item:setProperty("BackgroundEnabled", "false")
85    item:setProperty("FrameEnabled", "false")
86    item:setProperty("HorzFormatting", queue.alignment)
87    queue.items[queue.last] = item
88    queue.last = queue.last+1
89
[7399]90    -- If the queue has been invisible, set it to visible.
[7395]91    if queue.visible == false then
[7351]92        P.setVisible(queue, true)
93    end
[7338]94end
95
[7399]96-- Pops the least recently added notification from the queue.
[7338]97function P.popNotification(queueName)
[7395]98    local queue = P.queueList[queueName]
[7338]99    if queue == nil then
100        return
101    end
[8706]102    local item = queue.items[queue.first]
103    -- Removes the item from the bottom of the queue.
104    queue.window:removeChildWindow(item)
105    winMgr:destroyWindow(item)
106    queue.first = queue.first+1
[7351]107
[7399]108    -- Sets the queue to invisible if there are no more notifications in it.
[8706]109    if queue.last-queue.first == 0 then
[7351]110        P.setVisible(queue, false)
111    end
[7338]112end
113
[8706]114-- 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.
[7338]115function P.removeNotification(queueName, index)
[7395]116    local queue = P.queueList[queueName]
[7338]117    if queue == nil then
118        return
119    end
[8706]120
121    index = queue.last-tonumber(index)-1
122    --if index == queue.first then -- If we want to remove the oldest notification, we can just use pop.
123    --    P.popNotification(queueName)
124    --    return
125    --end
126
[7399]127    -- Removes the item.
[8706]128    local item = queue.items[index]
129    queue.window:removeChildWindow(item)
130    winMgr:destroyWindow(item)
131    queue.items[index] = nil
[7351]132
[8706]133    -- Move the items below, up.
134    local itemHeight = P.itemHeightHelper(queue)
135    local moved = false
136    if index > queue.first then -- Move all older notifications up in the list.
137        for i=index-1,-1,queue.first do
[8858]138            orxout(i)
[8706]139            item = queue.items[i]
140            item:setYposition(CEGUI.UDim(0, itemHeight*(queue.last-i-1)))
141            queue.items[i+1] = item
142        end
143    end
144    queue.items[queue.first] = nil
145    queue.first = queue.first+1
146
[7399]147    -- Sets the queue to invisible if there are no more notifications in it.
[8706]148    if queue.last-queue.first == 0 then
[7351]149        P.setVisible(queue, false)
150    end
[7338]151end
152
[7399]153-- Clears the queue. Removes all notifications from it.
154function P.clearQueue(queueName)
155    local queue = P.queueList[queueName]
[7338]156    if queue == nil then
157        return
158    end
[8706]159    for i=queue.first,queue.last-1 do
160        local item = queue.items[i]
161        queue.window:removeChildWindow(item)
162        winMgr:destroyWindow(item)
163    end
164    queue.items = {}
165    queue.first = 1
166    queue.last = 1
[7351]167
[7399]168    -- Sets the queue to invisible.
[7351]169    P.setVisible(queue, false)
[7338]170end
171
[7399]172-- Sets the visibility of the queue.
[7395]173function P.setVisible(queue, visible)
[7343]174    if queue == nil then
175        return
176    end
[7395]177    queue.window:setVisible(visible)
178    queue.visible = visible
[7343]179end
180
[8706]181-- Change the position of the queue.
182-- The parameters are (in order) 'name of the queue', 'relative x-position', 'absolute x-position in pixel', 'relative y-position', 'absolute y-position in pixel'.
183function P.moveQueue(queueName, relativeXPos, absoluteXPos, relativeYpos, absoluteYPos)
184    local queueWindow = P.queueList[queueName].window
185    queueWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(relativeXPos, absoluteXPos), CEGUI.UDim(relativeYpos, absoluteYPos)))
186end
[7354]187
[8706]188-- Change the size of the queue.
189-- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'.
190-- Additionally the last two parameters can be ommitted, which leads to the height being set such that all notifications can be displayed. using the size of the queue.
191function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth)
192    local queue = P.queueList[queueName]
193    local queueWindow = queue.window
194    if queueWindow == nil then
195        return
[7354]196    end
[8706]197    if absoluteHeigth == nil then
198        absoluteHeigth = P.queueHeightHelper(queue, queue.maxSize)
199        relativeHeight = 0
200    end
201    queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth)))
[7354]202end
203
[8706]204-- Change the horizontal alignment of the displayed notifications.
205-- The parameters are the name of the queue and the alignment parameter,
206function P.changeQueueAlignment(queueName, alignment)
207    local queue = P.queueList[queueName]
208    local queueWindow = queue.window
209    if queueWindow == nil then
210        return
211    end
[7399]212
[8706]213    queue.alignment = alignment
214    local item = nil
215    for i=queue.first,queue.last-1 do
216        item = queue.items[i]
217        item:setProperty("HorzFormatting", queue.alignment)
218    end
[7395]219end
220
[8706]221-- Change the font size  of all notifications in a queue.
222-- The parameters are (in order) 'name of the queue', 'font size'.
223function P.changeQueueFontSize(queueName, size)
224    local queue = P.queueList[queueName]
225    local queueWindow = queue.window
226    if queueWindow == nil then
227        return
[7354]228    end
[7362]229
[8706]230    queue.fontSize = size
231    for i=queue.first,queue.last-1 do
232        P.setItemFontHelper(queue.items[i], queue, false)
[7354]233    end
234end
235
[8706]236-- Change the font color of all notifications in a queue.
237-- The parameters are (in order) 'name of the queue', 'ARGB of the font color in hex notation'.
238function P.changeQueueFontColor(queueName, color)
239    local queue = P.queueList[queueName]
240    local queueWindow = queue.window
241    if queueWindow == nil then
[7413]242        return
243    end
244
[8706]245    queue.fontColor = color
246    for i=queue.first,queue.last-1 do
247        P.setItemFontHelper(queue.items[i], queue, true)
[7338]248    end
249end
250
[8706]251-- Helper function to set the font size and color of a item of a queue.
252-- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well'
253function P.setItemFontHelper(item, queue, changeColor)
254    --local item = tolua.cast(item, "CEGUI::ListboxTextItem")
255    local fontMgr = CEGUI.FontManager:getSingleton()
256    if (fontMgr["isFontPresent"] and fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize)) or -- cegui 0.6
257        (fontMgr["isDefined"] and fontMgr:isDefined("BlueHighway-" .. queue.fontSize)) then -- cegui 0.7
258        item:setFont("BlueHighway-" .. queue.fontSize)
259    else
260        orxonox.GUIManager:addFontHelper("BlueHighway-" .. queue.fontSize, queue.fontSize, "bluehigh.ttf")
261        item:setFont("BlueHighway-" .. queue.fontSize)
262    end
263    if changeColor then
264        item:setProperty("TextColours", "tl:" .. queue.fontColor .. " tr:" .. queue.fontColor .. " bl:" .. queue.fontColor .. " br:" .. queue.fontColor .. "")
265    end
[7395]266end
267
[7399]268-- Helper function. Returns height a queue needs to have to display 'size' items.
[7342]269function P.queueHeightHelper(queue, size)
[8706]270    --local listbox = CEGUI.toListbox(queue.window)
271    --local item = CEGUI.createListboxTextItem("Text")
272    --P.setItemFontHelper(item, queue, false)
273    --listbox:addItem(item)
274    --local singleItemHeight = listbox:getTotalItemsHeight()
275    local singleItemHeight = P.itemHeightHelper(queue)
276    --local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel())
277    --local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window)
278    --local frameHeight = queue.window:getUnclippedOuterRect():getHeight() - formattedArea:getHeight()
279    --listbox:removeItem(item)
280    --return frameHeight + singleItemHeight*size
281    return singleItemHeight*size + 1
[7342]282end
283
[8706]284function P.itemHeightHelper(queue)
285    local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Test/")
286    item:setText("text")
287    P.setItemFontHelper(item, queue, true)
288    queue.window:addChildWindow(item)
289    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
290    item:setProperty("FrameEnabled", "false")
291    local height = getStaticTextWindowHeight(item)
292    queue.window:removeChildWindow(item)
293    winMgr:destroyWindow(item)
294    return height
295end
296
[7338]297return P
Note: See TracBrowser for help on using the repository browser.