Mercurial > wow > worldplan
view QuestPOI.lua @ 31:d0114b51cdea
WorldPlan:
- Reworking filters to utilize newly added CVars
- Fleshed out POI tooltip for WQ's associated with Family Familiars
- Filter button tooltip includes reward icons
- Respond to tracking menu clicks when they change filter options
author | Nenue |
---|---|
date | Fri, 28 Oct 2016 19:54:00 -0400 |
parents | 8cb750e79952 |
children | be4db60219ca |
line wrap: on
line source
-- WorldPlan -- QuestPOI.lua -- Created: 10/1/2016 7:21 PM -- %file-revision% -- local TQ_GetQuestInfoByQuestID = C_TaskQuest.GetQuestInfoByQuestID -- Return the name of a quest with a given ID local TQ_GetQuestLocation = C_TaskQuest.GetQuestLocation local TQ_GetQuestTimeLeftMinutes = C_TaskQuest.GetQuestTimeLeftMinutes local TQ_IsActive = C_TaskQuest.IsActive local TQ_RequestPreloadRewardData = C_TaskQuest.RequestPreloadRewardData local QuestPOIGetIconInfo, WorldMapPOIFrame = QuestPOIGetIconInfo, WorldMapPOIFrame local print = DEVIAN_WORKSPACE and function(...) _G.print('WP', ...) end or function() end local qprint = DEVIAN_WORKSPACE and function(...) _G.print('POI', ...) end or function() end local wqprint = DEVIAN_WORKSPACE and function(...) _G.print('WorldQuests', ...) end or function() end local iprint = DEVIAN_WORKSPACE and function(...) _G.print('ItemScan', ...) end or function() end local QuestPOI = WorldPlanPOIMixin local ICON_UNKNOWN = "Interface\\ICONS\\inv_misc_questionmark" local ICON_MONEY = "Interface\\Buttons\\UI-GroupLoot-Coin-Up" local POI_BORDER_MASK = "Interface\\Minimap\\UI-Minimap-Background" local POI_BORDER_FILL = "Interface\\BUTTONS\\YELLOWORANGE64" local POI_BORDER_BLUE = "Interface\\BUTTONS\\GRADBLUE" local POI_BORDER_RED = "Interface\\BUTTONS\\RedGrad64" local POI_BORDER_YELLOW = "Interface\\BUTTONS\\YELLOWORANGE64" local POI_BORDER_GREEN = "Interface\\BUTTONS\\GREENGRAD64" 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 LE_QUEST_TAG_TYPE_PVP = LE_QUEST_TAG_TYPE_PVP local LE_QUEST_TAG_TYPE_PET_BATTLE = LE_QUEST_TAG_TYPE_PET_BATTLE local LE_QUEST_TAG_TYPE_DUNGEON = LE_QUEST_TAG_TYPE_DUNGEON local LE_QUEST_TAG_TYPE_PROFESSION = LE_QUEST_TAG_TYPE_PROFESSION local LE_QUEST_TAG_TYPE_NORMAL = LE_QUEST_TAG_TYPE_NORMAL local LE_QUEST_TAG_TYPE_PVP = LE_QUEST_TAG_TYPE_PVP local LE_QUEST_TAG_TYPE_PET_BATTLE = LE_QUEST_TAG_TYPE_PET_BATTLE local LE_QUEST_TAG_TYPE_DUNGEON = LE_QUEST_TAG_TYPE_DUNGEON local LE_QUEST_TAG_TYPE_PROFESSION = LE_QUEST_TAG_TYPE_PROFESSION local LE_QUEST_TAG_TYPE_NORMAL = LE_QUEST_TAG_TYPE_NORMAL local subStyles = { continent = { PinSize = 14, Border = 2, TrackingBorder = 1, TagSize = 6, TimeleftStage = 0, showNumber = false, numberFontObject = 'WorldPlanFont' }, zone = { PinSize = 22, Border = 3, TrackingBorder = 2, TagSize = 12, TimeleftStage = 3, showNumber = true, numberFontObject = 'WorldPlanNumberFontThin' }, minimized = { PinSize = 4, Border = 0, TrackingBorder = 1, NoIcon = true, TimeleftStage = 1, showNumber = false, } } -- Pin color/display variables local familiars = { [42159] = {npc = 106552, name = 'Nightwatcher Merayl'}, [40277] = {npc = 97804, name = 'Tiffany Nelson'}, [40298] = {npc = 99182, name = 'Sir Galveston'}, [40282] = {npc= 99150, name = 'Grixis Tinypop'}, [40278] = {npc = 98270, name = 'Robert Craig'}, [48195] = {npc = 105250, name = 'Aulier'}, [41990] = {npc = 105674, name = 'Varenne'}, [41860] = {npc = 104970, name = 'Xorvasc'}, [40299] = {npc = 99210, name = 'Bodhi Sunwayver'}, [42442] = {npc = 107489, name = 'Amalia'}, [40280] = {npc = 99077, name = 'Bredda Tenderhide'}, [41687] = {npc = 104553, name = 'Odrogg'}, [41944] = {npc = 105455, name = 'Trapper Jarrun'}, [40337] = {npc = 97709, name = 'Master Tamer Flummox'}, [40279] = {npc = 99035, name = 'Durian Strongfruit'} } local familiars_id = 9696 -- update a masked texture without messing up its blending mask local SetMaskedTexture = function(region, file, mask) mask = mask or POI_BORDER_MASK region:SetMask(nil) region:SetTexture(file) region:SetMask(mask) end -- use tooltip object to extract item details local ParseItemReward = function(questID) local name, icon, quantity, quality, _, itemID = GetQuestLogRewardInfo(1, questID) local scanner = _G.WorldPlanTooltip if not itemID then return end 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'] if ttl2 then local text = ttl2:GetText() -- Artifact Power 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 --print('|cFFFF4400it is a reagent', text) return REWARD_REAGENT, icon, quantity, name, itemID, quality end end elseif ttl3 then local text = ttl3:GetText() if text:match("Crafting Reagent") then --print('|cFFFF4400it is a reagent', text) return REWARD_REAGENT, icon, quantity, name, itemID, quality end end return 128, icon, quantity, name, itemID, quality end function WorldPlanPOIMixin:OnEnter() local completed = select(4,GetAchievementInfo(familiars_id)) if not completed then if self.worldQuestType == LE_QUEST_TAG_TYPE_PET_BATTLE and familiars[self.questID] then WorldMapTooltip:SetOwner(self, 'ANCHOR_RIGHT') WorldMapTooltip:AddLine(self.title, 1, 1, 1) if self.quality then local c = ITEM_QUALITY_COLORS[self.quality] WorldMapTooltip:AddLine(" ") WorldMapTooltip:AddLine('Rewards') WorldMapTooltip:AddLine(self.itemName .. (self.quantity and (' x'..self.quantity) or ''), c.r, c.g, c.b) WorldMapTooltip:AddTexture(self.itemTexture) local cLine = WorldMapTooltip:NumLines() local line = _G['WorldMapTooltipTextLeft'..cLine] local pline = _G['WorldMapTooltipTextLeft'..(cLine-1)] local icon = _G['WorldMapTooltipTexture'..(cLine-3)] icon:SetSize(24,24) icon:ClearAllPoints() icon:SetPoint('TOPLEFT', pline, 'BOTTOMLEFT', 0, -2) line:ClearAllPoints() line:SetPoint('TOPLEFT', icon, 'TOPRIGHT', 7, 0) --- voodoo workaround for IDs getting coerced to string if type(self.itemTexture) == 'number' then icon:Show() icon:SetTexture(self.itemTexture) end end WorldMapTooltip:AddLine(" ") -- causes crash for some reason WorldMapTooltip:AddLine('Family Familiars') local trainer = familiars[self.questID].name local numCheevs = GetAchievementNumCriteria(familiars_id) for index = 1, numCheevs do local cheevName, cType, cCompleted, quantity, requiredQuantity, charName, flags, cheevID, quantityString, criteriaID = GetAchievementCriteriaInfo(familiars_id, index) local numTrainers = GetAchievementNumCriteria(cheevID) for subIndex = 1, numTrainers do local desc, cType, partCompleted = GetAchievementCriteriaInfo(cheevID, subIndex) if desc == trainer then if not partCompleted then local iconPath = select(10, GetAchievementInfo(cheevID)) WorldMapTooltip:AddLine(cheevName) WorldMapTooltip:AddTexture(iconPath) end end end end WorldMapTooltip:Show() return end end TaskPOI_OnEnter(self) end function WorldPlanPOIMixin:OnLeave() TaskPOI_OnLeave(self) end function WorldPlanPOIMixin:OnMouseDown() TaskPOI_OnClick(self) end -- create or update the pin using the given questID and C_TaskQuest results function WorldPlanPOIMixin:RefreshData (info) qprint('|cFF00FF88'..self:GetName()..':RefreshData()|r') if info then self.inProgress = info.inProgress self.floor = info.floor self.numObjectives = info.numObjectives or 0 if info.x and info.y then self.x = info.x or self.x self.y = info.y or self.y qprint('|cFFFF4400applying taskInfo coords:', info.x, info.y) end end local questID = self:GetID() local questTitle, rewardIcon, rewardName, rewardCount, rewardStyle, rewardType, itemID, quantity, quality, _ local hasUpdate, isPending = (self.hasUpdate or self.isNew), self.isPending if not HaveQuestData(questID) then TQ_RequestPreloadRewardData(questID) isPending = true else -- set reward category local numRewards = GetNumQuestLogRewards(questID) local numCurrency = GetNumQuestLogRewardCurrencies(questID) local money = GetQuestLogRewardMoney(questID) if numRewards >= 1 then rewardType, rewardIcon, rewardCount, rewardName, itemID, quality = ParseItemReward(questID) elseif numCurrency >= 1 then rewardName, rewardIcon, rewardCount = GetQuestLogRewardCurrencyInfo(1, questID) rewardType = REWARD_CURRENCY elseif money >= 1 then rewardIcon = ICON_MONEY rewardName = GetMoneyString(money) rewardType = REWARD_CASH end rewardStyle = self:GetTypeInfo(rewardType) self.itemNumber = rewardCount or self.itemNumber self.rewardType = rewardType or REWARD_ITEM self.style = rewardStyle self.quality = quality -- title, faction, capped state local questTitle, factionID, capped = TQ_GetQuestInfoByQuestID(questID) self.factionID = factionID self.capped = capped -- set tag details local tagID, tagName, worldQuestType, rarity, isElite, tradeskillLineIndex = GetQuestTagInfo(questID); local tagAtlas if worldQuestType == LE_QUEST_TAG_TYPE_PET_BATTLE then tagAtlas = "worldquest-icon-petbattle" elseif worldQuestType == LE_QUEST_TAG_TYPE_PVP then tagAtlas = "worldquest-icon-pvp-ffa" elseif worldQuestType == LE_QUEST_TAG_TYPE_PROFESSION then local id = tradeskillLineIndex and select(7, GetProfessionInfo(tradeskillLineIndex)) if id then tagAtlas = WORLD_QUEST_ICONS_BY_PROFESSION[id] end elseif worldQuestType == LE_QUEST_TAG_TYPE_DUNGEON then tagAtlas = "worldquest-icon-dungeon" end self.tagID = tagID self.tagName = tagName self.worldQuestType = worldQuestType self.isElite = isElite self.tradeskillLineIndex = tradeskillLineIndex self.rarity = rarity self.tagAtlas = tagAtlas -- flag unresolved info if not (rewardIcon and rewardName) then isPending = true qprint('because not have icon') TQ_RequestPreloadRewardData (questID) --WorldPlan:print('|cFFFFFF00'..tostring(self.title)..'|r waiting on texture info') else if (rewardIcon and rewardName) and isPending then --WorldPlan:print('|cFF00FF00'..tostring(self.title)..'|r has info', rewardIcon, rewardName) hasUpdate = true end isPending = false end self.title = questTitle or "|cFFFF0000Retrieving..." self.itemTexture = rewardIcon or self.itemTexture self.itemName = rewardName or self.itemName self.hasUpdate = hasUpdate self.isPending = isPending qprint(' |cFF00FFFF'..questID..'|r hasUpdate:', hasUpdate, 'isPending:', isPending) qprint(' ', 'rewardType:', self.rewardType, 'tag:', self.tagID) qprint(' ', tostring(self.title), " |T"..tostring(self.itemTexture)..":12:12|t", tostring(self.itemName)) end self.cheevos = familiars[self.questID] return hasUpdate, isPending end function WorldPlanPOIMixin:SetAchievementProgressTooltip() print('cheevos') end function WorldPlanPOIMixin:ShowNew() self:SetShown(true) self.isNew = nil self.hasUpdate = true self.FadeIn:Play() end function WorldPlanPOIMixin:OnShow () qprint('|cFFFFFF00["'..tostring(self.title)..'"]|r:OnShow() update:', self.hasUpdate, 'new:', self.isNew, 'animation:', self.isAnimating) -- pop this on principle if self.hasUpdate then self:Refresh() end end function WorldPlanPOIMixin:OnHide() qprint('|cFFFFFF00["'..tostring(self.title)..'"]|r:OnHide()') end function WorldPlanPOIMixin:SetAnchor(frame, mapID, mapWidth, mapHeight) qprint(' |cFF00FF00'..self:GetName()..':SetAnchor()|r', self.questID, mapID, mapWidth) self:ClearAllPoints() local dX, dY = TQ_GetQuestLocation(self.questID) if not dX or dX == 0 then local _, x, y = QuestPOIGetIconInfo(self.questID) if x and floor(x) ~= 0 then dX, dY = x, y else dX, dY = self.x, self.y end end self.x = dX self.y = dY --qprint(' |cFF00FF00'..self.questID..':|r', format("%0.2f %0.2f", dX, dY)) local pX = (dX * mapWidth) local pY = (-dY * mapHeight) self:SetParent(WorldMapPOIFrame) self:SetPoint('CENTER', frame, 'TOPLEFT', pX, pY) end function WorldPlanPOIMixin:OnLoad() qprint('|cFF00FF88'..self:GetName()..':OnLoad()|r',WorldPlan.db) self:RegisterEvent('SUPER_TRACKED_QUEST_CHANGED') self.style = WorldPlan.db.defaultPinStyle self.subStyle = WorldPlan.db.defaultPinStyle.continent end function WorldPlanPOIMixin:OnEvent(event, ...) if event == 'SUPER_TRACKED_QUEST_CHANGED' then self.hasUpdate = true end end local PIN_UPDATE_DELAY = .016 local TOP_PIN_ID function WorldPlanPOIMixin:OnUpdate (sinceLast) if self.hasUpdate then wqprint('|cFFFFFF00push poi update') self:Refresh() return end -- control update check intervals self.throttle = (self.throttle or PIN_UPDATE_DELAY) - sinceLast if self.throttle <= 0 then -- factor overtime into the throttle timer self.throttle = PIN_UPDATE_DELAY - self.throttle else return end -- query for reward data if it wasn't found in the original scan local questID = self.questID if self.isPending then self:RefreshData() if not (self.PendingFade:IsPlaying() or self.isAnimating) then self.PendingFade:Play() end return else if self.PendingFade:IsPlaying() then self.PendingFade:Stop() end end -- update time elements local tl = self.timeThreschold local timeLeft = TQ_GetQuestTimeLeftMinutes(questID) if timeLeft > 0 then local text, timeState = WorldPlan:GetTimeInfo(timeLeft, self.TimeleftStage) if tl ~= timeState then tl = timeState self.timeLabel:SetText(text) end else -- remove self in a timely manner if not TQ_IsActive(self.questID) then print('|cFFFF4400'..self:GetName()..' pin hard timeout') if self.worldQuestType ~= LE_QUEST_TAG_TYPE_PROFESSION then self:Hide() end end end self.timeThreschold = tl if self:IsMouseOver() then self.MouseGlow:Show() else self.MouseGlow:Hide() end end function WorldPlanPOIMixin:Refresh () local db = WorldPlan.db local print = wqprint print('|cFF00FF88'..self:GetName()..'|r:Refresh()') local questID = self:GetID() local style,subStyle = self:GetTypeInfo(self.rewardType) if self.filtered then subStyle = style.minimized end self.style = style self.subStyle = subStyle local borderMask = style.mask local borderFill = style.texture local iconBorder = self.iconBorder local icon = self.icon local count = self.count self.hasNumeric = style.hasNumeric self.numberRGB = style.numberRGB self.showNumber = subStyle.showNumber --WorldPlan:print(tostring(self.title), "|T"..tostring(self.itemTexture)..":16:16|t", tostring(self.itemName)) SetMaskedTexture(icon, self.itemTexture or ICON_UNKNOWN, borderMask) icon:SetAllPoints(self) if self.itemName then if self.hasNumeric then if subStyle.numberFontObject then wqprint('change font', _G[subStyle.numberFontObject]:GetName()) self.count:SetFontObject(_G[subStyle.numberFontObject]) end wqprint('filtered:', self.filtered, 'showNumber:', self.showNumber) self.count:SetShown(self.showNumber) self.count:SetText(self.itemNumber) self.count:SetTextColor(unpack(self.numberRGB)) else self.count:SetShown(false) self.count:SetText(nil) end end SetMaskedTexture(iconBorder, borderFill, borderMask) local border = self:GetTypeInfo(self.rewardType) iconBorder:SetVertexColor(border.r, border.g, border.b, border.a) iconBorder:SetDesaturated(true) local trackingBorder = self.supertrackBorder self.highlight:SetMask(nil) if questID == GetSuperTrackedQuestID() then trackingBorder:SetVertexColor(0,0,0,1) else trackingBorder:SetVertexColor(0,0,0,0.5) end self.highlight:SetAllPoints(trackingBorder) SetMaskedTexture(trackingBorder, borderFill, borderMask) self.highlight:SetMask(borderMask) local qType = self.worldQuestType self.tagIcon:SetAtlas(self.tagAtlas) self.tagIcon:SetTexCoord(0,1,0,1) if self.isElite then self.EliteBorder:Show() else self.EliteBorder:Hide() end --qprint('|cFF88FF00updated', questID, self.title, self.rewardType, (style.showNumber and self.itemNumber) or '') --print(' - subStyle:', (self.filtered == true), self.subStyle) self:UpdateSize() self.hasUpdate = nil end function WorldPlanFilterPinMixin:OnEnter () local filter = WorldPlan.FilterOptions[self:GetID()] local mapID = GetCurrentMapAreaID() local quests = (mapID == WorldPlan.BrokenIsleID) and WorldPlan.QuestsByID or WorldPlan.QuestsByZone[mapID] if quests then GameTooltip:SetOwner(self, 'ANCHOR_RIGHT') GameTooltip:AddLine(filter.label) local filterKey = self.filterKey local filterValue = self.filterValue if filterKey then for questID, pin in pairs(quests) do if pin.used and not pin.filtered then if pin[filterKey] == filterValue then local style = pin.style or WorldPlan.FilterStyle if familiars[questID] then GameTooltip:AddLine(pin.title,0,1,0) else GameTooltip:AddLine(pin.title,1,1,1) end end end end else GameTooltip:AddLine('Reset all filters') end GameTooltip:Show() end end