View Single Post
12-24-19, 03:38 PM   #3
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Here's what i'm using and built around nPower code.

Lua Code:
  1. local A, C, L = select(2, ...):unpack()
  2. local RuneBar = CreateFrame("Frame")
  3. local DataBars = A["DataBars"]
  4. local Panels = A["Panels"]
  5.  
  6. -- Lib Globals
  7. local select = select
  8. local unpack = unpack
  9.  
  10. -- WoW Globals
  11. local GetRuneCooldown = GetRuneCooldown
  12. local GetTime = GetTime
  13. local UnitClass = UnitClass
  14. local GetSpecialization = GetSpecialization
  15.  
  16. -- Locals
  17. local Class = select(2, UnitClass("player"))
  18.  
  19. -- Color Tabels
  20. local Mult = 2.5
  21. local BloodColor = { 1 * Mult, 0, 0 }
  22. local FrostColor = { 0, 0.35 * Mult, 1 * Mult }
  23. local UnholyColor = { 0.25 * Mult, 0.55 * Mult, 0.10 * Mult }
  24.  
  25. function RuneBar:OnUpdate(Elapsed)
  26.     local Duration = self.Duration + Elapsed
  27.     self.Duration = Duration
  28.     self:SetValue(Duration)
  29. end
  30.  
  31. function RuneBar:Update()
  32.     for i = 1, 6 do
  33.         local Start, Duration, RuneIsReady = GetRuneCooldown(i)
  34.         if (Start) then        
  35.             self.RunesBars[i].Duration = GetTime() - Start
  36.             self.RunesBars[i]:SetMinMaxValues(0, Duration)
  37.             self.RunesBars[i]:SetScript("OnUpdate", self.OnUpdate)
  38.         else
  39.             self.RunesBars[i]:SetMinMaxValues(0, 1)
  40.             self.RunesBars[i]:SetValue(1)
  41.             self.RunesBars[i]:SetScript("OnUpdate", nil)
  42.         end
  43.     end
  44. end
  45.  
  46. function RuneBar:UpdateSpec()  
  47.     for i = 1, 6 do
  48.         local GetSpecialization = GetSpecialization()
  49.         if (GetSpecialization == 1) then
  50.             self.RunesBars[i]:SetStatusBarColor(unpack(BloodColor))
  51.         elseif (GetSpecialization == 2) then
  52.             self.RunesBars[i]:SetStatusBarColor(unpack(FrostColor))
  53.         elseif (GetSpecialization == 3) then
  54.             self.RunesBars[i]:SetStatusBarColor(unpack(UnholyColor))
  55.         end
  56.     end
  57. end
  58.  
  59. function RuneBar:OnEvent(event)
  60.     if (event == "RUNE_POWER_UPDATE") then
  61.         self:Update()
  62.     elseif (event == "PLAYER_ENTERING_WORLD" or event == "PLAYER_SPECIALIZATION_CHANGED" or event == "PLAYER_TALENT_UPDATE") then
  63.         self:UpdateSpec()
  64.     end
  65. end
  66.  
  67. function RuneBar:CreateBar()
  68.     local Bar = CreateFrame("StatusBar", nil, UIParent)
  69.     Bar:Size(220, 12)
  70.     Bar:Point("TOP", Panels.ActionBarPanelMiddle, 0, 32)
  71.    
  72.     local RunesBars = {}
  73.  
  74.     for i = 1, 6 do
  75.         local Bars = CreateFrame("StatusBar", nil, Bar)
  76.         Bars:Size(210/6, 12)
  77.         Bars:SetStatusBarTexture(C.Media.Texture)
  78.         Bars:CreateBackdrop()
  79.         Bars:CreateShadow()
  80.        
  81.         if (i == 1) then
  82.             Bars:Point("LEFT", Bar, 2, 0)
  83.         else
  84.             Bars:Point("LEFT", RunesBars[i-1], "RIGHT", 2, 0)
  85.         end
  86.        
  87.         RunesBars[i] = Bars
  88.     end
  89.    
  90.     RegisterStateDriver(Bar, "visibility", "[vehicleui][petbattle] hide; show")
  91.  
  92.     self:RegisterEvent("RUNE_POWER_UPDATE")
  93.     self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
  94.     self:RegisterEvent("PLAYER_TALENT_UPDATE")
  95.     self:RegisterEvent("PLAYER_REGEN_ENABLED")
  96.     self:RegisterEvent("PLAYER_REGEN_DISABLED")
  97.     self:RegisterEvent("PLAYER_ENTERING_WORLD")
  98.     self:SetScript("OnEvent", self.OnEvent)
  99.    
  100.     self.Bar = Bar
  101.     self.RunesBars = RunesBars
  102. end
  103.  
  104. function RuneBar:Enable()
  105.     if not (C.DataBars.RuneBar) or (Class ~= "DEATHKNIGHT") then
  106.         return
  107.     end
  108.  
  109.     self:CreateBar()
  110. end
  111.  
  112. DataBars.RuneBar = RuneBar
  Reply With Quote