Changeset 7831
- Timestamp:
- Jan 17, 2011, 8:51:15 PM (14 years ago)
- Location:
- code/branches/tutoriallevel/data/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/tutoriallevel/data/gui/layouts/QuestGUI.layout
r7830 r7831 41 41 </Window> 42 42 43 <Window Type="MenuWidgets/ScrollablePane" Name="orxonox/QuestGUI/Quest/ Wrapper">44 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{1, 0},{1,0}}" />43 <Window Type="MenuWidgets/ScrollablePane" Name="orxonox/QuestGUI/Quest/ScrollWrapper"> 44 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,30},{1,-4},{1,-4}}" /> 45 45 46 <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Description"> 47 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,0}}" /> 48 <Property Name="HorzFormatting" Value="WordWrapLeftAligned" /> 49 <Property Name="VertFormatting" Value="TopAligned" /> 46 <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Wrapper"> 47 <Property Name="UnifiedAreaRect" Value="{{0,5},{0,5},{1,-5},{0,0}}" /> 50 48 <Property Name="FrameEnabled" Value="false" /> 51 <Property Name="Text" Value="Quest Description"/> 52 </Window> 49 <Property Name="Alpha" Value="0" /> 53 50 54 <Window Type="MenuWidgets/Listbox" Name="orxonox/QuestGUI/Quest/SubquestsList"> 55 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" /> 56 <Event Name="ItemSelectionChanged" Function="QuestGUI.changeToSubquest_clicked"/> 57 </Window> 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> 58 59 59 <Window Type="MenuWidgets/StaticText" Name="orxonox/QuestGUI/Quest/Hints"> 60 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{0,0}}" /> 61 <Property Name="VertFormatting" Value="TopAligned" /> 62 <Property Name="FrameEnabled" Value="false" /> 63 <Property Name="Text" Value="Hints:" /> 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> 64 73 </Window> 65 74 </Window> -
code/branches/tutoriallevel/data/gui/scripts/QuestGUI.lua
r7830 r7831 16 16 P.titleHeight = 26 17 17 18 -- old:19 P.rootWindow = nil20 P.detailsWindows = {}21 P.quests = {}22 P.hints = {}23 P.player = nil24 25 -- design parameters26 P.indentWidth = 2027 P.buttonHeight = 3028 P.borderWidth = 529 30 18 --TODO: 31 19 -- Highlight whether we are currently looking at active or finished quests 32 -- Distinguish completet from failed quests 33 -- Add hints 20 -- Distinguish completed from failed quests 34 21 35 22 function P.onLoad() 36 P.questManager = orxonox.QuestManager:getInstance() 23 P.questManager = orxonox.QuestManager:getInstance() -- Store the pointer to the QuestManager as an internal variable to allow for faster access, 37 24 end 38 25 … … 45 32 end 46 33 47 function P.onHide() 48 --P.cleanup() 49 end 50 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. 51 36 function P.loadQuestsList(selectQuest) 52 37 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList")) … … 64 49 while i <= numRootQuests-1 do 65 50 local quest = P.questManager:getRootQuest(P.player, i) 51 -- Insert the current quest into the list. 66 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. 67 54 if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(quest) then 68 55 list:setItemSelectState(item, true) 69 56 end 57 -- Insert all subquests of this rootquest. 70 58 P.insertSubQuests(list, quest, selectQuestId) 71 59 i = i+1 72 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. 73 62 if list:getItemCount() > 0 then 74 63 if selectQuestId == nil then 75 64 list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first quest. 76 65 end 66 -- If there werent any quests added the standard "no quests" message is loaded. 77 67 else 78 68 P.loadQuest() … … 81 71 end 82 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. 83 77 function P.insertSubQuests(list, quest, selectQuestId) 84 78 -- Iterate through all sub-quests. … … 88 82 while i <= numQuests-1 do 89 83 local subquest = P.questManager:getSubQuest(quest, P.player, i) 84 -- Insert the current quest into the list. 90 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. 91 87 if selectQuestId ~= nil and item ~= nil and selectQuestId == P.questManager:getId(subquest) then 92 88 list:setItemSelectState(item, true) … … 97 93 end 98 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. 99 98 function P.insertQuest(list, quest) 100 99 if P.showActive == quest:isActive(P.player) then … … 108 107 end 109 108 109 -- Loads the input quest. 110 -- quest the quest to be loaded. 110 111 function P.loadQuest(quest) 111 112 112 P.clearQuest() 113 if quest == nil then 113 P.clearQuest() -- Clear the old quest. 114 if quest == nil then -- If quets is nil there is nothing to display. 114 115 return 115 116 else … … 122 123 local descriptionWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Description") 123 124 descriptionWindow:setText(description:getDescription()) 124 descriptionWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P. scrollbarWidth-P.borderSize), CEGUI.UDim(1, 0)))125 descriptionWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(1, 0))) 125 126 descriptionWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, P.borderSize))) 126 127 local height = getStaticTextWindowHeight(descriptionWindow) … … 134 135 while i <= numQuests-1 do 135 136 local quest = P.questManager:getSubQuest(quest, P.player, i) 136 --if P.showActive == quest:isActive(P.player) then 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 --end 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) 142 141 i = i+1 143 142 end … … 146 145 height = height+P.frameHeigth 147 146 end 148 list:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P. scrollbarWidth-P.borderSize), CEGUI.UDim(0, height)))147 list:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(0, height))) 149 148 list:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset))) 150 offset = offset + height 149 offset = offset + height + P.borderSize 151 150 152 151 -- Load hints 153 152 local hintsWindow = winMgr:getWindow("orxonox/QuestGUI/Quest/Hints") 154 153 hintsWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset))) 155 hintsWindow:set Width(CEGUI.UDim(1, -P.scrollbarWidth-P.borderSize))154 hintsWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(0, 0))) 156 155 height = P.titleHeight 157 156 local numHints = P.questManager:getNumHints(quest, P.player) … … 162 161 i = i+1 163 162 end 163 if numHints == 0 then 164 height = 0 165 end 164 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))) 165 172 end 166 173 … … 168 175 end 169 176 177 -- Clear the currently displayed quest. 170 178 function P.clearQuest() 171 179 -- clear title … … 200 208 end 201 209 210 -- Clear the quests list 202 211 function P.clearQuestList() 203 212 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList")) … … 206 215 end 207 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. 208 220 function P.selectQuest(list, quest) 209 if quest == nil then 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. 210 222 cout(1, "Error in QuestGUI: selectQuest(), input quest is nil. Selecting first.") 211 223 list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first … … 216 228 local found = false 217 229 local index = 0 230 -- Iterate over all quests currently in the list. 218 231 for k,v in pairs(P.quests) do 232 -- If the id's are the same we have found the quest. 219 233 if P.questManager:getId(v) == questId then 220 234 found = true … … 222 236 end 223 237 end 224 cout(0, questId .. " " .. index) 225 if found then 238 239 if found then -- If the quest was found it is selected. 226 240 list:setItemSelectState(list:getListboxItemFromIndex(index), true) 227 else 241 else -- If the quest isn't found an error is output and the first quest is selected instead. 228 242 cout(1, "Error in QuestGUI: selectQuest(), input quest is not in list. Selecting first.") 229 243 list:setItemSelectState(list:getListboxItemFromIndex(0), true) -- Select first … … 231 245 end 232 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. 233 252 function P.insertHint(hintsWindow, hint, index, offset) 253 -- Create the window for the hint. 234 254 local window = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/QuestGUI/Quest/Hints/" .. index) 235 255 window:setProperty("HorzFormatting", "WordWrapLeftAligned") … … 240 260 local description = P.questManager:getDescription(hint) 241 261 window:setText(description:getDescription()) 242 window:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P. scrollbarWidth-P.borderSize), CEGUI.UDim(1, 0)))262 window:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.borderSize), CEGUI.UDim(1, 0))) 243 263 local height = getStaticTextWindowHeight(window) 244 264 window:setHeight(CEGUI.UDim(0, height)) 245 265 window:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderSize), CEGUI.UDim(0, offset))) 246 return height+P.borderSize 247 end 248 266 return height 267 end 268 269 -- Show the currently active quests in the quests list. 249 270 function P.showActiveQuestsButton_clicked(e) 250 271 if P.showActive == false then … … 254 275 end 255 276 277 -- Show the finished (i.e. inactive) quests in the quests list. 256 278 function P.showFinishedQuestsButton_clicked(e) 257 279 if P.showActive == true then … … 261 283 end 262 284 285 -- Change to a new quest. 263 286 function P.changeQuest_clicked(e) 264 287 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/QuestsList")) … … 273 296 end 274 297 298 -- Change to a new subquest. 275 299 function P.changeToSubquest_clicked(e) 276 300 local list = CEGUI.toListbox(winMgr:getWindow("orxonox/QuestGUI/Quest/SubquestsList")) … … 281 305 local quest = P.subquests[index+1] 282 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. 283 308 if quest:isActive(P.player) == P.showActive then 284 309 P.selectQuest(questsList, quest)
Note: See TracChangeset
for help on using the changeset viewer.