Back to Home

ESO Lua File v101043

ingame/map/worldmapquests_shared.lua

[◄ back to folders ]
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
--Shared Trade Window Prototype
ZO_WorldMapQuests_Shared = ZO_Object:Subclass()
function ZO_WorldMapQuests_Shared:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
function ZO_WorldMapQuests_Shared:Initialize(control)
    self.control = control
    control:RegisterForEvent(EVENT_LEVEL_UPDATE, function(eventCode, unitTag)
        if(unitTag == "player") then
            self:RefreshHeaders()
        end
    end)
    local function LayoutList(forceLayout)
        if not self.control:IsHidden() or forceLayout then
            self:LayoutList()
        end
    end
    CALLBACK_MANAGER:RegisterCallback("OnWorldMapQuestsDataRefresh", LayoutList)
    CALLBACK_MANAGER:RegisterCallback("OnWorldMapChanged", function() self:RefreshNoQuestsLabel() end)
end
function ZO_WorldMapQuests_Shared:RefreshNoQuestsLabel()
    if #self.data.masterList > 0 then
        self.noQuestsLabel:SetHidden(true)    
    else
        self.noQuestsLabel:SetHidden(false)
        if ZO_WorldMapQuestsData_Singleton.ShouldMapShowQuestsInList() then
            self.noQuestsLabel:SetText(GetString(SI_WORLD_MAP_NO_QUESTS))
        else
            self.noQuestsLabel:SetText(GetString(SI_WORLD_MAP_DOESNT_SHOW_QUESTS_DISTANCE))
        end
    end
end
-- Singleton shared data
ZO_WorldMapQuestsData_Singleton = ZO_Object:Subclass()
function ZO_WorldMapQuestsData_Singleton:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
function ZO_WorldMapQuestsData_Singleton:Initialize(control)
    self.listDirty = false
    self.masterList = {}
    self.CompareQuests = function(a, b)
        local aCon = GetCon(a.level)
        local bCon = GetCon(b.level)
        if(aCon == bCon) then
            return a.name < b.name
        else
            return aCon < bCon
        end
    end
    WORLD_MAP_QUEST_BREADCRUMBS:RegisterCallback("QuestAvailable", function(...) self:OnQuestAvailable(...) end)
    WORLD_MAP_QUEST_BREADCRUMBS:RegisterCallback("QuestRemoved", function(...) self:OnQuestRemoved(...) end)
    EVENT_MANAGER:RegisterForUpdate("ZO_WorldMapQuestsData_Singleton", 100, function()
        if self.listDirty then
            self.listDirty = false
            self:LayoutList(true)
        end
    end)
end
function ZO_WorldMapQuestsData_Singleton.ShouldMapShowQuestsInList()
    local mapType = GetMapType()
    --We don't want to track any quests when we are showing these high map levels
    if mapType >= MAPTYPE_WORLD then
        return false
    end
    return true
end
function ZO_WorldMapQuestsData_Singleton.IsQuestInCurrentMapNormalizedBounds(questSteps)
    for stepIndex, questConditions in pairs(questSteps) do
        for conditionIndex, conditionData in pairs(questConditions) do
            if conditionData.xLoc >= 0 and conditionData.xLoc <= 1 and conditionData.yLoc >= 0 and conditionData.yLoc <= 1 and conditionData.insideCurrentMapWorld then
                return true
            end
        end
    end
    return false
end
function ZO_WorldMapQuestsData_Singleton:OnQuestAvailable(questIndex)
    if not ZO_WorldMapQuestsData_Singleton.ShouldMapShowQuestsInList() then
        return
    end
        
    if self:GetQuestMasterListIndex(questIndex) then
        -- We already have this quest in the list.
        return
    end
    local shouldAddQuest
    local questSteps = WORLD_MAP_QUEST_BREADCRUMBS:GetSteps(questIndex)
    if questSteps then
        shouldAddQuest = ZO_WorldMapQuestsData_Singleton.IsQuestInCurrentMapNormalizedBounds(questSteps)
    else
        shouldAddQuest = IsJournalQuestInCurrentMapZone(questIndex)
    end
    if shouldAddQuest then
        local questType = GetJournalQuestType(questIndex)
        local name = GetJournalQuestName(questIndex)
        local level = GetJournalQuestLevel(questIndex)
        local displayType = GetJournalQuestZoneDisplayType(questIndex)
        table.insert(self.masterList, {
            questIndex = questIndex,
            name = name,
            level = level,
            questType = questType,
            displayType = displayType,
        })
        self.listDirty = true
    end       
end
function ZO_WorldMapQuestsData_Singleton:OnQuestRemoved(questIndex)
    local masterListIndex = self:GetQuestMasterListIndex(questIndex)
    if masterListIndex then
        table.remove(self.masterList, masterListIndex)
        self.listDirty = true
    end
end
function ZO_WorldMapQuestsData_Singleton:GetQuestMasterListIndex(questIndex)
    for i, questData in ipairs(self.masterList) do
        if questData.questIndex == questIndex then
            return i
        end
    end
    return nil
end
function ZO_WorldMapQuestsData_Singleton:LayoutList(forceLayout)
    self:Sort()
    CALLBACK_MANAGER:FireCallbacks("OnWorldMapQuestsDataRefresh", forceLayout)
end
function ZO_WorldMapQuestsData_Singleton:Sort()
    table.sort(self.masterList, self.CompareQuests)
end
    if not WORLD_MAP_QUESTS_DATA then
        WORLD_MAP_QUESTS_DATA = ZO_WorldMapQuestsData_Singleton:New(control)
    end
    return WORLD_MAP_QUESTS_DATA
end
local AddConditionLine = function(self, labels, text)
    local conditionLabel = self.labelPool:AcquireObject()
    conditionLabel:SetWidth(0)
    zo_bulletFormat(conditionLabel, text)
    table.insert(labels, conditionLabel)
end
    local labels = {}
    local questName, bgText, stepText, stepType, stepOverrideText, completed, tracked = GetJournalQuestInfo(questIndex)
    if completed then
        AddConditionLine(self, labels, GetJournalQuestEnding(questIndex))
    else
        local tasks = {}
        QUEST_JOURNAL_MANAGER:BuildTextForTasks(stepOverrideText, questIndex, tasks)
        for i = 1, #tasks do
            AddConditionLine(self, labels, tasks[i].name)
        end
    end
    local width = 0
    for i = 1, #labels do
        local labelWidth = labels[i]:GetTextDimensions() 
        width = zo_max(width, labelWidth)
    end
    local MAX_WIDTH = 250
    width = zo_min(width, MAX_WIDTH)
    return labels, width
end