View Single Post
06-17-17, 05:06 AM   #11
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
I had a similar issue with my "arrows" a few weeks back.

Here's my code for my class bars, hope it helps

Lua Code:
  1. -----------------------------------------------------
  2. --- Heavy Modifed Version of Neal's "Neav" nPower! --
  3. -----------------------------------------------------
  4.  
  5. local PowerBar = CreateFrame("Frame")
  6.  
  7. function PowerBar:CreateBar()
  8.     local StatusBar = CreateFrame("StatusBar", nil, UIParent)
  9.     StatusBar:Size(198, 8)
  10.     StatusBar:Point("CENTER", UIParent, 0, -102)
  11.     StatusBar:SetStatusBarTexture("Interface\\Buttons\\WHITE8x8")
  12.     StatusBar:CreateBackdrop()
  13.     StatusBar:Hide()
  14.  
  15.     StatusBar:RegisterEvent("PLAYER_REGEN_ENABLED")
  16.     StatusBar:RegisterEvent("PLAYER_REGEN_DISABLED")
  17.     StatusBar:RegisterEvent("PLAYER_TARGET_CHANGED")
  18.     StatusBar:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
  19.     StatusBar:RegisterEvent("RUNE_TYPE_UPDATE")
  20.     StatusBar:RegisterUnitEvent("UNIT_COMBO_POINTS", "player")
  21.     StatusBar:RegisterUnitEvent("UNIT_DISPLAYPOWER", "player")
  22.     StatusBar:RegisterUnitEvent("UNIT_POWER_FREQUENT", "player")
  23.     StatusBar:SetScript("OnEvent", PowerBar.OnEvent)
  24.    
  25.     local Animation = A["Animation"]
  26.     Animation:AddSmooth(StatusBar)
  27.  
  28.     local InvisFrame = CreateFrame("Frame", nil, StatusBar)
  29.     InvisFrame:SetFrameLevel(StatusBar:GetFrameLevel() + 2)
  30.     InvisFrame:SetAllPoints()
  31.  
  32.     local Text = InvisFrame:CreateFontString(nil, "OVERLAY")
  33.     Text:SetFontTemplate(C.Media.Font2, 18)
  34.     Text:Point("CENTER", StatusBar)
  35.    
  36.     local ExtraText = InvisFrame:CreateFontString(nil, "OVERLAY")
  37.     ExtraText:SetFontTemplate(C.Media.Font2, 24)
  38.     ExtraText:Point("CENTER", StatusBar, 0, 32)
  39.    
  40.     local ArrowDown = StatusBar:CreateTexture(nil, "OVERLAY")
  41.     ArrowDown:Size(12, 12)
  42.     ArrowDown:SetTexture(C.Media.PowerArrowDown)
  43.  
  44.     local ArrowUp = StatusBar:CreateTexture(nil, "OVERLAY")
  45.     ArrowUp:Size(12, 12)
  46.     ArrowUp:SetTexture(C.Media.PowerArrowUp)
  47.    
  48.     if (Class == "DEATHKNIGHT") then
  49.         local Runes = {}   
  50.    
  51.         for i = 1, 6 do
  52.             local RuneText = StatusBar:CreateFontString(nil, "OVERLAY")
  53.             RuneText:SetFontTemplate(C.Media.Font2, 22)
  54.             RuneText:SetTextColor(0.00, 0.82, 1.00)
  55.        
  56.             Runes[i] = RuneText
  57.         end
  58.  
  59.         Runes[1]:Point("CENTER", StatusBar, -86.5, 32)
  60.         Runes[2]:Point("CENTER", StatusBar, -51.5, 32)
  61.         Runes[3]:Point("CENTER", StatusBar, -16.5, 32)
  62.         Runes[4]:Point("CENTER", StatusBar, 16.5, 32)
  63.         Runes[5]:Point("CENTER", StatusBar, 51.5, 32)
  64.         Runes[6]:Point("CENTER", StatusBar, 86.5, 32)
  65.    
  66.         self.Runes = Runes
  67.     end
  68.    
  69.     self.StatusBar = StatusBar
  70.     self.Text = Text
  71.     self.ExtraText = ExtraText
  72.     self.ArrowDown = ArrowDown
  73.     self.ArrowUp = ArrowUp
  74. end
  75.  
  76. function PowerBar:UpdateBar()
  77.     local StatusBar = self.StatusBar
  78.     local Text = self.Text
  79.  
  80.     local Min, Max = UnitPower("player"), UnitPowerMax("player")
  81.     local R, G, B = A.ColorGradient(Min, Max, 0.8, 0, 0, 0.8, 0.8, 0, 0, 0.8, 0)
  82.  
  83.     if (StatusBar) then
  84.         StatusBar:SetMinMaxValues(0, Max)
  85.         StatusBar:SetValue(Min)    
  86.  
  87.         local PowerType, PowerToken = UnitPowerType("player")
  88.         local PowerColor = A.Colors.power[PowerToken]
  89.        
  90.         if (PowerColor) then
  91.             StatusBar:SetStatusBarColor(PowerColor[1], PowerColor[2], PowerColor[3])
  92.             StatusBar:SetBackdropColor(PowerColor[1]*0.5, PowerColor[2]*0.5, PowerColor[3]*0.5)
  93.         end
  94.     end
  95.  
  96.     if (Text) then
  97.         --Text:SetText(A.ShortNumbers(Min) .. " (" .. math.floor(Min/Max*100) ..  "%)")
  98.         Text:SetText(A.ShortNumbers(Min))
  99.         Text:SetTextColor(R, G, B)
  100.     end
  101.    
  102.     self.ArrowDown:SetVertexColor(R, G, B)
  103.     self.ArrowDown:Point("TOP", self.StatusBar, "BOTTOMLEFT", Min / Max * 198, 0)
  104.    
  105.     self.ArrowUp:SetVertexColor(R, G, B)
  106.     self.ArrowUp:Point("BOTTOM", self.ArrowDown, "TOP", 0, 8)
  107. end
  108.  
  109. function PowerBar:UpdateExtraPoints()
  110.     local PowerType
  111.     local Text = self.ExtraText
  112.  
  113.     if (Class == "ROGUE" or Class == "DRUID") then
  114.         PowerType = UnitPower("player", SPELL_POWER_COMBO_POINTS)
  115.     elseif (Class == "PALADIN") then
  116.         PowerType = UnitPower("player", SPELL_POWER_HOLY_POWER)
  117.     elseif (Class == "WARLOCK") then
  118.         PowerType = UnitPower("player", SPELL_POWER_SOUL_SHARDS)
  119.     elseif (Class == "MONK") then
  120.         PowerType = UnitPower("player", SPELL_POWER_CHI)
  121.     elseif (Class == "MAGE") then
  122.         PowerType = UnitPower("player", SPELL_POWER_ARCANE_CHARGES)
  123.     else
  124.         return
  125.     end
  126.  
  127.     if (Text) then
  128.         if (PowerType == 1) then
  129.             Text:SetTextColor(0.80, 0.22, 0)
  130.         elseif (PowerType == 2) then
  131.             Text:SetTextColor(0.80, 0.42, 0)
  132.         elseif (PowerType == 3) then
  133.             Text:SetTextColor(0.80, 0.62, 0)
  134.         elseif (PowerType == 4) then
  135.             Text:SetTextColor(0.80, 0.82, 0)
  136.         elseif (PowerType == 5) then
  137.             Text:SetTextColor(0, 1, 0)
  138.         end
  139.        
  140.         Text:SetText(PowerType == 0 and "" or PowerType)
  141.     end
  142. end
  143.  
  144. function PowerBar:RuneCooldown(self)
  145.     if (Class == "DEATHKNIGHT") then
  146.         local Start, Duration, RuneIsReady = GetRuneCooldown(self)
  147.         local Time = floor(GetTime() - Start)
  148.         local Cooldown = ceil(Duration - Time)
  149.  
  150.         if (RuneIsReady) then
  151.             return "#"
  152.         elseif (Cooldown) then
  153.             return Cooldown
  154.         end
  155.     end
  156. end
  157.  
  158. function PowerBar:UpdateRunes()
  159.     if (Class == "DEATHKNIGHT") then
  160.         PowerBar:SetScript("OnUpdate", function(self, Elapsed)
  161.             self.Update = (self.Update or 0) + Elapsed
  162.  
  163.             if (self.Update > 0.1) then
  164.                 for i = 1, 6 do
  165.                     local RuneText = self.Runes[i]
  166.                     RuneText:SetText(PowerBar:RuneCooldown(i))
  167.                 end
  168.  
  169.                 self.Update = 0
  170.             end
  171.         end)
  172.     end
  173. end
  174.  
  175. function PowerBar:OnEvent(event)
  176.     PowerBar:UpdateBar()
  177.     PowerBar:UpdateExtraPoints()
  178.     PowerBar:UpdateRunes()
  179.    
  180.     if (event == "PLAYER_REGEN_DISABLED") then
  181.         self:Show()
  182.     elseif (event == "PLAYER_REGEN_ENABLED") then
  183.         self:Hide()
  184.     end
  185. end
  186.  
  187. function PowerBar:Enable()
  188.     if not (self.IsCreated) then
  189.         PowerBar:CreateBar()
  190.    
  191.         self.IsCreated = true
  192.     end
  193. end
  194.  
  195. PowerBar:RegisterEvent("PLAYER_LOGIN")
  196. PowerBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  197. PowerBar:RegisterEvent("ADDON_LOADED")
  198.  
  199. PowerBar:SetScript("OnEvent", function(self, event)
  200.     PowerBar:Enable()
  201. end)
  Reply With Quote