1questLogButton = nil
2questLineWindow = nil
3
4function init()
5 g_ui.importStyle('questlogwindow')
6 g_ui.importStyle('questlinewindow')
7
8 if not g_app.isMobile() then
9 --questLogButton = modules.client_topmenu.addLeftGameButton('questLogButton', tr('Quest Log'), '/images/topbuttons/questlog', function() g_game.requestQuestLog() end, false, 8)
10 end
11
12 connect(g_game, { onQuestLog = onGameQuestLog,
13 onQuestLine = onGameQuestLine,
14 onGameEnd = destroyWindows})
15end
16
17function terminate()
18 disconnect(g_game, { onQuestLog = onGameQuestLog,
19 onQuestLine = onGameQuestLine,
20 onGameEnd = destroyWindows})
21
22 destroyWindows()
23 --if questLogButton then
24 -- questLogButton:destroy()
25 --end
26end
27
28function destroyWindows()
29 if questLogWindow then
30 questLogWindow:destroy()
31 end
32
33 if questLineWindow then
34 questLineWindow:destroy()
35 end
36end
37
38function onGameQuestLog(quests)
39 destroyWindows()
40
41 questLogWindow = g_ui.createWidget('QuestLogWindow', rootWidget)
42 local questList = questLogWindow:getChildById('questList')
43
44 for i,questEntry in pairs(quests) do
45 local id, name, completed = unpack(questEntry)
46
47 local questLabel = g_ui.createWidget('QuestLabel', questList)
48 questLabel:setOn(completed)
49 questLabel:setText(name)
50 questLabel.onDoubleClick = function()
51 questLogWindow:hide()
52 g_game.requestQuestLine(id)
53 end
54 end
55
56 questLogWindow.onDestroy = function()
57 questLogWindow = nil
58 end
59
60 questList:focusChild(questList:getFirstChild())
61end
62
63function onGameQuestLine(questId, questMissions)
64 if questLogWindow then questLogWindow:hide() end
65 if questLineWindow then questLineWindow:destroy() end
66
67 questLineWindow = g_ui.createWidget('QuestLineWindow', rootWidget)
68 local missionList = questLineWindow:getChildById('missionList')
69 local missionDescription = questLineWindow:getChildById('missionDescription')
70
71 connect(missionList, { onChildFocusChange = function(self, focusedChild)
72 if focusedChild == nil then return end
73 missionDescription:setText(focusedChild.description)
74 end })
75
76 for i,questMission in pairs(questMissions) do
77 local name, description = unpack(questMission)
78
79 local missionLabel = g_ui.createWidget('MissionLabel')
80 missionLabel:setText(name)
81 missionLabel.description = description
82 missionList:addChild(missionLabel)
83 end
84
85 questLineWindow.onDestroy = function()
86 if questLogWindow then questLogWindow:show() end
87 questLineWindow = nil
88 end
89
90 missionList:focusChild(missionList:getFirstChild())
91end
92
93