changeset 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 edf9047ebcc8
files Spotlight.lua Spotlight.toc
diffstat 2 files changed, 135 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Spotlight.lua	Sat Jan 28 10:27:43 2017 -0500
@@ -0,0 +1,123 @@
+local dataobj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("Spotlight", {
+	type = "data source", 
+	text = "Everything Unlocked!", 
+	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);
+				output = output .. string.format(" %.1s", key) .. ":" .. Spotlight.Format(key);
+			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" then
+		Spotlight.Update();
+	end
+end
+
+local EventListener = CreateFrame("FRAME", "Spotlight");
+EventListener:RegisterEvent("VARIABLES_LOADED");
+EventListener:RegisterEvent("CRITERIA_UPDATE");
+EventListener:SetScript("OnEvent", EventHandler);
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Spotlight.toc	Sat Jan 28 10:27:43 2017 -0500
@@ -0,0 +1,12 @@
+## Interface: 70100
+## Title: Spotlight
+## Notes: A simple LDB add-on for displaying the status of hidden artifact skin unlocks
+## Author: Vynn of Khadgar (US)
+## Version: 0.7.1.0
+## SavedVariables: Spotlight
+## X-Category: LDB
+## X-Website: 
+## X-Email: 
+
+Spotlight.lua
+