Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mac_osx/data/gui/scripts/QuestGUI.lua @ 8359

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

Reviewing documentation fo Questsystem, moving documentation fully into doxygen.
Added some files to modules they belong to.

  • Property svn:eol-style set to native
File size: 11.1 KB
Line 
1-- QuestGUI.lua
2
3local P = createMenuSheet("QuestGUI")
4
5P.rootWindow = nil
6P.detailsWindows = {}
7P.quests = {}
8P.hints = {}
9P.player = nil
10
11-- design parameters
12P.indentWidth = 20
13P.scrollbarWidth = 13
14P.buttonHeight = 30
15P.titleHeight = 26
16P.borderWidth = 5
17
18function P.onShow()
19
20    local questsList = winMgr:getWindow("orxonox/QuestGUI/QuestsList")
21
22    P.player = orxonox.GUIManager:getInstance():getPlayer(P.name)
23    P.rootWindow = P.createQuestGUI();
24
25    questsList:addChildWindow(P.rootWindow)
26end
27
28function P.onHide()
29    P.cleanup()
30end
31
32function P.createQuestGUI()
33    local questManager = orxonox.QuestManager:getInstance()
34
35    local depth = 0
36    local index = 0
37
38    local questWindow = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/QuestGUI/Quests")
39    questWindow:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0),CEGUI.UDim(1, 0)))
40
41    -- Iterate through all root-quests.
42    local numRootQuests = orxonox.QuestManager:getInstance():getNumRootQuests(P.player)
43    local i = 0
44    while i <= numRootQuests-1 do
45        local quest = orxonox.QuestManager:getInstance():getRootQuest(P.player, i)
46        index = P.createQuestNodes(questWindow, quest, depth, index)
47        i = i+1
48    end
49
50    return questWindow
51end
52
53function P.createQuestNodes(root, parent, depth, index)
54    local number = table.getn(P.quests)+1
55    local name = "orxonox/QuestGUI/Quests/" .. number
56    local node = winMgr:createWindow("MenuWidgets/TabButton", name)
57    node:setText(orxonox.QuestManager:getInstance():getDescription(parent):getTitle())
58    node:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.indentWidth*depth), CEGUI.UDim(0, P.buttonHeight*index)))
59    node:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.indentWidth*depth-P.scrollbarWidth), CEGUI.UDim(0, P.buttonHeight)))
60    orxonox.GUIManager:subscribeEventHelper(node, "Clicked", P.name .. ".openDetails_clicked")
61    root:addChildWindow(node)
62   
63    table.insert(P.quests, parent)
64
65    index = index+1
66
67    -- Iterate through all sub-quests.
68    local numQuests = orxonox.QuestManager:getInstance():getNumSubQuests(parent, P.player)
69    local i = 0
70    while i <= numQuests-1 do
71        local quest = orxonox.QuestManager:getInstance():getSubQuest(parent, P.player, i)
72        index = P.createQuestNodes(root, quest, depth+1, index)
73        i = i+1
74    end
75
76    return index;
77end
78
79function P.cleanup()
80    winMgr:destroyWindow(P.rootWindow)
81    for k,v in pairs(P.detailsWindows) do
82        if v ~= nil then
83            winMgr:destroyWindow(v)
84            P.detailsWindows[k] = nil
85        end
86    end
87    P.detailsWindows = {}
88
89    P.quests = {}
90    P.hints = {}
91    P.player = nil
92
93    winMgr:destroyWindow(P.rootWindow)
94    P.rootWindow = nil
95end
96
97function P.openDetails_clicked(e)
98    --Get some numbers from the window
99    local we = CEGUI.toWindowEventArgs(e)
100    local name = we.window:getName()
101    local match = string.gmatch(name, "%d+")
102    local questNr = tonumber(match())
103
104    name = name .. "/Details" .. P.getNewDetailNumber()
105    quest = P.quests[questNr]
106
107    local details = winMgr:createWindow("MenuWidgets/FrameWindow", name)
108    details:setSize(CEGUI.UVector2(CEGUI.UDim(0.7, 0), CEGUI.UDim(0.7, 0)))
109    details:setPosition(CEGUI.UVector2(CEGUI.UDim(0.1, 0), CEGUI.UDim(0.1, 0)))
110    details:setText(orxonox.QuestManager:getInstance():getDescription(quest):getTitle())
111    details:setProperty("Alpha", 1.0)
112    details:setProperty("InheritsAlpha", "setFalse")
113    orxonox.GUIManager:subscribeEventHelper(details, "CloseClicked", P.name .. ".closeDetails_clicked")
114
115    table.insert(P.detailsWindows, details)
116
117    name = name .. "/Scrollable"
118    local window = winMgr:createWindow("MenuWidgets/ScrollablePane", name)
119    window:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -2*P.borderWidth),CEGUI.UDim(1.0, -P.titleHeight)))
120    window:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderWidth), CEGUI.UDim(0, P.titleHeight)))
121    details:addChildWindow(window)
122
123    local offset = 0
124
125    local status = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Status")
126    window:addChildWindow(status)
127    status:setProperty("HorzFormatting", "WordWrapLeftAligned")
128    status:setProperty("VertFormatting", "TopAligned")
129    if quest:isActive(P.player) then
130        status:setText("This quest is active.")
131    elseif quest:isCompleted(P.player) then
132        status:setText("This quest was completed.")
133    elseif quest:isFailed(P.player) then
134        status:setText("This quest was failed.")
135    end
136    status:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, offset)))
137    status:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(1.0, 0)))
138    local height = getStaticTextWindowHeight(status)
139    status:setHeight(CEGUI.UDim(0, height))
140    offset = offset + height
141
142    local descriptionTitle = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Description/Title");
143    window:addChildWindow(descriptionTitle)
144    descriptionTitle:setProperty("HorzFormatting", "HorzCentred")
145    descriptionTitle:setProperty("VertFormatting", "TopAligned")
146    descriptionTitle:setText("Description:")
147    descriptionTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, offset)))
148    descriptionTitle:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(1.0, 0)))
149    height = getStaticTextWindowHeight(descriptionTitle)
150    descriptionTitle:setHeight(CEGUI.UDim(0, height))
151    offset = offset + height
152
153    local description = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Description");
154    window:addChildWindow(description)
155    description:setProperty("HorzFormatting", "WordWrapLeftAligned")
156    description:setProperty("VertFormatting", "TopAligned")
157    description:setText(orxonox.QuestManager:getInstance():getDescription(quest):getDescription())
158    description:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, offset)))
159    description:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(1.0, 0)))
160    height = getStaticTextWindowHeight(description)
161    description:setHeight(CEGUI.UDim(0, height))
162    offset = offset + height
163
164    -- Display the hints of this quest
165    local numHints = orxonox.QuestManager:getInstance():getNumHints(quest, P.player)
166    if numHints > 0 then
167        local hintsTitle = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Hints/Title");
168        window:addChildWindow(hintsTitle)
169        hintsTitle:setProperty("HorzFormatting", "HorzCentred")
170        hintsTitle:setProperty("VertFormatting", "TopAligned")
171        hintsTitle:setText("Hints:")
172        hintsTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, offset)))
173        hintsTitle:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(1.0, 0)))
174        height = getStaticTextWindowHeight(hintsTitle)
175        hintsTitle:setHeight(CEGUI.UDim(0, height))
176        offset = offset + height
177    end
178    local i = 0
179    while i <= numHints-1 do
180        local hint = orxonox.QuestManager:getInstance():getHints(quest, P.player, i)
181        table.insert(P.hints, hint)
182        local number = table.getn(P.hints)
183        local node = winMgr:createWindow("MenuWidgets/TabButton", name .. "/Hints" .. number)
184        node:setText(orxonox.QuestManager:getInstance():getDescription(hint):getTitle())
185        node:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, offset)))
186        node:setSize(CEGUI.UVector2(CEGUI.UDim(1, -P.scrollbarWidth), CEGUI.UDim(0, P.buttonHeight)))
187        window:addChildWindow(node)
188        offset = offset + P.buttonHeight
189
190        orxonox.GUIManager:subscribeEventHelper(node, "Clicked", P.name .. ".openHintDetails_clicked")
191        i = i+1
192    end
193
194    local window = winMgr:getWindow("orxonox/QuestGUI/Background")
195    window:addChildWindow(details)
196end
197
198function P.getNewDetailNumber()
199    local number = table.getn(P.detailsWindows)
200    for k,v in pairs(P.detailsWindows) do
201        if v == nil then
202            number = k-1
203        end
204    end
205    return number+1
206end
207
208function P.closeDetails_clicked(e)
209    local we = CEGUI.toWindowEventArgs(e)
210    local name = we.window:getName()
211    local match = string.gmatch(name, "%d+")
212    match()
213    local detailsNr = tonumber(match())
214
215    winMgr:destroyWindow(P.detailsWindows[detailsNr])
216    P.detailsWindows[detailsNr] = nil
217end
218
219function P.openHintDetails_clicked(e)
220    --Get some numbers from the window
221    local we = CEGUI.toWindowEventArgs(e)
222    local name = we.window:getName()
223    local match = string.gmatch(name, "%d+")
224    match()
225    match()
226    local hintNr = tonumber(match())
227
228    name = name .. "/Details" .. P.getNewDetailNumber()
229    hint = P.hints[hintNr]
230
231    local details = winMgr:createWindow("MenuWidgets/FrameWindow", name)
232    details:setSize(CEGUI.UVector2(CEGUI.UDim(0.7, 0), CEGUI.UDim(0.7, 0)))
233    details:setPosition(CEGUI.UVector2(CEGUI.UDim(0.1, 0), CEGUI.UDim(0.1, 0)))
234    details:setText(orxonox.QuestManager:getInstance():getDescription(hint):getTitle())
235    details:setProperty("Alpha", 1.0)
236    details:setProperty("InheritsAlpha", "setFalse")
237    orxonox.GUIManager:subscribeEventHelper(details, "CloseClicked", P.name .. ".closeHintDetails_clicked")
238
239    table.insert(P.detailsWindows, details)
240
241    name = name .. "/Scrollable"
242    local window = winMgr:createWindow("MenuWidgets/ScrollablePane", name)
243    window:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -2*P.borderWidth),CEGUI.UDim(1.0, -P.titleHeight)))
244    window:setPosition(CEGUI.UVector2(CEGUI.UDim(0, P.borderWidth), CEGUI.UDim(0, P.titleHeight)))
245    details:addChildWindow(window)
246
247    local offset = 0
248   
249    local descriptionTitle = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Description/Title");
250    window:addChildWindow(descriptionTitle)
251    descriptionTitle:setProperty("HorzFormatting", "HorzCentred")
252    descriptionTitle:setProperty("VertFormatting", "TopAligned")
253    descriptionTitle:setText("Description:")
254    descriptionTitle:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, offset)))
255    descriptionTitle:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(1.0, 0)))
256    height = getStaticTextWindowHeight(descriptionTitle)
257    descriptionTitle:setHeight(CEGUI.UDim(0, height))
258    offset = offset + height
259
260    local description = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Description");
261    window:addChildWindow(description)
262    description:setProperty("HorzFormatting", "WordWrapLeftAligned")
263    description:setProperty("VertFormatting", "TopAligned")
264    description:setText(orxonox.QuestManager:getInstance():getDescription(hint):getDescription())
265    description:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, offset)))
266    description:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(1.0, 0)))
267    height = getStaticTextWindowHeight(description)
268    description:setHeight(CEGUI.UDim(0, height))
269
270    local window = winMgr:getWindow("orxonox/QuestGUI/Background")
271    window:addChildWindow(details)
272end
273
274function P.closeHintDetails_clicked(e)
275    local we = CEGUI.toWindowEventArgs(e)
276    local name = we.window:getName()
277    local match = string.gmatch(name, "%d+")
278    match()
279    match()
280    match()
281    local detailsNr = tonumber(match())
282
283    winMgr:destroyWindow(P.detailsWindows[detailsNr])
284    P.detailsWindows[detailsNr] = nil
285end
286
287return P
288
Note: See TracBrowser for help on using the repository browser.