From c0446ad8be74638294f9beff5b8a3dcebdfd6894 Mon Sep 17 00:00:00 2001 From: omicron Date: Thu, 16 Mar 2023 04:43:26 +0100 Subject: [PATCH] Add support for hiding unit frames in raid groups --- src/frames.lua | 21 +++++++++------------ src/types/unitframe.lua | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/frames.lua b/src/frames.lua index 7c81182..f6b93b0 100644 --- a/src/frames.lua +++ b/src/frames.lua @@ -46,31 +46,28 @@ function CreateRaidFrames(left, top, width, height) frame:SetPosition(left + (j-2)*width, top - i*height) end end - - local player = UnitFrame:new("player", width, height) - player:SetPosition(left-3*width - 50, top) - local target = UnitFrame:new("target", width, height) - target:SetPosition(left+3*width + 50, top) end function CreatePartyFrames(left, top, width, height) - local player = UnitFrame:new("player", width, height) + local player = UnitFrame:new("player", width, height, true) player:SetPosition(-2*width, top) for i=1,4 do - local frame = UnitFrame:new("party" .. i, width, height) + local frame = UnitFrame:new("party" .. i, width, height, true) frame:SetPosition((i-2)*width, top) end - +end + +function CreateTargetFrames(left, top, width, height) local target = UnitFrame:new("target", width, height) - target:SetPosition(3*width + 50, top) + target:SetPosition(left, top) local focus = UnitFrame:new("focus", width, height) - focus:SetPosition(3*width + 50, top - height) + focus:SetPosition(left, top-height) end function CreateFrames() CreatePartyFrames(0, -290, 110, 45) - --CreateRaidFrames(-850, 400, 110, 45) - --CreateRaidFrames(0, -290, 100, 45) + CreateRaidFrames(0, -290, 110, 45) + CreateTargetFrames(110*3+50, -290, 110, 45) HideBlizzardFrames() end omif.SetEventHandler("OMICRON_LOADING", CreateFrames) diff --git a/src/types/unitframe.lua b/src/types/unitframe.lua index fe0dbf6..2d53514 100644 --- a/src/types/unitframe.lua +++ b/src/types/unitframe.lua @@ -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