SFrames.ToT = {} local _A = SFrames.ActiveTheme function SFrames.ToT:ApplyConfig() local f = self.frame if not f then return end SFrames:ApplyStatusBarTexture(f.health, "totHealthTexture", "barTexture") local tex = SFrames:ResolveBarTexture("totHealthTexture", "barTexture") if f.health and f.health.bg then f.health.bg:SetTexture(tex) end if SFrames:IsGradientStyle() then SFrames:ApplyGradientStyle(f.health) if f.hbg then f.hbg:Hide() end if f.health and f.health.bg then f.health.bg:Hide() end else SFrames:RemoveGradientStyle(f.health) if f.hbg then f.hbg:Show() end if f.health and f.health.bg then f.health.bg:Show() end end end function SFrames.ToT:Initialize() local f = CreateFrame("Button", "SFramesToTFrame", UIParent) f:SetWidth(120) f:SetHeight(25) if SFramesDB and SFramesDB.Positions and SFramesDB.Positions["ToTFrame"] then local pos = SFramesDB.Positions["ToTFrame"] f:SetPoint(pos.point or "BOTTOMLEFT", UIParent, pos.relativePoint or "BOTTOMLEFT", pos.xOfs or 0, pos.yOfs or 0) else f:SetPoint("BOTTOMLEFT", SFramesTargetFrame, "BOTTOMRIGHT", 5, 0) end f:RegisterForClicks("LeftButtonUp", "RightButtonUp") f:SetScript("OnClick", function() if arg1 == "LeftButton" then TargetUnit("targettarget") end end) -- Health Bar f.health = SFrames:CreateStatusBar(f, "SFramesToTHealth") f.health:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1) f.health:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1) local hbg = CreateFrame("Frame", nil, f) hbg:SetPoint("TOPLEFT", f.health, "TOPLEFT", -1, 1) hbg:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT", 1, -1) hbg:SetFrameLevel(f:GetFrameLevel() - 1) SFrames:CreateUnitBackdrop(hbg) f.hbg = hbg f.health.bg = f.health:CreateTexture(nil, "BACKGROUND") f.health.bg:SetAllPoints() f.health.bg:SetTexture(SFrames:GetTexture()) f.health.bg:SetVertexColor(_A.slotBg[1], _A.slotBg[2], _A.slotBg[3], _A.slotBg[4] or 1) f.nameText = SFrames:CreateFontString(f.health, 10, "CENTER") f.nameText:SetPoint("CENTER", f.health, "CENTER", 0, 0) self.frame = f f:Hide() self:ApplyConfig() if SFrames.Movers and SFrames.Movers.RegisterMover then SFrames.Movers:RegisterMover("ToTFrame", f, "目标的目标", "BOTTOMLEFT", "SFramesTargetFrame", "BOTTOMRIGHT", 5, 0, nil, { alwaysShowInLayout = true }) end -- Update loop since targettarget changes don't fire precise events in Vanilla self.updater = CreateFrame("Frame") self.updater.timer = 0 self.updater:SetScript("OnUpdate", function() this.timer = this.timer + arg1 if this.timer >= 0.2 then SFrames.ToT:Update() this.timer = 0 end end) end function SFrames.ToT:Update() if UnitExists("targettarget") then self.frame:Show() local hp = UnitHealth("targettarget") local maxHp = UnitHealthMax("targettarget") self.frame.health:SetMinMaxValues(0, maxHp) self.frame.health:SetValue(hp) self.frame.nameText:SetText(UnitName("targettarget")) if UnitIsPlayer("targettarget") then local _, class = UnitClass("targettarget") local color = SFrames.Config.colors.class[class] if color then self.frame.health:SetStatusBarColor(color.r, color.g, color.b) self.frame.nameText:SetTextColor(color.r, color.g, color.b) else self.frame.health:SetStatusBarColor(0, 1, 0) self.frame.nameText:SetTextColor(1, 1, 1) end else local r, g, b = 0.85, 0.77, 0.36 -- Neutral if UnitIsEnemy("player", "targettarget") then r, g, b = 0.78, 0.25, 0.25 -- Enemy elseif UnitIsFriend("player", "targettarget") then r, g, b = 0.33, 0.59, 0.33 -- Friend end self.frame.health:SetStatusBarColor(r, g, b) self.frame.nameText:SetTextColor(r, g, b) end else self.frame:Hide() end end