- Timestamp:
- May 1, 2011, 2:16:43 PM (14 years ago)
- Location:
- code/branches/tutoriallevel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/tutoriallevel/data/gui/scripts/NotificationLayer.lua
r7894 r8370 17 17 function P.createQueue(name, size) 18 18 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 19 local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name) 20 queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent. 19 --local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name) 20 --queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent. 21 local queue = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/Queue/" .. name) 22 queue:setProperty("Alpha", 0.0) 23 --queue:setProperty("FrameEnabled", "false") 21 24 root:addChildWindow(queue) 22 25 … … 28 31 ["visible"] = false, 29 32 ["fontSize"] = 12, 30 ["fontColor"] = CEGUI.colour(1.0, 1.0, 1.0, 1.0) 33 ["fontColor"] = "#FFFFFFFF", 34 ["items"] = {}, 35 ["first"] = 1, 36 ["last"] = 1 31 37 } 32 38 … … 54 60 return 55 61 end 56 item = CEGUI.createListboxTextItem(notification) 62 63 local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Queue/" .. queueName .. "/" .. queue.last) 64 item:setText(notification) 57 65 P.setItemFontHelper(item, queue, true) 58 local listbox = CEGUI.toListbox(queue.window) 59 -- Add the item to the top of the listbox. 60 if listbox:getItemCount() == 0 then 61 listbox:addItem(item) 62 else 63 listbox:insertItem(item, listbox:getListboxItemFromIndex(0)) 64 end 66 -- Add the item to the top of the queue. 67 local itemHeight = P.itemHeightHelper(queue) 68 if queue.last-queue.first > 0 then -- If the queue is not empty move all items down 69 for i=queue.first,queue.last-1 do 70 local item = queue.items[i] 71 item:setYPosition(CEGUI.UDim(0, itemHeight*(queue.last-i))) 72 end 73 end 74 queue.window:addChildWindow(item) 75 item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, itemHeight))) 76 item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) 77 item:setProperty("Alpha", 1.0) 78 item:setProperty("InheritsAlpha", "false") 79 item:setProperty("BackgroundEnabled", "false") 80 item:setProperty("FrameEnabled", "false") 81 queue.items[queue.last] = item 82 queue.last = queue.last+1 65 83 66 84 -- If the queue has been invisible, set it to visible. … … 76 94 return 77 95 end 78 local listbox = CEGUI.toListbox(queue.window) 79 -- Removes the item from the bottom of the listbox. 80 listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1)) 96 local item = queue.items[queue.first] 97 -- Removes the item from the bottom of the queue. 98 queue.window:removeChildWindow(item) 99 winMgr:destroyWindow(item) 100 queue.first = queue.first+1 81 101 82 102 -- Sets the queue to invisible if there are no more notifications in it. 83 if listbox:getItemCount()== 0 then103 if queue.last-queue.first == 0 then 84 104 P.setVisible(queue, false) 85 105 end 86 106 end 87 107 88 -- Removes a notification at a given index from the queue. 108 -- 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. 89 109 function P.removeNotification(queueName, index) 90 110 local queue = P.queueList[queueName] … … 92 112 return 93 113 end 94 local listbox = CEGUI.toListbox(queue.window) 114 115 index = queue.last-tonumber(index)-1 116 --if index == queue.first then -- If we want to remove the oldest notification, we can just use pop. 117 -- P.popNotification(queueName) 118 -- return 119 --end 120 95 121 -- Removes the item. 96 listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index))) 122 local item = queue.items[index] 123 queue.window:removeChildWindow(item) 124 winMgr:destroyWindow(item) 125 queue.items[index] = nil 126 127 -- Move the items below, up. 128 local itemHeight = P.itemHeightHelper(queue) 129 local moved = false 130 if index > queue.first then -- Move all older notifications up in the list. 131 for i=index-1,-1,queue.first do 132 cout(0, i) 133 item = queue.items[i] 134 item:setYposition(CEGUI.UDim(0, itemHeight*(queue.last-i-1))) 135 queue.items[i+1] = item 136 end 137 end 138 queue.items[queue.first] = nil 139 queue.first = queue.first+1 97 140 98 141 -- Sets the queue to invisible if there are no more notifications in it. 99 if listbox:getItemCount()== 0 then142 if queue.last-queue.first == 0 then 100 143 P.setVisible(queue, false) 101 144 end … … 108 151 return 109 152 end 110 local listbox = CEGUI.toListbox(queue.window) 111 CEGUI.toListbox(queue.window):resetList() 153 for i=queue.first,queue.last-1 do 154 local item = queue.items[i] 155 queue.window:removeChildWindow(item) 156 winMgr:destroyWindow(item) 157 end 158 queue.items = {} 159 queue.first = 1 160 queue.last = 1 112 161 113 162 -- Sets the queue to invisible. … … 147 196 148 197 -- Change the font size and font color of all notifications in a queueHeightHelper 149 -- The parameters are (in order) 'name of the queue', 'font size', 'RGBA of the font color , with values from 0 to 1 each'.150 function P.changeQueueFont(queueName, size, color Red, colorGreen, colorBlue, colorAlpha)198 -- The parameters are (in order) 'name of the queue', 'font size', 'RGBA of the font color in hex notation'. 199 function P.changeQueueFont(queueName, size, color) 151 200 local queue = P.queueList[queueName] 152 201 local queueWindow = queue.window … … 154 203 return 155 204 end 156 if colorAlpha == nil then 157 colorAlpha = 1.0 158 end 159 160 local list = CEGUI.toListbox(queueWindow) 161 local num = list:getItemCount() 205 162 206 queue.fontSize = size 163 207 local changeColor = false 164 if color Red ~= nil and colorGreen ~= nil and colorBlue~= nil then165 queue.fontColor :set(colorRed, colorGreen, colorBlue, colorAlpha)208 if color ~= nil then 209 queue.fontColor = color 166 210 changeColor = true 167 211 end 168 for i= 0,num-1 do169 P.setItemFontHelper( item, queue, changeColor)212 for i=queue.first,queue.last-1 do 213 P.setItemFontHelper(queue.items[i], queue, changeColor) 170 214 end 171 215 end … … 174 218 -- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well' 175 219 function P.setItemFontHelper(item, queue, changeColor) 176 local item = tolua.cast(item, "CEGUI::ListboxTextItem")220 --local item = tolua.cast(item, "CEGUI::ListboxTextItem") 177 221 local fontMgr = CEGUI.FontManager:getSingleton() 178 222 if fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize) then … … 183 227 end 184 228 if changeColor then 185 item:setTextColours(queue.fontColor)229 --item:setProperty("TextColours", "tl:[" .. queue.fontColor .. "] tr:[" .. queue.fontColor .. "] bl:[" .. queue.fontColor .. "] br:[" .. queue.fontColor .. "]") 186 230 end 187 231 end … … 544 588 -- Helper function. Returns height a queue needs to have to display 'size' items. 545 589 function P.queueHeightHelper(queue, size) 546 local listbox = CEGUI.toListbox(queue.window) 547 local item = CEGUI.createListboxTextItem("Text") 548 P.setItemFontHelper(item, queue, false) 549 listbox:addItem(item) 550 local singleItemHeight = listbox:getTotalItemsHeight() 551 local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel()) 552 local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window) 553 local frameHeight = queue.window:getUnclippedPixelRect():getHeight() - formattedArea:getHeight() 554 listbox:removeItem(item) 555 return frameHeight + singleItemHeight*size 590 --local listbox = CEGUI.toListbox(queue.window) 591 --local item = CEGUI.createListboxTextItem("Text") 592 --P.setItemFontHelper(item, queue, false) 593 --listbox:addItem(item) 594 --local singleItemHeight = listbox:getTotalItemsHeight() 595 local singleItemHeight = P.itemHeightHelper(queue) 596 --local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel()) 597 --local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window) 598 --local frameHeight = queue.window:getUnclippedPixelRect():getHeight() - formattedArea:getHeight() 599 --listbox:removeItem(item) 600 --return frameHeight + singleItemHeight*size 601 return singleItemHeight*size + 1 602 end 603 604 function P.itemHeightHelper(queue) 605 local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Test/") 606 item:setText("text") 607 P.setItemFontHelper(item, queue, true) 608 queue.window:addChildWindow(item) 609 item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0))) 610 item:setProperty("FrameEnabled", "false") 611 local height = getStaticTextWindowHeight(item) 612 queue.window:removeChildWindow(item) 613 winMgr:destroyWindow(item) 614 return height 556 615 end 557 616 -
code/branches/tutoriallevel/src/modules/notifications/NotificationManager.cc
r7894 r8370 419 419 420 420 NotificationQueue* infoQueue = new NotificationQueue("info", NotificationManager::ALL, 1, -1); 421 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, 1.0, 1.0, 0.0, 0.8)");421 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"FFFFFF00\")"); 422 422 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")"); 423 423 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");
Note: See TracChangeset
for help on using the changeset viewer.