Add support for hiding unit frames in raid groups

This commit is contained in:
2023-03-16 04:43:26 +01:00
parent 86825dd6e5
commit c0446ad8be
2 changed files with 22 additions and 17 deletions

View File

@@ -43,8 +43,9 @@ local colors = {
white = {1.0, 1.0, 1.0}
}
function UnitFrame:Init(unit, width, height)
function UnitFrame:Init(unit, width, height, hideInRaid)
self.unit = unit
self.hideInRaid = hideInRaid or false
local secure = self:CreateSecureFrame(width, height)
secure:Hide()
self.hp = StatusBar:new(self, width, height)
@@ -187,8 +188,13 @@ function UnitFrame:CreateSecureFrame(width, height)
end
function UnitFrame:Enable()
if self.unit ~= "player" then
RegisterUnitWatch(self.secureFrame)
local secure = self.secureFrame
if self.hideInRaid then
local condition = "[@UNIT,exists,nogroup:raid] show; hide"
condition = condition:gsub("@UNIT", "@" .. self.unit)
RegisterAttributeDriver(secure, "state-visibility", condition)
elseif self.unit ~= "player" then
RegisterUnitWatch(self.secureFrame, false)
else
self.secureFrame:Show()
end
@@ -198,8 +204,10 @@ function UnitFrame:Enable()
end
function UnitFrame:Disable()
if self.unit ~= "player" then
UnregisterUnitWatch(self.secure_frame)
if self.hideInRaid then
UnregisterAttributeDriver(self.secureFrame, "state-visibility")
elseif self.unit ~= "player" then
UnregisterUnitWatch(self.secure_frame, self.condition)
else
self.secureFrame:Hide()
end