Guest User

WoW addon

a guest
Nov 23rd, 2018
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local debugging = true;
  2.  
  3.     --main parent frame
  4.     local mainFrame = CreateFrame("Frame", "Main", UIParent)
  5.     mainFrame:SetPoint("CENTER", 0, 0)
  6.     mainFrame:SetWidth(1)
  7.     mainFrame:SetHeight(1)
  8.     mainFrame:SetShown(true)
  9.  
  10.     local allFrames = {}
  11.     local framesConstructor = {}
  12.     function framesConstructor:create(name, width, height, constructor, updater)--method for frame creation - simulates OOP
  13.         self.frame = CreateFrame("Frame", name .. "BackgroundFrame", mainFrame)
  14.         self.name = name
  15.         self.height = height
  16.         self.width = width
  17.         self.constructor = constructor
  18.         self.updater = updater
  19.         return self
  20.     end
  21.  
  22.     function getFrameIndexFromTable(name)
  23.         for i = 1, table.getn(allFrames) do
  24.             if allFrames[i].name == name then return i
  25.             end
  26.         end
  27.     end
  28.  
  29.     local ServerReady = false
  30.     mainFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  31.     mainFrame:SetScript("OnEvent", function(self, event)
  32.         if event == "PLAYER_ENTERING_WORLD" then
  33.             mainFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
  34.             ServerReady = true
  35.         end
  36.     end)
  37.  
  38.  
  39.  
  40.  
  41.     --constructs base frames for each component
  42.     allFrames[table.getn(allFrames) + 1] = framesConstructor:create("runicpower", 120, 16, setupRpower, updateRpower)
  43.     allFrames[table.getn(allFrames) + 1] = framesConstructor:create("runes", 120, 12, setupRunes, updateRunes)
  44.     allFrames[table.getn(allFrames) + 1] = framesConstructor:create("diseases", 64, 64, setupDis, updateDis)
  45.  
  46.     --runic power
  47.  
  48.     function setupRpower()
  49.             local base = allFrames[getFrameIndexFromTable("runicpower")]
  50.  
  51.             rpowerFrame = CreateFrame("Frame", nil, base.frame)
  52.             rpowerFrame:SetPoint("TOP", base.frame, "TOP")
  53.             rpowerFrame:SetHeight(base.width)
  54.             rpowerFrame:SetWidth(base.height)
  55.  
  56.             rpowerBackground = RpowerFrame:CreateTexture("ARTWORK")
  57.             rpowerBackground:SetAllPoints(rpowerFrame)
  58.             rpowerBackground:SetColorTexture(0, 209, 255)
  59.  
  60.             barFrame = CreateFrame("StatusBar", nil, rpowerFrame)
  61.             barFrame:SetStatusBarTexture("Interface\\TARGETINGFRAME\\UI-StatusBar")
  62.             barFrame:SetMinMaxValues(0, UnitPowerMax("player"))
  63.             barFrame:SetHeight(base.height)
  64.             barFrame:SetWidth(base.height)
  65.             barFrame:SetPoint("CENTER", rpowerFrame, "CENTER")
  66.             barFrame:SetStatusBarColor(0, 209, 255)
  67.  
  68.             rpowerText = CreateFontString("Rpower number", "ARTWORK", barFrame)
  69.             rpowerText:SetText(0)
  70.  
  71.             base.frame:Show()
  72.  
  73.             if debugging then
  74.                 print("runic power setup")
  75.             end
  76.  
  77.     end
  78.  
  79.     function updateRpower()
  80.             barFrame:SetMinMaxValues(0, UnitPowerMax("player"))
  81.             barFrame:SetValue(UnitPower("player"))
  82.             rpowerText:SetText("" .. UnitPower("player") .. " / " .. UnitPowerMax("player") .. "")
  83.  
  84.     end
  85.  
  86.  
  87.     --runes
  88.  
  89.     function setupRunes()
  90.             local base = allFrames[getFrameIndexFromTable("runes")]
  91.  
  92.             runesFrame = CreateFrame("Frame", nil, base.frame)
  93.             runesFrame:SetPoint("TOP", base.frame, "TOP")
  94.             runesFrame:SetHeight(base.height)
  95.             runesFrame:SetWidth(base.width)
  96.  
  97.             runeBars = {}
  98.             for i = 1, 6 do
  99.                 local start, duration, runeReady = GetRuneCooldown(i)
  100.                 runeBars[i] = CreateFrame("StatusBar", nil, base.frame)
  101.                 runeBars[i]:SetStatusBarTexture("Interface\\TARGETINGFRAME\\UI-StatusBar")
  102.                 runeBars[i]:SetHeight(base.height)
  103.                 runeBars[i]:SetWidth(base.width)
  104.                 if i<3 then
  105.                     runeBars[i]:SetPoint("CENTER", runesFrame, -base.width, (i-1)*(-base.height))
  106.                 else
  107.                     runeBars[i]:SetPoint("CENTER", runesFrame, base.width, (i-4)*(-base.height))
  108.                 end
  109.  
  110.                 --status bar colors - blood is red, frost blue, unholy purple
  111.                 if specName == "blood" then
  112.                     runeBars[i]:SetStatusBarColor(255, 0, 0)
  113.                 elseif specName == "frost" then
  114.                     runeBars[i]:SetStatusBarColor(0, 191, 255)
  115.                 elseif specName == "unholy" then
  116.                     runeBars[i]:SetStatusBarColor(225, 0, 255)
  117.                 end
  118.  
  119.             end
  120.  
  121.             base.frame:Show()
  122.  
  123.             if debugging then
  124.                 print("runes setup")
  125.             end
  126.         end
  127.  
  128.  
  129.  
  130.     function updateRunes()
  131.         for i = 1, 6 do
  132.             runeStart, runeDuration, runeReady = GetRuneCooldown(i)
  133.             if runeReady ~= true then
  134.                 runeBars[i]:SetMinMaxValues(0, runeDuration-runeStart)
  135.                 runeBars[i]:SetValue(GetTime() - runeStart)
  136.             end
  137.         end
  138.     end
  139.  
  140.  
  141.  
  142.  
  143.     --diseases
  144.  
  145.         local currentSpec = GetSpecialization()
  146.         local specID = GetInspectSpecialization("player")
  147.         local specName
  148.         if specID == 250 then
  149.             specName = "blood"
  150.             elseif specID == 251 then
  151.             specName = "frost"
  152.             elseif specID == 252 then
  153.             specName = "unholy"
  154.         end
  155.         local diseaseIds = {}
  156.         local diseaseTextures = {}
  157.         diseaseIds["blood"], diseaseIds["frost"], diseaseIds["unholy"] = { 55078, 55095, 191587 }
  158.         diseaseTextures["blood"], diseaseTextures["frost"], diseaseTextures["unholy"] =
  159.             {
  160.                 "Interface\\Icons\\spell_deathknight_bloodplague",
  161.                 "Interface\\Icons\\spell_deathknight_frostfever",
  162.                 "Interface\\Icons\\ability_creature_disease_02",
  163.             }
  164.  
  165.     function setupDis()
  166.             local base = allFrames[getFrameIndexFromTable("diseases")]
  167.  
  168.             disFrame = CreateFrame("Frame", nil, base.frame)
  169.             disFrame:SetPoint("TOP", base.frame, "TOP")
  170.             disFrame:SetHeight(base.height)
  171.             disFrame:SetWidth(base.width)
  172.  
  173.             disTexture = disFrame:CreateTexture("ARTWORK")
  174.             disTexture:SetTexture(diseaseTextures[specName])
  175.  
  176.             disCd = CreateFrame("Cooldown", nil, disFrame, "CooldownFrameTemplate")
  177.             disCd:SetReverse(true)
  178.  
  179.  
  180.             base.frame:Show()
  181.  
  182.  
  183.         if debugging then
  184.             print("diseases setup")
  185.         end
  186.     end
  187.  
  188.     function updateDis()
  189.         for i =1, 40 do
  190.             local name, _, _, _, duration, expire, _, _, _, id = UnitDebuff("target", i, "PLAYER")
  191.             if duration ~= nil and expire ~= nil then
  192.                 if id == diseaseIds[specName] and id ~= nil then
  193.                     disCd:SetCooldown(expire-duration, duration)
  194.                 end
  195.             end
  196.         end
  197.     end
  198.    
  199.    
  200.    
  201.  
  202.  
  203.     local hasInitialized = false
  204.     mainFrame:SetScript("OnUpdate", function(self, elapsed)
  205.         if ServerReady == true then
  206.             if hasInitialized == false then
  207.                 for i =1, table.getn(allFrames) do
  208.                     allFrames[i].constructor()
  209.                     allFrames[i].frame:Show()
  210.                 end
  211.             hasInitialized = true;
  212.         end
  213.  
  214.            
  215.  
  216.         end
  217.  
  218.  
  219.             for i=1, table.getn(allFrames) do
  220.                 allFrames[i].updater()
  221.             end
  222.         end)
RAW Paste Data