Quantcast WoWInterface - View Single Post - make blizz frames appear when damaged
View Single Post
08-05-18, 11:00 AM   #11
Vrul
An Onyxian Warder
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 352
This should get you started at least:
Code:
local frame, forceShow, inCombat, queue = CreateFrame("Frame")

local function UnitFrame_OnShow(self)
    if not (inCombat or forceShow) then
        self:Hide()
    end
end
PetFrame:HookScript("OnShow", UnitFrame_OnShow)
TargetFrame:HookScript("OnShow", UnitFrame_OnShow)

local function DisableShowMode()
    frame:RegisterUnitEvent("UNIT_HEALTH", "player", "vehicle")
    frame:RegisterUnitEvent("UNIT_MAXHEALTH", "player", "vehicle")
    if not inCombat then
        PetFrame:Hide()
        TargetFrame:Hide()
    else
        queue = DisableShowMode
    end
end

local function EnableShowMode(override)
    frame:UnregisterEvent("UNIT_HEALTH")
    frame:UnregisterEvent("UNIT_MAXHEALTH")
    if not inCombat or override then
        PlayerFrame:Show()
        PetFrame:SetShown(UnitExists("pet"))
        TargetFrame:SetShown(UnitExists("target"))
    else
        queue = EnableShowMode
    end
end

local function OnEvent(self, event, unit)
    if event == "PLAYER_REGEN_DISABLED" then
        inCombat = true
        EnableShowMode(true)
    elseif event == "PLAYER_REGEN_ENABLED" then
        inCombat = false
        (queue or DisableShowMode)()
    end
    if not (inCombat or forceShow) then
        unit = PlayerFrame.unit
        PlayerFrame:SetShown(UnitHealth(unit) < UnitHealthMax(unit))
    end
end

frame:SetScript("OnEvent", OnEvent)
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterUnitEvent("UNIT_ENTERED_VEHICLE", "player")
frame:RegisterUnitEvent("UNIT_EXITED_VEHICLE", "player")
DisableShowMode()

function ToggleUnitFrameForceShow()
    forceShow = not forceShow
    if forceShow then
        EnableShowMode()
    else
        DisableShowMode()
        OnEvent(frame)
    end
end
To toggle forcing to show the frames in your macro use:
Code:
/run ToggleUnitFrameForceShow()
  Reply With Quote