Quantcast
local T, C, L = unpack(Tukui)
if not C.unitframes.enable then return end
local oUF = oUFTukui or oUF

local barTex = T.GetBarTexture()

T.unitframefuncs["general"] = function(self)
	local name = self:GetName()
	local unit = strlower(strsub(name, strfind(name, "Tukui")+5, strfind(name, "%d") and strfind(name, "%d")-1))
	if not C.unitframes.Units[unit] then return end
	local enable, width, height = T.GetUnitConfig(unit)

	if enable~=true then self:Kill() return end

	local health = self.Health
	local power = self.Power
	local panel = self.panel
	local nameText = self.Name
	local castbar = self.Castbar

	self:SetSize(width, height)

	self:SetBackdrop(nil)
	self.shadow:Kill()

	if health then
		if health.PostUpdate then
			hooksecurefunc(health, "PostUpdate", T.ReverseBar)
		end
		health:ClearAllPoints()
		health:AllPoints(self, 2)
		health:SetStatusBarTexture(barTex)
		health.bg:Kill()
		health:CreateBackdrop("Transparent")
		health:ThickBorder()
		health:AddSpark()
		if health.value then
			health.value:SetFont(T.GetPixelFont())
			health.value:SetShadowOffset(0, 0)
		end
		health.PreUpdate = T.PreUpdateHealth
		health.PostUpdate = T.PostUpdateHealth
	end

	if power then
		power:SetStatusBarTexture(barTex)
		power.bg:Kill()
		power:CreateBackdrop("Transparent")
		power:ThickBorder()
		power:AddSpark()
		power.PostUpdate = T.PostUpdatePower
		if power.value then
			power.value.colorPower = true
			power.value:SetFont(T.GetPixelFont())
			power.value:SetShadowOffset(0, 0)
		end
	end

	if panel then
		panel:SetBackdrop(nil)
		panel:ClearAllPoints()
		panel:SetAllPoints(health)
		panel:SetFrameLevel(health:GetFrameLevel()+10)
	end

	if nameText then
		nameText:SetFont(T.GetPixelFont())
	end

	if castbar then
		castbar:ClearAllPoints()
		castbar:SetPoint("TOPLEFT", power, "BOTTOMLEFT", 0, -7)
		castbar:SetPoint("TOPRIGHT", power, "BOTTOMRIGHT", 0, -7)
		castbar:SetHeight(13)
		castbar:CreateBackdrop("Transparent")
		castbar:ThickBorder()
		if castbar.bg then castbar.bg:Kill() end

		castbar.Time:ClearAllPoints()
		castbar.Time:Point("RIGHT", castbar, "RIGHT", -4, 0)
		castbar.Time:SetFont(T.GetPixelFont())
		castbar.Time:SetShadowOffset(0, 0)

		castbar.Text:ClearAllPoints()
		castbar.Text:Point("LEFT", castbar, "LEFT", 4, 0)
		castbar.Text:SetFont(T.GetPixelFont())
		castbar.Text:SetShadowOffset(0, 0)
	end

	if self.Experience then self.Experience:Kill() end
	if self.Reputation then self.Reputation:Kill() end

	self:UpdateAllElements()
end