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