/Tukui/modules/misc/threatbar.lua

http://github.com/Asphyxia/Tukui · Lua · 89 lines · 70 code · 14 blank · 5 comment · 19 complexity · 32050fa5b5ff8e3ffd8f2b73baf2a572 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. -- Very simple threat bar for T.
  3. -- cannot work without Info Right DataText Panel.
  4. if not TukuiInfoRight then return end
  5. local aggroColors = {
  6. [1] = {12/255, 151/255, 15/255},
  7. [2] = {166/255, 171/255, 26/255},
  8. [3] = {163/255, 24/255, 24/255},
  9. }
  10. -- create the bar
  11. local TukuiThreatBar = CreateFrame("StatusBar", "TukuiThreatBar", UIParent)
  12. TukuiThreatBar:SetStatusBarTexture(C.media.normTex)
  13. TukuiThreatBar:GetStatusBarTexture():SetHorizTile(false)
  14. TukuiThreatBar:SetBackdrop({bgFile = C.media.blank})
  15. TukuiThreatBar:SetBackdropColor(0, 0, 0, 1)
  16. TukuiThreatBar:SetMinMaxValues(0, 100)
  17. TukuiThreatBar:SetOrientation("HORIZONTAL")
  18. local TukuiThreatBarBG = CreateFrame("Frame", nil, TukuiThreatBar)
  19. TukuiThreatBarBG:CreatePanel("Default", TukuiBar1:GetWidth(), 20, "TOP", TukuiBar1, "BOTTOM", 0, -3)
  20. TukuiThreatBar:Point("TOPLEFT", TukuiThreatBarBG, 2, -2)
  21. TukuiThreatBar:Point("BOTTOMRIGHT", TukuiThreatBarBG, -2, 2)
  22. TukuiThreatBar.text = T.SetFontString(TukuiThreatBar, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  23. TukuiThreatBar.text:Point("RIGHT", TukuiThreatBar, "RIGHT", -30, 0)
  24. TukuiThreatBar.Title = T.SetFontString(TukuiThreatBar, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  25. TukuiThreatBar.Title:SetText(L.unitframes_ouf_threattext)
  26. TukuiThreatBar.Title:SetPoint("LEFT", TukuiThreatBar, "LEFT", T.Scale(30), 0)
  27. -- event func
  28. local function OnEvent(self, event, ...)
  29. local party = GetNumPartyMembers()
  30. local raid = GetNumRaidMembers()
  31. local pet = select(1, HasPetUI())
  32. if event == "PLAYER_ENTERING_WORLD" then
  33. self:Hide()
  34. self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  35. elseif event == "PLAYER_REGEN_ENABLED" then
  36. self:Hide()
  37. elseif event == "PLAYER_REGEN_DISABLED" then
  38. if party > 0 or raid > 0 or pet == 1 then
  39. self:Show()
  40. else
  41. self:Hide()
  42. end
  43. else
  44. if (InCombatLockdown()) and (party > 0 or raid > 0 or pet == 1) then
  45. self:Show()
  46. else
  47. self:Hide()
  48. end
  49. end
  50. end
  51. local function OnUpdate(self, event, unit)
  52. if UnitAffectingCombat(self.unit) then
  53. local _, _, threatpct, rawthreatpct, _ = UnitDetailedThreatSituation(self.unit, self.tar)
  54. local threatval = threatpct or 0
  55. self:SetValue(threatval)
  56. self.text:SetFormattedText("%3.1f", threatval)
  57. local r, g, b = oUFTukui.ColorGradient(threatval/100, 0,.8,0,.8,.8,0,.8,0,0)
  58. self:SetStatusBarColor(r, g, b)
  59. if threatval > 0 then
  60. self:SetAlpha(1)
  61. else
  62. self:SetAlpha(0)
  63. end
  64. end
  65. end
  66. TukuiThreatBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  67. TukuiThreatBar:RegisterEvent("PLAYER_REGEN_ENABLED")
  68. TukuiThreatBar:RegisterEvent("PLAYER_REGEN_DISABLED")
  69. TukuiThreatBar:SetScript("OnEvent", OnEvent)
  70. TukuiThreatBar:SetScript("OnUpdate", OnUpdate)
  71. TukuiThreatBar.unit = "player"
  72. TukuiThreatBar.tar = TukuiThreatBar.unit.."target"
  73. TukuiThreatBar.Colors = aggroColors
  74. TukuiThreatBar:SetAlpha(0)
  75. -- THAT'S IT!