-- PetFrame.lua local _; local unpack, pairs = unpack, pairs; local format = string.format; local GameTooltip = GameTooltip; local GameTooltip_SetDefaultAnchor = GameTooltip_SetDefaultAnchor; local registerUnitEvents = OmaUFEvents.RegisterUnitEvents; 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 healabsorbColor = Settings.HealabsorbColor; local width, height = Settings.Pet.Width, Settings.Pet.Height; local anchorX, anchorY = Settings.Pet.AnchorX, Settings.Pet.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("UNIT_ENTERED_VEHICLE"); frame:RegisterEvent("UNIT_EXITED_VEHICLE"); frame:RegisterEvent("UNIT_PET"); frame:RegisterEvent("PLAYER_ENTERING_WORLD"); registerUnitEvents(frame); unitEvent(frame, "UPDATE_ALL_BARS"); end local function frameHide(frame) frame:UnregisterAllEvents(); end local function showTooltip(secure) GameTooltip_SetDefaultAnchor(GameTooltip, secure); GameTooltip:SetUnit(secure:GetAttribute("displayed")); end local function hideTooltip(secure) GameTooltip:FadeOut(); end local vehicletoggle = [=[ if newstate == "vehicle" then self:SetAttribute("displayed", self:GetAttribute("vehicle")); else self:SetAttribute("displayed", self:GetAttribute("unit")); end ]=] function OmaUnitFrames.UpdatePetTooltips() GameTooltip = _G["GameTooltip"]; GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"]; end function OmaUnitFrames.InitializePet(parent) attributes = Settings.Character.Clickheal; -- TODO pet clickheal separate with Mend Pet etc. local secure = CreateFrame("Button", "OmaPetSecure", parent, inheritedFrames); local frame = CreateFrame("Frame", "OmaPet", parent); local unit = "pet"; secure:SetPoint("TOPRIGHT", parent, "TOPLEFT", anchorX, anchorY); secure:SetAttribute("unit", unit); secure:SetAttribute("displayed", unit); secure:SetAttribute("vehicle", "player"); frame:SetPoint("TOPRIGHT", parent, "TOPLEFT", anchorX, anchorY); frame:SetAttribute("unit", unit); frame.unit = unit; frame.displayed = unit; frame.vehicle = "player"; -- 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, "BOTTOMRIGHT", -1, 1); 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, 0); frame.targeticon = frame:CreateTexture(nil, "OVERLAY"); frame.targeticon:SetPoint("CENTER", frame.healthback, "TOP"); frame.targeticon:SetWidth(18); frame.targeticon:SetHeight(18); frame.targeticon:SetTexture("Interface\\TARGETINGFRAME\\UI-RaidTargetingIcons"); frame.targeticon:Hide(); -- set scripts frame:SetScript("OnShow", frameShow); frame:SetScript("OnHide", frameHide); frame:SetScript("OnEvent", unitEvent); secure:SetScript("OnEnter", showTooltip); secure:SetScript("OnLeave", hideTooltip); -- set attributes 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"); secure:SetAttribute("toggleForVehicle", true); RegisterUnitWatch(frame); RegisterUnitWatch(secure); RegisterStateDriver(secure, "vehicleui", "[vehicleui] vehicle; no"); secure:SetAttribute("_onstate-vehicleui", vehicletoggle); return frame; end