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

------------------------------------------------------------------
-- Custom oUF Tags -----------------------------------------------
------------------------------------------------------------------

oUF.TagEvents['st:cpoints'] = 'PLAYER_TARGET_CHANGED UNIT_COMBO_POINTS PLAYER_ENTERING_WORLD'
oUF.Tags['st:cpoints'] = function(unit)
	return GetComboPoints("player", unit)
end

oUF.TagEvents['st:level'] = 'UNIT_LEVEL PLAYER_LEVEL_UP UNIT_CLASSIFICATION_CHANGED'
oUF.Tags['st:level'] = function(unit)
	local level = UnitLevel(unit)
	local c = ""

	if(UnitClassification(unit) == 'rare') then
		c = 'R'
	elseif(UnitClassification(unit) == 'eliterare') then
		c = 'R+'
	elseif(UnitClassification(unit) == 'elite') then
		c = '+'
	elseif(UnitClassification(unit) == 'worldboss') then
		c = 'B'
	end

	local r, g, b
	if (level < 1) then
		r, g, b = 0.69, 0.31, 0.31
		level = "??"
	else
		local DiffColor = UnitLevel(unit) - UnitLevel('player')
		if (DiffColor >= 5) then
			r, g, b = 0.69, 0.31, 0.31
		elseif (DiffColor >= 3) then
			r, g, b = 0.71, 0.43, 0.27
		elseif (DiffColor >= -2) then
			r, g, b = 0.84, 0.75, 0.65
		elseif (-DiffColor <= GetQuestGreenRange()) then
			r, g, b = 0.33, 0.59, 0.33
		else
			r, g, b = 0.55, 0.57, 0.61
		end
		if DiffColor == 0 then
			level = ""
		else
			level = level.." "
		end
	end
	return string.format('|cff%02x%02x%02x%s%s|r', r * 255, g * 255, b * 255, level, c)
end

oUF.TagEvents['st:nametiny'] = 'UNIT_NAME_UPDATE'
oUF.Tags['st:nametiny'] = function(unit)
	local name = UnitName(unit)
	if not name then return end
	return strsub(name, 1, 4)
end

oUF.TagEvents['st:nameshort'] = 'UNIT_NAME_UPDATE'
oUF.Tags['st:nameshort'] = function(unit)
	local name = UnitName(unit)
	if not name then return end
	return strsub(name, 1, 10)
end

oUF.TagEvents['st:namemedium'] = 'UNIT_NAME_UPDATE'
oUF.Tags['st:namemedium'] = function(unit)
	local name = UnitName(unit)
	if not name then return end
	return strsub(name, 1, 15)
end

oUF.TagEvents['st:namelong'] = 'UNIT_NAME_UPDATE'
oUF.Tags['st:namelong'] = function(unit)
	local name = UnitName(unit)
	if not name then return end
	return strsub(name, 1, 20)
end

oUF.TagEvents['st:status'] = 'UNIT_HEALTH UNIT_CONNECTION'
oUF.Tags['st:status'] = function(unit)
	if(not UnitIsConnected(unit)) then
		return '|cffff0000<D/C>|r'
	elseif(UnitIsDead(unit)) then
		return '|cffff0000<Dead>|r'
	elseif(UnitIsGhost(unit)) then
		return '|cffff0000<Ghost>|r'
	end
end