Mercurial > wow > spotlight-hidden-artifact-skin-tracking
view Spotlight.lua @ 3:c5024af04845
Changed some verbage in the display
Updated LDB display to hide artifact progress that hasn't been started (as well as that has been completed)
Fixed a bug with the LDB icon on load
author | Vynn <mischivin@gmail.com> |
---|---|
date | Sun, 29 Jan 2017 07:55:39 -0500 |
parents | defdd6787d6d |
children | 59c355620405 |
line wrap: on
line source
local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("Spotlight", { type = "data source", text = "Nothing to track!", icon = GetInventoryItemTexture("player", 16), OnClick = function(clickedframe, button) Spotlight.ShowPercent = not Spotlight.ShowPercent; Spotlight.Update(); end, }) local function Initialize () if not Spotlight.Status then Spotlight.Status = { Dungeons = { Completed = false, Progress = 0, Max = 100, }, WorldQuests = { Completed = false, Progress = 0, Max = 200, }, PvP = { Completed = false, Progress = 0, Max = 1000, }, }; Spotlight.ShowPercent = true; end Spotlight.IDs = { Dungeons = 11152, WorldQuests = 11153, PvP = 11154, }; Spotlight.Calculate = function (key) local value = 0; for index = 1, GetAchievementNumCriteria(Spotlight.IDs[key]) do value = value + select(4, GetAchievementCriteriaInfo(Spotlight.IDs[key], index)); end return value; end Spotlight.GetColor = function (value) value = value * 2; local r = (2 - value); local g = value; local b = 0; if r > 1 then r = 1 end if g > 1 then g = 1 end if b > 1 then b = 1 end r = string.format("%i", r * 255); g = string.format("%i", g * 255); b = string.format("%i", b * 255); return "ff" .. string.format("%02x", r) .. string.format("%02x", g) .. string.format("%02x", b); end Spotlight.Format = function (key) local value = Spotlight.Status[key].Progress / Spotlight.Status[key].Max; if Spotlight.ShowPercent then value = string.format("|c" .. Spotlight.GetColor(value) .. "%.1f|cffffffff%%|r", value * 100); else value = "|c" .. Spotlight.GetColor(value) .. Spotlight.Status[key].Progress .. "|cffffffff/" .. Spotlight.Status[key].Max .. "|r"; end return value; end Spotlight.Update = function (self) local output = ""; for key, value in pairs(Spotlight.IDs) do Spotlight.Status[key].Completed = select(3, GetAchievementCriteriaInfo(value,1)); if not Spotlight.Status[key].Completed then Spotlight.Status[key].Progress = Spotlight.Calculate(key); if Spotlight.Status[key].Progress > 0 then output = output .. string.format(" %.1s", key) .. ":" .. Spotlight.Format(key); end end end dataobj.icon = GetInventoryItemTexture("player", 16); dataobj.text = output; end Spotlight.Update(); end function dataobj:OnTooltipShow() self:AddLine("Spotlight - Hidden Artifact Tracker|n|n"); for k, v in pairs(Spotlight.IDs) do self:AddDoubleLine(k .. ":", Spotlight.Format(k)); end self:AddLine("|nClick to toggle display method"); end function dataobj:OnEnter() GameTooltip:SetOwner(self, "ANCHOR_NONE"); GameTooltip:SetPoint("TOP", self, "BOTTOM"); GameTooltip:ClearLines(); dataobj.OnTooltipShow(GameTooltip); GameTooltip:Show(); end function dataobj:OnLeave() GameTooltip:Hide() end local function EventHandler(self, event, ...) if event == "VARIABLES_LOADED" then Initialize(); end if event == "CRITERIA_UPDATE" or "PLAYER_ENTERING_WORLD" then Spotlight.Update(); end end local EventListener = CreateFrame("FRAME", "Spotlight"); EventListener:RegisterEvent("VARIABLES_LOADED"); EventListener:RegisterEvent("CRITERIA_UPDATE"); EventListener:RegisterEvent("PLAYER_ENTERING_WORLD"); EventListener:SetScript("OnEvent", EventHandler);