From 7434a0edb37afe7c233f8ef5a504e17aeded3195 Mon Sep 17 00:00:00 2001 From: Solor Date: Wed, 6 Apr 2022 16:46:52 +0800 Subject: [PATCH] add option to toggle player tags visibility --- gui/options.lua | 1 + modules/unitframe/tags.lua | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/gui/options.lua b/gui/options.lua index e27d2f80c..09cce3aed 100644 --- a/gui/options.lua +++ b/gui/options.lua @@ -575,6 +575,7 @@ GUI.OptionsList = { {1, 'Unitframe', 'GCDIndicator', L['GCD Indicator'], true, nil, UpdateGCDTicker, L['Show global cooldown ticker above the player frame.']}, {1, 'Unitframe', 'AbbrName', L['Abbreviate Name'], nil, nil, UpdateUnitTags}, {1, 'Unitframe', 'ClassPower', L['Class Power'], true, SetupClassPower, nil, L['Show special resources of the class, such as Combo Points, Holy Power, Chi, Runes, etc.']}, + {1, 'Unitframe', 'HidePlayerTags', L['Hide Player Tags'], nil, nil, UpdateUnitTags, L['Only show player tags on mouseover.']}, {}, {1, 'Unitframe', 'OnlyShowPlayer', L['Player Debuffs Only'], nil, nil, nil, L['Display debuffs cast by player only.']}, {1, 'Unitframe', 'DesaturateIcon', L['Desaturate Debuffs'], true, nil, nil, L['Desaturate debuffs cast by others.']}, diff --git a/modules/unitframe/tags.lua b/modules/unitframe/tags.lua index cde5529f6..793d8bed3 100644 --- a/modules/unitframe/tags.lua +++ b/modules/unitframe/tags.lua @@ -35,7 +35,7 @@ local events = { -- abbreviate the name -- aaa.bbbbb -> a.bbbbb local function AbbrName(string, i) - if string.len(string) > i then + if string and string.len(string) > i then return string.gsub(string, '%s?(.[\128-\191]*)%S+%s', '%1. ') else return string @@ -389,8 +389,27 @@ local function Player_OnEnter(self) end local function Player_OnLeave(self) - self.LeftTag:Hide() - self.RightTag:Hide() + if C.DB.Unitframe.HidePlayerTags then + self.LeftTag:Hide() + self.RightTag:Hide() + else + self.LeftTag:Show() + self.RightTag:Show() + end +end + +local function UpdatePlayerTags(self) + if C.DB.Unitframe.HidePlayerTags then + self.LeftTag:Hide() + self.RightTag:Hide() + self:HookScript('OnEnter', Player_OnEnter) + self:HookScript('OnLeave', Player_OnLeave) + else + self.LeftTag:Show() + self.RightTag:Show() + self:HookScript('OnEnter', Player_OnEnter) + self:HookScript('OnLeave', Player_OnLeave) + end end function UNITFRAME:CreatePlayerTags(self) @@ -410,12 +429,7 @@ function UNITFRAME:CreatePlayerTags(self) self.LeftTag = leftTag self.RightTag = rightTag - if C.DB.Unitframe.HidePlayerTags then - self.LeftTag:Hide() - self.RightTag:Hide() - self:HookScript('OnEnter', Player_OnEnter) - self:HookScript('OnLeave', Player_OnLeave) - end + end function NAMEPLATE:CreateHealthTag(self) @@ -437,6 +451,9 @@ end function UNITFRAME:UpdateUnitTags() for _, frame in pairs(oUF.objects) do if frame.unitStyle ~= 'party' and frame.unitStyle ~= 'raid' then + if frame.unitStyle == 'player' then + UpdatePlayerTags(frame) + end frame:UpdateTags() end end