From 40bd1bf881fc36bdbde649ff1f1403cc2f1bbfc6 Mon Sep 17 00:00:00 2001 From: shagu Date: Fri, 19 Jul 2019 21:51:09 +0200 Subject: [PATCH] focus: properly handle focus frame visibility --- api/unitframes.lua | 72 ++++++++++++++++++++++++---------------------- modules/focus.lua | 7 ++--- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/api/unitframes.lua b/api/unitframes.lua index 20dfd494..1b579e13 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -207,47 +207,49 @@ function pfUI.uf:UpdateVisibility() end local unitstr = string.format("%s%s", self.label or "", self.id or "") - if UnitExists(unitstr) or (pfUI.unlock and pfUI.unlock:IsShown()) then + if pfUI.unlock and pfUI.unlock:IsShown() then self:Show() - else - --keep focus and named frames visible - if self.unitname and self.unitname ~= "focus" then - self:Show() + return - -- only update visibility state for existing units - elseif UnitName(unitstr) then - -- hide group while in raid and option is set - if C["unitframes"]["group"]["hide_in_raid"] == "1" and strsub(self.label,0,5) == "party" and UnitInRaid("player") then - self:Hide() - return + --keep focus and named frames visible + elseif self.unitname and self.unitname ~= "focus" then + self:Show() + return - -- hide existing but too far away pet and pets of old group members - elseif self.label == "partypet" then - if not UnitIsVisible(unitstr) or not UnitExists("party" .. self.id) then - self:Hide() - return - end - - elseif self.label == "pettarget" then - if not UnitIsVisible(unitstr) or not UnitExists("pet") then - self.frame:Hide() - return - end - - -- hide self in group if solo or hide in raid is set - elseif self.fname == "Group0" or self.fname == "PartyPet0" or self.fname == "Party0Target" then - if GetNumPartyMembers() <= 0 or ( C["unitframes"]["group"]["hide_in_raid"] == "1" and UnitInRaid("player") ) then - self:Hide() - return - end - end - - self:Show() - else - self.lastUnit = nil + -- only update visibility state for existing units + elseif UnitName(unitstr) then + -- hide group while in raid and option is set + if C["unitframes"]["group"]["hide_in_raid"] == "1" and strsub(self.label,0,5) == "party" and UnitInRaid("player") then self:Hide() return + + -- hide existing but too far away pet and pets of old group members + elseif self.label == "partypet" then + if not UnitIsVisible(unitstr) or not UnitExists("party" .. self.id) then + self:Hide() + return + end + + elseif self.label == "pettarget" then + if not UnitIsVisible(unitstr) or not UnitExists("pet") then + self.frame:Hide() + return + end + + -- hide self in group if solo or hide in raid is set + elseif self.fname == "Group0" or self.fname == "PartyPet0" or self.fname == "Party0Target" then + if GetNumPartyMembers() <= 0 or ( C["unitframes"]["group"]["hide_in_raid"] == "1" and UnitInRaid("player") ) then + self:Hide() + return + end end + + -- show everything else that has a name + self:Show() + else + self.lastUnit = nil + self:Hide() + return end end diff --git a/modules/focus.lua b/modules/focus.lua index 1d593e4d..54182d18 100644 --- a/modules/focus.lua +++ b/modules/focus.lua @@ -4,21 +4,19 @@ function SlashCmdList.PFFOCUS(msg) if msg ~= "" then pfUI.uf.focus.unitname = strlower(msg) - pfUI.uf.focus:Show() elseif UnitName("target") then pfUI.uf.focus.unitname = strlower(UnitName("target")) - pfUI.uf.focus:Show() else - pfUI.uf.focus:Hide() pfUI.uf.focus.unitname = nil + pfUI.uf.focus.label = nil end end SLASH_PFCLEARFOCUS1, SLASH_PFCLEARFOCUS2 = '/clearfocus', '/pfclearfocus' function SlashCmdList.PFCLEARFOCUS(msg) if pfUI.uf and pfUI.uf.focus then - pfUI.uf.focus:Hide() pfUI.uf.focus.unitname = nil + pfUI.uf.focus.label = nil end end @@ -75,7 +73,6 @@ function SlashCmdList.PFSWAPFOCUS(msg) if oldunit and pfUI.uf.focus.unitname then TargetByName(pfUI.uf.focus.unitname) pfUI.uf.focus.unitname = oldunit - pfUI.uf.focus:Show() end end