288 lines
8.7 KiB
Lua
288 lines
8.7 KiB
Lua
local name,addon = ...
|
|
|
|
local units = {}
|
|
units[#units+1] = CreateFrame("Button",name..'player',UIParent, BackdropTemplateMixin and "SecureUnitButtonTemplate BackdropTemplate" or "SecureUnitButtonTemplate")
|
|
units[#units]:SetAttribute("unit","playertarget")
|
|
for a = 1,4 do
|
|
local unit = "party"..a.."target"
|
|
local b = CreateFrame("Button",name..unit,UIParent, BackdropTemplateMixin and "SecureUnitButtonTemplate BackdropTemplate" or "SecureUnitButtonTemplate")
|
|
b:SetAttribute("unit",unit)
|
|
units[#units+1] = b
|
|
end
|
|
|
|
local guids = {}
|
|
|
|
local tanks = {}
|
|
local function getUnitName(unit)
|
|
if(not unit) then return end
|
|
local c,r = UnitName(unit)
|
|
if(not c) then return end
|
|
if(r and r~='') then
|
|
return format("%s-%s",c,r)
|
|
else
|
|
local realm = GetRealmName()
|
|
if(realm) then
|
|
return format("%s-%s",c,realm)
|
|
else
|
|
return c
|
|
end
|
|
end
|
|
end
|
|
local function setTanks()
|
|
wipe(tanks)
|
|
local tank = nil
|
|
if(GetNumGroupMembers()) then
|
|
for i = 1,MAX_RAID_MEMBERS do
|
|
local name, _, _, _, _, _, _, _, _, role, _, combatRole = GetRaidRosterInfo(i)
|
|
if(name and (role == "maintank" or combatRole == 'TANK')) then
|
|
tanks[#tanks+1] = getUnitName("raid"..i)
|
|
end
|
|
end
|
|
else
|
|
for i = 1,4 do
|
|
local isTank, isHeal, isDPS = UnitGroupRolesAssigned("party"..i)
|
|
if(isTank) then
|
|
tanks[#tanks+1] = getUnitName("party"..i)
|
|
end
|
|
end
|
|
end
|
|
if(#tanks < 1) then
|
|
tanks[#tanks+1] = getUnitName("player")
|
|
end
|
|
end
|
|
function addon:RAID_ROSTER_UPDATE(event, ...)
|
|
|
|
end
|
|
local function updateRaidTarget(self)
|
|
local unit = self:GetAttribute("unit")
|
|
local icon=GetRaidTargetIndex(unit)
|
|
local a,b,c,d
|
|
local b = 0
|
|
if UnitExists(unit) and icon then
|
|
if(icon<5) then
|
|
a = icon
|
|
c = 0
|
|
else
|
|
a = icon - 4
|
|
c = 0.25
|
|
end
|
|
a = 0.25 * a
|
|
b = a - 0.25
|
|
d = c + 0.25
|
|
self.raidiconframe.tex:SetTexCoord(b,a,c,d)
|
|
self.raidiconframe:Show()
|
|
local guid = UnitGUID(unit)
|
|
if(guids[guid] ~= icon) then
|
|
guids[guid] = icon
|
|
addon:AddScrollMessage("|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_"..icon..":0|t on "..UnitName(unit))
|
|
end
|
|
else
|
|
self.raidiconframe:Hide()
|
|
end
|
|
end
|
|
local function isTank(unit)
|
|
setTanks()
|
|
local uname = getUnitName(unit)
|
|
for k,v in pairs(tanks) do
|
|
if(uname == v) then return true end
|
|
end
|
|
end
|
|
local function updateThreat(self,event,tunit,...)
|
|
if(addon:IsClassic()) then return end
|
|
local unit = self:GetAttribute("unit")
|
|
if(UnitExists(unit)) then
|
|
if(tunit) then
|
|
if(isTank(tunit)) then
|
|
-- print("isTank "..getUnitName(tunit)..tostring(#tanks))
|
|
end
|
|
local stat = isTank(tunit) and UnitThreatSituation(tunit,unit) or UnitThreatSituation(unit)
|
|
if(stat) then
|
|
self:SetBackdropBorderColor(GetThreatStatusColor(stat))
|
|
end
|
|
end
|
|
|
|
end
|
|
if(event=="PLAYER_REGEN_ENABLED") then
|
|
self:SetBackdropBorderColor(1,1,1,.5)
|
|
end
|
|
end
|
|
local function updateHealth(self, event, unit, ...)
|
|
if(event=="UNIT_TARGET") then
|
|
unit = unit.."target"
|
|
updateRaidTarget(self)
|
|
updateThreat(self,event,unit,...)
|
|
elseif(event=="PLAYER_REGEN_ENABLED" or event=="PLAYER_REGEN_DISABLED") then
|
|
updateThreat(self,event,unit,...)
|
|
elseif(event=="UNIT_THREAT_LIST_UPDATE" or event=="UNIT_THREAT_SITUATION_UPDATE") then
|
|
updateThreat(self,event,unit,...)
|
|
elseif(event=="RAID_TARGET_UPDATE") then
|
|
for _,u in pairs(units) do
|
|
updateRaidTarget(u)
|
|
end
|
|
return
|
|
end
|
|
if(unit and UnitIsUnit(self:GetAttribute("unit"), unit)) then
|
|
local h = UnitHealth(unit)
|
|
local m = UnitHealthMax(unit)
|
|
local healers = addon:GetHealers()
|
|
local d = m/100
|
|
if(d > 0) then
|
|
local p = h / d
|
|
self['text']:SetText(addon:colorize(format("%.0f%%",p),healers[UnitName(unit)] and "00ff00" or "ffffff"))
|
|
else
|
|
self['text']:SetText(addon:colorize(format("%.0f%%",0),healers[UnitName(unit)] and "00ff00" or "ffffff"))
|
|
end
|
|
end
|
|
end
|
|
function addon:UpdateUnits()
|
|
for _,u in pairs(units) do
|
|
local unit = u:GetAttribute("unit")
|
|
updateHealth(u, "UNIT_HEALTH", unit)
|
|
end
|
|
end
|
|
local function showUnit(self)
|
|
GameTooltip:SetOwner(UIParent,"ANCHOR_CURSOR")
|
|
-- GameTooltip:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT",-40,40)
|
|
GameTooltip:SetUnit(self:GetAttribute("unit"))
|
|
ShowUIPanel(GameTooltip)
|
|
end
|
|
local function hideUnit(self)
|
|
GameTooltip:Hide()
|
|
end
|
|
local a = 20
|
|
ClickCastFrames = ClickCastFrames or {}
|
|
|
|
for _, u in pairs(units) do
|
|
u:SetWidth(40)
|
|
u:SetHeight(20)
|
|
u:ClearAllPoints()
|
|
u:SetPoint("BOTTOMLEFT",addon.davisframe,"TOPLEFT",a,12)
|
|
u:SetBackdrop({
|
|
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
|
tile = true,
|
|
tileSize = 1,
|
|
edgeFile = "Interface/Buttons/WHITE8x8",
|
|
edgeSize = 1,
|
|
insets = { left = 0, right = 0, top = 0, 0 }
|
|
})
|
|
u:SetBackdropBorderColor(1,1,1,1)
|
|
u:SetBackdropColor(0,0,0,.5)
|
|
u:RegisterUnitEvent("UNIT_HEALTH", u:GetAttribute("unit"))
|
|
u:RegisterUnitEvent("UNIT_TARGET", u:GetAttribute("unit"))
|
|
u:RegisterEvent("RAID_TARGET_UPDATE")
|
|
if(not addon:IsClassic()) then
|
|
u:RegisterUnitEvent("UNIT_THREAT_LIST_UPDATE", u:GetAttribute("unit"))
|
|
u:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", u:GetAttribute("unit"))
|
|
end
|
|
|
|
u:RegisterEvent("PLAYER_REGEN_ENABLED")
|
|
u:RegisterEvent("PLAYER_REGEN_DISABLED")
|
|
u:HookScript("OnEvent", updateHealth)
|
|
u:HookScript("OnEnter", showUnit)
|
|
u:HookScript("OnLeave", hideUnit)
|
|
local c = u:CreateFontString(nil,"OVERLAY","CombatLogFont")
|
|
c:ClearAllPoints()
|
|
c:SetAllPoints(u)
|
|
c:SetJustifyH("CENTER")
|
|
c:SetText("100")
|
|
u['text'] = c
|
|
|
|
ClickCastFrames[u] = true
|
|
RegisterUnitWatch(u)
|
|
a = a + u:GetWidth()
|
|
local ri = CreateFrame("FRAME",nil,u, BackdropTemplateMixin and "BackdropTemplate" or nil)
|
|
ri:SetSize(16,16)
|
|
ri:SetPoint("BOTTOM",u,"TOP")
|
|
ri.tex = ri:CreateTexture(nil,"OVERLAY")
|
|
ri.tex:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons")
|
|
ri.tex:SetAllPoints(ri)
|
|
u.raidiconframe = ri
|
|
updateRaidTarget(u)
|
|
end
|
|
local group = {
|
|
"player","party1","party2","party3","party4"
|
|
}
|
|
a = 20
|
|
local function hbShow(self)
|
|
local r,g,b = GetClassColor(select(2,UnitClass(self.unit)))
|
|
self:SetStatusBarColor(r,g,b,1)
|
|
end
|
|
local function pbShow(self)
|
|
local powerType, powerToken, altR, altG, altB = UnitPowerType(self.unit)
|
|
local info = PowerBarColor[powerToken]
|
|
if(info) then
|
|
self:SetStatusBarColor(info.r, info.g, info.b,1)
|
|
end
|
|
end
|
|
local function colorUpdate(self,event,unit,powertype)
|
|
if(event == "GROUP_ROSTER_UPDATE") then
|
|
local r,g,b = GetClassColor(select(2,UnitClass(self.unit)))
|
|
self:SetStatusBarColor(r,g,b,1)
|
|
elseif(unit and unit == self.unit) then
|
|
if(event == "UNIT_HEALTH" or event == "UNIT_HEALTH_FREQUENT" or event == "UNIT_MAXHEALTH" or event == "PLAYER_ENTERING_WORLD") then
|
|
self:SetValue(UnitHealth(unit) / (UnitHealthMax(unit)/100))
|
|
elseif(event == "UNIT_POWER_UPDATE" or event == "UNIT_POWER_FREQUENT" or event == "UNIT_MAXPOWER" or event == "PLAYER_ENTERING_WORLD") then
|
|
self:SetValue(UnitPower(unit) / (UnitPowerMax(unit)/100))
|
|
pbShow(self)
|
|
end
|
|
end
|
|
end
|
|
for _,unit in pairs(group) do
|
|
local u = CreateFrame("Button",name..unit,UIParent, BackdropTemplateMixin and "SecureUnitButtonTemplate BackdropTemplate" or "SecureUnitButtonTemplate")
|
|
u:SetAttribute("unit",unit)
|
|
u:SetSize(40,10)
|
|
u:ClearAllPoints()
|
|
u:SetPoint("BOTTOMLEFT",addon.davisframe,"TOPLEFT",a,0)
|
|
-- u:HookScript("OnEnter", showUnit)
|
|
-- u:HookScript("OnLeave", hideUnit)
|
|
u:SetBackdrop({
|
|
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
|
tile = true,
|
|
tileSize = 1,
|
|
edgeSize = 1,
|
|
edgeFile = "Interface/Buttons/WHITE8X8",
|
|
insets = { left = 0, right = 0, top = 0, 0 }
|
|
})
|
|
u:SetBackdropBorderColor(.3,.3,.3,.3)
|
|
u:SetBackdropColor(0,0,0,.5)
|
|
ClickCastFrames[u] = true
|
|
RegisterUnitWatch(u)
|
|
local s = CreateFrame("StatusBar", "$PARENThealthbar", u)
|
|
s:RegisterEvent("GROUP_ROSTER_UPDATE")
|
|
s:RegisterUnitEvent("UNIT_HEALTH", unit)
|
|
-- s:RegisterEvent("UNIT_HEALTH_FREQUENT")
|
|
s:RegisterUnitEvent("UNIT_MAXHEALTH", unit)
|
|
s.unit = unit
|
|
s:SetFrameStrata("BACKGROUND")
|
|
s:SetSize(40,5)
|
|
s:SetPoint("TOPLEFT",u,"TOPLEFT",0 ,0)
|
|
s:SetMinMaxValues(0,100)
|
|
s:SetOrientation("HORIZONTAL")
|
|
s:SetValue(100)
|
|
s:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
|
|
s:GetStatusBarTexture():SetHorizTile(false)
|
|
s:GetStatusBarTexture():SetVertTile(false)
|
|
s:SetScript("OnEvent", colorUpdate)
|
|
s:SetScript("OnShow", hbShow)
|
|
hbShow(s)
|
|
local h = CreateFrame("StatusBar", "$PARENTpowerbar", u)
|
|
h:RegisterEvent("GROUP_ROSTER_UPDATE")
|
|
h:RegisterEvent("PLAYER_ENTERING_WORLD")
|
|
h:RegisterUnitEvent("UNIT_POWER_UPDATE", unit)
|
|
-- h:RegisterEvent("UNIT_POWER_FREQUENT")
|
|
h:RegisterUnitEvent("UNIT_MAXPOWER", unit)
|
|
h:SetScript("OnEvent", colorUpdate)
|
|
h.unit = unit
|
|
h:SetFrameStrata("BACKGROUND")
|
|
h:SetSize(40,5)
|
|
h:SetPoint("TOPLEFT",u,"TOPLEFT",0 ,-5)
|
|
h:SetMinMaxValues(0,100)
|
|
h:SetOrientation("HORIZONTAL")
|
|
h:SetValue(100)
|
|
h:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
|
|
h:GetStatusBarTexture():SetHorizTile(false)
|
|
h:GetStatusBarTexture():SetVertTile(false)
|
|
h:SetScript("OnShow", pbShow)
|
|
pbShow(h)
|
|
a = a + u:GetWidth()
|
|
end |