-- BossFrames.lua local _; local unpack, pairs = unpack, pairs; local format = string.format; local UnitExists, ShowBossFrameWhenUninteractable = UnitExists, ShowBossFrameWhenUninteractable; local GameTooltip = GameTooltip; local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor; local registerUnitEvents = OmaUFEvents.RegisterUnitEvents; local registerCastEvents = OmaUFCastBar.RegisterCastEvents; local unregisterCastEvents = OmaUFCastBar.UnregisterCastEvents; local unitEvent = OmaUFEvents.UnitEvent; local Settings = OmaUFSettings; local baseColor = Settings.BaseColor; local bgColor = Settings.BgColor; local healthColor = Settings.HealthColor; local shieldColor = Settings.ShieldColor; local shieldhlColor = Settings.ShieldhlColor; local healpredColor = Settings.HealpredColor; local healabsorbColor = Settings.HealabsorbColor; local width, height = Settings.Boss.Width, Settings.Boss.Height; local anchorX, anchorY = Settings.Boss.AnchorX, Settings.Boss.AnchorY; -- placeholders with visible values when error happens local attributes = {}; local inheritedFrames = "SecureUnitButtonTemplate,SecureHandlerStateTemplate"; local barTexture = "Interface\\AddOns\\OmaRF\\images\\minimalist"; local function frameShow(frame) frame:RegisterEvent("PLAYER_ENTERING_WORLD"); frame:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT"); frame:RegisterEvent("UNIT_TARGETABLE_CHANGED"); frame:RegisterUnitEvent("UNIT_LEVEL", frame.unit); registerUnitEvents(frame); registerCastEvents(frame.castbar); unitEvent(frame, "UPDATE_ALL_BARS"); end local function frameHide(frame) frame:UnregisterAllEvents(); unregisterCastEvents(frame.castbar); end local function showTooltip(secure) GameTooltip_SetDefaultAnchor(GameTooltip, secure); GameTooltip:SetUnit(secure:GetAttribute("unit")); end local function hideTooltip(secure) GameTooltip:FadeOut(); end function OmaUnitFrames.UpdateBossTooltips() GameTooltip = _G["GameTooltip"]; GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"]; end local function bossEvent(self) -- INSTANCE_ENCOUNTER_ENGAGE_UNIT only for unit, frame in pairs(self.frames) do if UnitExists(unit) or ShowBossFrameWhenUninteractable(unit) then frame:Show(); else frame:Hide(); end end end local function createFrame(framename, securename, parent, unit, anchorX, anchorY) local secure = CreateFrame("Button", securename, parent, inheritedFrames); local frame = CreateFrame("Frame", framename, parent); secure:SetPoint("CENTER", parent, "CENTER", anchorX, anchorY); secure:SetAttribute("unit", unit); frame:SetPoint("CENTER", parent, "CENTER", anchorX, anchorY); frame:SetAttribute("unit", unit); frame.unit = unit; frame.displayed = unit; -- hide frame to get initial frameShow call frame:Hide(); -- create visuals secure:SetWidth(width+2); secure:SetHeight(height+2); frame:SetWidth(width+2); frame:SetHeight(height+2); frame.width = width; frame.base = frame:CreateTexture(nil, "BACKGROUND"); frame.base:SetAllPoints(); frame.base:SetColorTexture(1, 1, 1); frame.base:SetVertexColor(unpack(baseColor)); frame.healthback = frame:CreateTexture(nil, "BACKGROUND", nil, 1); frame.healthback:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1); frame.healthback:SetPoint("BOTTOMRIGHT", frame, "RIGHT", -1, -5); frame.healthback:SetTexture(barTexture); frame.healthback:SetVertexColor(unpack(bgColor)); frame.health = frame:CreateTexture(nil, "BORDER"); frame.health:SetPoint("TOPLEFT", frame.healthback, "TOPLEFT"); frame.health:SetPoint("BOTTOMLEFT", frame.healthback, "BOTTOMLEFT"); frame.health:SetTexture(barTexture); frame.health:SetVertexColor(unpack(healthColor)); frame.healthText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight"); frame.healthText:SetPoint("RIGHT", frame.healthback, "RIGHT", -2, 1); frame.healthText.percent = true; frame.manaback = frame:CreateTexture(nil, "BACKGROUND", nil, 1); frame.manaback:SetPoint("TOPLEFT", frame, "LEFT", 1, -5); frame.manaback:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1); frame.manaback:SetTexture(barTexture); frame.manaback:SetVertexColor(unpack(bgColor)); frame.mana = frame:CreateTexture(nil, "BORDER"); frame.mana:SetPoint("TOPLEFT", frame.manaback, "TOPLEFT"); frame.mana:SetPoint("BOTTOMLEFT", frame.manaback, "BOTTOMLEFT"); frame.mana:SetTexture(barTexture); frame.manaText = frame:CreateFontString(nil, "ARTWORK", "GameFontWhiteTiny"); frame.manaText:SetPoint("RIGHT", frame.manaback, "RIGHT", -2, 0); frame.manaText:Hide(); frame.shield = frame:CreateTexture(nil, "BORDER"); frame.shield:SetPoint("TOPLEFT", frame.health, "TOPRIGHT"); frame.shield:SetPoint("BOTTOMLEFT", frame.health, "BOTTOMRIGHT"); frame.shield:SetTexture(barTexture); frame.shield:SetVertexColor(unpack(shieldColor)); frame.shield:Hide(); frame.shieldhl = frame:CreateTexture(nil, "ARTWORK"); frame.shieldhl:SetPoint("TOPLEFT", frame.healthback, "TOPRIGHT", -1, 0); frame.shieldhl:SetPoint("BOTTOMRIGHT", frame.healthback, "BOTTOMRIGHT", 1, 0); frame.shieldhl:SetColorTexture(unpack(shieldhlColor)); frame.shieldhl:Hide(); frame.healabsorb = frame:CreateTexture(nil, "ARTWORK"); frame.healabsorb:SetPoint("TOPRIGHT", frame.health, "TOPRIGHT"); frame.healabsorb:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT"); frame.healabsorb:SetColorTexture(unpack(healabsorbColor)); frame.healabsorb:Hide(); frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight"); frame.name:SetPoint("LEFT", frame.healthback, "LEFT", 2, 1); frame.name.count = 10; frame.level = frame:CreateFontString(nil, "OVERLAY", "GameFontWhiteTiny"); frame.level:SetPoint("LEFT", frame.manaback, "LEFT", 2, 0); frame.targeticon = frame:CreateTexture(nil, "OVERLAY"); frame.targeticon:SetPoint("CENTER", frame.healthback, "TOP"); frame.targeticon:SetWidth(16); frame.targeticon:SetHeight(16); frame.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons"); frame.targeticon:Hide(); frame.castbar = OmaUFCastBar.CreateCastBar(frame, unit, -height-24); -- set scripts frame:SetScript("OnShow", frameShow); frame:SetScript("OnHide", frameHide); frame:SetScript("OnEvent", unitEvent); secure:SetScript("OnEnter", showTooltip); secure:SetScript("OnLeave", hideTooltip); -- set attributes -- TODO other set of click cast on boss frames possibly --secure:RegisterForClicks("AnyDown"); --for attr, val in pairs(attributes) do -- secure:SetAttribute(attr, val); --end -- rest give target and menu secure:SetAttribute("*type1", "target"); secure:SetAttribute("*type2", "togglemenu"); -- TODO dunno how to update frame securely without hiding frame too often -- ShowBossFrameWhenUninteractable not in restricted environment -- this way all frames are clickable, but there's some invisible clickframes RegisterStateDriver(secure, "visibility", "[@boss1,exists][@boss2,exists][@boss3,exists][@boss4,exists][@boss5,exists] show; hide"); return frame; end function OmaUnitFrames.InitializeBoss(parent) attributes = Settings.Character.Clickheal; -- hidden frame to handle hiding insecure boss frames local bossHeader = CreateFrame("Frame"); bossHeader.frames = {}; bossHeader:SetScript("OnEvent", bossEvent); bossHeader:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT"); bossHeader.frames["boss1"] = createFrame("OmaBoss1", "OmaBossSecure1", parent, "boss1", anchorX, anchorY); for i = 2,MAX_BOSS_FRAMES do bossHeader.frames["boss"..i] = createFrame("OmaBoss"..i, "OmaBossSecure"..i, _G["OmaBossSecure"..(i-1)], "boss"..i, 0, -height-26); end bossEvent(bossHeader); -- Arena frames are in the same spot --[[createFrame("OmaArena1", "OmaArenaSecure1", parent, "arena1", anchorX, anchorY); -- MAX_ARENA_ENEMIES from AddOns/Blizzard_ArenaUI/Blizzard_ArenaUI.lua not available -- as the addon is not loaded yet, update manually if it changes for i = 2,5 do createFrame("OmaArena"..i, "OmaArenaSecure"..i, _G["OmaArena"..(i-1)], "arena"..i, 0, -height-26); end--]] end