annotate Spotlight.lua @ 27:915a2b4cd5d5

Updated some terminology to be more consistent.
author Vynn <mischivin@gmail.com>
date Sun, 02 Apr 2017 14:24:16 -0400
parents 6c495455f069
children c5ff9082ba94
rev   line source
mischivin@14 1 local initizlized = false;
mischivin@14 2
mischivin@0 3 local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("Spotlight", {
mischivin@0 4 type = "data source",
mischivin@3 5 text = "Nothing to track!",
mischivin@0 6 icon = GetInventoryItemTexture("player", 16),
mischivin@0 7 OnClick = function(clickedframe, button)
mischivin@23 8 if button == "LeftButton" then
mischivin@23 9 Spotlight.ShowPercent = not Spotlight.ShowPercent;
mischivin@23 10 elseif button == "RightButton" then
mischivin@23 11 Spotlight.ShowIcon = not Spotlight.ShowIcon;
mischivin@23 12 end
mischivin@0 13 Spotlight.Update();
mischivin@0 14 end,
mischivin@0 15 })
mischivin@0 16
mischivin@5 17 SLASH_SPOTLIGHT1, SLASH_SPOTLIGHT2 = "/spotlight", "/Spotlight";
mischivin@5 18
mischivin@23 19 local ICONS = {
mischivin@23 20 PvP = "|T1339312:12:12:0:0:512:128:416:432:42:58|t",
mischivin@23 21 Dungeons = "|T1339312:12:12:0:0:512:128:416:432:24:40|t",
mischivin@23 22 WorldQuests = "|T1339312:12:12:0:0:512:128:428:444:87:103|t",
mischivin@23 23 }
mischivin@23 24
mischivin@5 25 local function SlashHandler(msg)
mischivin@9 26 print("|T" .. Spotlight.Icon .. ":0|t |cffe5cc80Spotlight|r - Artifact Hidden Skin Progress:");
mischivin@5 27 if Spotlight.IDs then
mischivin@5 28 for key, value in pairs(Spotlight.IDs) do
mischivin@26 29 if not Spotlight.Status[key].Completed then
mischivin@26 30 print(" " .. ICONS[tostring(key)] .. " |cffe5cc80" .. key .. " - " .. Spotlight.Format(key, false) .. " (" .. Spotlight.Format(key, true) .. ")|r");
mischivin@26 31 else
mischivin@27 32 print(" " .. ICONS[tostring(key)] .. " |cffe5cc80" .. key .. " - |cff00ff00Unlocked!|r");
mischivin@26 33 end
mischivin@5 34 end
mischivin@5 35 end
mischivin@5 36 end
mischivin@5 37
mischivin@5 38 function SlashCmdList.SPOTLIGHT(msg, editbox)
mischivin@5 39 SlashHandler(msg);
mischivin@5 40 end
mischivin@5 41
mischivin@14 42 local function Initialize()
mischivin@0 43 if not Spotlight.Status then
mischivin@0 44 Spotlight.Status = {
mischivin@0 45 Dungeons = {
mischivin@0 46 Completed = false,
mischivin@0 47 Progress = 0,
mischivin@0 48 Max = 100,
mischivin@0 49 },
mischivin@0 50 WorldQuests = {
mischivin@0 51 Completed = false,
mischivin@0 52 Progress = 0,
mischivin@0 53 Max = 200,
mischivin@0 54 },
mischivin@0 55 PvP = {
mischivin@0 56 Completed = false,
mischivin@0 57 Progress = 0,
mischivin@0 58 Max = 1000,
mischivin@0 59 },
mischivin@0 60 };
mischivin@0 61 Spotlight.ShowPercent = true;
mischivin@23 62 Spotlight.ShowIcon = false;
mischivin@0 63 end
mischivin@0 64
mischivin@0 65 Spotlight.IDs = {
mischivin@0 66 Dungeons = 11152,
mischivin@0 67 WorldQuests = 11153,
mischivin@0 68 PvP = 11154,
mischivin@0 69 };
mischivin@0 70
mischivin@0 71 Spotlight.Calculate = function (key)
mischivin@0 72 local value = 0;
mischivin@0 73 for index = 1, GetAchievementNumCriteria(Spotlight.IDs[key]) do
mischivin@0 74 value = value + select(4, GetAchievementCriteriaInfo(Spotlight.IDs[key], index));
mischivin@0 75 end
mischivin@0 76 return value;
mischivin@0 77 end
mischivin@0 78
mischivin@0 79 Spotlight.GetColor = function (value)
mischivin@0 80 value = value * 2;
mischivin@0 81 local r = (2 - value);
mischivin@0 82 local g = value;
mischivin@0 83 local b = 0;
mischivin@0 84
mischivin@0 85 if r > 1 then r = 1 end
mischivin@0 86 if g > 1 then g = 1 end
mischivin@0 87 if b > 1 then b = 1 end
mischivin@0 88
mischivin@0 89 r = string.format("%i", r * 255);
mischivin@0 90 g = string.format("%i", g * 255);
mischivin@0 91 b = string.format("%i", b * 255);
mischivin@0 92
mischivin@0 93 return "ff" .. string.format("%02x", r) .. string.format("%02x", g) .. string.format("%02x", b);
mischivin@0 94 end
mischivin@0 95
mischivin@5 96 Spotlight.Format = function (key, showPercent)
mischivin@0 97 local value = Spotlight.Status[key].Progress / Spotlight.Status[key].Max;
mischivin@5 98 if showPercent then
mischivin@0 99 value = string.format("|c" .. Spotlight.GetColor(value) .. "%.1f|cffffffff%%|r", value * 100);
mischivin@0 100 else
mischivin@0 101 value = "|c" .. Spotlight.GetColor(value) .. Spotlight.Status[key].Progress .. "|cffffffff/" .. Spotlight.Status[key].Max .. "|r";
mischivin@0 102 end
mischivin@0 103 return value;
mischivin@0 104 end
mischivin@0 105
mischivin@0 106 Spotlight.Update = function (self)
mischivin@9 107 Spotlight.Icon = GetInventoryItemTexture("player", 16);
mischivin@9 108
mischivin@0 109 local output = "";
mischivin@0 110 for key, value in pairs(Spotlight.IDs) do
mischivin@0 111 Spotlight.Status[key].Completed = select(3, GetAchievementCriteriaInfo(value,1));
mischivin@0 112 if not Spotlight.Status[key].Completed then
mischivin@0 113 Spotlight.Status[key].Progress = Spotlight.Calculate(key);
mischivin@26 114 if Spotlight.Status[key].Progress >= 0 then
mischivin@26 115 if output == "" then
mischivin@26 116 output = " ";
mischivin@26 117 else
mischivin@26 118 output = output .. " || ";
mischivin@26 119 end
mischivin@23 120 if Spotlight.ShowIcon then
mischivin@23 121 output = output .. ICONS[tostring(key)] .. Spotlight.Format(key, Spotlight.ShowPercent);
mischivin@23 122 else
mischivin@23 123 output = output .. string.format("|cffe5cc80%.1s", key) .. ":|r " .. Spotlight.Format(key, Spotlight.ShowPercent);
mischivin@23 124 end
mischivin@3 125 end
mischivin@0 126 end
mischivin@0 127 end
mischivin@23 128 if output == "" then
mischivin@26 129 output = " |cff00ff00All Hidden Skins Unlocked!|r";
mischivin@23 130 end
mischivin@9 131
mischivin@9 132 dataobj.icon = Spotlight.Icon
mischivin@0 133 dataobj.text = output;
mischivin@0 134 end
mischivin@0 135
mischivin@0 136 Spotlight.Update();
mischivin@5 137
mischivin@5 138 return true
mischivin@0 139 end
mischivin@0 140
mischivin@0 141 function dataobj:OnTooltipShow()
mischivin@5 142 self:AddLine("|cffe5cc80Spotlight - Hidden Artifact Skins|r|n|n");
mischivin@0 143 for k, v in pairs(Spotlight.IDs) do
mischivin@19 144 if not Spotlight.Status[k].Completed then
mischivin@23 145 self:AddDoubleLine(ICONS[tostring(k)] .. " " .. k .. ":", Spotlight.Format(k, false) .. " (" .. Spotlight.Format(k, true) .. ")");
mischivin@26 146 else
mischivin@27 147 self:AddDoubleLine(ICONS[tostring(k)] .. " " .. k .. ":", "|cff00ff00Unlocked!|r";
mischivin@26 148
mischivin@19 149 end
mischivin@0 150 end
mischivin@23 151 self:AddLine("|nLeft Click to toggle Percentage or Fractional Display");
mischivin@23 152 self:AddLine("|nRight Click to toggle Icon or Text Labels")
mischivin@0 153 end
mischivin@0 154
mischivin@0 155 function dataobj:OnEnter()
mischivin@0 156 GameTooltip:SetOwner(self, "ANCHOR_NONE");
mischivin@0 157 GameTooltip:SetPoint("TOP", self, "BOTTOM");
mischivin@0 158 GameTooltip:ClearLines();
mischivin@0 159 dataobj.OnTooltipShow(GameTooltip);
mischivin@0 160 GameTooltip:Show();
mischivin@0 161 end
mischivin@0 162
mischivin@0 163 function dataobj:OnLeave()
mischivin@0 164 GameTooltip:Hide()
mischivin@0 165 end
mischivin@0 166
mischivin@0 167 local function EventHandler(self, event, ...)
mischivin@0 168 if event == "VARIABLES_LOADED" then
mischivin@5 169 if Initialize() then
mischivin@14 170 initialized = true;
mischivin@14 171 print("|T" .. (Spotlight.Icon or 1355359) .. ":0|t |cffe5cc80Spotlight v" .. GetAddOnMetadata("Spotlight", "Version") .. " Loaded!|r");
mischivin@5 172 end
mischivin@0 173 end
mischivin@14 174 if event == "CRITERIA_UPDATE" or "PLAYER_ENTERING_WORLD" and initialized then
mischivin@0 175 Spotlight.Update();
mischivin@0 176 end
mischivin@0 177 end
mischivin@0 178
mischivin@0 179 local EventListener = CreateFrame("FRAME", "Spotlight");
mischivin@0 180 EventListener:RegisterEvent("VARIABLES_LOADED");
mischivin@0 181 EventListener:RegisterEvent("CRITERIA_UPDATE");
mischivin@3 182 EventListener:RegisterEvent("PLAYER_ENTERING_WORLD");
mischivin@0 183 EventListener:SetScript("OnEvent", EventHandler);
mischivin@0 184