Mercurial > wow > worldplan
comparison WorldQuests.lua @ 40:589c444d4837
WowAce/Curseforge migration push
author | Nenue |
---|---|
date | Sun, 25 Dec 2016 13:04:57 -0500 |
parents | 78cf1f19856a |
children | 79e5e96e5f18 |
comparison
equal
deleted
inserted
replaced
39:89ddef0594bc | 40:589c444d4837 |
---|---|
1 -- WorldPlan | 1 -- WorldPlan |
2 -- WorldQuests.lua | 2 -- WorldQuests.lua |
3 -- Created: 11/2/2016 3:40 PM | 3 -- Created: 11/2/2016 3:40 PM |
4 -- %file-revision% | 4 -- %file-revision% |
5 | 5 local _, db = ... |
6 local WorldQuests = WorldPlanQuestsMixin | 6 local WorldQuests = WorldPlanQuestsMixin |
7 | 7 |
8 local MC_GetNumZones, MC_GetZoneInfo = C_MapCanvas.GetNumZones, C_MapCanvas.GetZoneInfo | 8 local MC_GetNumZones, MC_GetZoneInfo = C_MapCanvas.GetNumZones, C_MapCanvas.GetZoneInfo |
9 local TQ_GetQuestsForPlayerByMapID = C_TaskQuest.GetQuestsForPlayerByMapID -- This function is not yet documented | 9 local TQ_GetQuestsForPlayerByMapID = C_TaskQuest.GetQuestsForPlayerByMapID -- This function is not yet documented |
10 local TQ_GetQuestZoneID = C_TaskQuest.GetQuestZoneID | 10 local TQ_GetQuestZoneID = C_TaskQuest.GetQuestZoneID |
11 local GetMapInfo = GetMapInfo | 11 local GetMapInfo = GetMapInfo |
12 local print = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end | 12 local print = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuests', ...) end or function() end |
13 local rprint = DEVIAN_WORKSPACE and function(...) _G.print('WQRefresh', ...) end or function() end | |
13 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end | 14 local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end |
14 local wqprint = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuests', ...) end or function() end | |
15 local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end | 15 local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end |
16 local mprint = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or function() end | 16 local mprint = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or function() end |
17 | 17 |
18 | 18 |
19 local PinBaseIndex = 1000 | 19 local PinBaseIndex = 1200 |
20 local BROKEN_ISLES_ID, DALARAN_ID, AZSUNA_ID, VALSHARAH_ID, HIGHMOUNTAIN_ID, STORMHEIM_ID, SURAMAR_ID, EOA_ID = 1007, 1014, 1015,1018, 1024, 1017, 1033, 1096 | 20 local BROKEN_ISLES_ID, DALARAN_ID, AZSUNA_ID, VALSHARAH_ID, HIGHMOUNTAIN_ID, STORMHEIM_ID, SURAMAR_ID, EOA_ID = 1007, 1014, 1015,1018, 1024, 1017, 1033, 1096 |
21 local WORLD_QUEST_MAPS = { [DALARAN_ID] = 'Dalaran70', [AZSUNA_ID] = 'Azsuna', [VALSHARAH_ID] = "Val'sharah", | 21 local WORLD_QUEST_MAPS = { [DALARAN_ID] = 'Dalaran70', [AZSUNA_ID] = 'Azsuna', [VALSHARAH_ID] = "Val'sharah", |
22 [HIGHMOUNTAIN_ID] = 'Highmountain', [STORMHEIM_ID] = 'Stormheim', [SURAMAR_ID] = 'Suramar', [EOA_ID] = 'EyeOfAszhara', } | 22 [HIGHMOUNTAIN_ID] = 'Highmountain', [STORMHEIM_ID] = 'Stormheim', [SURAMAR_ID] = 'Suramar', [EOA_ID] = 'EyeOfAszhara', } |
23 | 23 |
24 local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD | 24 local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD |
27 local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES | 27 local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES |
28 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS | 28 local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS |
29 | 29 |
30 | 30 |
31 local numPins = 0 | 31 local numPins = 0 |
32 local ZoneInfo = {} | |
33 local NumPinFrames = 1 | 32 local NumPinFrames = 1 |
34 | 33 WorldQuests.TasksByID = {} |
35 | 34 |
36 --%debug% | 35 --%debug% |
37 local SetTimedCallbackForAllPins = function(seconds, callback) | 36 local SetTimedCallbackForAllPins = function(seconds, callback) |
38 C_Timer.After(seconds, function() | 37 C_Timer.After(seconds, function() |
39 for id, pin in pairs(WorldPlanQuests.QuestsByID) do | 38 for id, pin in pairs(WorldPlanQuests.QuestsByID) do |
40 callback(pin) | 39 callback(pin) |
41 end | 40 end |
42 end) | 41 end) |
43 end | 42 end |
44 | 43 |
44 function WorldQuests:OnShow() | |
45 self:Refresh(true) | |
46 end | |
47 | |
48 function WorldQuests:OnUpdate(sinceLast) | |
49 if self.filtersDirty or self.isStale then | |
50 self:Refresh() | |
51 end | |
52 end | |
53 | |
45 function WorldQuests:Setup() | 54 function WorldQuests:Setup() |
46 | 55 print('|cFFFF4400'..self:GetName()..':Setup()') |
47 | 56 |
48 for mapID, mapName in pairs(WORLD_QUEST_MAPS) do | 57 for mapID, mapName in pairs(WORLD_QUEST_MAPS) do |
49 self.QuestsByZone[mapID] = {} | 58 db.QuestsByZone[mapID] = {} |
50 end | 59 end |
51 | 60 |
52 | 61 |
53 -- refresh positions any time blizzard does so (i.e. mousewheel zoom) | 62 -- refresh positions any time blizzard does so (i.e. mousewheel zoom) |
54 hooksecurefunc("WorldMapScrollFrame_ReanchorQuestPOIs", function() | 63 hooksecurefunc("WorldMapScrollFrame_ReanchorQuestPOIs", function() |
64 print('|cFFFF4400WorldMapScrollFrame_ReanchorQuestPOIs') | |
55 self:Refresh(true) | 65 self:Refresh(true) |
56 end) | 66 end) |
57 | 67 |
68 | |
58 -- hide the original world quest POIs | 69 -- hide the original world quest POIs |
70 | |
59 hooksecurefunc("WorldMap_UpdateQuestBonusObjectives", function() | 71 hooksecurefunc("WorldMap_UpdateQuestBonusObjectives", function() |
72 print('|cFFFF4400WorldMap_UpdateQuestBonusObjectives') | |
60 for i = 1, NUM_WORLDMAP_TASK_POIS do | 73 for i = 1, NUM_WORLDMAP_TASK_POIS do |
61 local button = _G['WorldMapFrameTaskPOI'..i] | 74 local button = _G['WorldMapFrameTaskPOI'..i] |
62 if button and button.worldQuest then | 75 if button and button.worldQuest then |
63 button:Hide() | 76 button:Hide() |
64 end | 77 end |
65 end | 78 end |
66 end) | 79 end) |
67 end | 80 end |
68 local WorldMapPOIFrame | |
69 local defaults = {} | 81 local defaults = {} |
82 local REWARD_UNKNOWN = 768 | |
70 function WorldQuests:OnLoad() | 83 function WorldQuests:OnLoad() |
71 print('|cFF00FF88'..self:GetName()..':OnLoad') | 84 print('|cFFFF4400'..self:GetName()..':OnLoad()') |
72 | 85 |
86 self:SetParent(WorldMapFrame) | |
73 WorldPlan:AddHandler(self, defaults) | 87 WorldPlan:AddHandler(self, defaults) |
74 | 88 |
75 local rgbWhite = {1, 1, 1} | 89 local rgbWhite = {1, 1, 1 } |
90 WorldPlan:AddTypeInfo(self, REWARD_UNKNOWN, { r = 1, g = 1, b = 1}) | |
76 WorldPlan:AddTypeInfo(self, REWARD_REAGENT, { r = 0, g = 1, b = 1 }) | 91 WorldPlan:AddTypeInfo(self, REWARD_REAGENT, { r = 0, g = 1, b = 1 }) |
77 WorldPlan:AddTypeInfo(self, REWARD_ARTIFACT_POWER, { r = 1, g = .25, b = .5, hasNumeric = true, numberRGB = rgbWhite }) | 92 WorldPlan:AddTypeInfo(self, REWARD_ARTIFACT_POWER, { r = 1, g = .25, b = .5, hasNumeric = true, numberRGB = rgbWhite }) |
78 WorldPlan:AddTypeInfo(self, REWARD_GEAR, { r = .1, g = .2, b = 1 }) | 93 WorldPlan:AddTypeInfo(self, REWARD_GEAR, { r = .1, g = .2, b = 1 }) |
79 WorldPlan:AddTypeInfo(self, REWARD_CURRENCY, { r = 1, g = 1, b = 0, hasNumeric = true, numberRGB = {1,1,0}, }) | 94 WorldPlan:AddTypeInfo(self, REWARD_CURRENCY, { r = 1, g = 1, b = 0, hasNumeric = true, numberRGB = {1,1,0}, }) |
80 WorldPlan:AddTypeInfo(self, REWARD_CASH, { r = .7, g = .6, b = .32, pinMask = false, rewardMask = false }) | 95 WorldPlan:AddTypeInfo(self, REWARD_CASH, { r = 1, g = 1, b = .32, pinMask = false, rewardMask = false }) |
81 | 96 |
82 for areaID, fileName in pairs(WORLD_QUEST_MAPS) do | 97 for areaID, fileName in pairs(WORLD_QUEST_MAPS) do |
83 self.QuestsByZone[areaID] = {} | 98 db.QuestsByZone[areaID] = {} |
84 end | 99 end |
85 | 100 |
86 self:RegisterEvent('WORLD_QUEST_COMPLETED_BY_SPELL') | 101 self:RegisterEvent('WORLD_QUEST_COMPLETED_BY_SPELL') |
87 self:RegisterEvent('SKILL_LINES_CHANGED') | 102 self:RegisterEvent('SKILL_LINES_CHANGED') |
88 | 103 |
89 WorldMapPOIFrame = _G.WorldMapPOIFrame | 104 WorldMapPOIFrame = _G.WorldMapPOIFrame |
90 | 105 |
91 end | 106 end |
92 | 107 |
93 function WorldQuests:OnEvent (event, ...) | 108 function WorldQuests:OnEvent (event, ...) |
94 local print = wqprint | 109 |
95 print('|cFFFFFF00'..self:GetName()..':OnEvent()'..event..'|r', GetTime(), ...) | 110 print('|cFFFFFF00'..self:GetName()..':OnEvent() '..event..'|r', GetTime(), ...) |
96 if event == 'QUEST_LOG_UPDATE' then | 111 if event == 'QUEST_LOG_UPDATE' or event == 'PLAYER_LOGIN' then |
97 local questID, added = ... | 112 local questID, added = ... |
98 if questID and added then | 113 if questID and added then |
99 local questPOI = self:AcquirePin(questID) | 114 local questPOI = self:AcquirePin(questID) |
100 self.isStale, self.isPending = questPOI:RefreshData() | 115 questPOI:GetQuestInfo() |
116 questPOI.isStale = true | |
117 self.isStale = true | |
101 else | 118 else |
102 self:RefreshData() | 119 self:Refresh(true) |
103 end | 120 end |
104 print('WorldMapFrame', WorldMapFrame:IsVisible(), 'hasUpdates:', self.isStale) | 121 print('WorldMapFrame', WorldMapFrame:IsVisible(), 'hasUpdates:', self.isStale) |
105 elseif event == 'WORLD_MAP_UPDATE' or event == 'PLAYER_ENTERING_WORLD' then | 122 elseif event == 'WORLD_MAP_UPDATE' then |
106 self.isStale = true | 123 self:Refresh(true) |
107 elseif event == 'WORLD_QUEST_COMPLETED_BY_SPELL' then | 124 elseif event == 'WORLD_QUEST_COMPLETED_BY_SPELL' then |
108 local questID = ... | 125 local questID = ... |
109 if questID and self.QuestsByID[questID] then | 126 if questID and db.QuestsByID[questID] then |
110 self:ReleasePin(self.QuestsByID[questID]) | 127 self:ReleasePin(db.QuestsByID[questID]) |
128 rprint('|cFFFF4400release|r', questID) | |
111 end | 129 end |
112 elseif event == 'SKILL_LINES_CHANGED' then | 130 elseif event == 'SKILL_LINES_CHANGED' then |
113 self.isStale = true | 131 self:SetFilteredPins() |
114 end | 132 end |
115 end | 133 end |
116 | 134 |
135 local totalPins = 0 | |
117 local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation | 136 local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation |
118 function WorldQuests:AcquirePin (questID, mapID) | 137 function WorldQuests:AcquirePin (info) |
119 local pin = self.QuestsByID[questID] | 138 local questID = info.questId |
120 local isNew = false | 139 if not questID then |
140 return nil | |
141 end | |
142 | |
143 if not QuestUtils_IsQuestWorldQuest(questID) then | |
144 return nil | |
145 end | |
146 | |
147 | |
148 local pin = db.QuestsByID[questID] | |
121 if not pin then | 149 if not pin then |
122 isNew = true | 150 local numFree = #db.FreePins |
123 local numFree = #self.freePins | |
124 if numFree >= 1 then | 151 if numFree >= 1 then |
125 pin = tremove(self.freePins, numFree) | 152 pin = tremove(db.FreePins, numFree) |
126 --print('|cFF00FF00Re-using', pin:GetName()) | 153 --print('|cFF00FF00Re-using', pin:GetName()) |
127 else | 154 else |
155 totalPins = totalPins + 1 | |
128 local name = 'WorldPlanQuestMarker' .. NumPinFrames | 156 local name = 'WorldPlanQuestMarker' .. NumPinFrames |
129 --print('|cFF00FF00Creating', name) | 157 --print('|cFF00FF00Creating', name) |
130 pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin') | 158 pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin') |
131 | 159 |
132 pin:SetFrameStrata('HIGH') | 160 pin:SetFrameStrata('HIGH') |
133 pin.GetTypeInfo = function(frame, typeID) | 161 pin.GetTypeInfo = function(frame, typeID) |
134 return self:GetTypeInfo(typeID) | 162 return self:GetTypeInfo(typeID) |
135 end | 163 end |
164 pin:SetID(totalPins) | |
136 NumPinFrames = NumPinFrames + 1 | 165 NumPinFrames = NumPinFrames + 1 |
137 --pin.iconBorder:SetVertexColor(0,0,0,1) | 166 --pin.iconBorder:SetVertexColor(0,0,0,1) |
138 end | 167 end |
139 pin:SetID(questID) | 168 pin.questID = questID |
169 pin.worldQuest = true | |
170 pin.throttle = 1 | |
140 pin.isNew = true | 171 pin.isNew = true |
141 pin.currentWidth = nil | 172 pin.currentWidth = nil |
142 | 173 db.QuestsByID[questID] = pin |
143 -- used by TaskPOI_x scripts | 174 tinsert(db.UsedPins, pin) |
144 pin.questID = questID | 175 end |
145 pin.worldQuest = true | 176 |
146 | 177 if pin and info then |
147 self.QuestsByID[questID] = pin | 178 pin.inProgress = info.inProgress |
148 else | 179 pin.floor = info.floor |
149 --print('|cFF00FF00Using', pin:GetName()) | 180 pin.numObjectives = info.numObjectives or 0 |
150 end | 181 if info.x and info.y then |
151 mapID = mapID or TQ_GetQuestZoneID(questID) | 182 pin.x = info.x or pin.x |
152 self.QuestsByZone[mapID][questID] = pin | 183 pin.y = info.y or pin.y |
153 | 184 rprint('|cFFFF4400coords|r', info.x, info.y) |
154 return pin, isNew | 185 end |
186 end | |
187 | |
188 pin:GetData() | |
189 C_TaskQuest.RequestPreloadRewardData(info.questId) | |
190 return pin | |
155 end | 191 end |
156 | 192 |
157 -- remove from index and add it to the recycling heap | 193 -- remove from index and add it to the recycling heap |
158 function WorldQuests:ReleasePin (pin) | 194 function WorldQuests:ReleasePin (pin) |
159 | 195 |
160 local id = pin.questId | 196 local id = pin.questID |
161 if id then | 197 if id then |
162 self.QuestsByID[id] = nil | 198 db.QuestsByID[id] = nil |
163 for i, zone in pairs(self.QuestsByZone) do | 199 |
200 for i, zone in pairs(db.QuestsByZone) do | |
164 print('-', i, zone[i]) | 201 print('-', i, zone[i]) |
165 zone[id] = nil | 202 zone[id] = nil |
166 end | 203 end |
167 end | 204 db.TasksByID[id] = nil |
168 pin:Hide() | 205 end |
206 pin:SetShown(false) | |
169 pin:ClearAllPoints() | 207 pin:ClearAllPoints() |
170 tinsert(self.freePins, pin) | 208 tinsert(db.FreePins, pin) |
171 print('|cFFFF4400Clearing out', pin:GetName(),id) | 209 |
172 end | 210 print('|cFF00FF00-'.. (pin.mapID and GetMapNameByID(pin.mapID) or '???') ..'|r', id, pin.title) |
173 | 211 end |
212 | |
213 function WorldQuests:GetBonusObjectives() | |
214 | |
215 | |
216 local tasksTable = GetTasksTable() | |
217 if tasksTable ~= nil then | |
218 print('|cFF00FF88'..self:GetName()..':BonusObjectives()|r ') | |
219 self.numTasks = #tasksTable | |
220 for i, taskID in ipairs(tasksTable) do | |
221 if not QuestUtils_IsQuestWorldQuest(taskID) then | |
222 local info = db.TasksByID[taskID] | |
223 if not info then | |
224 local isInArea, isOnMap, numObjectives, taskName, displayAsObjective = GetTaskInfo(taskID) | |
225 if isOnMap then | |
226 print(' * '..i, taskID, GetTaskInfo(taskID)) | |
227 info = { | |
228 questID = taskID, | |
229 numObjectives = numObjectives, | |
230 title = taskName, | |
231 isInArea = isInArea, | |
232 isOnMap = isOnMap, | |
233 displayAsObjective = displayAsObjective, | |
234 worldQuest = false, | |
235 isPending = false, | |
236 isNew = true, | |
237 } | |
238 | |
239 | |
240 db.TasksByID[taskID] = info | |
241 | |
242 local pin = self:AcquirePin(taskID) | |
243 for k,v in pairs(info) do | |
244 pin[k] = v | |
245 end | |
246 pin:GetBonusObjectiveInfo(info) | |
247 end | |
248 end | |
249 end | |
250 | |
251 | |
252 end | |
253 end | |
254 end | |
255 | |
256 | |
257 | |
258 | |
259 -- use tooltip object to extract item details | |
260 function WorldQuests:GetRewardHeader(questID) | |
261 local name, icon, quantity, quality, _, itemID = GetQuestLogRewardInfo(1, questID) | |
262 local scanner = _G.WorldPlanTooltip | |
263 local print = qprint | |
264 if not itemID then | |
265 return | |
266 end | |
267 --print('GetRewardHeader', questID) | |
268 | |
269 scanner:SetOwner(WorldPlan, "ANCHOR_NONE") | |
270 scanner:SetItemByID(itemID) | |
271 scanner:Show() | |
272 local ttl1 = _G['WorldPlanTooltipTextLeft1'] | |
273 local ttl2 = _G['WorldPlanTooltipTextLeft2'] | |
274 local ttl3 = _G['WorldPlanTooltipTextLeft3'] | |
275 local ttl4 = _G['WorldPlanTooltipTextLeft4'] | |
276 --print(ttl2, ttl3, ttl4) | |
277 if ttl2 then | |
278 local text = ttl2:GetText() | |
279 -- Artifact Power | |
280 --print(text) | |
281 if text then | |
282 if text:match("|cFFE6CC80") then | |
283 --print('AP token!', text) | |
284 local power | |
285 if ttl4 then | |
286 local text = ttl4:GetText() | |
287 --print('tip line 4', text) | |
288 if text then | |
289 power = text:gsub("%p", ""):match("%d+") | |
290 power = tonumber(power) | |
291 end | |
292 | |
293 end | |
294 return REWARD_ARTIFACT_POWER, "Interface\\ICONS\\inv_7xp_inscription_talenttome01", power, name, itemID, quality | |
295 elseif text:match("Item Level") then | |
296 --print('equipment!', text) | |
297 quantity = text:match("Item Level ([%d\+]+)") | |
298 return REWARD_GEAR, icon, quantity, name, itemID, quality | |
299 elseif text:match("Crafting Reagent") then | |
300 --print('|cFFFF4400it is a reagent', text) | |
301 return REWARD_REAGENT, icon, quantity, name, itemID, quality | |
302 end | |
303 end | |
304 end | |
305 | |
306 if ttl3 then | |
307 local text = ttl3:GetText() | |
308 if text and text:match("Crafting Reagent") then | |
309 --print('|cFFFF4400it is a reagent', text) | |
310 return REWARD_REAGENT, icon, quantity, name, itemID, quality | |
311 end | |
312 end | |
313 return 128, icon, quantity, name, itemID, quality | |
314 end | |
315 | |
316 local GetCurrentMapAreaID, GetMapNameByID= GetCurrentMapAreaID, GetMapNameByID | |
317 local wipe, pairs = wipe, pairs | |
174 -- create of update quest pins for a map and its underlying zones | 318 -- create of update quest pins for a map and its underlying zones |
175 function WorldQuests:RefreshData (mapID) | 319 function WorldQuests:UpdateWorldQuests (mapID) |
176 local print = wqprint | 320 |
177 mapID = mapID or WorldPlan.currentMapID | 321 mapID = mapID or db.currentMapID |
178 if not mapID then | 322 if not mapID then |
179 -- info not available yet | 323 -- info not available yet |
180 return | 324 return |
181 end | 325 end |
182 | 326 |
183 | 327 |
184 print('|cFF00FF88'..self:GetName()..':RefreshData()|r', 'map:', mapID, 'realMap:', GetCurrentMapAreaID()) | 328 print('|cFF00FF88'..self:GetName()..':UpdateWorldQuests()|r', 'map:', mapID, 'realMap:', db.currentMapID) |
185 | 329 |
186 if mapID == BROKEN_ISLES_ID then | 330 |
187 self.isStale = false | 331 self.isStale = nil |
188 print('|cFF00FFFFContinent:|r', mapID, GetMapNameByID(mapID), superTrackedID) | 332 print('|cFF00FFFFContinent:|r', BROKEN_ISLES_ID, GetMapNameByID(BROKEN_ISLES_ID)) |
189 self.fullSearch = true | 333 self.isRecursed = true |
190 for i = 1, MC_GetNumZones(mapID) do | 334 for i = 1, MC_GetNumZones(BROKEN_ISLES_ID) do |
191 local submapID, name, depth = MC_GetZoneInfo(mapID, i) | 335 local submapID, name, depth = MC_GetZoneInfo(BROKEN_ISLES_ID, i) |
192 self:RefreshData(submapID) | 336 local taskInfo = TQ_GetQuestsForPlayerByMapID(submapID, BROKEN_ISLES_ID) |
193 end | 337 if taskInfo then |
194 self.fullSearch = nil | 338 local zoneName = GetMapNameByID(submapID) |
195 elseif self.QuestsByZone[mapID] then | 339 print('|cFF00FFFF Zone:|r', submapID, zoneName, #taskInfo) |
196 local taskInfo = TQ_GetQuestsForPlayerByMapID(mapID, WorldPlan.currentMapID) | 340 db.QuestsByZone[submapID] = db.QuestsByZone[submapID] or {} |
197 local numQuests = 0 | 341 for i, info in ipairs(taskInfo) do |
198 if taskInfo and #taskInfo >= 1 then | 342 if HaveQuestData(info.questId) then |
199 print('|cFF00FFFF Zone:|r', mapID, GetMapNameByID(mapID), #taskInfo) | 343 rprint('|cFF44FF44update|r', info.questId, zoneName) |
200 wipe(self.QuestsByZone[mapID]) | 344 local questID = info.questId |
201 ZoneInfo[mapID] = taskInfo | 345 local pin = self:AcquirePin(questID) |
202 qprint('|cFFFF4400START of', GetMapNameByID(mapID)) | 346 local pin = db.QuestsByID[questID] |
203 for taskID, info in pairs(taskInfo) do | 347 if pin then |
204 local questID = info.questId | 348 pin.isStale = true |
205 info.mapID = mapID | 349 if pin.isPending then |
206 local questPOI = self:AcquirePin(questID, mapID) | 350 self.isPending = true |
207 local hasUpdate, isPending = questPOI:RefreshData(info) | 351 end |
208 -- WorldPlan:print('|cFF0088FF'..questPOI.title..'|r', hasUpdate) | 352 end |
209 self.isStale = (self.isStale or hasUpdate) | 353 else |
210 self.isPending = (self.isPending or isPending) | 354 rprint('|cFFFF4400no data|r', info.questId, zoneName) |
211 numQuests = numQuests + 1 | 355 end |
212 end | 356 end |
213 qprint('|cFFFF4400END of', GetMapNameByID(mapID)) | 357 end |
214 end | 358 end |
215 end | 359 |
216 | 360 self:GetBonusObjectives() |
217 if not self.fullSearch then | 361 |
218 print(' hasUpdate:', self.isStale, 'isPending:', self.isPending, 'timer:', (self.OnNext and 'waiting' or '')) | 362 print(' hasUpdate:', self.isStale, 'isPending:', self.isPending, 'timer:', (self.OnNext and 'waiting' or '')) |
219 --WorldPlan.isStale = (self.isStale or WorldPlan.isStale) | 363 --WorldPlan.isStale = (self.isStale or WorldPlan.isStale) |
220 end | 364 if self.isStale and self:IsVisible() then |
221 | 365 self:Refresh() |
222 end | 366 end |
223 | 367 end |
224 function WorldQuests:Refresh(forced) | 368 |
225 local print = wqprint | 369 function WorldQuests:Report() |
226 print('|cFF00FF88'..self:GetName()..':Refresh()|r') | 370 for i, pin in ipairs(db.UsedPins) do |
371 db:print(i, pin.questID, pin.title) | |
372 end | |
373 | |
374 for id, pin in pairs(db.QuestsByID) do | |
375 db:print(id, pin.worldQuestType, pin.rewardType, pin.title) | |
376 end | |
377 end | |
378 | |
379 function WorldQuests:Refresh(fromUser) | |
380 self.currentMapID = GetCurrentMapAreaID() | |
381 print('|cFF00FF88'..self:GetName()..':Refresh()|r', fromUser or '|cFFFFFF00internal') | |
227 if not self:IsVisible() then | 382 if not self:IsVisible() then |
383 print(' not visible, flag for later') | |
228 self.isStale = true | 384 self.isStale = true |
229 print('frame closed, do it later') | |
230 return | 385 return |
231 end | 386 end |
232 | 387 wprint(' |cFF00FF88'..self:GetName()..':Refresh()|r', fromUser or '|cFFFFFF00internal') |
233 self:Reset() | 388 |
234 self:UpdateAnchors() | 389 for index, pin in pairs(db.QuestsByID) do |
235 self:Cleanup () | |
236 end | |
237 | |
238 -- prepares elements for a map update | |
239 function WorldQuests:Reset () | |
240 local print = wqprint | |
241 print('|cFF00FF88'..self:GetName()..':Reset()|r') | |
242 for questID, pin in pairs(self.QuestsByID) do | |
243 pin.used = nil | 390 pin.used = nil |
244 end | 391 pin:SetShown(false) |
392 end | |
393 | |
394 self:SetFilteredPins(db.QuestsByID) | |
395 self:UpdateAnchors(nil, fromUser) | |
396 self:Cleanup (fromUser) | |
397 self.isStale = nil | |
245 end | 398 end |
246 | 399 |
247 -- update visibility states of all pins | 400 -- update visibility states of all pins |
248 function WorldQuests:UpdateAnchors (submapID) | 401 function WorldQuests:SetFilteredPins(pins) |
249 | 402 print(' |cFFFFFF00'..self:GetName()..':SetFilteredPins()|r', pins) |
250 local print = wqprint | 403 pins = pins or db.QuestsByID |
251 local db = WorldPlan.db | 404 for questID, pin in pairs(pins) do |
405 pin.filtered = pin:IsFiltered() | |
406 pin.isStale = true | |
407 rprint('|cFF00FF00filter', pin.questID, pin.filtered, 'used:', pin.used) | |
408 end | |
409 end | |
410 | |
411 local abs = math.abs | |
412 function WorldQuests:UpdateQuestButton(info, mapID) | |
413 local questID, x, y = info.questId, info.x, info.y | |
414 local pin = self:AcquirePin(info) | |
415 if not pin then | |
416 return | |
417 end | |
418 | |
419 | |
420 print('~ ', pin.mapID, pin.questID, pin.title) | |
421 rprint('|cFF00FF00update|r', x, y, pin.title) | |
422 pin:IsShowable() | |
423 | |
424 if x and y then | |
425 | |
426 pin.x = x | |
427 pin.y = y | |
428 pin:SetFrameLevel(PinBaseIndex+numPins) | |
429 pin:SetPoint('CENTER', self.hostFrame, 'TOPLEFT', self.hostWidth * pin.x, -self.hostHeight * pin.y) | |
430 pin.throttle = 1 | |
431 pin:SetShown(pin.used) | |
432 tinsert(self.UsedPositions, pin) | |
433 end | |
434 pin.owningFrame = self.hostFrame | |
435 pin:SetParent(self.hostFrame) | |
436 | |
437 if mapID then | |
438 if not db.QuestsByZone[mapID] then | |
439 db.QuestsByZone[mapID] = {} | |
440 end | |
441 db.QuestsByZone[mapID][questID] = pin | |
442 end | |
443 end | |
444 | |
445 function WorldQuests:UpdateMap(taskInfo, mapID) | |
446 print('Map', GetMapNameByID(mapID), GetMapNameByID(self.currentMapID)) | |
447 for index, info in pairs(taskInfo) do | |
448 self:UpdateQuestButton(info, mapID) | |
449 end | |
450 end | |
451 | |
452 function WorldQuests:UpdateAnchors (fromUser) | |
453 | |
454 | |
455 wipe(self.UsedPositions) | |
456 print(' |cFF00FF00'..self:GetName()..':UpdateAnchors()', fromUser) | |
457 self.hostFrame = WorldMapPOIFrame | |
458 self.hostWidth, self.hostHeight = self.hostFrame:GetSize() | |
459 self.nudgeThrescholdX = 16/self.hostWidth | |
460 self.nudgeThrescholdY = 16/self.hostHeight | |
461 local print = rprint | |
462 print('|cFF00FF00'..self:GetName()..':UpdateAnchors()', fromUser) | |
252 local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo() | 463 local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo() |
253 if isMicroDungeon then | 464 if isMicroDungeon then |
254 return | 465 return |
255 end | 466 end |
256 | 467 |
257 local currentMap = GetCurrentMapAreaID() | 468 numPins = 0 |
258 local submapID = submapID or currentMap | 469 local taskInfo = TQ_GetQuestsForPlayerByMapID(self.currentMapID) |
259 | 470 if taskInfo then |
260 if submapID == BROKEN_ISLES_ID and (not db.DisplayContinentPins) then | 471 self:UpdateMap(taskInfo, self.currentMapID) |
261 print('not updating map for reasons') | 472 end |
262 return | 473 local numZones = MC_GetNumZones(self.currentMapID) |
263 end | |
264 print('|cFF88FF00'..self:GetName()..':UpdateAnchors|r', submapID, GetMapNameByID(submapID), 'pin count:', numPins) | |
265 local numZones = MC_GetNumZones(submapID) | |
266 if numZones then | 474 if numZones then |
267 for i = 1, numZones do | 475 for i = 1, numZones do |
268 local subMapID = MC_GetZoneInfo(submapID, i) | 476 local mapAreaID = MC_GetZoneInfo(self.currentMapID, i) |
269 self:UpdateAnchors(subMapID) | 477 local taskInfo = TQ_GetQuestsForPlayerByMapID(mapAreaID, self.currentMapID) |
270 end | 478 if taskInfo then |
271 end | 479 self:UpdateMap(taskInfo, mapAreaID) |
272 local pins = self.QuestsByZone[submapID] | 480 end |
273 | 481 end |
274 if pins then | 482 end |
275 local hostFrame = WorldMapPOIFrame | 483 if self.filtersDirty then |
276 local mapWidth, mapHeight = hostFrame:GetSize() | 484 self:SetFilteredPins(db.QuestsByID) |
277 for questID, pin in pairs(pins) do | |
278 pin:IsShowable() | |
279 if pin.used then | |
280 pin.isStale = true | |
281 pin:SetFrameLevel(PinBaseIndex+ numPins) | |
282 print('level', PinBaseIndex+ numPins) | |
283 pin:SetAnchor(_G.WorldMapPOIFrame, currentMap, mapWidth, mapHeight) | |
284 numPins = numPins + 1 | |
285 end | |
286 end | |
287 end | 485 end |
288 end | 486 end |
289 | 487 |
290 -- shows, animates, or hides pins based on their current visibility flags | 488 -- shows, animates, or hides pins based on their current visibility flags |
291 local debug_show = {} | 489 function WorldQuests:Cleanup (fromUser) |
292 local debug_animate = {} | 490 |
293 local debug_hide = {} | |
294 function WorldQuests:Cleanup () | |
295 local print = wqprint | |
296 local showQuestPOI = WorldPlan.db.EnablePins | |
297 print('|cFFFFFF00'..self:GetName()..':Cleanup()|r') | 491 print('|cFFFFFF00'..self:GetName()..':Cleanup()|r') |
298 -- continent or zone sizing | 492 local print = rprint |
299 | 493 print('|cFFFFFF00'..self:GetName()..':Cleanup()|r') |
300 | 494 --local showQuestPOI = db.Config.EnablePins |
301 numPins = 0 | 495 for questID, pin in pairs(db.QuestsByID) do |
302 for questID, pin in pairs(self.QuestsByID) do | 496 local oV = pin:IsShown() |
303 pin:SetShown((showQuestPOI and pin.used)) | 497 if pin.used then |
304 end | 498 pin:SetShown(true) |
305 self.isStale = nil | 499 pin.throttle = 1 |
306 end | 500 if oV == false then |
307 | 501 print('|cFF00FF00cleanup +|r', questID, pin.title) |
308 function WorldQuests:FilterCheckByID(questID) | 502 end |
309 local pin = WorldQuests:GetPinByQuestID(questID) | 503 else |
310 return pin:IsShowable() | 504 if oV == true then |
311 end | 505 print('|cFFFF4400 -|r', questID, pin.title) |
312 | 506 end |
313 | 507 end |
508 | |
509 if pin.worldQuest and (not C_TaskQuest.IsActive(pin.questID)) then | |
510 self:ReleasePin(pin) | |
511 end | |
512 pin.isStale = true | |
513 end | |
514 end | |
515 |