Mercurial > wow > spotlight-hidden-artifact-skin-tracking
view Spotlight.lua @ 23:4ec7ae897af0 v1.7.2.0
Updated Spotlight's display to support icons - may make it easier to read for some people :) Thanks for the suggestion pros4c!
author | Vynn <mischivin@gmail.com> |
---|---|
date | Sat, 01 Apr 2017 21:54:13 -0400 |
parents | e801ab5c2e1b |
children | 6c495455f069 |
line wrap: on
line source
local initizlized = false; local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("Spotlight", { type = "data source", text = "Nothing to track!", icon = GetInventoryItemTexture("player", 16), OnClick = function(clickedframe, button) if button == "LeftButton" then Spotlight.ShowPercent = not Spotlight.ShowPercent; elseif button == "RightButton" then Spotlight.ShowIcon = not Spotlight.ShowIcon; end Spotlight.Update(); end, }) SLASH_SPOTLIGHT1, SLASH_SPOTLIGHT2 = "/spotlight", "/Spotlight"; local ICONS = { PvP = "|T1339312:12:12:0:0:512:128:416:432:42:58|t", Dungeons = "|T1339312:12:12:0:0:512:128:416:432:24:40|t", WorldQuests = "|T1339312:12:12:0:0:512:128:428:444:87:103|t", } local function SlashHandler(msg) print("|T" .. Spotlight.Icon .. ":0|t |cffe5cc80Spotlight|r - Artifact Hidden Skin Progress:"); if Spotlight.IDs then for key, value in pairs(Spotlight.IDs) do print(" " .. ICONS[tostring(key)] .. " |cffe5cc80" .. key .. " - " .. Spotlight.Format(key, false) .. " (" .. Spotlight.Format(key, true) .. ")|r"); end end end function SlashCmdList.SPOTLIGHT(msg, editbox) SlashHandler(msg); 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; Spotlight.ShowIcon = false; 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, showPercent) local value = Spotlight.Status[key].Progress / Spotlight.Status[key].Max; if 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) Spotlight.Icon = GetInventoryItemTexture("player", 16); 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 output == "" then output = " "; else output = output .. " || "; end if Spotlight.Status[key].Progress > 0 then if Spotlight.ShowIcon then output = output .. ICONS[tostring(key)] .. Spotlight.Format(key, Spotlight.ShowPercent); else output = output .. string.format("|cffe5cc80%.1s", key) .. ":|r " .. Spotlight.Format(key, Spotlight.ShowPercent); end end end end if output == "" then output = " Everything Unlocked!"; end dataobj.icon = Spotlight.Icon dataobj.text = output; end Spotlight.Update(); return true end function dataobj:OnTooltipShow() self:AddLine("|cffe5cc80Spotlight - Hidden Artifact Skins|r|n|n"); for k, v in pairs(Spotlight.IDs) do if not Spotlight.Status[k].Completed then self:AddDoubleLine(ICONS[tostring(k)] .. " " .. k .. ":", Spotlight.Format(k, false) .. " (" .. Spotlight.Format(k, true) .. ")"); end end self:AddLine("|nLeft Click to toggle Percentage or Fractional Display"); self:AddLine("|nRight Click to toggle Icon or Text Labels") 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 if Initialize() then initialized = true; print("|T" .. (Spotlight.Icon or 1355359) .. ":0|t |cffe5cc80Spotlight v" .. GetAddOnMetadata("Spotlight", "Version") .. " Loaded!|r"); end end if event == "CRITERIA_UPDATE" or "PLAYER_ENTERING_WORLD" and initialized 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);