Quantcast
local A, L = ...

local thin = L.C.thin

local function ReskinStatusBar(self)
	self:SetBackdrop(nil)
	self.SetBackdrop = L.Dummy

	local backdrop = self.edgeBackdrop or self.backdrop
	if backdrop then
		backdrop:SetBackdrop(nil)
		backdrop.SetBackdrop = L.Dummy
	end

    L.CreateBackdrop(self, nil, thin)
end

local function SkinThreatClassic2()
	if not IsAddOnLoaded("ThreatClassic2") then return end

    local frame = _G.ThreatClassic2BarFrame
    if not frame then return end

    frame:SetScale(L.C.scale)

    local frameBg = frame.bg
    if frameBg then
        frameBg:SetColorTexture(0, 0, 0, 0)
        frameBg:SetVertexColor(0, 0, 0, 0)
        frameBg.SetVertexColor = L.Dummy
    end

    local header = frame.header
    if header then
        ReskinStatusBar(header)
        header:SetStatusBarColor(0, 0, 0, 0)
        header.SetStatusBarColor = L.Dummy
        header.text:SetPoint("LEFT", header, 4, 0)
    end

    for _, child in pairs {frame:GetChildren()} do
        if child:GetObjectType() == "StatusBar" and child.bg and child.val then
            ReskinStatusBar(child)
            child.bg:SetVertexColor(0, 0, 0, 0)
            child.bg.SetVertexColor = L.Dummy
        end
    end

    if rSkinDB.resets.threatclassic2 then
        ThreatClassic2DB = ThreatClassic2DB or {}
        ThreatClassic2DB["profiles"] = ThreatClassic2DB["profiles"] or {}
        ThreatClassic2DB["profiles"]["Default"] = ThreatClassic2DB["profiles"]["Default"] or {}

        local profile = ThreatClassic2DB["profiles"]["Default"]
        if profile then
            local barCfg = L.C.bar
            local w, h = unpack(barCfg.small)
            profile.bar = profile.bar or {}
            profile.bar.texture = profile.bar.texture or "normTex"
            profile.bar.padding = barCfg.space.small
            profile.bar.count = 5
            profile.bar.height = h + 1
            profile.frame = profile.frame or {}
            profile.frame.scale = L.C.scale
			profile.frame.width = w
            profile.frame.height = (h+profile.bar.padding)*profile.bar.count
            profile.frame.headerShow = false
            profile.frame.locked = true
            profile.frame.position = {"BOTTOMRIGHT", nil, "BOTTOMRIGHT", -20-w , 54}
        end
        rSkinDB.resets.threatclassic2 = false
    end
end

rSkin:RegisterSkin("ThreatClassic2", SkinThreatClassic2)