local addonname = ...
local storage
local progressBar = CreateFrame("Frame",nil,UIParent)
progressBar:SetPoint("CENTER")
progressBar:SetSize(200,50)
progressBar.tex = progressBar:CreateTexture(nil,"BACKGROUND")
progressBar.tex:SetTexture(0,0.5,0)
progressBar.tex:SetAllPoints()
progressBar.tex2 = progressBar:CreateTexture(nil,"ARTWORK")
progressBar.tex2:SetTexture(0,1,0)
progressBar.tex2:SetPoint("TOPLEFT")
progressBar.tex2:SetPoint("BOTTOMLEFT")
progressBar.text = progressBar:CreateFontString()
progressBar.text:SetPoint("CENTER")
progressBar.text:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
progressBar.text:SetTextColor(1,1,1)
progressBar:Hide()
function progressBar:SetValue(cur,max)
if cur == 0 then
progressBar.tex2:Hide()
else
progressBar.tex2:Show()
progressBar.tex2:SetWidth(200*(cur/max))
end
progressBar.text:SetText(math.floor((cur/max)*100).."%")
end
progressBar:SetScript("OnEvent", function(self,event,arg1)
if (event == "ADDON_LOADED") or (arg1 == addonname) then
storage = LibStub("LibStringStorage-1.0"):NewStorage("mySavedVar")
self:UnregisterEvent("ADDON_LOADED")
end
end)
progressBar:RegisterEvent("ADDON_LOADED")
local function doSomethingWithMyData(data)
print(data)
-- or whatever you want
end
local function retrieveMyData(key)
if not key then return end
local didRetrieve, retrieveData = storage:ReadValue(key)
if not didRetrieve then
progressBar:Show()
progressBar:SetValue(0,1)
local function setprogress(self,callback,x,y)
progressBar:SetValue(x,y)
end
local function complete(self,callback,x,z)
progressBar:Hide()
storage:WipeCallback("DECODE_PROGRESS",setprogress)
storage:WipeCallback("DECODE_COMPLETE", complete)
doSomethingWithMyData(z)
end
storage:NewCallback("DECODE_PROGRESS",setprogress)
storage:NewCallback("DECODE_COMPLETE", complete)
else
doSomethingWithMyData(retrieveData)
end
end
SlashCmdList["PRINTMYDATA"]=function(input)
retrieveMyData(input)
end
SLASH_PRINTMYDATA1 = "/printmydata"
Comments