Mercurial > wow > worldplan
view WorldQuests.lua @ 69:31de7e9e7849
stop hiding pins when the timeleft returns 0; use C_TQ.IsActive
author | Nenue |
---|---|
date | Wed, 05 Apr 2017 11:36:06 -0400 |
parents | 96183f981acb |
children | d6c0bed32c51 |
line wrap: on
line source
-- WorldPlan -- WorldQuests.lua -- Created: 11/2/2016 3:40 PM -- %file-revision% local _, db = ... local Module = WorldPlanQuestsMixin local _G = _G local MC_GetNumZones, MC_GetZoneInfo = C_MapCanvas.GetNumZones, C_MapCanvas.GetZoneInfo local TQ_GetQuestsForPlayerByMapID = C_TaskQuest.GetQuestsForPlayerByMapID -- This function is not yet documented local TQ_GetQuestZoneID = C_TaskQuest.GetQuestZoneID local TQ_IsActive = C_TaskQuest.IsActive local pairs, ipairs, tinsert, tremove, wipe = pairs, ipairs, tinsert, tremove, table.wipe local GetTaskInfo, GetTasksTable, HaveQuestData = GetTaskInfo, GetTasksTable, HaveQuestData local GetTime = GetTime local SpellCanTargetQuest, IsQuestIDValidSpellTarget = SpellCanTargetQuest, IsQuestIDValidSpellTarget local tonumber, abs = tonumber, math.abs local GetQuestLogRewardInfo = GetQuestLogRewardInfo local GetCurrentMapAreaID, GetMapInfo, GetMapNameByID = GetCurrentMapAreaID, GetMapInfo, GetMapNameByID local print = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuests', ...) end or function() end local rprint = DEVIAN_WORKSPACE and function(...) _G.print('WQRefresh', ...) end or function() end local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end local wprint = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end local mprint = DEVIAN_WORKSPACE and function(...) _G.print('Canvas', ...) end or function() end local ToggleButton = {} local callbacks = {} local PinBaseIndex = 1200 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 local WORLD_QUEST_MAPS = { [DALARAN_ID] = 'Dalaran70', [AZSUNA_ID] = 'Azsuna', [VALSHARAH_ID] = "Val'sharah", [HIGHMOUNTAIN_ID] = 'Highmountain', [STORMHEIM_ID] = 'Stormheim', [SURAMAR_ID] = 'Suramar', [EOA_ID] = 'EyeOfAszhara', } local REWARD_CASH = WORLD_QUEST_REWARD_TYPE_FLAG_GOLD local REWARD_ARTIFACT_POWER = WORLD_QUEST_REWARD_TYPE_FLAG_ARTIFACT_POWER local REWARD_GEAR = WORLD_QUEST_REWARD_TYPE_FLAG_EQUIPMENT local REWARD_CURRENCY = WORLD_QUEST_REWARD_TYPE_FLAG_ORDER_RESOURCES local REWARD_REAGENT = WORLD_QUEST_REWARD_TYPE_FLAG_MATERIALS local SCALE_FACTORS = { 0.25, 0.7, 1 } local currentScale = WorldMapDetailFrame:GetScale() local canTargetQuests local numShown = 0 local numLoaded = 0 local isDataLoaded = true local numOverlays = 1 local scaleConstant = 1 Module.TasksByID = {} --%debug% local SetTimedCallbackForAllPins = function(seconds, callback) C_Timer.After(seconds, function() for id, pin in pairs(WorldPlanQuests.QuestsByID) do callback(pin) end end) end function Module:OnUpdate(sinceLast) if self.filtersDirty or self.isStale then self:Refresh() end if #db.UpdatedPins >= 1 then print('|cFF00FF88pending updates', #db.UpdatedPins) self:UpdateQueuedPins() end end function Module:Setup() print('|cFFFF4400'..self:GetName()..':Setup()') for mapID, mapName in pairs(WORLD_QUEST_MAPS) do db.QuestsByZone[mapID] = {} end for target, arg in pairs(callbacks) do print(type(target)) if type(target) == 'table' then local callerName = target:GetName() for name, method in pairs(arg) do print(callerName, arg) hooksecurefunc(target, name, function(...) self:OnSecureHook(callerName .. '.' .. arg, method, ...) end) end else hooksecurefunc(target, function(...) self:OnSecureHook(target, arg, ...) end) end end self.Status = CreateFrame('Frame', nil, self) self.Status:SetPoint('TOPLEFT', WorldMapPOIFrame, 'TOPLEFT', 0, 0) self.Status:SetPoint('BOTTOMRIGHT', WorldMapPOIFrame, 'TOPRIGHT', 0, -4) self.Status.t = self.Status:CreateTexture(nil, 'OVERLAY') self.Status.b = self.Status:CreateTexture(nil, 'BACKGROUND') self.Status.b:SetColorTexture(0,0,0,.25) self.Status.b:SetAllPoints(self.Status) self.Status.t:SetColorTexture(1,1,1,.5) self.Status.t:SetPoint('TOP') self.Status.t:SetPoint('BOTTOM') self.Status.t:SetPoint('LEFT') local translationEnd, translationStart self.Status:SetScript('OnUpdate', function(status) local translateTo if numLoaded < numShown then translateTo = numLoaded/numShown * status:GetWidth() status.t:SetWidth(translateTo) else translateTo = numShown * status:GetWidth() status.t:SetWidth(translateTo) end end) self:SetAllPoints(WorldMapPOIFrame) for k,v in pairs( ToggleButton) do self.Toggle:SetScript(k,v) end self:Show() end callbacks.ClickWorldMapActionButton = function(WorldQuests) WorldQuests:GetUsedPOIs() end callbacks.WorldMap_UpdateQuestBonusObjectives = function(WorldQuests) WorldQuests:GetUsedPOIs() end callbacks.WorldMapFrame_UpdateMap = function(WorldQuests) WorldQuests:RefreshIfChanged() end callbacks.WorldMapScrollFrame_ReanchorQuestPOIs = function (WorldQuests) WorldQuests:RefreshIfChanged() end callbacks[WorldMapFrame.UIElementsFrame.BountyBoard] = { SetSelectedBountyIndex = function(WorldQuests) WorldQuests:UpdateBountyInfo() end } callbacks[WorldMapFrame.UIElementsFrame.ActionButton] = { UpdateCastingState = function(WorldQuests) WorldQuests:Refresh(true) end } local GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestFlaggedCompleted = GetQuestBountyInfoForMapID, GetQuestLogTitle, GetQuestLogIndexByID, IsQuestFlaggedCompleted function Module:UpdateBountyInfo() wipe(db.BountyInfo) db.selectedBounty = nil local selectedBounty = WorldMapFrame.UIElementsFrame.BountyBoard:GetSelectedBountyIndex() local bounties, numBounties = GetQuestBountyInfoForMapID(db.currentMapID) for index, data in ipairs(bounties) do if data.factionID then data.title = GetQuestLogTitle(GetQuestLogIndexByID(data.questID)) data.complete = IsQuestFlaggedCompleted(data.questID) db.BountyInfo[data.factionID] = data if index == selectedBounty then db.selectedBounty = data end end end for questID, pin in pairs(db.QuestsByID) do local doUpdate if pin.factionID and db.BountyInfo[pin.factionID] then if not pin.isCriteria then pin.isCriteria = true doUpdate = true end else if pin.isCriteria then doUpdate = true pin.isCriteria = nil end end if doUpdate then if pin:IsVisible() then pin:Refresh() else pin.isStale = true end end end db.BountyUpdate = nil end function Module:OnConfigUpdate() print('|cFFFFFF00OnConfigUpdate()|r') if db.Config.FadeWhileGrouped then db.PinAlpha = 0.15 else db.PinAlpha = 1 end if not db.Config.EnablePins then for _, pin in pairs(db.QuestsByID) do pin:SetShown(false) end end ToggleButton.OnShow(self.Toggle) end local InternalHideButton = function(button, index) button:Hide() if button.questID and db.QuestsByID[button.questID] then if db.QuestsByID[button.questID].used and not db.QuestsByID[button.questID].filtered then db.QuestsByID[button.questID]:SetShown(true) end end end local InternalShowButton = function(button, index) button:Show() if button.questID and db.QuestsByID[button.questID] then db.QuestsByID[button.questID]:SetShown(false) end end db.UsedPOIs = {} function Module:GetUsedPOIs() db.canTargetQuests = SpellCanTargetQuest() local func = db.canTargetQuests and InternalShowButton or InternalHideButton wipe(db.UsedPOIs) for i = 1, NUM_WORLDMAP_TASK_POIS do local button = _G['WorldMapFrameTaskPOI'..i] if button and button.worldQuest then func(button, i) db.UsedPOIs[button.questID] = button end end end function Module:OnSecureHook(callbackName, func, ...) rprint('|cFFFF4400'..callbackName..'|r', ...) func(self, ...) end local defaults = {} local REWARD_UNKNOWN = 768 function Module:OnLoad() print('|cFFFF4400'..self:GetName()..':OnLoad()') self:SetParent(WorldMapPOIFrame) WorldPlan:AddHandler(self, defaults) for areaID, fileName in pairs(WORLD_QUEST_MAPS) do db.QuestsByZone[areaID] = {} end -- WORLD_MAP_UPDATE and PLAYER_ENTERING_WORLD are passed down from a higher level self:RegisterEvent('WORLD_QUEST_COMPLETED_BY_SPELL') self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED') self:RegisterEvent('SKILL_LINES_CHANGED') self:RegisterEvent('CURRENT_SPELL_CAST_CHANGED') self:RegisterEvent('ARTIFACT_UPDATE') end function Module:OnMapInfo(isBrokenIsle, isZoomedOut, mapAreaID, isNewMap, isMapOpen) print('|cFFFFFF00'..self:GetName()..':OnMapInfo()|r, mapAreaID =', mapAreaID,'visible =', isMapOpen, 'changed =', isNewMap) if db.BountyUpdate then self:UpdateBountyInfo() end if isNewMap then print('|cFF00FF88refreshing for changed map') if isMapOpen then self:Refresh(true) else self.isStale = true end end end local superTrackedQuestID function Module:OnEvent (event, ...) print('|cFFFFFF00'..self:GetName()..':OnEvent() '..event..'|r', GetTime(), ...) if (event == 'QUEST_LOG_UPDATE') then if self:IsVisible() then self:Refresh() else self.isStale = true end print('WorldMapFrame', WorldMapFrame:IsVisible(), 'hasUpdates:', self.isStale) elseif event == 'WORLD_QUEST_COMPLETED_BY_SPELL' then local questID = ... if questID and db.QuestsByID[questID] then self:ReleasePin(db.QuestsByID[questID]) rprint('|cFFFF4400release|r', questID) end elseif event == 'SKILL_LINES_CHANGED' or event == 'CURRENT_SPELL_CAST_CHANGED' then self:Refresh() elseif event == 'ARTIFACT_UPDATE' then local ak = C_ArtifactUI.GetArtifactKnowledgeMultiplier() if ak and (ak ~= self.akLevel) then print('push artifact knowledge update', self.akLevel, 'to', ak) self.akLevel = ak for index, pin in pairs( db.QuestsByID) do if pin.rewardType == REWARD_ARTIFACT_POWER then pin.dataLoaded = nil end end end elseif event == 'SUPER_TRACKED_QUEST_CHANGED' then if superTrackedQuestID and db.QuestsByID[superTrackedQuestID] then db.QuestsByID[superTrackedQuestID].isStale = true end local newID = GetSuperTrackedQuestID() if newID and db.QuestsByID[newID] then db.QuestsByID[newID].isStale = true end end end local totalPins = 0 local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation function Module:AcquirePin (info) local questID = info.questId if not questID then return nil end if not QuestUtils_IsQuestWorldQuest(questID) then return nil end -- if we're grabbing a pin, the filters need to be checked local pin = db.QuestsByID[questID] if not pin then local numFree = #db.FreePins if numFree >= 1 then pin = tremove(db.FreePins, numFree) --print('|cFF00FF00Re-using', pin:GetName()) else totalPins = totalPins + 1 local name = 'WorldPlanQuestMarker' .. numOverlays --print('|cFF00FF00Creating', name) pin = CreateFrame('Frame', name, WorldMapPOIFrame, 'WorldPlanQuestPin') pin:SetFrameStrata('HIGH') pin.GetTypeInfo = function(frame, typeID) return self:GetTypeInfo(typeID) end pin:SetID(totalPins) numOverlays = numOverlays + 1 --pin.iconBorder:SetVertexColor(0,0,0,1) end pin.questID = questID pin.worldQuest = true pin.throttle = 1 pin.isNew = true pin.currentWidth = nil db.QuestsByID[questID] = pin tinsert(db.UsedPins, pin) end if pin and info then pin.inProgress = info.inProgress pin.floor = info.floor pin.numObjectives = info.numObjectives or 0 if info.x and info.y then pin.x = info.x or pin.x pin.y = info.y or pin.y rprint('|cFFFF4400coords|r', info.x, info.y) end end if (not pin.dataLoaded) then local dataLoaded = pin:GetData() isDataLoaded = (isDataLoaded and dataLoaded) WorldPlan.dataFlush = true end pin.isActive = TQ_IsActive(questID) pin:CheckFilterRules() rprint(pin:GetID(), pin.filtered, pin.used) return pin end -- remove from index and add it to the recycling heap function Module:ReleasePin (pin) local id = pin.questID if id then db.QuestsByID[id] = nil for i, zone in pairs(db.QuestsByZone) do print('-', i, zone[i]) zone[id] = nil end db.TasksByID[id] = nil end pin.isActive = nil pin.dataLoaded = nil pin:HideFrames() tinsert(db.FreePins, pin) WorldPlan.dataFlush = true print('|cFF00FF00-'.. (pin.mapID and GetMapNameByID(pin.mapID) or '???') ..'|r', id, pin.title) end function Module:GetBonusObjectives() local tasksTable = GetTasksTable() if tasksTable ~= nil then print('|cFF00FF88'..self:GetName()..':BonusObjectives()|r ') self.numTasks = #tasksTable for i, taskID in ipairs(tasksTable) do if not QuestUtils_IsQuestWorldQuest(taskID) then local info = db.TasksByID[taskID] if not info then local isInArea, isOnMap, numObjectives, taskName, displayAsObjective = GetTaskInfo(taskID) if isOnMap then print(' * '..i, taskID, GetTaskInfo(taskID)) info = { questID = taskID, numObjectives = numObjectives, title = taskName, isInArea = isInArea, isOnMap = isOnMap, displayAsObjective = displayAsObjective, worldQuest = false, isPending = false, isNew = true, } db.TasksByID[taskID] = info local pin = self:AcquirePin(taskID) for k,v in pairs(info) do pin[k] = v end pin:GetBonusObjectiveInfo(info) end end end end end end -- use tooltip object to extract item details function Module:GetRewardHeader(questID) local name, icon, quantity, quality, _, itemID = GetQuestLogRewardInfo(1, questID) local scanner = _G.WorldPlanTooltip local print = qprint if not itemID then return end qprint('GetRewardHeader', questID) scanner:SetOwner(WorldPlan, "ANCHOR_NONE") scanner:SetItemByID(itemID) scanner:Show() local ttl1 = _G['WorldPlanTooltipTextLeft1'] local ttl2 = _G['WorldPlanTooltipTextLeft2'] local ttl3 = _G['WorldPlanTooltipTextLeft3'] local ttl4 = _G['WorldPlanTooltipTextLeft4'] --print(ttl2, ttl3, ttl4) if ttl2 then local text = ttl2:GetText() -- Artifact Power --print(text) if text then if text:match("|cFFE6CC80") then --print('AP token!', text) local power if ttl4 then local text = ttl4:GetText() --print('tip line 4', text) if text then power = text:gsub("%p", ""):match("%d+") power = tonumber(power) end end return REWARD_ARTIFACT_POWER, "Interface\\ICONS\\inv_7xp_inscription_talenttome01", power, name, itemID, quality elseif text:match("Item Level") then --print('equipment!', text) quantity = text:match("Item Level ([%d\+]+)") return REWARD_GEAR, icon, quantity, name, itemID, quality elseif text:match("Crafting Reagent") then qprint('|cFFFF4400it is a reagent', text) return REWARD_REAGENT, icon, quantity, name, itemID, quality end end end if ttl3 then local text = ttl3:GetText() if text and text:match("Crafting Reagent") then qprint('|cFFFF4400it is a reagent', text) return REWARD_REAGENT, icon, quantity, name, itemID, quality end end return 128, icon, quantity, name, itemID, quality end -- pins are queued by their OnUpdate and are ostensibly already visible, we just need to fix the zoom and anchor function Module:UpdateQueuedPins() print('|cFF00FF88UpdateQueuedPins()') local pin = tremove(db.UpdatedPins) while pin do pin:CheckFilterRules() local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1] print(pin.title, pin.dataLoaded and not pin.filtered, scaleFactor) pin:SetAnchor(nil, pin.x, pin.y, self.hostWidth, self.hostHeight, scaleFactor) if pin.isNew then pin:OnShow() end pin = tremove(db.UpdatedPins) end end -- create of update quest pins for a map and its underlying zones function Module:UpdateWorldQuests (mapID) mapID = mapID or db.currentMapID if not mapID then -- info not available yet return end local scalingConstant = 1 local style = DEFAULT_STYLE if self.dataLoaded then style = REWARD_TYPE_STYLES[self.rewardType] scalingConstant = db.isContinentMap and 2 or 3 end local pinScale = SCALE_FACTORS[scalingConstant] print(pinScale) self:SetScale(pinScale) self.Overlay:SetScale(pinScale) print('|cFF00FF88'..self:GetName()..':UpdateWorldQuests()|r', 'map:', mapID, 'realMap:', db.currentMapID) self.isStale = nil print('|cFF00FFFFContinent:|r', BROKEN_ISLES_ID, GetMapNameByID(BROKEN_ISLES_ID)) self.isRecursed = true for i = 1, MC_GetNumZones(BROKEN_ISLES_ID) do local submapID, name, depth = MC_GetZoneInfo(BROKEN_ISLES_ID, i) local taskInfo = TQ_GetQuestsForPlayerByMapID(submapID, BROKEN_ISLES_ID) if taskInfo then local zoneName = GetMapNameByID(submapID) print('|cFF00FFFF Zone:|r', submapID, zoneName, #taskInfo) db.QuestsByZone[submapID] = db.QuestsByZone[submapID] or {} for i, info in ipairs(taskInfo) do if HaveQuestData(info.questId) then rprint('|cFF44FF44update|r', info.questId, zoneName) local questID = info.questId local pin = self:AcquirePin(questID) local pin = db.QuestsByID[questID] if pin then pin.isStale = true if pin.isPending then self.isPending = true end end else rprint('|cFFFF4400no data|r', info.questId, zoneName) end end end end self:GetBonusObjectives() print(' hasUpdate:', self.isStale, 'isPending:', self.isPending, 'timer:', (self.OnNext and 'waiting' or '')) --WorldPlan.isStale = (self.isStale or WorldPlan.isStale) if self.isStale and self:IsVisible() then self:Refresh() end end function Module:Report() for i, pin in ipairs(db.UsedPins) do db:print(i, pin.questID, pin.title) end for id, pin in pairs(db.QuestsByID) do db:print(id, pin.worldQuestType, pin.rewardType, pin.title) end end local bountiesInitialized function Module:Refresh(...) rprint('|cFF00FF88'..self:GetName()..':Refresh()|r', ...) print('|cFF00FF88'..self:GetName()..':Refresh()|r', ...) if not self:IsVisible() then print(' not visible, flag for later') self.isStale = true return self:MarkAllPins() end if not db.Config.EnablePins then numShown = 0 return end wprint(' |cFF00FF88'..self:GetName()..':Refresh()|r') scaleConstant = db.isContinentMap and 2 or 3 for index, pin in pairs(db.QuestsByID) do pin.used = nil end canTargetQuests = SpellCanTargetQuest() self:UpdateAnchors() -- calculate quests shown numShown = 0 numLoaded = 0 for questID, pin in pairs(db.QuestsByID) do local oV = pin:IsShown() if pin.used then pin.throttle = 1 if oV == false then rprint('|cFF00FF00cleanup +|r', questID, pin.title) end pin:SetShown(true) numShown = numShown + 1 if pin.dataLoaded then numLoaded = numLoaded + 1 end else if oV == true then rprint('|cFFFF4400 -|r', questID, pin.title) end pin.hideReason = "Not used in map area " .. (db.currentMapID) pin:HideFrames() end end print(numShown, 'shown', numLoaded, 'loaded') if numShown > numLoaded then self.Status:Show() end self.isStale = nil self.sizesDirty = nil self.isZoomDirty = nil end function Module:RefreshIfChanged() local scaleCheck = WorldMapDetailFrame:GetScale() if scaleCheck ~= currentScale then print('|cFF00FF88scale changed from', currentScale, 'to', scaleCheck) self:Refresh() currentScale = scaleCheck elseif self.isStale then print('|cFF00FF88isStale flag was set') self:Refresh() end end -- update visibility states of all pins function Module:MarkAllPins(pins) print(' |cFFFFFF00'..self:GetName()..':MarkAllPins()|r', pins) pins = pins or db.QuestsByID for questID, pin in pairs(pins) do pin.isStale = true rprint('|cFF00FF00filter', pin.questID, pin.filtered, 'used:', pin.used) end end function Module:UpdateQuestButton(info, mapID) local questID, x, y = info.questId, info.x, info.y local pin = self:AcquirePin(info) if not pin then return end --print(' |- ', pin.questID, pin.title) rprint('|cFF00FF00update|r', pin.questID, pin.title) if x and y then local scaleFactor = SCALE_FACTORS[(pin.dataLoaded and not pin.filtered) and scaleConstant or 1] pin:SetFrameLevel(PinBaseIndex+pin:GetID()) pin.owningFrame = WorldMapFrame pin:SetAnchor(WorldMapPOIFrame, x, y, self.hostWidth, self.hostHeight, scaleFactor) --tinsert(self.UsedPositions, pin) end if self:IsVisible() and (pin.isStale) then pin:Refresh() end if mapID then if not db.QuestsByZone[mapID] then db.QuestsByZone[mapID] = {} end db.QuestsByZone[mapID][questID] = pin end end -- Updates quest markers in taskInfo while associating them with the given map function Module:UpdateQuestsForMap(taskInfo, mapID) rprint('Map', GetMapNameByID(mapID), GetMapNameByID(db.currentMapID)) for index, info in pairs(taskInfo) do self:UpdateQuestButton(info, mapID) end end -- Used to refresh the visible quest markers function Module:UpdateAnchors () wipe(self.UsedPositions) print(' |cFF00FF00'..self:GetName()..':UpdateAnchors()') self.hostWidth, self.hostHeight = WorldMapPOIFrame:GetSize() self.nudgeThrescholdX = 16/self.hostWidth self.nudgeThrescholdY = 16/self.hostHeight rprint('|cFF00FF00'..self:GetName()..':UpdateAnchors()') local mapFileName, textureHeight, textureWidth, isMicroDungeon, microDungeonMapName = GetMapInfo() if isMicroDungeon then return end isDataLoaded = true local taskInfo = TQ_GetQuestsForPlayerByMapID(db.currentMapID) if taskInfo then self:UpdateQuestsForMap(taskInfo, db.currentMapID) end local numZones = MC_GetNumZones(db.currentMapID) if numZones then for i = 1, numZones do local mapAreaID = MC_GetZoneInfo(db.currentMapID, i) local taskInfo = TQ_GetQuestsForPlayerByMapID(mapAreaID, db.currentMapID) if taskInfo then self:UpdateQuestsForMap(taskInfo, mapAreaID) end end end end function ToggleButton:OnShow() self:SetChecked(db.Config.EnablePins and true or false) end function ToggleButton:OnClick() print(self:GetChecked()) db.Config.EnablePins = self:GetChecked() _G.WorldPlan:OnConfigUpdate() end