comparison Spotlight.lua @ 0:defdd6787d6d v0.7.1.0

Initial Commit of files for Spotlight.
author Vynn <mischivin@gmail.com>
date Sat, 28 Jan 2017 10:27:43 -0500
parents
children c5024af04845
comparison
equal deleted inserted replaced
-1:000000000000 0:defdd6787d6d
1 local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("Spotlight", {
2 type = "data source",
3 text = "Everything Unlocked!",
4 icon = GetInventoryItemTexture("player", 16),
5 OnClick = function(clickedframe, button)
6 Spotlight.ShowPercent = not Spotlight.ShowPercent;
7 Spotlight.Update();
8 end,
9 })
10
11 local function Initialize ()
12 if not Spotlight.Status then
13 Spotlight.Status = {
14 Dungeons = {
15 Completed = false,
16 Progress = 0,
17 Max = 100,
18 },
19 WorldQuests = {
20 Completed = false,
21 Progress = 0,
22 Max = 200,
23 },
24 PvP = {
25 Completed = false,
26 Progress = 0,
27 Max = 1000,
28 },
29 };
30 Spotlight.ShowPercent = true;
31 end
32
33 Spotlight.IDs = {
34 Dungeons = 11152,
35 WorldQuests = 11153,
36 PvP = 11154,
37 };
38
39 Spotlight.Calculate = function (key)
40 local value = 0;
41 for index = 1, GetAchievementNumCriteria(Spotlight.IDs[key]) do
42 value = value + select(4, GetAchievementCriteriaInfo(Spotlight.IDs[key], index));
43 end
44 return value;
45 end
46
47 Spotlight.GetColor = function (value)
48 value = value * 2;
49 local r = (2 - value);
50 local g = value;
51 local b = 0;
52
53 if r > 1 then r = 1 end
54 if g > 1 then g = 1 end
55 if b > 1 then b = 1 end
56
57 r = string.format("%i", r * 255);
58 g = string.format("%i", g * 255);
59 b = string.format("%i", b * 255);
60
61 return "ff" .. string.format("%02x", r) .. string.format("%02x", g) .. string.format("%02x", b);
62 end
63
64 Spotlight.Format = function (key)
65 local value = Spotlight.Status[key].Progress / Spotlight.Status[key].Max;
66 if Spotlight.ShowPercent then
67 value = string.format("|c" .. Spotlight.GetColor(value) .. "%.1f|cffffffff%%|r", value * 100);
68 else
69 value = "|c" .. Spotlight.GetColor(value) .. Spotlight.Status[key].Progress .. "|cffffffff/" .. Spotlight.Status[key].Max .. "|r";
70 end
71 return value;
72 end
73
74 Spotlight.Update = function (self)
75 local output = "";
76 for key, value in pairs(Spotlight.IDs) do
77 Spotlight.Status[key].Completed = select(3, GetAchievementCriteriaInfo(value,1));
78 if not Spotlight.Status[key].Completed then
79 Spotlight.Status[key].Progress = Spotlight.Calculate(key);
80 output = output .. string.format(" %.1s", key) .. ":" .. Spotlight.Format(key);
81 end
82 end
83 dataobj.icon = GetInventoryItemTexture("player", 16);
84 dataobj.text = output;
85 end
86
87 Spotlight.Update();
88 end
89
90 function dataobj:OnTooltipShow()
91 self:AddLine("Spotlight - Hidden Artifact Tracker|n|n");
92 for k, v in pairs(Spotlight.IDs) do
93 self:AddDoubleLine(k .. ":", Spotlight.Format(k));
94 end
95 self:AddLine("|nClick to toggle display method");
96 end
97
98 function dataobj:OnEnter()
99 GameTooltip:SetOwner(self, "ANCHOR_NONE");
100 GameTooltip:SetPoint("TOP", self, "BOTTOM");
101 GameTooltip:ClearLines();
102 dataobj.OnTooltipShow(GameTooltip);
103 GameTooltip:Show();
104 end
105
106 function dataobj:OnLeave()
107 GameTooltip:Hide()
108 end
109
110 local function EventHandler(self, event, ...)
111 if event == "VARIABLES_LOADED" then
112 Initialize();
113 end
114 if event == "CRITERIA_UPDATE" then
115 Spotlight.Update();
116 end
117 end
118
119 local EventListener = CreateFrame("FRAME", "Spotlight");
120 EventListener:RegisterEvent("VARIABLES_LOADED");
121 EventListener:RegisterEvent("CRITERIA_UPDATE");
122 EventListener:SetScript("OnEvent", EventHandler);
123