Changeset 8637 for code/branches/presentation
- Timestamp:
- May 28, 2011, 5:10:01 PM (13 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 4 deleted
- 75 edited
- 5 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
- Property svn:mergeinfo changed
/code/branches/tutoriallevel (added) merged: 7828-7831,7894,8370 /code/branches/tutoriallevel2 (added) merged: 8371,8374,8376-8378,8444-8451 /code/branches/tutoriallevel3 (added) merged: 8453,8634,8636
- Property svn:mergeinfo changed
-
code/branches/presentation/data/gui/layouts/QuestGUI.layout
r6746 r8637 1 1 <?xml version="1.0" ?> 2 2 <GUILayout> 3 <Window Type="MenuWidgets/StaticImage" Name="orxonox/QuestGUI/Background"> 4 <Property Name="UnifiedSize" Value="{{1.0,0},{1.0,0}}"/> 5 <Property Name="Image" Value="set:MainMenuBackground image:Background"/> 6 <Property Name="FrameEnabled" Value="set:true"/> 7 <Property Name="BackgroundEnabled" Value="set:false"/> 8 <Property Name="InheritsAlpha" Value="False" /> 3 <Window Type="DefaultWindow" Name="orxonox/QuestGUI/Background"> 4 <Property Name="InheritsAlpha" Value="False" /> 5 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" /> 9 6 10 <Window Type="MenuWidgets/Titlebar" Name="orxonox/QuestGUI/Title"> 11 <Property Name="UnifiedPosition" Value="{{0.05,0},{0.05,0}}"/> 12 <Property Name="UnifiedSize" Value="{{0.9,0},{0.05,0}}"/> 13 <Property Name="Text" Value="Your Quests"/> 7 <Window Type="DefaultWindow" Name="orxonox/QuestGUI/MainWindow"> 8 <Property Name="UnifiedAreaRect" Value="{{0.1,0},{0.1,0},{0.9,0},{0.9,0}}" /> 9 10 <Window Type="MenuWidgets/Titlebar" Name="orxonox/QuestGUI/Title"> 11 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,30}}" /> 12 <Property Name="Text" Value="Your Quests"/> 13 </Window> 14 15 <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/MainWindow/LeftPanel"> 16 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{0.5,0},{1,0}}" /> 17 18 <Window Type="MenuWidgets/TabButton" Name="orxonox/QuestGUI/ActiveQuestsButton"> 19 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{0.5,0},{0,30}}" /> 20 <Property Name="Text" Value="active quests"/> 21 <Event Name="Clicked" Function="QuestGUI.showActiveQuestsButton_clicked"/> 22 </Window> 23 <Window Type="MenuWidgets/TabButton" Name="orxonox/QuestGUI/FinishedQuestsButton"> 24 <Property Name="UnifiedAreaRect" Value="{{0.5,0},{0,0},{1,0},{0,30}}" /> 25 <Property Name="Text" Value="finished quests"/> 26 <Event Name="Clicked" Function="QuestGUI.showFinishedQuestsButton_clicked"/> 27 </Window> 28 29 <Window Type="MenuWidgets/Listbox" Name="orxonox/QuestGUI/QuestsList"> 30 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{1,0},{1,0}}" /> 31 <Event Name="ItemSelectionChanged" Function="QuestGUI.changeQuest_clicked"/> 32 </Window> 33 </Window> 34 35 <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/MainWindow/RightPanel"> 36 <Property Name="UnifiedAreaRect" Value="{{0.5,0},{0,30},{1,0},{1,0}}" /> 37 38 <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Title"> 39 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,30}}" /> 40 <Property Name="Text" Value="Quest Title"/> 41 </Window> 42 43 <Window Type="MenuWidgets/ScrollablePane" Name="orxonox/QuestGUI/Quest/ScrollWrapper"> 44 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{1,-4},{1,-4}}" /> 45 46 <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Wrapper"> 47 <Property Name="UnifiedAreaRect" Value="{{0,5},{0,5},{1,-5},{0,0}}" /> 48 <Property Name="FrameEnabled" Value="false" /> 49 <Property Name="Alpha" Value="0" /> 50 51 <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Description"> 52 <Property Name="UnifiedAreaRect" Value="{{0,5},{0,0},{1,-5},{0,0}}" /> 53 <Property Name="InheritsAlpha" Value="False" /> 54 <Property Name="HorzFormatting" Value="WordWrapLeftAligned" /> 55 <Property Name="VertFormatting" Value="TopAligned" /> 56 <Property Name="FrameEnabled" Value="false" /> 57 <Property Name="Text" Value="Quest Description"/> 58 </Window> 59 60 <Window Type="MenuWidgets/Listbox" Name="orxonox/QuestGUI/Quest/SubquestsList"> 61 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" /> 62 <Property Name="InheritsAlpha" Value="False" /> 63 <Event Name="ItemSelectionChanged" Function="QuestGUI.changeToSubquest_clicked"/> 64 </Window> 65 66 <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Hints"> 67 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,0}}" /> 68 <Property Name="InheritsAlpha" Value="False" /> 69 <Property Name="VertFormatting" Value="TopAligned" /> 70 <Property Name="FrameEnabled" Value="false" /> 71 <Property Name="Text" Value="Hints:" /> 72 </Window> 73 </Window> 74 </Window> 75 </Window> 14 76 </Window> 15 16 <Window Type="MenuWidgets/Listbox" Name="orxonox/QuestGUI/QuestsList">17 <Property Name="UnifiedPosition" Value="{{0.07,0},{0.18,0}}" />18 <Property Name="UnifiedSize" Value="{{0.86,0},{0.8,0}}" />19 <Property Name="Alpha" Value="0.8" />20 </Window>21 22 77 </Window> 23 78 </GUILayout> -
code/branches/presentation/data/gui/scripts/NotificationLayer.lua
r8351 r8637 4 4 5 5 P.queueList = {} 6 P.editMode = false7 6 8 7 P.sampleWindow = nil … … 17 16 function P.createQueue(name, size) 18 17 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. 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") 21 23 root:addChildWindow(queue) 22 23 queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))24 queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))25 24 26 25 local queueTuple = 27 26 { 28 ["window"] = queue, 29 ["name"] = name, 30 ["edit"] = nil, 31 ["visible"] = false 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 32 37 } 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)))) 33 41 34 42 P.queueList[name] = queueTuple -- name access … … 41 49 42 50 if queue ~= nil then 51 queue.window:getParent():removeChildWindow(queue.window) 43 52 winMgr:destroyWindow(queue.window) 44 53 end … … 52 61 return 53 62 end 54 item = CEGUI.createListboxTextItem(notification) 55 local listbox = CEGUI.toListbox(queue.window) 56 -- Add the item to the top of the listbox. 57 if listbox:getItemCount() == 0 then 58 listbox:addItem(item) 59 else 60 listbox:insertItem(item, listbox:getListboxItemFromIndex(0)) 61 end 63 64 local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Queue/" .. queueName .. "/" .. queue.last) 65 item:setText(notification) 66 P.setItemFontHelper(item, queue, true) 67 -- Add the item to the top of the queue. 68 local itemHeight = P.itemHeightHelper(queue) 69 if queue.last-queue.first > 0 then -- If the queue is not empty move all items down 70 for i=queue.first,queue.last-1 do 71 local item = queue.items[i] 72 item:setYPosition(CEGUI.UDim(0, itemHeight*(queue.last-i))) 73 end 74 end 75 queue.window:addChildWindow(item) 76 item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, itemHeight))) 77 item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) 78 item:setProperty("Alpha", 1.0) 79 item:setProperty("InheritsAlpha", "false") 80 item:setProperty("BackgroundEnabled", "false") 81 item:setProperty("FrameEnabled", "false") 82 item:setProperty("HorzFormatting", queue.alignment) 83 queue.items[queue.last] = item 84 queue.last = queue.last+1 62 85 63 86 -- If the queue has been invisible, set it to visible. … … 73 96 return 74 97 end 75 local listbox = CEGUI.toListbox(queue.window) 76 -- Removes the item from the bottom of the listbox. 77 listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1)) 98 local item = queue.items[queue.first] 99 -- Removes the item from the bottom of the queue. 100 queue.window:removeChildWindow(item) 101 winMgr:destroyWindow(item) 102 queue.first = queue.first+1 78 103 79 104 -- Sets the queue to invisible if there are no more notifications in it. 80 if listbox:getItemCount()== 0 then105 if queue.last-queue.first == 0 then 81 106 P.setVisible(queue, false) 82 107 end 83 108 end 84 109 85 -- Removes a notification at a given index from the queue. 110 -- 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. 86 111 function P.removeNotification(queueName, index) 87 112 local queue = P.queueList[queueName] … … 89 114 return 90 115 end 91 local listbox = CEGUI.toListbox(queue.window) 116 117 index = queue.last-tonumber(index)-1 118 --if index == queue.first then -- If we want to remove the oldest notification, we can just use pop. 119 -- P.popNotification(queueName) 120 -- return 121 --end 122 92 123 -- Removes the item. 93 listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index))) 124 local item = queue.items[index] 125 queue.window:removeChildWindow(item) 126 winMgr:destroyWindow(item) 127 queue.items[index] = nil 128 129 -- Move the items below, up. 130 local itemHeight = P.itemHeightHelper(queue) 131 local moved = false 132 if index > queue.first then -- Move all older notifications up in the list. 133 for i=index-1,-1,queue.first do 134 cout(0, i) 135 item = queue.items[i] 136 item:setYposition(CEGUI.UDim(0, itemHeight*(queue.last-i-1))) 137 queue.items[i+1] = item 138 end 139 end 140 queue.items[queue.first] = nil 141 queue.first = queue.first+1 94 142 95 143 -- Sets the queue to invisible if there are no more notifications in it. 96 if listbox:getItemCount()== 0 then144 if queue.last-queue.first == 0 then 97 145 P.setVisible(queue, false) 98 146 end … … 105 153 return 106 154 end 107 local listbox = CEGUI.toListbox(queue.window) 108 CEGUI.toListbox(queue.window):resetList() 155 for i=queue.first,queue.last-1 do 156 local item = queue.items[i] 157 queue.window:removeChildWindow(item) 158 winMgr:destroyWindow(item) 159 end 160 queue.items = {} 161 queue.first = 1 162 queue.last = 1 109 163 110 164 -- Sets the queue to invisible. … … 121 175 end 122 176 123 -- Enter the edit mode of the notification layer. 124 function P.enterEditMode() 125 P.editMode = true 126 127 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 128 129 --Add control frame window. 130 local window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/ControlWindow") 131 local frame = tolua.cast(window, "CEGUI::FrameWindow") 132 frame:setCloseButtonEnabled(false) 133 frame:setText("NotificationLayer Control Window") 134 frame:setSize(CEGUI.UVector2(CEGUI.UDim(0.7, 0), CEGUI.UDim(0.2, 0))) 135 root:addChildWindow(window) 136 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/ScrollingPane") 137 pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30))) 138 pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26))) 139 window:addChildWindow(pane) 140 141 vertOffset = 0 142 horzOffset = 0 143 -- Line to be able to create a new queue. 144 local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle") 145 newQueueTitle:setText("Create a new NotificationQueue:") 146 local size = getMinTextSize(newQueueTitle) 147 local textHeight = size[1] 148 newQueueTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 149 newQueueTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 150 pane:addChildWindow(newQueueTitle) 151 horzOffset = horzOffset + size[2] + 5 152 local newQueueName = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName") 153 newQueueName:setProperty("ReadOnly", "set:False") 154 newQueueName:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 155 newQueueName:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 156 horzOffset = horzOffset + size[2] + 5 157 pane:addChildWindow(newQueueName) 158 local create = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/CreateNewQueue") 159 create:setText("create") 160 P.sampleWindow:setText("create") 161 size = getMinTextSize(P.sampleWindow) 162 create:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight))) 163 create:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 164 orxonox.GUIManager:subscribeEventHelper(create, "Clicked", P.name .. ".createNewQueue_clicked") 165 pane:addChildWindow(create) 166 horzOffset = horzOffset + size[2]+20 + 5 167 vertOffset = vertOffset + textHeight + 5 168 169 horzOffset = 0 170 -- Button to leave the edit mode. 171 local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton") 172 leave:setText("leave Edit Mode") 173 P.sampleWindow:setText("leave Edit Mode") 174 size = getMinTextSize(P.sampleWindow) 175 leave:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]+20), CEGUI.UDim(0, textHeight))) 176 leave:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 177 orxonox.GUIManager:subscribeEventHelper(leave, "Clicked", P.name .. ".leaveEditMode_clicked") 178 pane:addChildWindow(leave) 179 horzOffset = horzOffset + size[2]+20 + 5 180 vertOffset = vertOffset + textHeight + 5 181 182 --Replace all queues with FrameWindows 183 for k,v in pairs(P.queueList) do 184 if v ~= nil then 185 local queue = P.queueList[k] 186 -- Remove the window that displays the queue from the root window such that it is no longer displayed. 187 root:removeChildWindow(v.window) 188 189 -- Create the frame window, with options to edit the queue, that is displayed instead of the queue. 190 local window = P.createQueueEditFrame(v.name) 191 window:setArea(v.window:getArea()) -- Set the frame window size and position to the same as the queue. 192 193 v.edit = window 194 end 195 end 196 end 197 198 -- Helper function. Creates a frame for the input queue. 199 function P.createQueueEditFrame(queueName) 200 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 201 202 window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. queueName) 203 local frame = tolua.cast(window, "CEGUI::FrameWindow") 204 frame:setCloseButtonEnabled(true) 205 orxonox.GUIManager:subscribeEventHelper(frame, "CloseClicked", P.name .. ".closeQueue_clicked") 206 frame:setText("NotificationQueue \"" .. queueName .. "\"") 207 root:addChildWindow(window) 208 local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/ScrollingPane") 209 pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30))) 210 pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26))) 211 window:addChildWindow(pane) 212 213 local horzOffset = 0 214 local vertOffset = 0 215 216 -- The line that lets you edit the targets of the queue. 217 local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/TargetsTitle") 218 targetsTitle:setText("Targets:") 219 local size = getMinTextSize(targetsTitle) 220 local textHeight = size[1] 221 targetsTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 222 targetsTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 223 pane:addChildWindow(targetsTitle) 224 horzOffset = horzOffset + size[2] + 5 225 local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets") 226 targets:setProperty("ReadOnly", "set:False") 227 local targetsText = orxonox.NotificationManager:getInstance():getQueue(queueName):getTargets() 228 targets:setText(targetsText) 229 P.sampleWindow:setText(targetsText) 230 size = getMinTextSize(P.sampleWindow) 231 targets:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) 232 targets:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 233 horzOffset = horzOffset + size[2]*2+20 + 5 234 pane:addChildWindow(targets) 235 local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save") 236 save:setText("save") 237 P.sampleWindow:setText("save") 238 size = getMinTextSize(P.sampleWindow) 239 local saveTextWidth = size[2]+20 240 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) 241 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 242 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveTargets_clicked") 243 pane:addChildWindow(save) 244 horzOffset = horzOffset + saveTextWidth 245 vertOffset = vertOffset + textHeight + 5 246 247 horzOffset = 0 248 -- The line that lets you edit the size of the queue. 249 local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/SizeTitle") 250 sizeTitle:setText("Size:") 251 size = getMinTextSize(sizeTitle) 252 sizeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 253 sizeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 254 pane:addChildWindow(sizeTitle) 255 horzOffset = horzOffset + size[2] + 5 256 local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size") 257 queueSize:setProperty("ReadOnly", "set:False") 258 local maxSize = orxonox.NotificationManager:getInstance():getQueue(queueName):getMaxSize() 259 queueSize:setText(maxSize) 260 P.sampleWindow:setText(maxSize) 261 size = getMinTextSize(P.sampleWindow) 262 queueSize:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) 263 queueSize:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 264 horzOffset = horzOffset + size[2]*2+20 + 5 265 pane:addChildWindow(queueSize) 266 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save") 267 save:setText("save") 268 P.sampleWindow:setText("save") 269 size = getMinTextSize(P.sampleWindow) 270 local saveTextWidth = size[2]+20 271 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) 272 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 273 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveSize_clicked") 274 pane:addChildWindow(save) 275 horzOffset = horzOffset + saveTextWidth 276 vertOffset = vertOffset + textHeight + 5 277 278 horzOffset = 0 279 -- The line that lets you edit the display time of the queue. 280 local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTimeTitle") 281 displayTimeTitle:setText("Display time:") 282 size = getMinTextSize(displayTimeTitle) 283 displayTimeTitle:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]), CEGUI.UDim(0, textHeight))) 284 displayTimeTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 285 pane:addChildWindow(displayTimeTitle) 286 horzOffset = horzOffset + size[2] + 5 287 local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime") 288 displayTime:setProperty("ReadOnly", "set:False") 289 local time = orxonox.NotificationManager:getInstance():getQueue(queueName):getDisplayTime() 290 displayTime:setText(time) 291 P.sampleWindow:setText(time) 292 size = getMinTextSize(P.sampleWindow) 293 displayTime:setSize(CEGUI.UVector2(CEGUI.UDim(0, size[2]*2+20), CEGUI.UDim(0, textHeight))) 294 displayTime:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 295 horzOffset = horzOffset + size[2]*2+20 + 5 296 pane:addChildWindow(displayTime) 297 save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save") 298 save:setText("save") 299 P.sampleWindow:setText("save") 300 size = getMinTextSize(P.sampleWindow) 301 local saveTextWidth = size[2]+20 302 save:setSize(CEGUI.UVector2(CEGUI.UDim(0, saveTextWidth), CEGUI.UDim(0, textHeight))) 303 save:setPosition(CEGUI.UVector2(CEGUI.UDim(0, horzOffset), CEGUI.UDim(0, vertOffset))) 304 orxonox.GUIManager:subscribeEventHelper(save, "Clicked", P.name .. ".saveDisplayTime_clicked") 305 pane:addChildWindow(save) 306 horzOffset = horzOffset + saveTextWidth 307 vertOffset = vertOffset + textHeight + 5 308 309 return window 310 end 311 312 -- Leave the edit mode. 313 function P.leaveEditMode() 314 P.editMode = false 315 316 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 317 --Replace all queues with FrameWindows 318 for k,v in pairs(P.queueList) do 319 if v ~= nil then 320 -- Add the queue window to the root window to have it displayed again. 321 root:addChildWindow(v.window) 322 -- Set the size and position of the queue window to the size and position of the queue edit frame. 323 v.window:setArea(v.edit:getArea()) 324 -- Destroy the edit frame. 325 winMgr:destroyWindow(v.edit) 326 v.edit = nil 327 end 328 end 329 330 --Remove control window 331 winMgr:destroyWindow(winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow")) 332 end 333 334 -- Is called after the sheet has been hidden. 335 function P.onQuit() 336 -- If we leave the edit mode we show the sheet again. 337 if P.editMode then 338 P.leaveEditMode() 339 showMenuSheet(P.name, false, true) 340 end 341 end 342 343 -- If the button to save the targets of a queue has been clicked. 344 function P. saveTargets_clicked(e) 345 local we = CEGUI.toWindowEventArgs(e) 346 local name = we.window:getName() 347 348 local match = string.gmatch(name, "EditMode/.*/Targets/Save") 349 local nameStr = match() 350 local queueName = string.sub(nameStr, 10, string.len(nameStr)-13) 351 352 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets") 353 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save") 354 local width = window:getWidth():asAbsolute(1) 355 356 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 357 -- Set the new targets. 358 queue:setTargets(window:getText()) 359 local targets = queue:getTargets() 360 361 window:setText(targets) 362 P.sampleWindow:setText(targets) 363 local size = getMinTextSize(P.sampleWindow) 364 -- Adjust the width of the targets field. 365 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 366 -- Adjust the position of the save button after the targets field. 367 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 368 end 369 370 -- If the button to save the size if a queue has been clicked. 371 function P. saveSize_clicked(e) 372 local we = CEGUI.toWindowEventArgs(e) 373 local name = we.window:getName() 374 375 local match = string.gmatch(name, "EditMode/.*/Size/Save") 376 local nameStr = match() 377 local queueName = string.sub(nameStr, 10, string.len(nameStr)-10) 378 379 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size") 380 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save") 381 local width = window:getWidth():asAbsolute(1) 382 383 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 384 -- Set the new size. 385 queue:setMaxSize(tonumber(window:getText())) 386 local maxSize = queue:getMaxSize() 387 388 window:setText(maxSize) 389 P.sampleWindow:setText(maxSize) 390 local size = getMinTextSize(P.sampleWindow) 391 -- Adjust the width of the size field. 392 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 393 -- Adjust the position of the save button after the size field. 394 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 395 end 396 397 -- If the button to save the display time if a queue has been clicked. 398 function P. saveDisplayTime_clicked(e) 399 local we = CEGUI.toWindowEventArgs(e) 400 local name = we.window:getName() 401 402 local match = string.gmatch(name, "EditMode/.*/DisplayTime/Save") 403 local nameStr = match() 404 local queueName = string.sub(nameStr, 10, string.len(nameStr)-17) 405 406 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime") 407 local save = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save") 408 local width = window:getWidth():asAbsolute(1) 409 410 local queue = orxonox.NotificationManager:getInstance():getQueue(queueName) 411 -- Set the new display time. 412 queue:setDisplayTime(tonumber(window:getText())) 413 local time = queue:getDisplayTime() 414 415 window:setText(time) 416 P.sampleWindow:setText(time) 417 local size = getMinTextSize(P.sampleWindow) 418 -- Adjust the width of the display time field. 419 window:setWidth(CEGUI.UDim(0, size[2]*2+20)) 420 -- Adjust the position of the save button after the display time field. 421 save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1))) 422 end 423 424 -- if the button to create a new queue has been clicked. 425 function P.createNewQueue_clicked(e) 426 local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName") 427 local name = window:getText() 428 429 local queue = P.queueList[name] 430 -- Test if a queue with that name already exists. 431 if queue ~= nil then 432 window:setText("Queue with that name already exists.") 433 return 434 end 435 436 -- Creates the new queue. 437 orxonox.NotificationManager:getInstance():createQueue(name) 438 439 queue = P.queueList[name] 440 if queue == nil then 441 return 442 end 443 444 -- Create the frame that represents the queue in edit mode, since that's what we're in. 445 local frame = P.createQueueEditFrame(name) 446 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 447 -- Remove the queue window from the root window, since we're in edit mode. 448 root:removeChildWindow(queue.window) 449 -- Set the frame window size and position to that of the queue window. 450 frame:setArea(queue.window:getArea()) 451 queue.edit = frame 452 453 -- Reset the text to create a new queue. 454 window:setText("") 455 end 456 457 -- If the button to leave the edit mode has been clicked. 458 function P.leaveEditMode_clicked(e) 459 hideMenuSheet(P.name) 460 end 461 462 -- If the button to close the queue has been clicked. 463 function P.closeQueue_clicked(e) 464 local we = CEGUI.toWindowEventArgs(e) 465 local name = we.window:getName() 466 467 local match = string.gmatch(name, "EditMode/.*") 468 local nameStr = match() 469 local queueName = string.sub(nameStr, 10, string.len(nameStr)) 470 471 -- Destroy the frame window, 472 winMgr:destroyWindow(P.queueList[queueName].edit) 473 P.queueList[queueName].edit = nil 474 -- Destroy the queue. 475 orxonox.NotificationManager:getInstance():getQueue(queueName):destroy() 177 -- Change the position of the queue. 178 -- 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'. 179 function P.moveQueue(queueName, relativeXPos, absoluteXPos, relativeYpos, absoluteYPos) 180 local queueWindow = P.queueList[queueName].window 181 queueWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(relativeXPos, absoluteXPos), CEGUI.UDim(relativeYpos, absoluteYPos))) 182 end 183 184 -- Change the size of the queue. 185 -- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'. 186 -- 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. 187 function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth) 188 local queue = P.queueList[queueName] 189 local queueWindow = queue.window 190 if queueWindow == nil then 191 return 192 end 193 if absoluteHeigth == nil then 194 absoluteHeigth = P.queueHeightHelper(queue, queue.maxSize) 195 relativeHeight = 0 196 end 197 queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth))) 198 end 199 200 -- Change the horizontal alignment of the displayed notifications. 201 -- The parameters are the name of the queue and the alignment parameter, 202 function P.changeQueueAlignment(queueName, alignment) 203 local queue = P.queueList[queueName] 204 local queueWindow = queue.window 205 if queueWindow == nil then 206 return 207 end 208 209 queue.alignment = alignment 210 local item = nil 211 for i=queue.first,queue.last-1 do 212 item = queue.items[i] 213 item:setProperty("HorzFormatting", queue.alignment) 214 end 215 end 216 217 -- Change the font size of all notifications in a queue. 218 -- The parameters are (in order) 'name of the queue', 'font size'. 219 function P.changeQueueFontSize(queueName, size) 220 local queue = P.queueList[queueName] 221 local queueWindow = queue.window 222 if queueWindow == nil then 223 return 224 end 225 226 queue.fontSize = size 227 for i=queue.first,queue.last-1 do 228 P.setItemFontHelper(queue.items[i], queue, false) 229 end 230 end 231 232 -- Change the font color of all notifications in a queue. 233 -- The parameters are (in order) 'name of the queue', 'ARGB of the font color in hex notation'. 234 function P.changeQueueFontColor(queueName, color) 235 local queue = P.queueList[queueName] 236 local queueWindow = queue.window 237 if queueWindow == nil then 238 return 239 end 240 241 queue.fontColor = color 242 for i=queue.first,queue.last-1 do 243 P.setItemFontHelper(queue.items[i], queue, true) 244 end 245 end 246 247 -- Helper function to set the font size and color of a item of a queue. 248 -- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well' 249 function P.setItemFontHelper(item, queue, changeColor) 250 --local item = tolua.cast(item, "CEGUI::ListboxTextItem") 251 local fontMgr = CEGUI.FontManager:getSingleton() 252 if fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize) then 253 item:setFont("BlueHighway-" .. queue.fontSize) 254 else 255 orxonox.GUIManager:addFontHelper("BlueHighway-" .. queue.fontSize, queue.fontSize, "bluehigh.ttf") 256 item:setFont("BlueHighway-" .. queue.fontSize) 257 end 258 if changeColor then 259 item:setProperty("TextColours", "tl:" .. queue.fontColor .. " tr:" .. queue.fontColor .. " bl:" .. queue.fontColor .. " br:" .. queue.fontColor .. "") 260 end 476 261 end 477 262 478 263 -- Helper function. Returns height a queue needs to have to display 'size' items. 479 264 function P.queueHeightHelper(queue, size) 480 local listbox = CEGUI.toListbox(queue) 481 local item = CEGUI.createListboxTextItem("Text") 482 listbox:addItem(item) 483 local singleItemHeight = listbox:getTotalItemsHeight() 484 local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel()) 485 local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue) 486 local frameHeight = queue:getUnclippedOuterRect():getHeight() - formattedArea:getHeight() 487 listbox:removeItem(item) 488 return frameHeight + singleItemHeight*size 265 --local listbox = CEGUI.toListbox(queue.window) 266 --local item = CEGUI.createListboxTextItem("Text") 267 --P.setItemFontHelper(item, queue, false) 268 --listbox:addItem(item) 269 --local singleItemHeight = listbox:getTotalItemsHeight() 270 local singleItemHeight = P.itemHeightHelper(queue) 271 --local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel()) 272 --local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window) 273 --local frameHeight = queue.window:getUnclippedOuterRect():getHeight() - formattedArea:getHeight() 274 --listbox:removeItem(item) 275 --return frameHeight + singleItemHeight*size 276 return singleItemHeight*size + 1 277 end 278 279 function P.itemHeightHelper(queue) 280 local item = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/Test/") 281 item:setText("text") 282 P.setItemFontHelper(item, queue, true) 283 queue.window:addChildWindow(item) 284 item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0))) 285 item:setProperty("FrameEnabled", "false") 286 local height = getStaticTextWindowHeight(item) 287 queue.window:removeChildWindow(item) 288 winMgr:destroyWindow(item) 289 return height 489 290 end 490 291 -
code/branches/presentation/data/gui/scripts/QuestGUI.lua
r7732 r8637 3 3 local P = createMenuSheet("QuestGUI") 4 4 5 P.rootWindow = nil 6 P.detailsWindows = {} 5 P.questManager = nil -- The QuestManager. 6 P.showActive = true -- Whether the active or finished quest list is displayed. 7 P.currentQuest = nil -- The quest that is currently displayed. 8 P.player = nil -- The player the quests are displayed for. 7 9 P.quests = {} 8 P.hints = {} 9 P.player = nil 10 P.subquests = {} 10 11 11 12 -- design parameters 12 P.indentWidth = 2013 13 P.scrollbarWidth = 13 14 P.buttonHeight = 30 14 P.frameHeigth = 18 15 P.borderSize = 5 15 16 P.titleHeight = 26 16 P.borderWidth = 5 17 18 --TODO: 19 -- Highlight whether we are currently looking at active or finished quests 20 -- Distinguish completed from failed quests 21 22 function P.onLoad() 23 P.questManager = orxonox.QuestManager:getInstance() -- Store the pointer to the QuestManager as an internal variable to allow for faster access, 24 end 17 25 18 26 function P.onShow() 19 20 local questsList = winMgr:getWindow("orxonox/QuestGUI/QuestsList") 21 27 -- Get the player. 22 28 P.player = orxonox.GUIManager:getInstance():getPlayer(P.name) 23 P.rootWindow = P.createQuestGUI() 24 25 questsList:addChildWindow(P.rootWindow) 26 end 27 28 function P.onHide() 29 P.cleanup() 30 end 31 29 30 -- Load the list of quests to be displayed. 31 P.loadQuestsList(P.currentQuest) 32 end 33 34 -- Loads the list of quests, depending on P.showActive, either the active (P.showActive == true) or the finished, i.e. inactive quests are loaded. 35 -- selectQuest is a pointer to a quest that should be selected, if it is nil the first quest is selected. 36 function P.loadQuestsList(selectQuest) 37 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList")) 38 P.clearQuestList() 39 40 local selectQuestId = nil 41 if selectQuest ~= nil then 42 selectQuestId = P.questManager:getId(selectQuest) 43 end 44 45 -- Iterate through all root-quests. 46 local numRootQuests = P.questManager:getNumRootQuests(P.player) 47 if numRootQuests > 0 then 48 local i = 0 49 while i <= numRootQuests-1 do 50 local quest = P.questManager:getRootQuest(P.player, i) 51 -- Insert the current quest into the list. 52 local item = P.insertQuest(list, quest) 53 -- If the quest was inserted in the list and is has the same id as the selectQuest (thus it is the same quest) it is selected. 54 if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(quest) then 55 list:setItemSelectState(item, true) 56 end 57 -- Insert all subquests of this rootquest. 58 P.insertSubQuests(list, quest, selectQuestId) 59 i = i+1 60 end 61 -- If there were quests added to the list but there was no selectQuest specified (i.e. selectQuest was nil), the first item is selected. 62 if list:getItemCount() > 0 then 63 if selectQuestId == nil then 64 list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first quest. 65 end 66 -- If there werent any quests added the standard "no quests" message is loaded. 67 else 68 P.loadQuest() 69 end 70 end 71 end 72 73 -- Helper function, recursively inserts all the (active or inactive, depending on P.showActive) subquests of the input quest. 74 -- list is the list into which the subquests should be insterted. 75 -- quest is the quest, whose subquests should be inserted. 76 -- selectQuestId is the id of the quest that should be selected. 77 function P.insertSubQuests(list, quest, selectQuestId) 78 -- Iterate through all sub-quests. 79 local numQuests = P.questManager:getNumSubQuests(quest, P.player) 80 if numQuests > 0 then 81 local i = 0 82 while i <= numQuests-1 do 83 local subquest = P.questManager:getSubQuest(quest, P.player, i) 84 -- Insert the current quest into the list. 85 local item = P.insertQuest(list, subquest) 86 -- If the quest was inserted in the list and is has the same id as the selectQuest (thus it is the same quest) it is selected. 87 if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(subquest) then 88 list:setItemSelectState(item, true) 89 end 90 i = i+1 91 end 92 end 93 end 94 95 -- Helper function, inserts a quest into the list (depending whether active or inactive quests are being shown). Returns nil if the quest was not inserted. 96 -- list is the list into which the quets should be inserted. 97 -- quest is the quest to be inserted. 98 function P.insertQuest(list, quest) 99 if P.showActive == quest:isActive(P.player) then 100 local item = CEGUI.createListboxTextItem(P.questManager:getDescription(quest):getTitle()) 101 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 102 list:addItem(item) 103 table.insert(P.quests, quest) 104 return item 105 end 106 return nil 107 end 108 109 -- Loads the input quest. 110 -- quest the quest to be loaded. 111 function P.loadQuest(quest) 112 113 P.clearQuest() -- Clear the old quest. 114 if quest == nil then -- If quets is nil there is nothing to display. 115 return 116 else 117 local offset = 0 118 119 -- Load title and description 120 local description = P.questManager:getDescription(quest) 121 local titleWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Title") 122 titleWindow:setText(description:getTitle()) 123 local descriptionWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Description") 124 descriptionWindow:setText(description:getDescription()) 125 descriptionWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(1, 0))) 126 descriptionWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, P.borderSize))) 127 local height = getStaticTextWindowHeight(descriptionWindow) 128 descriptionWindow:setHeight(CEGUI.UDim(0, height)) 129 offset = offset + height 130 131 -- Load subquests 132 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList")) 133 local numQuests = P.questManager:getNumSubQuests(quest, P.player) 134 local i = 0 135 while i <= numQuests-1 do 136 local quest = P.questManager:getSubQuest(quest, P.player, i) 137 local item = CEGUI.createListboxTextItem(P.questManager:getDescription(quest):getTitle()) 138 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 139 list:addItem(item) 140 table.insert(P.subquests, quest) 141 i = i+1 142 end 143 height = list:getTotalItemsHeight() 144 if height > 0 then 145 height = height+P.frameHeigth 146 end 147 list:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(0, height))) 148 list:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset))) 149 offset = offset + height + P.borderSize 150 151 -- Load hints 152 local hintsWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Hints") 153 hintsWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset))) 154 hintsWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(0, 0))) 155 height = P.titleHeight 156 local numHints = P.questManager:getNumHints(quest, P.player) 157 local i = 0 158 while i <= numHints-1 do 159 local hint = P.questManager:getHints(quest, P.player, i) 160 height = height + P.insertHint(hintsWindow, hint, i, height) 161 i = i+1 162 end 163 if numHints == 0 then 164 height = 0 165 end 166 hintsWindow:setHeight(CEGUI.UDim(0, height)) 167 offset = offset + height 168 169 -- Set the size of the wrapper 170 local window = winMgr:getWindow("orxonox/QuestGUI/Quest/Wrapper") 171 window:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize-P.scrollbarWidth), CEGUI.UDim(0,offset+P.borderSize))) 172 end 173 174 P.currentQuest = quest 175 end 176 177 -- Clear the currently displayed quest. 178 function P.clearQuest() 179 -- clear title 180 local titleWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Title") 181 titleWindow:setText("no Quests") 182 183 -- clear description 184 local descriptionWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Description") 185 descriptionWindow:setText("There is currently no quest that can be displayed.") 186 187 -- clear list fo subquests 188 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList")) 189 list:resetList() 190 list:setHeight(CEGUI.UDim(0, 0)) 191 P.subquests = {} 192 193 -- clear hints 194 local hints = winMgr:getWindow("orxonox/QuestGUI/Quest/Hints") 195 local numChildren = hints:getChildCount()-2 -- TODO: HACK 196 local i = 0 197 while i < numChildren do 198 local hint = hints:getChild("orxonox/QuestGUI/Quest/Hints/" .. i) 199 if hint ~= nil then 200 hints:removeChildWindow(hint) 201 winMgr:destroyWindow(hint) 202 end 203 i = i+1 204 end 205 hints:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize), CEGUI.UDim(0, 0))) 206 207 P.currentQuest = nil 208 end 209 210 -- Clear the quests list 211 function P.clearQuestList() 212 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList")) 213 list:resetList() 214 P.quests = {} 215 end 216 217 -- Select an input quest in the input list. 218 -- list is the list in which the input quest is to be selected. 219 -- quest is the quest to be selected. 220 function P.selectQuest(list, quest) 221 if quest == nil then -- If the input quest is nil, there is nothing to be selected, an error is output and the first quest is selected instead. 222 cout(1, "Error in QuestGUI: selectQuest(), input quest is nil. Selecting first.") 223 list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first 224 return 225 end 226 227 local questId = P.questManager:getId(quest) 228 local found = false 229 local index = 0 230 -- Iterate over all quests currently in the list. 231 for k,v in pairs(P.quests) do 232 -- If the id's are the same we have found the quest. 233 if P.questManager:getId(v) == questId then 234 found = true 235 index = k-1 236 end 237 end 238 239 if found then -- If the quest was found it is selected. 240 list:setItemSelectState(list:getListboxItemFromIndex(index), true) 241 else -- If the quest isn't found an error is output and the first quest is selected instead. 242 cout(1, "Error in QuestGUI: selectQuest(), input quest is not in list. Selecting first.") 243 list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first 244 end 245 end 246 247 -- Helper function, insert the input hint into the input hintsWindow. Returns the height of the newly inserted hint. 248 -- hintsWindow is the window in which the hint is to be inserted. 249 -- hint is the hint to be inserted. 250 -- index is the index of the hint. 251 -- offset is the current offset in the hintsWindow. 252 function P.insertHint(hintsWindow, hint, index, offset) 253 -- Create the window for the hint. 254 local window = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/QuestGUI/Quest/Hints/" .. index) 255 window:setProperty("HorzFormatting", "WordWrapLeftAligned") 256 window:setProperty("VertFormatting", "TopAligned") 257 window:setProperty("FrameEnabled", "false") 258 window:setID(index) 259 hintsWindow:addChildWindow(window) 260 local description = P.questManager:getDescription(hint) 261 window:setText(description:getDescription()) 262 window:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(1, 0))) 263 local height = getStaticTextWindowHeight(window) 264 window:setHeight(CEGUI.UDim(0, height)) 265 window:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset))) 266 return height 267 end 268 269 -- Show the currently active quests in the quests list. 270 function P.showActiveQuestsButton_clicked(e) 271 if P.showActive == false then 272 P.showActive = true 273 P.loadQuestsList() 274 end 275 end 276 277 -- Show the finished (i.e. inactive) quests in the quests list. 278 function P.showFinishedQuestsButton_clicked(e) 279 if P.showActive == true then 280 P.showActive = false 281 P.loadQuestsList() 282 end 283 end 284 285 -- Change to a new quest. 286 function P.changeQuest_clicked(e) 287 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList")) 288 local choice = list:getFirstSelectedItem() 289 if choice ~= nil then 290 local index = list:getItemIndex(choice) 291 local quest = P.quests[index+1] 292 if quest ~= nil then 293 P.loadQuest(quest) 294 end 295 end 296 end 297 298 -- Change to a new subquest. 299 function P.changeToSubquest_clicked(e) 300 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList")) 301 local questsList = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList")) 302 local choice = list:getFirstSelectedItem() 303 if choice ~= nil then 304 local index = list:getItemIndex(choice) 305 local quest = P.subquests[index+1] 306 if quest ~= nil then 307 -- If the P.showActive must be changed to display the quest the quests list also has to be regenerated. 308 if quest:isActive(P.player) == P.showActive then 309 P.selectQuest(questsList, quest) 310 else 311 P.showActive = quest:isActive(P.player) 312 P.loadQuestsList(quest) 313 end 314 else 315 cout(1, "Error in QuestGUI: changeToSubquest(), quest was nil. Ignoring...") 316 end 317 end 318 end 319 320 -- old: 321 --[[ 32 322 function P.createQuestGUI() 33 323 local questManager = orxonox.QuestManager:getInstance() … … 283 573 winMgr:destroyWindow(P.detailsWindows[detailsNr]) 284 574 P.detailsWindows[detailsNr] = nil 285 end 575 end --]] 286 576 287 577 return P -
code/branches/presentation/data/gui/scripts/SingleplayerMenu.lua
r8079 r8637 54 54 index = index + 1 55 55 end 56 56 57 for k,v in pairs(P.levelList) do 57 58 local item = CEGUI.createListboxTextItem(v:getName()) -
code/branches/presentation/data/levels/FPSTest.oxw
r8079 r8637 21 21 <Template link=lodtemplate_default /> 22 22 </templates> 23 <?lua include("includes/notifications.oxi") ?> 23 24 24 25 <Scene -
code/branches/presentation/data/levels/asteroids.oxw
r8079 r8637 14 14 <Template link=lodtemplate_default /> 15 15 </templates> 16 <?lua include("includes/notifications.oxi") ?> 16 17 17 18 <Scene -
code/branches/presentation/data/levels/docking.oxw
r8561 r8637 19 19 <Template link="lodtemplate_default" /> 20 20 </templates> 21 <?lua include("includes/notifications.oxi") ?> 21 22 22 23 <Scene -
code/branches/presentation/data/levels/dynamicMatch.oxw
r8079 r8637 16 16 <Template link=lodtemplate_default /> 17 17 </templates> 18 <?lua include("includes/notifications.oxi") ?> 18 19 19 20 <Scene -
code/branches/presentation/data/levels/earth.oxw
r8498 r8637 19 19 <Template link="lodtemplate_default" /> 20 20 </templates> 21 <?lua include("includes/notifications.oxi") ?> 21 22 22 23 <Template name=PortalDefault> -
code/branches/presentation/data/levels/emptyLevel.oxw
r8593 r8637 23 23 <Template link=lodtemplate_default /> 24 24 </templates> 25 <?lua include("includes/notifications.oxi") ?> 25 26 26 27 <Scene -
code/branches/presentation/data/levels/events.oxw
r7679 r8637 20 20 <Template link=lodtemplate_default /> 21 21 </templates> 22 <?lua include("includes/notifications.oxi") ?> 22 23 23 24 <Scene -
code/branches/presentation/data/levels/fightInOurBack.oxw
r8213 r8637 68 68 <Template link=lodtemplate_default /> 69 69 </templates> 70 <?lua include("includes/notifications.oxi") ?> 70 71 71 72 <!-- Ausgang: Szene ===> ambientlight/skybox --> -
code/branches/presentation/data/levels/lastManStanding.oxw
r8178 r8637 23 23 <Template link=lodtemplate_default /> 24 24 </templates> 25 <?lua include("includes/notifications.oxi") ?> 25 26 26 27 <Scene -
code/branches/presentation/data/levels/lastTeamStanding.oxw
r8179 r8637 22 22 <Template link=lodtemplate_default /> 23 23 </templates> 24 <?lua include("includes/notifications.oxi") ?> 24 25 25 26 <Scene … … 27 28 skybox = "Orxonox/skypanoramagen1" 28 29 > 30 <?lua include("includes/notifications.oxi") ?> 29 31 30 32 <?lua -
code/branches/presentation/data/levels/lastTeamStandingII.oxw
r8351 r8637 22 22 <Template link=lodtemplate_default /> 23 23 </templates> 24 <?lua include("includes/notifications.oxi") ?> 24 25 25 26 <Scene -
code/branches/presentation/data/levels/myTestLevel.oxw
r8614 r8637 23 23 <Template link=lodtemplate_default /> 24 24 </templates> 25 <?lua include("includes/notifications.oxi") ?> 25 26 26 27 <Scene -
code/branches/presentation/data/levels/notifications.oxw
r7679 r8637 19 19 <Template link=lodtemplate_default /> 20 20 </templates> 21 <?lua include("includes/notifications.oxi") ?> 21 22 22 23 <Scene … … 24 25 skybox = "Orxonox/skypanoramagen1" 25 26 > 26 27 <Script code="showGUI NotificationLayer false true" needsGraphics="true" />28 27 29 28 <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" /> -
code/branches/presentation/data/levels/pickups.oxw
r8556 r8637 23 23 <Template link=lodtemplate_default /> 24 24 </templates> 25 <?lua include("includes/notifications.oxi") ?> 25 26 26 27 <Scene -
code/branches/presentation/data/levels/pirateAttack.oxw
r8213 r8637 35 35 <Template link=lodtemplate_default /> 36 36 </templates> 37 <?lua include("includes/notifications.oxi") ?> 37 38 38 39 <Scene -
code/branches/presentation/data/levels/planets.oxw
r8498 r8637 19 19 <Template link="lodtemplate_default" /> 20 20 </templates> 21 <?lua include("includes/notifications.oxi") ?> 21 22 22 23 <Scene -
code/branches/presentation/data/levels/pong.oxw
r7865 r8637 56 56 <Template link=lodtemplate_default /> 57 57 </templates> 58 <?lua include("includes/notifications.oxi") ?> 58 59 59 60 <WorldAmbientSound source="mainmenu.ogg" playOnLoad=true /> -
code/branches/presentation/data/levels/portals.oxw
r8605 r8637 21 21 <Template link=lodtemplate_default /> 22 22 </templates> 23 <?lua include("includes/notifications.oxi") ?> 23 24 24 25 <Scene -
code/branches/presentation/data/levels/presentation.oxw
r7679 r8637 19 19 <Template link=lodtemplate_default /> 20 20 </templates> 21 <?lua include("includes/notifications.oxi") ?> 21 22 22 23 <Scene -
code/branches/presentation/data/levels/presentation09.oxw
r8079 r8637 21 21 <Template link=lodtemplate_default /> 22 22 </templates> 23 <?lua include("includes/notifications.oxi") ?> 23 24 24 25 <Scene -
code/branches/presentation/data/levels/presentation09b.oxw
r8079 r8637 23 23 <Template link=lodtemplate_default /> 24 24 </templates> 25 <?lua include("includes/notifications.oxi") ?> 25 26 26 27 <Scene -
code/branches/presentation/data/levels/presentationDM.oxw
r8079 r8637 20 20 <Template link=lodtemplate_default /> 21 21 </templates> 22 <?lua include("includes/notifications.oxi") ?> 22 23 23 24 <Scene -
code/branches/presentation/data/levels/presentationFS10.oxw
r7679 r8637 26 26 <Template link=lodtemplate_default /> 27 27 </templates> 28 <?lua include("includes/notifications.oxi") ?> 28 29 29 30 <Scene -
code/branches/presentation/data/levels/presentationFS102.oxw
r8079 r8637 21 21 <Template link=lodtemplate_default /> 22 22 </templates> 23 <?lua include("includes/notifications.oxi") ?> 23 24 24 25 <Scene -
code/branches/presentation/data/levels/presentationFS10Ed.oxw
r8079 r8637 21 21 <Template link=lodtemplate_default /> 22 22 </templates> 23 <?lua include("includes/notifications.oxi") ?> 23 24 24 25 <Scene -
code/branches/presentation/data/levels/presentationFS11.oxw
r8628 r8637 28 28 <Template link=lodtemplate_default /> 29 29 </templates> 30 <?lua include("includes/notifications.oxi") ?> 31 32 <NotificationQueueCEGUI 33 name="narrative" 34 targets="narrative" 35 size=1 36 displayTime=30 37 position="0.2, 0, 0.8, 0" 38 fontSize="24" 39 fontColor="1, 1, 0, 0.8" 40 alignment="HorzCentred" 41 displaySize="0.6, 0, 0, 0" 42 /> 30 43 31 44 <Scene … … 39 52 40 53 <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> 41 <SpawnPoint team=0 position="0,0,0" lookat="-2,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff /> 54 55 <SimpleNotification message="Welcome to Earth Orbit" > 56 <events> 57 <trigger> 58 <EventListener event=spawntrigger /> 59 </trigger> 60 </events> 61 </SimpleNotification> 62 <EventMultiTrigger name=spawntrigger> 63 <events> 64 <trigger> 65 <SpawnPoint position="0,0,0" lookat="-2,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff /> 66 </trigger> 67 </events> 68 </EventMultiTrigger> 42 69 43 70 <!-- PICKUPS --> -
code/branches/presentation/data/levels/presentationHS09.oxw
r8079 r8637 24 24 <Template link=lodtemplate_default /> 25 25 </templates> 26 <?lua include("includes/notifications.oxi") ?> 26 27 27 28 <Scene -
code/branches/presentation/data/levels/presentationHS09b.oxw
r8079 r8637 29 29 <Template link=lodtemplate_default /> 30 30 </templates> 31 <?lua include("includes/notifications.oxi") ?> 31 32 32 33 <Scene -
code/branches/presentation/data/levels/princessAeryn.oxw
r7679 r8637 24 24 <Template link=lodtemplate_default /> 25 25 </templates> 26 <?lua include("includes/notifications.oxi") ?> 26 27 27 28 <Scene -
code/branches/presentation/data/levels/screenshot.oxw
r7679 r8637 22 22 <Template link=lodtemplate_default /> 23 23 </templates> 24 <?lua include("includes/notifications.oxi") ?> 24 25 25 26 <Scene -
code/branches/presentation/data/levels/shieldTest.oxw
r8580 r8637 20 20 <Template link=lodtemplate_default /> 21 21 </templates> 22 <?lua include("includes/notifications.oxi") ?> 22 23 23 24 <Scene … … 25 26 skybox = "Orxonox/Starbox" 26 27 > 27 28 29 30 28 31 29 <Drone name="meineDrohne" -
code/branches/presentation/data/levels/sound.oxw
r7854 r8637 23 23 <Template link=lodtemplate_default /> 24 24 </templates> 25 <?lua include("includes/notifications.oxi") ?> 25 26 26 27 <Scene -
code/branches/presentation/data/levels/spaceRace.oxw
r8631 r8637 31 31 <Template link=lodtemplate_default /> 32 32 </templates> 33 <?lua include("includes/notifications.oxi") ?> 33 34 34 35 <Scene -
code/branches/presentation/data/levels/teamBaseMatch.oxw
r8079 r8637 23 23 <Template link=lodtemplate_default /> 24 24 </templates> 25 <?lua include("includes/notifications.oxi") ?> 25 26 26 27 <Scene -
code/branches/presentation/data/levels/teamDeathMatch.oxw
r7679 r8637 22 22 <Template link=lodtemplate_default /> 23 23 </templates> 24 <?lua include("includes/notifications.oxi") ?> 24 25 25 26 <Scene -
code/branches/presentation/data/levels/testStars.oxw
r7679 r8637 23 23 <Template link=lodtemplate_default /> 24 24 </templates> 25 <?lua include("includes/notifications.oxi") ?> 25 26 26 27 <Scene -
code/branches/presentation/data/levels/testSwallow.oxw
r8079 r8637 22 22 <Template link=lodtemplate_default /> 23 23 </templates> 24 <?lua include("includes/notifications.oxi") ?> 24 25 25 26 <Scene -
code/branches/presentation/data/levels/tetris.oxw
r8564 r8637 37 37 <Template link=lodtemplate_default /> 38 38 </templates> 39 <?lua include("includes/notifications.oxi") ?> 39 40 40 41 <Scene -
code/branches/presentation/data/levels/theTimeMachine.oxw
r8213 r8637 68 68 <Template link=lodtemplate_default /> 69 69 </templates> 70 <?lua include("includes/notifications.oxi") ?> 71 70 72 <Scene 71 73 ambientlight="0.8,0.8,0.8" -
code/branches/presentation/data/levels/tutorial.oxw
r7679 r8637 19 19 <Template link=lodtemplate_default /> 20 20 </templates> 21 <?lua include("includes/notifications.oxi") ?> 21 22 22 23 <Scene -
code/branches/presentation/data/levels/underAttack.oxw
r8079 r8637 15 15 <Template link=lodtemplate_default /> 16 16 </templates> 17 <?lua include("includes/notifications.oxi") ?> 17 18 18 19 <Scene -
code/branches/presentation/data/levels/waypoints.oxw
r7679 r8637 21 21 <Template link=lodtemplate_default /> 22 22 </templates> 23 <?lua include("includes/notifications.oxi") ?> 23 24 24 25 <Scene -
code/branches/presentation/data/overlays/debug.oxo
r8079 r8637 84 84 /> 85 85 86 <GametypeStatus87 name = "state"88 position = "0.5, 0.85"89 font = "VeraMono"90 textsize = 0.0591 colour = "1.0, 1.0, 0.0, 0.8"92 align = "center"93 />94 86 </OverlayGroup> 95 87 </Template> -
code/branches/presentation/doc/api/groups/Triggers.dox
r8351 r8637 55 55 - @b target Which specifies the class of objects that can trigger the @ref orxonox::DistanceTrigger "DistanceTrigger". Default is <code>"Pawn"</code>. 56 56 - @b beaconMode Which specifies, whether the @ref orxonox::DistanceTrigger "DistanceTrigger" operates on @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" or not. If <em>off</em> the DistanceMultiTrigger works as usual. If set to <em>identify</em> the @ref orxonox::DistanceTrigger "DistanceTrigger" is only triggered by objects that have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon", with the same name as specified in <em>targetname</em>, attached to them. If set to <em>exclude</em> the @ref orxonox::DistanceTrigger "DistanceTrigger" is only triggered by objects that don't have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon", with the same name as specified in <em>targetname</em>, attached to them. Default is <em>off</em>. 57 - @b targetname Which specifies the name @ref or oxnox::DistanceTriggerBeacon "DistanceTriggerBeacons" need to have to make the @ref orxonox::DistanceTrigger "DistanceTrigger" react to them if it is in <em>beacon-mode</em> (the beaconMode is not <em>off</em>).57 - @b targetname Which specifies the name @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" need to have to make the @ref orxonox::DistanceTrigger "DistanceTrigger" react to them if it is in <em>beacon-mode</em> (the beaconMode is not <em>off</em>). 58 58 59 59 A simple @ref orxonox::DistanceTrigger "DistanceTrigger" could look like this: -
code/branches/presentation/src/libraries/core/GUIManager.cc
r8627 r8637 38 38 #include <CEGUIDefaultLogger.h> 39 39 #include <CEGUIExceptions.h> 40 #include <CEGUIFontManager.h> 40 41 #include <CEGUIInputEvent.h> 41 42 #include <CEGUIMouseCursor.h> … … 44 45 #include <CEGUIWindow.h> 45 46 #include <CEGUIWindowManager.h> 47 #include <CEGUIXMLAttributes.h> 46 48 #include <elements/CEGUIListbox.h> 47 49 #include <elements/CEGUIListboxItem.h> … … 729 731 } 730 732 733 /** 734 @brief 735 Adds a new freetype font to the CEGUI system. 736 @param name 737 The name of the new font. 738 @param size 739 The font size of the new font in pixels. 740 @param fontName 741 The filename of the font. 742 */ 743 /*static*/ void GUIManager::addFontHelper(const std::string& name, int size, const std::string& fontName) 744 { 745 if(CEGUI::FontManager::getSingleton().isFontPresent(name)) // If a font with that name already exists. 746 return; 747 748 CEGUI::Font* font = NULL; 749 CEGUI::XMLAttributes xmlAttributes; 750 751 // Attributes specified within CEGUIFont 752 xmlAttributes.add("Name", name); 753 xmlAttributes.add("Filename", fontName); 754 xmlAttributes.add("ResourceGroup", ""); 755 xmlAttributes.add("AutoScaled", "true"); 756 xmlAttributes.add("NativeHorzRes", "800"); 757 xmlAttributes.add("NativeVertRes", "600"); 758 759 // Attributes specified within CEGUIXMLAttributes 760 xmlAttributes.add("Size", multi_cast<std::string>(size)); 761 xmlAttributes.add("AntiAlias", "true"); 762 763 font = CEGUI::FontManager::getSingleton().createFont("FreeType", xmlAttributes); 764 if(font != NULL) 765 font->load(); 766 } 767 731 768 } -
code/branches/presentation/src/libraries/core/GUIManager.h
r8627 r8637 128 128 129 129 // TODO: Temporary hack because the tolua exported CEGUI method does not seem to work 130 static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); //tolua_export 131 static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); //tolua_export 132 static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); //tolua_export 130 static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); // tolua_export 131 static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); // tolua_export 132 static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); // tolua_export 133 static void addFontHelper(const std::string& name, int size, const std::string& fontName); // tolua_export 133 134 134 135 static GUIManager& getInstance() { return Singleton<GUIManager>::getInstance(); } // tolua_export -
code/branches/presentation/src/libraries/network/synchronisable/Synchronisable.cc
r8329 r8637 383 383 /** 384 384 * This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction) 385 * @param id gamestate id386 385 * @param mode Synchronisation mode (toclient, toserver or bidirectional) 387 386 * @return true/false … … 397 396 /** 398 397 * This function determines, wheter the object should accept data from the bytestream (according to its syncmode/direction) 399 * @param id gamestate id400 398 * @param mode Synchronisation mode (toclient, toserver or bidirectional) 401 399 * @return true/false -
code/branches/presentation/src/modules/notifications/CMakeLists.txt
r7403 r8637 1 1 SET_SOURCE_FILES(NOTIFICATIONS_SRC_FILES 2 Notification.cc3 2 NotificationDispatcher.cc 4 3 NotificationManager.cc 5 4 NotificationQueue.cc 5 NotificationQueueCEGUI.cc 6 6 ) 7 7 … … 13 13 TOLUA_FILES 14 14 NotificationManager.h 15 NotificationQueue .h15 NotificationQueueCEGUI.h 16 16 PCH_FILE 17 17 NotificationsPrecompiledHeaders.h -
code/branches/presentation/src/modules/notifications/NotificationDispatcher.cc
r7552 r8637 41 41 42 42 #include "infos/PlayerInfo.h" 43 #include "interfaces/NotificationListener.h" 43 44 #include "interfaces/PlayerTrigger.h" 44 45 #include "worldentities/pawns/Pawn.h" 45 46 #include "NotificationManager.h"47 46 48 47 namespace orxonox … … 61 60 RegisterObject(NotificationDispatcher); 62 61 63 this->sender_ = Notification Manager::NONE;62 this->sender_ = NotificationListener::NONE; 64 63 this->registerVariables(); 65 64 } … … 114 113 { 115 114 const std::string message = this->createNotificationMessage(); 116 NotificationManager::sendNotification(message, clientId, this->getSender()); 115 // TODO: Make the type configurable. 116 NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::network, clientId); 117 117 } 118 118 else if(GameMode::isServer()) … … 164 164 if(player == NULL) 165 165 { 166 C OUT(3) << "The PlayerInfo* is NULL." << std::endl;166 CCOUT(3) << "The PlayerInfo* is NULL." << std::endl; 167 167 return false; 168 168 } -
code/branches/presentation/src/modules/notifications/NotificationManager.cc
r8079 r8637 36 36 #include "core/command/ConsoleCommand.h" 37 37 #include "core/CoreIncludes.h" 38 #include "core/GUIManager.h"39 38 #include "core/LuaState.h" 40 #include "network/Host.h"41 #include "network/NetworkFunction.h"42 39 #include "util/ScopedSingletonManager.h" 43 40 44 41 #include "interfaces/NotificationListener.h" 45 42 46 #include "Notification.h"47 43 #include "NotificationQueue.h" 48 49 #include "ToluaBindNotifications.h" 44 #include "NotificationQueueCEGUI.h" 50 45 51 46 namespace orxonox 52 47 { 53 48 54 const std::string NotificationManager::ALL("all");55 const std::string NotificationManager::NONE("none");56 57 // Register tolua_open function when loading the library.58 DeclareToluaInterface(Notifications);59 60 49 ManageScopedSingleton(NotificationManager, ScopeID::Root, false); 61 50 62 // Setting console command to enter the edit mode.63 SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);64 65 registerStaticNetworkFunction(NotificationManager::sendNotification);66 67 51 /** 68 52 @brief … … 73 57 RegisterRootObject(NotificationManager); 74 58 75 this->highestIndex_ = 0;76 77 ModifyConsoleCommand("enterEditMode").setObject(this);78 79 59 COUT(3) << "NotificatioManager created." << std::endl; 80 60 } … … 86 66 NotificationManager::~NotificationManager() 87 67 { 88 ModifyConsoleCommand("enterEditMode").setObject(NULL);89 90 68 // Destroys all Notifications. 91 69 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it!= this->allNotificationsList_.end(); it++) … … 106 84 while(it != this->queues_.end()) 107 85 { 108 it->second->destroy( true);86 it->second->destroy(); 109 87 it = this->queues_.begin(); 110 88 } … … 115 93 /** 116 94 @brief 117 Sends a Notification with the specified message to the specified client from the specified sender. 95 Creates and registers a Notification with the input message from the input sender. 96 This is called by the NotificationListener, whenever a new notification arrives. 118 97 @param message 119 The message that should be sent. 120 @param clientId 121 The id of the client the notification should be sent to. 98 The message of the new Notification. 122 99 @param sender 123 The sender that sent the notification. 124 @param isLocal 125 If this is set to true (false is default), then the Notification is sent to the client where this function is executed, meaning the Notification is sent locally. 126 */ 127 /*static*/ void NotificationManager::sendNotification(const std::string& message, unsigned int clientId, const std::string& sender, bool isLocal) 128 { 129 // If we're in standalone mode or we're already no the right client we create and send the Notification. 130 if(GameMode::isStandalone() || isLocal || Host::getPlayerID() == clientId) 131 { 132 Notification* notification = new Notification(message, sender); 133 if(NotificationManager::getInstance().registerNotification(notification)) 134 COUT(3) << "Notification \"" << notification->getMessage() << "\" sent." << std::endl; 135 } 136 // If we're on the server (and the server is not the intended recipient of the Notification) we send it over the network. 137 else if(GameMode::isServer()) 138 { 139 callStaticNetworkFunction(NotificationManager::sendNotification, clientId, message, clientId, sender); 140 } 141 } 142 143 /** 144 @brief 145 Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationListeners associated with its sender. 100 The name of the entity (of the collective) that sent the new Notification. 101 @param type 102 The type of the new Notification. 103 @return 104 Returns true if successful. 105 */ 106 bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type) 107 { 108 // TODO: Do something with the type. 109 Notification* notification = new Notification(message, sender, type); 110 return this->registerNotification(notification); 111 } 112 113 /** 114 @brief 115 Executes the input command from the input sender. 116 This is called by the NotificationListener, whenever a new command arrives. 117 @param command 118 The command to be executed, 119 @param sender 120 The The name of the entity (of the collective) that sent the command. 121 @return 122 Returns true if the command was successfully executed. 123 */ 124 bool NotificationManager::executeCommand(notificationCommand::Value command, const std::string& sender) 125 { 126 bool commandExecuted = false; 127 if(command == notificationCommand::clear) 128 { 129 if(this->commandClear(sender)) 130 commandExecuted = true; 131 } 132 133 if(commandExecuted) 134 COUT(3) << "Notification command \"" << NotificationListener::command2Str(command) << "\" executed." << endl; 135 136 return commandExecuted; 137 } 138 139 /** 140 @brief 141 The clear command. Clears all NotificationQueues that have its sender as a target. 142 @param sender 143 The sender of the clear command. 144 @return 145 Returns true if the command was successfully executed by at least one NotificationQueue, false if it was not executed. 146 */ 147 bool NotificationManager::commandClear(const std::string& sender) 148 { 149 bool all = (sender == NotificationListener::ALL); 150 bool executed = false; 151 // Clear all NotificationQueues that have the input sender as target. 152 for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) // Iterate through all NotificationQueues. 153 { 154 const std::set<std::string>& set = it->second->getTargetsSet(); 155 // If either the sender is 'all', the NotificationQueue has as target all or the NotificationQueue has the input sender as a target. 156 if(all || set.find(NotificationListener::ALL) != set.end() || set.find(sender) != set.end()) 157 executed = it->second->tidy() || executed; 158 } 159 160 return executed; 161 } 162 163 /** 164 @brief 165 Registers a Notification within the NotificationManager and makes sure that the Notification is sent to all the NotificationQueues associated with its sender. 146 166 @param notification 147 167 The Notification to be registered. … … 158 178 this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification)); 159 179 160 if(notification->getSender() == Notification Manager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.180 if(notification->getSender() == NotificationListener::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications. 161 181 return true; 162 182 163 bool all = false; 164 if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener. 165 all = true; 166 167 // Insert the Notification in all NotificationListeners that have its sender as target. 168 for(std::map<NotificationListener*, unsigned int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all NotificationListeners. 169 { 170 const std::set<std::string>& set = it->first->getTargetsSet(); 171 bool bAll = set.find(NotificationManager::ALL) != set.end(); 172 // If either the Notification has as sender 'all', the NotificationListener displays all Notifications or the NotificationListener has the sender of the Notification as target. 183 // If all are the sender, then the Notifications is added to every NotificationQueue. 184 bool all = (notification->getSender() == NotificationListener::ALL); 185 186 // Insert the Notification in all NotificationQueues that have its sender as target. 187 for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) // Iterate through all NotificationQueues. 188 { 189 const std::set<std::string>& set = it->second->getTargetsSet(); 190 bool bAll = set.find(NotificationListener::ALL) != set.end(); 191 // If either the Notification has as sender 'all', the NotificationQueue displays all Notifications or the NotificationQueue has the sender of the Notification as target. 173 192 if(all || bAll || set.find(notification->getSender()) != set.end()) 174 193 { 175 194 if(!bAll) 176 this->notificationLists_[it->second ]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationListener.177 it-> first->update(notification, time); // Update the NotificationListener.195 this->notificationLists_[it->second->getName()]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationQueue. 196 it->second->update(notification, time); // Update the NotificationQueue. 178 197 } 179 198 } … … 186 205 /** 187 206 @brief 188 Unregisters a Notification within the NotificationManager for a given Notification Listener.207 Unregisters a Notification within the NotificationManager for a given NotificationQueue. 189 208 @param notification 190 209 A pointer to the Notification to be unregistered. 191 @param listener192 A pointer to the Notification Listenerthe Notification is unregistered for.193 */ 194 void NotificationManager::unregisterNotification(Notification* notification, Notification Listener* listener)210 @param queue 211 A pointer to the NotificationQueue the Notification is unregistered for. 212 */ 213 void NotificationManager::unregisterNotification(Notification* notification, NotificationQueue* queue) 195 214 { 196 215 assert(notification); 197 assert( listener);198 199 // Remove the Notification from the list of Notifications of the input Notification Listener.200 this->removeNotification(notification, *(this->notificationLists_.find( this->listenerList_.find(listener)->second)->second));201 202 COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl;216 assert(queue); 217 218 // Remove the Notification from the list of Notifications of the input NotificationQueue. 219 this->removeNotification(notification, *(this->notificationLists_.find(queue->getName())->second)); 220 221 COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from NotificationQueue " << queue->getName() << "." << std::endl; 203 222 } 204 223 … … 230 249 /** 231 250 @brief 232 Registers a NotificationListener within the NotificationManager. 233 @param listener 234 The NotificationListener to be registered. 235 @return 236 Returns true if successful. Fales if the NotificationListener is already registered. 237 */ 238 bool NotificationManager::registerListener(NotificationListener* listener) 239 { 240 assert(listener); 241 242 // If the NotificationListener is already registered. 243 if(this->listenerList_.find(listener) != this->listenerList_.end()) 244 return false; 245 246 this->highestIndex_ += 1; 247 unsigned int index = this->highestIndex_; // An identifier that identifies each registered NotificationListener uniquely. 248 249 this->listenerList_[listener] = index; // Add the NotificationListener to the list of NotificationListeners. 250 251 const std::set<std::string>& set = listener->getTargetsSet(); 252 253 // If all senders are the target of the NotificationListener, then the list of Notifications for that specific NotificationListener is the same as the list of all Notifications. 254 bool bAll = set.find(NotificationManager::ALL) != set.end(); 255 std::multimap<std::time_t, Notification*>* map = NULL; 256 if(bAll) 257 this->notificationLists_[index] = &this->allNotificationsList_; 258 // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationListeners. 259 else 260 { 261 this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>; 262 map = this->notificationLists_[index]; 263 } 264 265 // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener. 266 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 267 { 268 if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target. 269 map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 270 } 271 272 listener->update(); // Update the listener. 273 274 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 275 276 return true; 277 } 278 279 /** 280 @brief 281 Unregisters a NotificationListener within the NotificationManager. 282 @param listener 283 The NotificationListener to be unregistered. 284 */ 285 void NotificationManager::unregisterListener(NotificationListener* listener) 286 { 287 assert(listener); 288 289 unsigned int identifier = this->listenerList_.find(listener)->second; 290 std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second; 291 292 // If the map is not the map of all Notifications, make sure all Notifications are unregistered. 293 std::multimap<std::time_t, Notification*>::iterator it = map->begin(); 294 if(map != &this->allNotificationsList_) 295 { 296 while(it != map->end()) 297 { 298 this->unregisterNotification(it->second, listener); 299 it = map->begin(); 300 } 301 delete map; 302 } 303 304 COUT(4) << "NotificationListener '" << identifier << "' unregistered with the NotificationManager." << std::endl; 305 306 // Remove the NotificationListener from the list of NotificationListeners. 307 this->listenerList_.erase(listener); 308 // Remove the Notifications list that was associated with the input NotificationListener. 309 this->notificationLists_.erase(identifier); 310 } 311 312 /** 313 @brief 314 Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map. 315 @param listener 316 The NotificationListener the Notifications are fetched for. 251 Fetches the Notifications for a specific NotificationQueue in a specified timeframe and stores them in the input map. 252 @param queue 253 The NotificationQueue the Notifications are fetched for. 317 254 @param map 318 255 A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. … … 324 261 Returns true if successful. 325 262 */ 326 void NotificationManager::getNotifications(Notification Listener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)327 { 328 assert( listener);263 void NotificationManager::getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd) 264 { 265 assert(queue); 329 266 assert(map); 330 267 331 std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[ this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.268 std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[queue->getName()]; // All the Notifications for the input NotificationQueue. 332 269 333 270 std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest; … … 342 279 /** 343 280 @brief 344 Enters the edit mode of the NotificationLayer. 345 */ 346 void NotificationManager::enterEditMode(void) 347 { 348 if(GameMode::showsGraphics()) 349 { 350 GUIManager::getInstance().hideGUI("NotificationLayer"); 351 GUIManager::getInstance().showGUI("NotificationLayer", false, false); 352 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.enterEditMode()"); 281 Fetches the newest Notifications for a specific NotificationQueue and stores them in the input map. 282 @param queue 283 The NotificationQueue the Notifications are fetched for. 284 @param map 285 A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. 286 @param numberOfNotifications 287 The number of newest Notifications to be got. 288 @return 289 Returns true if successful. 290 */ 291 void NotificationManager::getNewestNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications) 292 { 293 assert(queue); 294 assert(map); 295 296 std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[queue->getName()]; // All the Notifications for the input NotificationQueue. 297 298 if(!notifications->empty()) // If the list of Notifications is not empty. 299 { 300 std::multimap<std::time_t,Notification*>::iterator it = notifications->end(); 301 for(int i = 0; i < numberOfNotifications; i++) // Iterate through the Notifications from the newest until we have the specified number of notifications. 302 { 303 it--; 304 map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map. 305 if(it == notifications->begin()) 306 break; 307 } 353 308 } 354 309 } … … 357 312 @brief 358 313 Registers a NotificationQueue. 359 This makes sure that the NotificationQueue can be a ttained through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager.314 This makes sure that the NotificationQueue can be accessed through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager. 360 315 @param queue 361 316 A pointer to the NotificationQueue to be registered. … … 365 320 bool NotificationManager::registerQueue(NotificationQueue* queue) 366 321 { 322 assert(queue); 323 324 // If the NotificationQueue is already registered. 325 if(this->queues_.find(queue->getName()) != this->queues_.end()) 326 return false; 327 328 this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)); // Add the NotificationQueue to the list of NotificationQueues. 329 330 const std::set<std::string>& set = queue->getTargetsSet(); 331 332 // If all senders are the target of the NotificationQueue, then the list of Notifications for that specific NotificationQueue is the same as the list of all Notifications. 333 bool bAll = set.find(NotificationListener::ALL) != set.end(); 334 std::multimap<std::time_t, Notification*>* map = NULL; 335 if(bAll) 336 this->notificationLists_[queue->getName()] = &this->allNotificationsList_; 337 // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationQueues. 338 else 339 { 340 this->notificationLists_[queue->getName()] = new std::multimap<std::time_t, Notification*>; 341 map = this->notificationLists_[queue->getName()]; 342 } 343 344 // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue. 345 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 346 { 347 if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target. 348 map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 349 } 350 351 queue->update(); // Update the queue. 352 367 353 COUT(4) << "NotificationQueue '" << queue->getName() << "' registered with the NotificationManager." << std::endl; 368 return t his->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;354 return true; 369 355 } 370 356 … … 377 363 void NotificationManager::unregisterQueue(NotificationQueue* queue) 378 364 { 365 assert(queue); 366 367 std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(queue->getName())->second; 368 369 // If the map is not the map of all Notifications, make sure all Notifications are unregistered. 370 std::multimap<std::time_t, Notification*>::iterator it = map->begin(); 371 if(map != &this->allNotificationsList_) 372 { 373 while(it != map->end()) 374 { 375 this->unregisterNotification(it->second, queue); 376 it = map->begin(); 377 } 378 delete map; 379 } 380 381 // Remove the NotificationQueue from the list of NotificationQueues. 382 this->queues_.erase(queue->getName()); 383 // Remove the Notifications list that was associated with the input NotificationQueue. 384 this->notificationLists_.erase(queue->getName()); 385 379 386 COUT(4) << "NotificationQueue '" << queue->getName() << "' unregistered with the NotificationManager." << std::endl; 380 this->queues_.erase(queue->getName());381 }382 383 /**384 @brief385 Loads all the NotificationQueues that should exist.386 */387 void NotificationManager::loadQueues(void)388 {389 new NotificationQueue("all");390 }391 392 /**393 @brief394 Creates a new NotificationQueue.395 This is used in lua.396 @param name397 The name of the new NotificationQueue.398 */399 void NotificationManager::createQueue(const std::string& name)400 {401 new NotificationQueue(name);402 387 } 403 388 … … 420 405 } 421 406 407 /** 408 @brief 409 Loads all the NotificationQueues that should exist. 410 */ 411 void NotificationManager::loadQueues(void) 412 { 413 /*NotificationQueueCEGUI* allQueue = new NotificationQueueCEGUI("all"); 414 allQueue->setDisplaySize(Vector2(0.5, 0)); 415 allQueue->setPosition(Vector4(0.0, 10, 0.3, 0)); 416 417 NotificationQueueCEGUI* infoQueue = new NotificationQueueCEGUI("info", "gameinfo", 1, -1); 418 infoQueue->setPosition(Vector4(0.2, 0, 0.8, 0)); 419 infoQueue->setFontSize(24); 420 infoQueue->setFontColor(Vector4(1.0, 1.0, 0.0, 0.8)); 421 infoQueue->setAlignment("HorzCentred"); 422 infoQueue->setDisplaySize(Vector2(0.6, 0.0));*/ 423 } 424 425 // Notification class 426 427 /** 428 @brief 429 Constructor. Creates a Notification with the input message and sender. 430 @param message 431 The message of the Notification. 432 @param sender 433 The sender of the Notification. 434 @param type 435 436 */ 437 Notification::Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type) 438 { 439 this->initialize(); 440 this->message_ = message; 441 this->sender_ = sender; 442 this->type_ = type; 443 } 444 445 /** 446 @brief 447 Destructor. 448 */ 449 Notification::~Notification() 450 { 451 452 } 453 454 /** 455 @brief 456 Registers the object and sets some default values. 457 */ 458 void Notification::initialize(void) 459 { 460 this->message_.clear(); 461 this->sender_ = NotificationListener::NONE; 462 } 463 422 464 } -
code/branches/presentation/src/modules/notifications/NotificationManager.h
r7552 r8637 42 42 #include <string> 43 43 44 #include "core/OrxonoxClass.h" 44 45 #include "util/Singleton.h" 45 #include " core/OrxonoxClass.h"46 #include "interfaces/NotificationListener.h" 46 47 47 48 namespace orxonox // tolua_export … … 50 51 /** 51 52 @brief 52 The Singleton NotificationManager functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationListener "NotificationListeners". 53 It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationListener "NotificationListeners". 54 It also provides a static function to send @ref orxonox::Notification "Notifications" and works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer. 53 A Notification represents a short message used to inform the player about something that just happened. With the @ref orxonox::NotificationManager "NotificationManager" a Notification can be sent from any part of orxonox and is then displayed by the proper @ref orxonox::NotificationQueue "NotificationQueue(s)" (depending on which senders the specific @ref orxonox::NotificationQueue "NotificationQueues" accepts). 54 55 A Notification is just a data structure that is used internally by the Notifications module. 56 57 @author 58 Damian 'Mozork' Frick 59 60 @ingroup Notifications 61 */ 62 class _NotificationsExport Notification 63 { 64 public: 65 Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type); 66 virtual ~Notification(); 67 68 /** 69 @brief Destroys the Notification. 70 */ 71 void destroy(void) 72 { delete this; } 73 74 /** 75 @brief Get the message of the Notification. 76 @return Returns the message of the Notification. 77 */ 78 inline const std::string & getMessage(void) const 79 { return this->message_; } 80 81 /** 82 @brief Get the sender of the Notification. 83 @return Returns the sender of the Notification. 84 */ 85 inline const std::string & getSender(void) const 86 { return this->sender_; } 87 88 /** 89 @brief Get the type of the Notification. 90 @return Returns an enum with the type of the Notification. 91 */ 92 inline notificationMessageType::Value getType(void) const 93 { return this->type_; } 94 95 private: 96 std::string message_; //!< The Notification message. 97 std::string sender_; //!< The sender of the notification. 98 notificationMessageType::Value type_; //!< The type of the notification. 99 100 void initialize(void); //!< Registers the object and sets some default values. 101 102 }; 103 104 /** 105 @brief 106 The Singleton NotificationManager is a NotificationListener and functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationQueue "NotificationQueues". 107 It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationQueue "NotificationQueues". 108 It also works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer. 55 109 56 110 @author … … 60 114 */ 61 115 class _NotificationsExport NotificationManager // tolua_export 62 : public Singleton<NotificationManager>, public OrxonoxClass116 : public Singleton<NotificationManager>, public NotificationListener 63 117 { // tolua_export 64 118 friend class Singleton<NotificationManager>; … … 67 121 virtual ~NotificationManager(); 68 122 69 virtual void preDestroy(void); // !<Is called before the object is destroyed.123 virtual void preDestroy(void); // Is called before the object is destroyed. 70 124 71 125 /** … … 75 129 static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export 76 130 77 static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners.78 static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener.131 virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type); 132 virtual bool executeCommand(notificationCommand::Value command, const std::string& sender); 79 133 80 //! Sends a Notification with the specified message to the specified client from the specified sender.81 static void sendNotification(const std::string& message, unsigned int clientId, const std::string& sender = NotificationManager::NONE, bool isLocal = false);134 bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager. 135 void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue. 82 136 83 bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. 84 void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener. 85 bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager. 86 void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager. 87 88 void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map. 137 void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); // Fetches the Notifications for a specific NotificationQueue in a specified timeframe and stores them in the input map. 89 138 90 139 /** 91 @brief Fetches the Notifications for a specific Notification Listener in a timeframe from now-timeDelayto now and stores them in the input map.92 @param listener The NotificationListenerthe Notifications are fetched for.140 @brief Fetches the Notifications for a specific NotificationQueue in a timeframe from (now-timeDelay) to now and stores them in the input map. 141 @param queue The NotificationQueue the Notifications are fetched for. 93 142 @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. 94 143 @param timeDelay The timespan. 95 144 @return Returns true if successful. 96 145 */ 97 void getNotifications(Notification Listener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)98 { this->getNotifications( listener, map, std::time(0)-timeDelay, std::time(0)); }146 void getNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int timeDelay) 147 { this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); } 99 148 100 void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.149 void getNewestNotifications(NotificationQueue* queue, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications); // Fetches the newest Notifications for a specific NotificationQueue and stores them in the input map. 101 150 102 bool registerQueue(NotificationQueue* queue); // !<Registers a NotificationQueue.103 void unregisterQueue(NotificationQueue* queue); // !<Unregisters a NotificationQueue.151 bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue. 152 void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue. 104 153 105 // tolua_begin 106 void loadQueues(void); //!< Loads all the NotificationQueues that should exist. 107 void createQueue(const std::string& name); //!< Creates a new NotificationQueue. 108 orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name. 109 // tolua_end 154 void loadQueues(void); // tolua_export // Loads all the NotificationQueues that should exist. 155 156 NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name. 110 157 111 158 private: 112 159 static NotificationManager* singletonPtr_s; 113 160 114 unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.115 116 161 std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored. 117 std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. 118 std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. 162 std::map<const std::string, std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored. 119 163 120 164 std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager. 121 165 122 bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map. 166 bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map. 167 168 // Commands 169 bool commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target. 123 170 124 171 }; // tolua_export -
code/branches/presentation/src/modules/notifications/NotificationQueue.cc
r8079 r8637 38 38 39 39 #include "core/CoreIncludes.h" 40 #include "core/GameMode.h" 41 #include "core/GUIManager.h" 42 #include "core/LuaState.h" 43 #include "util/Convert.h" 40 #include "core/XMLPort.h" 44 41 #include "util/SubString.h" 45 46 #include "Notification.h"47 42 48 43 namespace orxonox 49 44 { 50 45 51 /** 52 @brief 53 Constructor. Creates and initializes the object. 46 CreateFactory(NotificationQueue); 47 48 /** 49 @brief 50 Default constructor. Registers and initializes the object. 51 @param creator 52 The creator of the NotificationQueue. 53 */ 54 NotificationQueue::NotificationQueue(BaseObject* creator) : BaseObject(creator), registered_(false) 55 { 56 RegisterObject(NotificationQueue); 57 58 this->initialize(); 59 } 60 61 // TODO move to docu. 62 /** 63 @brief 64 Constructor. Registers and initializes the object. 65 @param creator 66 The creator of the NotificationQueue 54 67 @param name 55 68 The name of the new NotificationQueue. It needs to be unique … … 62 75 The time during which a Notification is (at most) displayed. 63 76 */ 64 NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) 65 { 66 this->registered_ = false; 67 68 RegisterRootObject(NotificationQueue); 69 70 // Initialize. 77 78 /** 79 @brief 80 Destructor. 81 */ 82 NotificationQueue::~NotificationQueue() 83 { 84 this->targets_.clear(); 85 86 if(this->isRegistered()) // If the NotificationQueue is registered. 87 { 88 this->clear(true); 89 90 // Unregister with the NotificationManager. 91 NotificationManager::getInstance().unregisterQueue(this); 92 } 93 } 94 95 /** 96 @brief 97 Initializes the NotificationQueue. 98 */ 99 void NotificationQueue::initialize(void) 100 { 71 101 this->size_ = 0; 72 102 this->tickTime_ = 0.0f; 73 74 // Sets the input values. 75 this->setTargets(senders); 76 this->name_ = name; 77 this->maxSize_ = size; 78 this->setDisplayTime(displayTime); 79 103 this->maxSize_ = NotificationQueue::DEFAULT_SIZE; 104 this->displayTime_ = NotificationQueue::DEFAULT_DISPLAY_TIME; 105 106 this->creationTime_ = std::time(0); 107 } 108 109 /** 110 @brief 111 Creates the NotificationQueue. 112 */ 113 void NotificationQueue::create(void) 114 { 80 115 // Register the NotificationQueue with the NotificationManager. 81 116 bool queueRegistered = NotificationManager::getInstance().registerQueue(this); … … 88 123 } 89 124 90 this->create(); // Creates the NotificationQueue in lua.91 92 // Register the NotificationQueue as NotificationListener with the NotificationManager.93 bool listenerRegistered = NotificationManager::getInstance().registerListener(this);94 if(!listenerRegistered) // If the registration has failed.95 {96 this->registered_ = false;97 // Remove the NotificationQueue in lua.98 if(GameMode::showsGraphics())99 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")");100 NotificationManager::getInstance().unregisterQueue(this);101 COUT(1) << "Error: NotificationQueue '" << this->getName() << "' could not be registered." << std::endl;102 return;103 }104 105 125 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; 106 }107 108 /**109 @brief110 Destructor.111 */112 NotificationQueue::~NotificationQueue()113 {114 this->targets_.clear();115 116 if(this->registered_) // If the NotificationQueue is registered.117 {118 this->clear(true);119 120 // Unregister with the NotificationManager.121 NotificationManager::getInstance().unregisterListener(this);122 NotificationManager::getInstance().unregisterQueue(this);123 }124 }125 126 /**127 @brief128 Destroys the NotificationQueue.129 Used in lua and NotificationManager.130 @param noGraphics131 If this is set to true (false is default), then the queue is not removed in lua. This is used to destroy the queue, after the GUIManager has been destroyed.132 */133 void NotificationQueue::destroy(bool noGraphics)134 {135 // Remove the NotificationQueue in lua.136 if(GameMode::showsGraphics() && !noGraphics)137 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")");138 139 COUT(3) << "NotificationQueue '" << this->getName() << "' destroyed." << std::endl;140 141 this->OrxonoxClass::destroy();142 }143 144 /**145 @brief146 Creates the NotificationQueue in lua.147 */148 void NotificationQueue::create(void)149 {150 if(GameMode::showsGraphics())151 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");152 126 } 153 127 … … 161 135 { 162 136 this->tickTime_ += dt; // Add the time interval that has passed to the time counter. 163 if(this-> tickTime_ >= 1.0) // If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick.164 { 165 this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containi g the current time.137 if(this->displayTime_ != INF && this->tickTime_ >= 1.0) // If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick. 138 { 139 this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containing the current time. 166 140 167 141 std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin(); … … 177 151 } 178 152 153 void NotificationQueue::XMLPort(Element& xmlelement, XMLPort::Mode mode) 154 { 155 SUPER(NotificationQueue, XMLPort, xmlelement, mode); 156 157 XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlelement, mode).defaultValues(NotificationListener::ALL); 158 XMLPortParam(NotificationQueue, "size", setMaxSize, getMaxSize, xmlelement, mode); 159 XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlelement, mode); 160 161 this->create(); 162 } 163 179 164 /** 180 165 @brief 181 166 Updates the NotificationQueue. 182 167 Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue. 168 This is called by the NotificationManager when the Notifications have changed so much, that the NotificationQueue may have to re-initialize his operations. 183 169 */ 184 170 void NotificationQueue::update(void) … … 188 174 std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>; 189 175 // Get the Notifications sent in the interval from now to now minus the display time. 190 NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_); 176 if(this->displayTime_ == INF) 177 NotificationManager::getInstance().getNewestNotifications(this, notifications, this->getMaxSize()); 178 else 179 NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_); 191 180 192 181 if(!notifications->empty()) 193 182 { 194 // Add all Notifications .183 // Add all Notifications that have been created after this NotificationQueue was created. 195 184 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) 196 this->push(it->second, it->first); 185 { 186 if(it->first >= this->creationTime_) 187 this->push(it->second, it->first); 188 } 197 189 } 198 190 … … 246 238 this->notifications_.insert(this->notifications_.begin(), container); 247 239 248 // Push the Notification to the GUI. 249 if(GameMode::showsGraphics()) 250 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); 240 // Inform that a Notification was pushed. 241 this->notificationPushed(notification); 251 242 252 243 COUT(5) << "Notification \"" << notification->getMessage() << "\" pushed to NotificationQueue '" << this->getName() << "'" << endl; 244 COUT(3) << "NotificationQueue \"" << this->getName() << "\": " << notification->getMessage() << endl; 253 245 } 254 246 … … 279 271 delete container; 280 272 281 // Pops the Notification from the GUI. 282 if(GameMode::showsGraphics()) 283 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")"); 273 // Inform that a Notification was popped. 274 this->notificationPopped(); 284 275 } 285 276 … … 305 296 delete *containerIterator; 306 297 307 // Removes the Notification from the GUI.308 if(GameMode::showsGraphics())309 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");298 // TODO: index automatically cast? 299 // Inform that a Notification was removed. 300 this->notificationRemoved(index); 310 301 } 311 302 … … 314 305 Clears the NotificationQueue by removing all NotificationContainers. 315 306 @param noGraphics 316 If this is eset to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.307 If this is set to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally. 317 308 */ 318 309 void NotificationQueue::clear(bool noGraphics) … … 326 317 this->notifications_.clear(); 327 318 this->size_ = 0; 328 329 // Clear the NotificationQueue in the GUI.330 if(GameMode::showsGraphics() && !noGraphics)331 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");332 319 } 333 320 … … 354 341 return; 355 342 343 if(size == 0) 344 { 345 COUT(2) << "Trying to set maximal size of NotificationQueue '" << this->getName() << "' to 0. Ignoring..." << endl; 346 return; 347 } 348 356 349 this->maxSize_ = size; 357 350 358 if(this-> registered_)351 if(this->isRegistered()) 359 352 this->update(); 360 353 } … … 364 357 Sets the maximum number of seconds a Notification is displayed. 365 358 @param time 366 The number of seconds the Notifications is displayed. 367 @return 368 Returns true if successful. 369 */ 370 void NotificationQueue::setDisplayTime(unsigned int time) 359 The number of seconds a Notification is displayed. 360 */ 361 void NotificationQueue::setDisplayTime(int time) 371 362 { 372 363 if(this->displayTime_ == time) 373 364 return; 374 365 366 if(time != NotificationQueue::INF && time <= 0) 367 { 368 COUT(2) << "Trying to set display time of NotificationQueue '" << this->getName() << "' to non-positive value. Ignoring..." << endl; 369 } 370 375 371 this->displayTime_ = time; 376 372 377 if(this-> registered_)373 if(this->isRegistered()) 378 374 this->update(); 379 375 } … … 381 377 /** 382 378 @brief 383 Produces all targets of the NotificationQueue concat inated as string, with commas (',') as seperators.379 Produces all targets of the NotificationQueue concatenated as string, with commas (',') as separators. 384 380 @return 385 381 Returns the targets as a string. … … 407 403 The targets are the senders whose Notifications are displayed in this queue. 408 404 @param targets 409 Accepts a string of targets, each sep erated by commas (','), spaces are ignored.405 Accepts a string of targets, each separated by commas (','), spaces are ignored. 410 406 */ 411 407 void NotificationQueue::setTargets(const std::string & targets) … … 417 413 this->targets_.insert(string[i]); 418 414 419 if(this->registered_) 420 { 421 NotificationManager::getInstance().unregisterListener(this); 422 NotificationManager::getInstance().registerListener(this); 423 } 415 // TODO: Why? 416 if(this->isRegistered()) 417 { 418 NotificationManager::getInstance().unregisterQueue(this); 419 NotificationManager::getInstance().registerQueue(this); 420 } 421 } 422 423 /** 424 @brief 425 Pops all Notifications from the NotificationQueue. 426 @return 427 Returns true if successful, false if not. 428 */ 429 bool NotificationQueue::tidy(void) 430 { 431 while(this->size_ > 0) 432 this->pop(); 433 return true; 424 434 } 425 435 -
code/branches/presentation/src/modules/notifications/NotificationQueue.h
r7552 r8637 45 45 #include "NotificationManager.h" 46 46 47 #include "core/BaseObject.h" 47 48 #include "tools/interfaces/Tickable.h" 48 #include "interfaces/NotificationListener.h" 49 50 namespace orxonox // tolua_export 51 { // tolua_export 49 50 namespace orxonox 51 { 52 52 53 53 /** … … 78 78 Displays @ref orxonox::Notification "Notifications" from specific senders. 79 79 80 There are quite some parameters that influence the behavio ur of the NotificationQueue:80 There are quite some parameters that influence the behavior of the NotificationQueue: 81 81 - @b name The name of the NotificationQueue. It needs to be unique. 82 82 - @b senders The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays. … … 89 89 @ingroup Notifications 90 90 */ 91 class _NotificationsExport NotificationQueue // tolua_export 92 : public Tickable, public NotificationListener 93 { // tolua_export 91 class _NotificationsExport NotificationQueue : public BaseObject, public Tickable 92 { 94 93 95 94 public: 96 NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); 95 NotificationQueue(BaseObject* creator); 96 NotificationQueue(BaseObject* creator, const std::string& name, const std::string& senders = NotificationListener::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); 97 97 virtual ~NotificationQueue(); 98 98 99 //! Destroys the NotificationQueue. 100 void destroy(bool noGraphics = false); // tolua_export 101 102 virtual void tick(float dt); //!< To update from time to time. 103 104 void update(void); //!< Updates the NotificationQueue. 105 void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification. 99 virtual void tick(float dt); // To update from time to time. 100 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 101 102 void update(void); // Updates the NotificationQueue. 103 void update(Notification* notification, const std::time_t & time); // Updates the NotificationQueue by adding an new Notification. 106 104 107 105 // tolua_begin … … 110 108 @return Returns the name. 111 109 */ 112 inline const std::string& getName( ) const113 { return this-> name_; }114 115 void setMaxSize(unsigned int size); // !<Sets the maximum number of displayed Notifications.110 inline const std::string& getName(void) const 111 { return this->BaseObject::getName(); } 112 113 void setMaxSize(unsigned int size); // Sets the maximum number of displayed Notifications. 116 114 /** 117 115 @brief Returns the maximum number of Notifications displayed. 118 116 @return Returns maximum size. 119 117 */ 120 inline unsigned int getMaxSize( ) const118 inline unsigned int getMaxSize(void) const 121 119 { return this->maxSize_; } 122 120 123 void setDisplayTime( unsigned int time); //!<Sets the maximum number of seconds a Notification is displayed.121 void setDisplayTime(int time); // Sets the maximum number of seconds a Notification is displayed. 124 122 /** 125 123 @brief Returns the time interval the Notification is displayed. 126 124 @return Returns the display time. 127 125 */ 128 inline unsigned int getDisplayTime() const126 inline int getDisplayTime(void) const 129 127 { return this->displayTime_; } 130 128 // tolua_end … … 134 132 @return Returns the size of the NotificationQueue. 135 133 */ 136 inline unsigned int getSize( ) const134 inline unsigned int getSize(void) const 137 135 { return this->size_; } 138 136 … … 141 139 @return Returns a set of strings holding the different targets. 142 140 */ 143 inline const std::set<std::string> & getTargetsSet( )141 inline const std::set<std::string> & getTargetsSet(void) 144 142 { return this->targets_; } 145 143 146 // tolua_begin 147 void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue. 148 const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets. 149 // tolua_end 150 151 private: 144 void setTargets(const std::string & targets); // Set the targets of this NotificationQueue. 145 const std::string& getTargets(void) const; // Returns a string consisting of the concatenation of the targets. 146 147 /** 148 @brief Check whether the NotificationQueue is registered with the NotificationManager. 149 @return Returns true if it is registered, false if not. 150 */ 151 inline bool isRegistered(void) 152 { return this->registered_; } 153 154 bool tidy(void); // Pops all Notifications from the NotificationQueue. 155 156 protected: 157 /** 158 @brief Is called when a notification was pushed. 159 @param notification The Notification that was pushed. 160 */ 161 virtual void notificationPushed(Notification* notification) {} 162 /** 163 @brief Is called when a notification was popped. 164 */ 165 virtual void notificationPopped(void) {} 166 /** 167 @brief Is called when a notification was removed. 168 @param index The index the removed notification was at. 169 */ 170 virtual void notificationRemoved(unsigned int index) {} 171 172 virtual void clear(bool noGraphics = false); // Clears the NotificationQueue by removing all NotificationContainers. 173 174 protected: 152 175 static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. 153 176 static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 154 155 std::string name_; //!< The name of the NotificationQueue. 156 177 static const int INF = -1; //!< Constant denoting infinity. 178 179 virtual void create(void); // Creates the NotificationQueue. 180 181 private: 182 void initialize(void); // Initializes the NotificationQueue. 183 184 time_t creationTime_; // The time this NotificationQueue was created. 185 157 186 unsigned int maxSize_; //!< The maximal number of Notifications displayed. 158 187 unsigned int size_; //!< The number of Notifications displayed. 159 unsignedint displayTime_; //!< The time a Notification is displayed.188 int displayTime_; //!< The time a Notification is displayed. 160 189 161 190 bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already. … … 169 198 NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 170 199 171 void create(void); //!< Creates the NotificationQueue in lua.172 173 200 void setName(const std::string& name); //!< Sets the name of the NotificationQueue. 174 201 175 void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue. 176 void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue. 177 void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); //!< Removes the Notification that is stored in the input NotificationContainer. 178 179 void clear(bool noGraphics = false); //!< Clears the NotificationQueue by removing all NotificationContainers. 180 181 }; // tolua_export 182 183 } // tolua_export 184 185 #endif /* _NotificationOverlay_H__ */ 202 void push(Notification* notification, const std::time_t & time); // Adds (pushes) a Notification to the NotificationQueue. 203 void pop(void); // Removes (pops) the least recently added Notification form the NotificationQueue. 204 void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); // Removes the Notification that is stored in the input NotificationContainer. 205 206 }; 207 208 } 209 210 #endif /* _NotificationQueue_H__ */ -
code/branches/presentation/src/modules/objects/triggers/DistanceTrigger.cc
r8213 r8637 280 280 Check whether the DistanceTrigger is triggered. 281 281 It is triggered if it is triggered according only to its mode (i.e. its sub-triggers) and if a target is in range. 282 @param 282 @param mode 283 The mode for which it is tested, whether the DistanceTrigger is triggered. 284 @return 283 285 Returns true if it is triggered ,false if not. 284 286 */ -
code/branches/presentation/src/modules/objects/triggers/DistanceTrigger.h
r8213 r8637 71 71 - @b target Which specifies the class of objects that can trigger the DistanceTrigger. Default is <code>"Pawn"</code>. 72 72 - @b beaconMode Which specifies, whether the DistanceTrigger operates on @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" or not. If <em>off</em> the DistanceMultiTrigger works as usual. If set to <em>identify</em> the DistanceTrigger is only triggered by objects that have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon", with the same name as specified in <em>targetname</em>, attached to them. If set to <em>exclude</em> the DistanceTrigger is only triggered by objects that don't have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon", with the same name as specified in <em>targetname</em>, attached to them. Default is <em>off</em>. 73 - @b targetname Which specifies the name @ref or oxnox::DistanceTriggerBeacon "DistanceTriggerBeacons" need to have to make the DistanceTrigger react to them if it is in <em>beacon-mode</em> (the beaconMode is not <em>off</em>).73 - @b targetname Which specifies the name @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" need to have to make the DistanceTrigger react to them if it is in <em>beacon-mode</em> (the beaconMode is not <em>off</em>). 74 74 75 75 A simple DistanceTrigger could look like this: -
code/branches/presentation/src/modules/objects/triggers/EventTrigger.h
r8213 r8637 60 60 61 61 @see Trigger 62 For more information on @ref or oxnox::Trigger "Triggers".62 For more information on @ref orxonox::Trigger "Triggers". 63 63 64 64 @author -
code/branches/presentation/src/modules/objects/triggers/MultiTrigger.cc
r8561 r8637 198 198 if(bActive ^ this->isActive(state->originator)) 199 199 { 200 201 200 bool bFire = true; 202 201 -
code/branches/presentation/src/modules/objects/triggers/TriggerBase.h
r8213 r8637 133 133 inline int getActivations(void) const 134 134 { return this->remainingActivations_; } 135 /** 136 @brief Check whether the trigger has still at least one remaining activation. 137 @return Returns true if the trigger has remaining activations (i.e. the number of remaining activations is not zero). 138 */ 139 inline bool hasRemainingActivations(void) const 140 { return this->remainingActivations_ > 0 || this->remainingActivations_ == INF_s; } 135 141 136 142 /** -
code/branches/presentation/src/modules/overlays/hud/CMakeLists.txt
r8178 r8637 7 7 HUDTimer.cc 8 8 ChatOverlay.cc 9 GametypeStatus.cc10 9 AnnounceMessage.cc 11 10 KillMessage.cc -
code/branches/presentation/src/modules/questsystem/QuestDescription.cc
r7474 r8637 40 40 #include "infos/PlayerInfo.h" 41 41 42 #include " notifications/NotificationManager.h"42 #include "interfaces/NotificationListener.h" 43 43 44 44 namespace orxonox … … 119 119 } 120 120 121 Notification Manager::sendNotification(message, player->getClientID(), QuestDescription::SENDER);121 NotificationListener::sendNotification(message, QuestDescription::SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 122 122 return true; 123 123 } -
code/branches/presentation/src/modules/questsystem/QuestManager.cc
r8079 r8637 274 274 int QuestManager::getNumSubQuests(Quest* quest, PlayerInfo* player) 275 275 { 276 if(quest == NULL) 277 return this->getNumRootQuests(player); 278 276 279 std::list<Quest*> quests = quest->getSubQuestList(); 277 280 int numQuests = 0; … … 296 299 Quest* QuestManager::getSubQuest(Quest* quest, PlayerInfo* player, int index) 297 300 { 301 if(quest == NULL) 302 return this->getRootQuest(player, index); 303 298 304 std::list<Quest*> quests = quest->getSubQuestList(); 299 305 for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++) … … 312 318 @param player 313 319 The player. 314 @return Returns the number of QuestHints of the input Quest for the input player. 320 @return 321 Returns the number of QuestHints of the input Quest for the input player. 315 322 */ 316 323 int QuestManager::getNumHints(Quest* quest, PlayerInfo* player) … … 335 342 @param index 336 343 The index of the QuestHint. 344 @return 345 Returns a pointer to the index-th QuestHint of the input Quest for the input player. 337 346 */ 338 347 QuestHint* QuestManager::getHints(Quest* quest, PlayerInfo* player, int index) … … 345 354 } 346 355 return NULL; 356 } 357 358 /** 359 @brief 360 Get the parent-quest of the input Quest. 361 @param quest 362 The Quest to get the parent-quest of. 363 @return 364 Returns a pointer to the parent-quest of the input Quest. 365 */ 366 Quest* QuestManager::getParentQuest(Quest* quest) 367 { 368 return quest->getParentQuest(); 347 369 } 348 370 … … 375 397 /** 376 398 @brief 399 Get the id of the input Quest. 400 @param item 401 The Quest to get the id of. 402 @return 403 Returns the id of the input Quest. 404 */ 405 const std::string QuestManager::getId(Quest* item) const 406 { 407 return item->getId(); 408 } 409 410 /** 411 @brief 412 Get the id of the input QuestHint. 413 @param item 414 The QuestHint to get the id of. 415 @return 416 Returns the id of the input QuestHint. 417 */ 418 const std::string QuestManager::getId(QuestHint* item) const 419 { 420 return item->getId(); 421 } 422 423 /** 424 @brief 377 425 Retrieve the player for a certain GUI. 378 426 @param guiName -
code/branches/presentation/src/modules/questsystem/QuestManager.h
r7552 r8637 81 81 QuestHint* getHints(Quest* quest, orxonox::PlayerInfo* player, int index); //!< Get the index-th QuestHint of the input Quest for the input player. 82 82 83 QuestDescription* getDescription(Quest* item); 84 QuestDescription* getDescription(QuestHint* item); 83 Quest* getParentQuest(Quest* quest); //!< Get the parent-quest of the input Quest. 84 85 QuestDescription* getDescription(Quest* item); //!< Get the QuestDescription of the input Quest. 86 QuestDescription* getDescription(QuestHint* item); //!< Get the QuestDescription of the input QuestHint. 87 88 const std::string getId(Quest* item) const; //!< Get the id of the input Quest. 89 const std::string getId(QuestHint* item) const; //!< Get the id of the input QuestHint. 85 90 // tolua_end 86 91 -
code/branches/presentation/src/orxonox/LevelManager.cc
r8079 r8637 222 222 this->nextLevel_ = this->availableLevels_.begin(); 223 223 } 224 224 225 while(this->nextIndex_ != index) 225 226 { -
code/branches/presentation/src/orxonox/gametypes/Gametype.cc
r8631 r8637 58 58 59 59 this->defaultControllableEntity_ = Class(Spectator); 60 60 61 61 this->bAutoStart_ = false; 62 62 this->bForceSpawn_ = false; … … 121 121 } 122 122 123 if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_) 124 this->gtinfo_->startCountdown_ -= dt; 125 126 if (!this->gtinfo_->bStarted_) 123 if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted()) 124 this->gtinfo_->countdownStartCountdown(dt); 125 126 if (!this->gtinfo_->hasStarted()) 127 { 128 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 129 { 130 // Inform the GametypeInfo that the player is ready to spawn. 131 if(it->first->isHumanPlayer() && it->first->isReadyToSpawn()) 132 this->gtinfo_->playerReadyToSpawn(it->first); 133 } 134 127 135 this->checkStart(); 128 else if (!this->gtinfo_->bEnded_) 136 } 137 else if (!this->gtinfo_->hasEnded()) 129 138 this->spawnDeadPlayersIfRequested(); 130 139 … … 136 145 this->addBots(this->numberOfBots_); 137 146 138 this->gtinfo_-> bStarted_ = true;147 this->gtinfo_->start(); 139 148 140 149 this->spawnPlayersIfRequested(); … … 143 152 void Gametype::end() 144 153 { 145 this->gtinfo_-> bEnded_ = true;154 this->gtinfo_->end(); 146 155 147 156 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) … … 173 182 { 174 183 this->players_[player].state_ = PlayerState::Joined; 184 this->gtinfo_->playerEntered(player); 175 185 } 176 186 … … 269 279 } 270 280 } 281 282 if(victim->getPlayer()->isHumanPlayer()) 283 this->gtinfo_->pawnKilled(victim->getPlayer()); 271 284 272 285 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator()); … … 345 358 it->second.state_ = PlayerState::Dead; 346 359 347 if (!it->first->isReadyToSpawn() || !this->gtinfo_-> bStarted_)360 if (!it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted()) 348 361 { 349 362 this->spawnPlayerAsDefaultPawn(it->first); … … 356 369 void Gametype::checkStart() 357 370 { 358 if (!this->gtinfo_-> bStarted_)359 { 360 if (this->gtinfo_-> bStartCountdownRunning_)361 { 362 if (this->gtinfo_-> startCountdown_ <= 0)363 { 364 this->gtinfo_-> bStartCountdownRunning_ = false;365 this->gtinfo_->s tartCountdown_ = 0;371 if (!this->gtinfo_->hasStarted()) 372 { 373 if (this->gtinfo_->isStartCountdownRunning()) 374 { 375 if (this->gtinfo_->getStartCountdown() <= 0.0f) 376 { 377 this->gtinfo_->stopStartCountdown(); 378 this->gtinfo_->setStartCountdown(0.0f);; 366 379 this->start(); 367 380 } … … 388 401 // If in developer's mode, there is no start countdown. 389 402 if(Core::getInstance().inDevMode()) 390 this-> gtinfo_->startCountdown_ = 0;403 this->start(); 391 404 else 392 this->gtinfo_->s tartCountdown_ = this->initialStartCountdown_;393 this->gtinfo_-> bStartCountdownRunning_ = true;405 this->gtinfo_->setStartCountdown(this->initialStartCountdown_); 406 this->gtinfo_->startStartCountdown(); 394 407 } 395 408 } … … 401 414 { 402 415 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 416 { 403 417 if (it->first->isReadyToSpawn() || this->bForceSpawn_) 404 418 this->spawnPlayer(it->first); 419 } 405 420 } 406 421 … … 421 436 player->startControl(spawnpoint->spawn()); 422 437 this->players_[player].state_ = PlayerState::Alive; 438 439 if(player->isHumanPlayer()) 440 this->gtinfo_->playerSpawned(player); 441 423 442 this->playerPostSpawn(player); 424 443 } -
code/branches/presentation/src/orxonox/gametypes/Gametype.h
r8178 r8637 78 78 79 79 inline bool hasStarted() const 80 { return this->gtinfo_-> bStarted_; }80 { return this->gtinfo_->hasStarted(); } 81 81 inline bool hasEnded() const 82 { return this->gtinfo_-> bEnded_; }82 { return this->gtinfo_->hasEnded(); } 83 83 84 84 virtual void start(); … … 114 114 115 115 inline bool isStartCountdownRunning() const 116 { return this->gtinfo_-> bStartCountdownRunning_; }116 { return this->gtinfo_->isStartCountdownRunning(); } 117 117 inline float getStartCountdown() const 118 { return this->gtinfo_-> startCountdown_; }118 { return this->gtinfo_->getStartCountdown(); } 119 119 120 120 inline void setHUDTemplate(const std::string& name) 121 { this->gtinfo_-> hudtemplate_ = name; }121 { this->gtinfo_->setHUDTemplate(name); } 122 122 inline const std::string& getHUDTemplate() const 123 { return this->gtinfo_-> hudtemplate_; }123 { return this->gtinfo_->getHUDTemplate(); } 124 124 125 125 void addBots(unsigned int amount); … … 167 167 168 168 SmartPtr<GametypeInfo> gtinfo_; 169 169 170 170 bool bAutoStart_; 171 171 bool bForceSpawn_; -
code/branches/presentation/src/orxonox/infos/GametypeInfo.cc
r8327 r8637 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Damian 'Mozork' Frick 26 26 * 27 27 */ 28 29 /** 30 @file GametypeInfo.cc 31 @brief Implementation of the GametypeInfo class 32 */ 28 33 29 34 #include "GametypeInfo.h" … … 31 36 #include "core/CoreIncludes.h" 32 37 #include "core/GameMode.h" 38 #include "network/Host.h" 33 39 #include "network/NetworkFunction.h" 34 #include "network/Host.h" 40 #include "util/Convert.h" 41 42 #include "controllers/HumanController.h" 35 43 #include "interfaces/GametypeMessageListener.h" 44 #include "interfaces/NotificationListener.h" 45 46 #include "PlayerInfo.h" 36 47 37 48 namespace orxonox … … 45 56 registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage); 46 57 58 registerMemberNetworkFunction(GametypeInfo, changedReadyToSpawn); 59 registerMemberNetworkFunction(GametypeInfo, changedSpawned); 60 61 /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo"); 62 63 /** 64 @brief 65 Registers and initializes the object. 66 */ 47 67 GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator) 48 68 { 49 69 RegisterObject(GametypeInfo); 50 70 51 71 this->bStarted_ = false; 52 72 this->bEnded_ = false; 53 this->startCountdown_ = 0 ;73 this->startCountdown_ = 0.0f; 54 74 this->bStartCountdownRunning_ = false; 75 this->counter_ = 0; 76 this->spawned_ = false; 77 this->readyToSpawn_ = false; 55 78 56 79 this->registerVariables(); … … 63 86 void GametypeInfo::registerVariables() 64 87 { 65 registerVariable(this->bStarted_, VariableDirection::ToClient); 66 registerVariable(this->bEnded_, VariableDirection::ToClient); 88 registerVariable(this->bStarted_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStarted)); 89 registerVariable(this->bEnded_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedEnded)); 90 registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStartCountdownRunning)); 67 91 registerVariable(this->startCountdown_, VariableDirection::ToClient); 68 registerVariable(this-> bStartCountdownRunning_, VariableDirection::ToClient);92 registerVariable(this->counter_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedCountdownCounter)); 69 93 registerVariable(this->hudtemplate_, VariableDirection::ToClient); 70 94 } 95 96 /** 97 @brief 98 Is called when the game has changed to started. 99 */ 100 void GametypeInfo::changedStarted(void) 101 { 102 103 } 104 105 /** 106 @brief 107 Is called when the game has changed to ended. 108 */ 109 void GametypeInfo::changedEnded(void) 110 { 111 // If the game has ended, a "Game has ended" notification is displayed. 112 if(this->hasEnded()) 113 NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER); 114 } 115 116 /** 117 @brief 118 Is called when the start countdown has been either started or stopped. 119 */ 120 void GametypeInfo::changedStartCountdownRunning(void) 121 { 122 // Send first countdown notification if the countdown has started. 123 if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded()) 124 NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER); 125 } 126 127 /** 128 @brief 129 Is called when the start countdown counter has changed. 130 */ 131 void GametypeInfo::changedCountdownCounter(void) 132 { 133 // Send countdown notification if the counter has gone down. 134 if(this->isReadyToSpawn() && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded()) 135 NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER); 136 } 137 138 /** 139 @brief 140 Inform the GametypeInfo that the local player has changed its ready to spawn status. 141 @param ready 142 Whether the player has become ready to spawn or not. 143 */ 144 void GametypeInfo::changedReadyToSpawn(bool ready) 145 { 146 if(this->readyToSpawn_ == ready) 147 return; 148 149 this->readyToSpawn_ = ready; 150 151 // Send "Waiting for other players" if the player is ready to spawn but the game has not yet started nor is the countdown running. 152 if(this->readyToSpawn_ && !this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded()) 153 NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER); 154 // Send current countdown if the player is ready to spawn and the countdown has already started. 155 else if(this->readyToSpawn_ && !this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded()) 156 NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER); 157 } 158 159 /** 160 @brief 161 Inform the GametypeInfo that the game has started. 162 */ 163 void GametypeInfo::start(void) 164 { 165 if(this->bStarted_) 166 return; 167 168 this->bStarted_ = true; 169 this->changedStarted(); 170 } 171 172 /** 173 @brief 174 Inform the GametypeInfo that the game has ended. 175 */ 176 void GametypeInfo::end(void) 177 { 178 if(this->bEnded_) 179 return; 180 181 this->bEnded_ = true; 182 this->changedEnded(); 183 } 184 185 /** 186 @brief 187 Set the start countdown to the input value. 188 @param countdown 189 The countdown to be set. 190 */ 191 void GametypeInfo::setStartCountdown(float countdown) 192 { 193 if(this->startCountdown_ == countdown || countdown < 0.0f) 194 return; 195 196 this->startCountdown_ = countdown; 197 // Set the counter to the ceiling of the current countdown. 198 this->counter_ = ceil(countdown); 199 this->changedCountdownCounter(); 200 } 201 202 /** 203 @brief 204 Count down the start countdown by the specified value. 205 @param countDown 206 The amount by which we count down. 207 */ 208 void GametypeInfo::countdownStartCountdown(float countDown) 209 { 210 float newCountdown = this->startCountdown_ - countDown; 211 // If we have switched integers or arrived at zero, we also count down the start countdown counter. 212 if(ceil(newCountdown) != ceil(this->startCountdown_) || newCountdown <= 0.0f) 213 this->countDown(); 214 this->startCountdown_ = newCountdown; 215 } 216 217 /** 218 @brief 219 Count down the start countdown counter. 220 */ 221 void GametypeInfo::countDown() 222 { 223 if(this->counter_ == 0) 224 return; 225 226 this->counter_--; 227 this->changedCountdownCounter(); 228 } 229 230 /** 231 @brief 232 Inform the GametypeInfo about the start of the start countdown. 233 */ 234 void GametypeInfo::startStartCountdown(void) 235 { 236 if(GameMode::isMaster()) 237 { 238 if(this->bStartCountdownRunning_) 239 return; 240 241 this->bStartCountdownRunning_ = true; 242 this->changedStartCountdownRunning(); 243 } 244 } 245 246 /** 247 @brief 248 Inform the GametypeInfo about the stop of the start countdown. 249 */ 250 void GametypeInfo::stopStartCountdown(void) 251 { 252 if(GameMode::isMaster()) 253 { 254 if(!this->bStartCountdownRunning_) 255 return; 256 257 this->bStartCountdownRunning_ = false; 258 this->changedStartCountdownRunning(); 259 } 260 } 261 262 /** 263 @brief 264 Inform the GametypeInfo about a player that is ready to spawn. 265 @param player 266 The player that is ready to spawn. 267 */ 268 void GametypeInfo::playerReadyToSpawn(PlayerInfo* player) 269 { 270 if(GameMode::isMaster()) 271 { 272 // If the player has spawned already. 273 if(this->spawnedPlayers_.find(player) != this->spawnedPlayers_.end()) 274 return; 275 276 this->spawnedPlayers_.insert(player); 277 this->setReadyToSpawnHelper(player, true); 278 } 279 } 280 281 /** 282 @brief 283 Inform the GametypeInfo about a player whose Pawn has been killed. 284 @param player 285 The player whose Pawn has been killed. 286 */ 287 void GametypeInfo::pawnKilled(PlayerInfo* player) 288 { 289 if(GameMode::isMaster()) 290 { 291 NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 292 // Remove the player from the list of players that have spawned, since it currently is not. 293 this->spawnedPlayers_.erase(player); 294 this->setReadyToSpawnHelper(player, false); 295 this->setSpawnedHelper(player, false); 296 } 297 } 298 299 /** 300 @brief 301 Inform the GametypeInfo about a player that has spawned. 302 @param player 303 The player that has spawned. 304 */ 305 void GametypeInfo::playerSpawned(PlayerInfo* player) 306 { 307 if(GameMode::isMaster()) 308 { 309 if(this->hasStarted() && !this->hasEnded()) 310 { 311 //NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID()); 312 this->setSpawnedHelper(player, true); 313 } 314 } 315 } 316 317 /** 318 @brief 319 Inform the GametypeInfo that the local player has changed its spawned status. 320 @param spawned 321 Whether the local player has changed to spawned or to not spawned. 322 */ 323 void GametypeInfo::changedSpawned(bool spawned) 324 { 325 if(this->spawned_ == spawned) 326 return; 327 328 this->spawned_ = spawned; 329 // Clear the notifications if the Player has spawned. 330 if(this->spawned_ && !this->hasEnded()) 331 NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER); 332 } 333 334 /** 335 @brief 336 Inform the GametypeInfo about a player that has entered, 337 @param player 338 The player that has entered. 339 */ 340 void GametypeInfo::playerEntered(PlayerInfo* player) 341 { 342 if(GameMode::isMaster()) 343 { 344 // Display "Press [Fire] to start the match" if the game has not yet ended. 345 if(!this->hasEnded()) 346 NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 347 // Else display "Game has ended". 348 else 349 NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID()); 350 } 351 } 352 353 /** 354 @brief 355 Helper method. Sends changedReadyToSpawn notifiers over the network. 356 @param player 357 The player that has changed its ready to spawn status. 358 @param ready 359 The new ready to spawn status. 360 */ 361 void GametypeInfo::setReadyToSpawnHelper(PlayerInfo* player, bool ready) 362 { 363 if(GameMode::isMaster()) 364 { 365 if(player->getClientID() == CLIENTID_SERVER) 366 this->changedReadyToSpawn(ready); 367 else 368 callMemberNetworkFunction(GametypeInfo, changedReadyToSpawn, this->getObjectID(), player->getClientID(), ready); 369 } 370 } 371 372 /** 373 @brief 374 Helper method. Sends changedSpawned notifiers over the network. 375 @param player 376 The player that has changed its spawned status. 377 @param ready 378 The new spawned status. 379 */ 380 void GametypeInfo::setSpawnedHelper(PlayerInfo* player, bool spawned) 381 { 382 if(GameMode::isMaster()) 383 { 384 if(player->getClientID() == CLIENTID_SERVER) 385 this->changedSpawned(spawned); 386 else 387 callMemberNetworkFunction(GametypeInfo, changedSpawned, this->getObjectID(), player->getClientID(), spawned); 388 } 389 } 390 391 // Announce messages. 392 // TODO: Replace with notifications. 71 393 72 394 void GametypeInfo::sendAnnounceMessage(const std::string& message) -
code/branches/presentation/src/orxonox/infos/GametypeInfo.h
r7163 r8637 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Damian 'Mozork' Frick 26 26 * 27 27 */ 28 29 /** 30 @file GametypeInfo.h 31 @brief Definition of the GametypeInfo class 32 */ 28 33 29 34 #ifndef _GametypeInfo_H__ … … 33 38 34 39 #include <string> 40 35 41 #include "Info.h" 36 42 37 43 namespace orxonox 38 44 { 45 46 /** 47 @brief 48 The GametypeInfo class keeps track of the state of the game and provides facilities to inform the player about it. 49 50 @author 51 Fabian 'x3n' Landau 52 @author 53 Damian 'Mozork' Frick 54 */ 39 55 class _OrxonoxExport GametypeInfo : public Info 40 56 { … … 45 61 virtual ~GametypeInfo(); 46 62 63 /** 64 @brief Get whether the game has started yet. 65 @return Returns true if the game has started, false if not. 66 */ 47 67 inline bool hasStarted() const 48 68 { return this->bStarted_; } 69 void changedStarted(void); // Is called when the game has changed to started. 70 71 /** 72 @brief Get whether the game has ended yet. 73 @return Returns true if the game has ended, false if not. 74 */ 49 75 inline bool hasEnded() const 50 76 { return this->bEnded_; } 77 void changedEnded(void); // Is called when the game has changed to ended. 51 78 79 /** 80 @brief Get whether the start countdown is currently running. 81 @return Returns true if the countdown is running, false if not. 82 */ 52 83 inline bool isStartCountdownRunning() const 53 84 { return this->bStartCountdownRunning_; } 85 void changedStartCountdownRunning(void); // Is called when the start countdown has been either started or stopped. 86 87 /** 88 @brief Get the current value of the start countdown. 89 @return Returns the current value of the start countdown. 90 */ 54 91 inline float getStartCountdown() const 55 92 { return this->startCountdown_; } 93 94 /** 95 @brief Get the current start countdown counter. 96 The start countdown counter only has integer values that correspond to the actually displayed countdown. 97 @return Returns the current integer countdown counter. 98 */ 99 inline unsigned int getStartCountdownCounter() const 100 { return this->counter_; } 101 void changedCountdownCounter(void); // Is called when the start countdown counter has changed. 102 103 /** 104 @brief Get whether the local player is ready to spawn. 105 @return Returns true if the player is ready to spawn, false if not. 106 */ 107 inline bool isReadyToSpawn() const 108 { return this->readyToSpawn_; } 109 void changedReadyToSpawn(bool ready); // Inform the GametypeInfo that the local player has changed its spawned status. 110 111 /** 112 @brief Get whether the local player is spawned. 113 @return Returns true if the local player is currently spawned, false if not. 114 */ 115 inline bool isSpawned() const 116 { return this->spawned_; } 117 void changedSpawned(bool spawned); // Inform the GametypeInfo that the local player has changed its spawned status. 56 118 57 119 inline const std::string& getHUDTemplate() const … … 70 132 void dispatchStaticMessage(const std::string& message,const ColourValue& colour); 71 133 void dispatchFadingMessage(const std::string& message); 134 135 protected: 136 void start(void); // Inform the GametypeInfo that the game has started. 137 void end(void); // Inform the GametypeInfo that the game has ended. 138 void setStartCountdown(float countdown); // Set the start countdown to the input value. 139 void countdownStartCountdown(float countDown); // Count down the start countdown by the specified value. 140 void countDown(); // Count down the start countdown counter. 141 void startStartCountdown(void); // Inform the GametypeInfo about the start of the start countdown. 142 void stopStartCountdown(void); // Inform the GametypeInfo about the stop of the start countdown. 143 void playerReadyToSpawn(PlayerInfo* player); // Inform the GametypeInfo about a player that is ready to spawn. 144 void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed. 145 void playerSpawned(PlayerInfo* player); // Inform the GametypeInfo about a player that has spawned. 146 void playerEntered(PlayerInfo* player); // Inform the GametypeInfo about a player that has entered, 147 148 inline void setHUDTemplate(const std::string& templateName) 149 { this->hudtemplate_ = templateName; }; 72 150 73 151 private: 74 152 void registerVariables(); 153 void setSpawnedHelper(PlayerInfo* player, bool spawned); // Helper method. Sends changedReadyToSpawn notifiers over the network. 154 void setReadyToSpawnHelper(PlayerInfo* player, bool ready); // Helper method. Sends changedSpawned notifiers over the network. 75 155 76 bool bStarted_; 77 bool bEnded_; 78 bool bStartCountdownRunning_; 79 float startCountdown_; 156 static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications. 157 158 bool bStarted_; //!< Whether the game has started, 159 bool bEnded_; //!< Whether the game has ended. 160 bool bStartCountdownRunning_; //!< Whether the start countdown is running. 161 float startCountdown_; //!< The current value of the start countdown. 162 unsigned int counter_; //!< The current integer value of the start countdown, the start countdown counter. 80 163 std::string hudtemplate_; 164 165 std::set<PlayerInfo*> spawnedPlayers_; //!< A set of players that are currently spawned. 166 bool spawned_; //!< Whether the local Player is currently spawned. 167 bool readyToSpawn_; //!< Whether the local Player is ready to spawn. 81 168 }; 82 169 } -
code/branches/presentation/src/orxonox/interfaces/CMakeLists.txt
r7504 r8637 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 InterfaceCompilation.cc 3 NotificationListener.cc 3 4 Pickupable.cc 4 5 PickupCarrier.cc -
code/branches/presentation/src/orxonox/interfaces/InterfaceCompilation.cc
r7606 r8637 86 86 RegisterRootObject(Rewardable); 87 87 } 88 89 //----------------------------90 // NotificationListener91 //----------------------------92 NotificationListener::NotificationListener()93 {94 RegisterRootObject(NotificationListener);95 }96 88 } -
code/branches/presentation/src/orxonox/interfaces/NotificationListener.h
r7552 r8637 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Damian 'Mozork' Frick 24 24 * Co-authors: 25 25 * ... … … 48 48 namespace orxonox 49 49 { 50 class Notification; 50 // TODO: Document. 51 namespace notificationMessageType 52 { 53 enum Value { 54 info, 55 important 56 }; 57 } 58 59 namespace notificationSendMode 60 { 61 enum Value { 62 local, 63 network, 64 broadcast 65 }; 66 } 67 68 namespace notificationCommand 69 { 70 enum Value { 71 none, 72 clear 73 }; 74 } 51 75 76 // TODO: Update doc. 52 77 /** 53 78 @brief 54 79 NotificationListener interface. 55 80 56 The NotificationListener interface presents a means to being informed when @ref orxonox::Notification "Notifications" in the target set of this NotificationListener change. (e.g. @ref orxonox::Notification "Notifications" were added or removed) 57 When inheriting from a NotificationListener it is important to register (in the constructor) and unregister (in the destructor) it to and from the @ref orxonox::NotificationManager "NotificationManager". 81 The NotificationListener interface (or more precisely abstract class) presents a means of being informed when a new @ref orxonox::Notification "Notification" is sent. 82 The NotificationListener can be used to send a new notification message (with NotificationListener::sendNotification() ) or a new notification command (with NotificationListener::sendCommand() ). Each NotificationListener is then informed about the new @ref orxonox::Notification "Notification" and can take appropriate action. Currently the only NotificationListener ist the @ref orxonox::NotificationManager "NotificationManager" singleton. 83 84 When inheriting from a NotificationListener it is important to provide an appropriate implementation of registerNotification() and executeCommand(). 58 85 59 86 @author 60 Fabian 'x3n' Landau61 87 Damian 'Mozork' Frick 88 62 89 @ingroup Notifications 90 @todo Consistent terminology between message, notification and command. 63 91 */ 64 92 class _OrxonoxExport NotificationListener : virtual public OrxonoxClass … … 69 97 70 98 /** 71 @brief Get the senders that are targets of this NotificationListener. 72 @return Returns the set of senders that are targets of this NotificationListener. 99 @brief Sends a Notification with the specified message to the specified client from the specified sender. 100 @param message The message that should be sent. 101 @param sender The sender that sent the notification. Default is 'none'. 102 @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'. 103 @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is notificationSendMode::local. 104 @param clientId The id of the client the notification should be sent to. Default is 0. 73 105 */ 74 virtual const std::set<std::string> & getTargetsSet(void) = 0; 106 static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, notificationMessageType::Value messageType = notificationMessageType::info, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0) 107 { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); } 108 /** 109 @brief Sends a specified command to the specified client from the specified sender. 110 @param command The command that should be sent (and later executed). 111 @param sender The sender that sent the notification. Default is 'none'. 112 @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is notificationSendMode::local. 113 @param clientId The id of the client the command should be sent to. Default is 0. 114 */ 115 static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0) 116 { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); } 75 117 118 static void sendHelper(const std::string& message, const std::string& sender, bool isCommand = false, unsigned int messageMode = 0); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network. 119 120 //TODO: Make protected? 121 76 122 /** 77 @brief Updates the whole NotificationListener. 78 This is called by the @ref orxonox::NotificationManager "NotificationManager" when the @ref orxonox::Notification "Notifications" have changed so much, that the NotificationListener may have to re-initialize his operations. 123 @brief Registers a notification with the NotificationListener. 124 This needs to be overloaded by each class inheriting from NotificationListener. 125 @param message The notification's message. 126 @param sender The sender of the notification. 127 @param type The type of the notification. 128 @return Returns true if the notification was successfully registered, false if not. 79 129 */ 80 virtual void update(void) = 0; 130 virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type) 131 { return false; } 81 132 /** 82 @brief Updates the NotificationListener, when a new Notification has come in at the specified time. 83 @param notification A pointer to the @ref orxonox::Notification "Notification". 84 @param time The time the @ref orxonox::Notification "Notification" has come in. 133 @brief Executes a command with the NotificationListener 134 This needs to be overloaded by each class inheriting from NotificationListener. 135 @param command The command to be executed. 136 @param sender The sender of the command. 137 @return Returns true if the command was successfully executed, false if not. 85 138 */ 86 virtual void update(Notification* notification, const std::time_t & time) = 0; 139 virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; } 140 141 public: 142 143 static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationQueues. 144 static const std::string NONE; //!< Static string to indicate a sender that sends to no specific NotificationQueues. 145 146 //! Commands 147 static const std::string COMMAND_CLEAR; 148 static const std::string COMMAND_NONE; 149 150 protected: 151 static void sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand = false, notificationMessageType::Value messageType = notificationMessageType::info); // Helper method to send both notifications and commands over the network. 152 153 static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command. 154 static const std::string& command2Str(notificationCommand::Value command); // Helper method. Converts a command enum into its corresponding string. 87 155 }; 88 156 }
Note: See TracChangeset
for help on using the changeset viewer.