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