-------------------------------------------------------------------------------
--
--  Mod Name : BlinkHealthText 0.16
--  Author   : Blink
--  Date     : 2005/05/10
--  LastUpdate : 2006/03/30
--
-------------------------------------------------------------------------------

BHT_TextAlphaValue = 0.3;
BHT_PowerTextAlphaValue = 0.4;
BHT_TextHeight = 30;
BHT_InCombat = 0;

--BHT_ManaBarColor = {};
--BHT_ManaBarColor[0] = { r = 0.50, g = 0.50, b = 1.00, prefix = TEXT(MANA) };
--BHT_ManaBarColor[1] = { r = 1.00, g = 0.50, b = 0.50, prefix = TEXT(RAGE_POINTS) };
--BHT_ManaBarColor[2] = { r = 1.00, g = 0.50, b = 0.50, prefix = TEXT(FOCUS_POINTS) };
--BHT_ManaBarColor[3] = { r = 1.00, g = 1.00, b = 0.50, prefix = TEXT(ENERGY_POINTS) };
--BHT_ManaBarColor[4] = { r = 0.50, g = 1.00, b = 1.00, prefix = TEXT(HAPPINESS_POINTS) };

function BlinkHealthText_OnLoad()
	this:RegisterEvent("PLAYER_REGEN_DISABLED");
	this:RegisterEvent("PLAYER_REGEN_ENABLED");
	this:RegisterEvent("PLAYER_TARGET_CHANGED");
	this:RegisterEvent("PLAYER_ENTERING_WORLD");
	this:RegisterEvent("UNIT_PET");
	this:RegisterEvent("PLAYER_PET_CHANGED");

	BlinkHealthTextPlayerText:SetAlpha(BHT_TextAlphaValue);
	BlinkPowerTextPlayerText:SetAlpha(BHT_PowerTextAlphaValue);
	BlinkComboTextPlayerText:SetAlpha(BHT_PowerTextAlphaValue);
	BlinkHealthTextPetText:SetAlpha(BHT_PowerTextAlphaValue);
	BlinkPowerTextPetText:SetAlpha(BHT_PowerTextAlphaValue);

	BlinkHealthTextTargetText:SetAlpha(BHT_TextAlphaValue);
	BlinkPowerTextTargetText:SetAlpha(BHT_PowerTextAlphaValue);
end

function BlinkHealthText_OnEvent()
	if ( event == "PLAYER_TARGET_CHANGED" )then
		if( UnitExists("target") and BHT_InCombat == 1 ) then
			BHT_DisplayTargetHealthText();
			BHT_DisplayTargetPowerText();
			BlinkHealthTextTarget:Show();
			BlinkPowerTextTarget:Show();
		else
			BlinkHealthTextTarget:Hide();
			BlinkPowerTextTarget:Hide();
		end
	elseif ( ( event == "UNIT_PET" and arg1 == "player" ) or event == "PLAYER_PET_CHANGED" ) then
		if ( UnitExists("pet") and BHT_InCombat == 1 ) then 
			BHT_DisplayPetHealthText();
			BHT_DisplayPetPowerText();
			BlinkHealthTextPet:Show();
			BlinkPowerTextPet:Show();
		else
			BlinkHealthTextPet:Hide();
			BlinkPowerTextPet:Hide();
		end
	elseif ( event == "PLAYER_REGEN_DISABLED" ) then
		if ( event == "PLAYER_ENTERING_WORLD" ) then
			BlinkHealthTextPlayer:Hide();
			BlinkPowerTextPlayer:Hide();
			BlinkComboTextPlayer:Hide();
			BlinkHealthTextPet:Hide();
			BlinkPowerTextPet:Hide();
			BlinkHealthTextTarget:Hide();
			BlinkPowerTextTarget:Hide();
			BHT_InCombat = 0;
		else
			BHT_DisplayPlayerHealthText();
			BHT_DisplayPlayerPowerText();
			BHT_DisplayPlayerComboText();
			BlinkHealthTextPlayer:Show();
			BlinkPowerTextPlayer:Show();
			BlinkComboTextPlayer:Show();
			BHT_InCombat = 1;
		end
		if ( UnitExists("pet") ) then 
			BHT_DisplayPetHealthText();
			BHT_DisplayPetPowerText();
			BlinkHealthTextPet:Show();
			BlinkPowerTextPet:Show();
		end
		if( UnitExists("target") )then
			BHT_DisplayTargetHealthText();
			BHT_DisplayTargetPowerText();
			BlinkHealthTextTarget:Show();
			BlinkPowerTextTarget:Show();
		end
	elseif ( ( event == "PLAYER_REGEN_ENABLED" ) or ( event == "PLAYER_ENTERING_WORLD" ) ) then
		BlinkHealthTextPlayer:Hide();
		BlinkPowerTextPlayer:Hide();
		BlinkComboTextPlayer:Hide();
		BlinkHealthTextPet:Hide();
		BlinkPowerTextPet:Hide();
		BlinkHealthTextTarget:Hide();
		BlinkPowerTextTarget:Hide();
		BHT_InCombat = 0;
	end
end

-------------------------------------------------------------------------------

function BlinkHealthTextPlayer_OnLoad()
	this:RegisterEvent("UNIT_HEALTH");
end

function BlinkHealthTextPlayer_OnEvent(event)
	if( arg1 == "player" )then
		BHT_DisplayPlayerHealthText();
	end
end

function BHT_DisplayPlayerHealthText()
	local perH = UnitHealth("player") / UnitHealthMax("player") * 100;
	if ( perH < 20 )then
		BlinkHealthTextPlayerText:SetTextColor(1.0, 0.0, 0.2);
	elseif( perH < 40 and perH >= 20 )then
		BlinkHealthTextPlayerText:SetTextColor(1.0, 0.5, 0.2);
	elseif( perH < 60 and perH >= 40 )then
		BlinkHealthTextPlayerText:SetTextColor(1.0, 1.0, 0.2);
	elseif( perH < 80 and perH >= 60 )then
		BlinkHealthTextPlayerText:SetTextColor(0.5, 1.0, 0.2);
	else
		BlinkHealthTextPlayerText:SetTextColor(0.0, 1.0, 0.2);
	end
	BlinkHealthTextPlayerText:SetText(format("%d",perH));
	BlinkHealthTextPlayerText:SetAlpha(BHT_TextAlphaValue);
end

-------------------------------------------------------------------------------

function BlinkPowerTextPlayer_OnLoad()
	-- Mana Events
	this:RegisterEvent("UNIT_MANA");
	this:RegisterEvent("UNIT_RAGE");
	this:RegisterEvent("UNIT_FOCUS");
	this:RegisterEvent("UNIT_ENERGY");
	this:RegisterEvent("UNIT_HAPPINESS");
	this:RegisterEvent("UNIT_MAXMANA");
	this:RegisterEvent("UNIT_MAXRAGE");
	this:RegisterEvent("UNIT_MAXFOCUS");
	this:RegisterEvent("UNIT_MAXENERGY");
	this:RegisterEvent("UNIT_MAXHAPPINESS");
	this:RegisterEvent("UNIT_DISPLAYPOWER");
end

function BlinkPowerTextPlayer_OnEvent(event)
	if( arg1 == "player" )then
		BHT_DisplayPlayerPowerText();
	end
end

function BHT_DisplayPlayerPowerText()
	local currValue = UnitMana("player");
	--local info = ManaBarColor[UnitPowerType(arg1)];
	if( UnitClass("player") == "드루이드" ) then
		if( UnitPowerType("player") == 1 ) then
			BlinkPowerTextPlayerText:SetTextColor(1.0, 0.2, 0.2);
		elseif( UnitPowerType("player") == 3 ) then
			BlinkPowerTextPlayerText:SetTextColor(1.0, 1.0, 0.2);
		else
			BlinkPowerTextPlayerText:SetTextColor(0.0, 0.5, 1.0);
		end
	elseif( UnitClass("player") == "전사" ) then
		BlinkPowerTextPlayerText:SetTextColor(1.0, 0.2, 0.2);
	elseif( UnitClass("player") == "도적" ) then
		BlinkPowerTextPlayerText:SetTextColor(1.0, 1.0, 0.2);
	else
		BlinkPowerTextPlayerText:SetTextColor(0.0, 0.5, 1.0);
	end
	BlinkPowerTextPlayerText:SetText(currValue);
	BlinkPowerTextPlayerText:SetAlpha(BHT_PowerTextAlphaValue);
end

-------------------------------------------------------------------------------

function BlinkComboTextPlayer_OnLoad()
	if ( select(2,UnitClass("player")) == "DRUID" or select(2,UnitClass("player")) == "ROGUE" ) then
	this:RegisterEvent("PLAYER_COMBO_POINTS");

end

function BlinkComboTextPlayer_OnEvent(event)
	if( event == "PLAYER_COMBO_POINTS" ) then
		BHT_DisplayPlayerComboText();
	end
end

function BHT_DisplayPlayerComboText()

		local combo = GetComboPoints();
		local perS = "";
		if( combo > 0 )then
			perS = "|cFFFF6622"..combo.."|r";
		else
			perS = "";
		end


		BlinkComboTextPlayerText:SetText(perS);
		BlinkComboTextPlayerText:SetAlpha(BHT_PowerTextAlphaValue);
	
	end
end

-------------------------------------------------------------------------------

function BlinkHealthTextPet_OnLoad()
	this:RegisterEvent("UNIT_HEALTH");
end

function BlinkHealthTextPet_OnEvent(event)
	if ( arg1 == "pet" ) then
		BHT_DisplayPetHealthText();
	end
end

function BHT_DisplayPetHealthText()
	local perH = UnitHealth("pet") / UnitHealthMax("pet") * 100;
	if ( perH < 20 )then
		BlinkHealthTextPetText:SetTextColor(1.0, 0.0, 0.2);
	elseif( perH < 40 and perH >= 20 )then
		BlinkHealthTextPetText:SetTextColor(1.0, 0.5, 0.2);
	elseif( perH < 60 and perH >= 40 )then
		BlinkHealthTextPetText:SetTextColor(1.0, 1.0, 0.2);
	elseif( perH < 80 and perH >= 60 )then
		BlinkHealthTextPetText:SetTextColor(0.5, 1.0, 0.2);
	else
		BlinkHealthTextPetText:SetTextColor(0.0, 1.0, 0.2);
	end
	BlinkHealthTextPetText:SetText(format("%d",perH));
	BlinkHealthTextPetText:SetAlpha(BHT_TextAlphaValue);
end

-------------------------------------------------------------------------------

function BlinkPowerTextPet_OnLoad()
	-- Mana Events
	this:RegisterEvent("UNIT_MANA");
	this:RegisterEvent("UNIT_RAGE");
	this:RegisterEvent("UNIT_FOCUS");
	this:RegisterEvent("UNIT_ENERGY");
	this:RegisterEvent("UNIT_HAPPINESS");
	this:RegisterEvent("UNIT_MAXMANA");
	this:RegisterEvent("UNIT_MAXRAGE");
	this:RegisterEvent("UNIT_MAXFOCUS");
	this:RegisterEvent("UNIT_MAXENERGY");
	this:RegisterEvent("UNIT_MAXHAPPINESS");
	this:RegisterEvent("UNIT_DISPLAYPOWER");
end

function BlinkPowerTextPet_OnEvent(event)
	if ( arg1 == "pet" ) then
		BHT_DisplayPetPowerText();
	end
end

function BHT_DisplayPetPowerText()
	if (UnitManaMax("pet") ~= 0 ) then
		local currValue = UnitMana("pet");
		--local info = ManaBarColor[UnitPowerType(arg1)];
		if( UnitClass("pet") == "전사" ) then
			if( UnitIsPlayer("pet") ) then
				BlinkPowerTextPetText:SetTextColor(1.0, 0.2, 0.2);
			else
				BlinkPowerTextPetText:SetTextColor(1.0, 0.6, 0.2);
			end
		elseif( UnitClass("pet") == "도적" ) then
			BlinkPowerTextPetText:SetTextColor(1.0, 1.0, 0.2);
		else
			BlinkPowerTextPetText:SetTextColor(0.0, 0.5, 1.0);
		end
		BlinkPowerTextPetText:SetText(currValue);
		BlinkPowerTextPetText:SetAlpha(BHT_PowerTextAlphaValue);
	else
		BlinkPowerTextPetText:SetText("");
	end
end

-------------------------------------------------------------------------------

function BlinkHealthTextTarget_OnLoad()
	this:RegisterEvent("UNIT_HEALTH");
end

function BlinkHealthTextTarget_OnEvent(event)
	if( arg1 == "target" )then
		BHT_DisplayTargetHealthText();
	end
end

function BHT_DisplayTargetHealthText()
--	local perH = TargetFrameHealthBar:GetValue();
	local perH = UnitHealth("target") / UnitHealthMax("target") * 100;
	if ( perH < 20 )then
		BlinkHealthTextTargetText:SetTextColor(1.0, 0.0, 0.2);
	elseif( perH < 40 and perH >= 20 )then
		BlinkHealthTextTargetText:SetTextColor(1.0, 0.5, 0.2);
	elseif( perH < 60 and perH >= 40 )then
		BlinkHealthTextTargetText:SetTextColor(1.0, 1.0, 0.2);
	elseif( perH < 80 and perH >= 60 )then
		BlinkHealthTextTargetText:SetTextColor(0.5, 1.0, 0.2);
	else
		BlinkHealthTextTargetText:SetTextColor(0.0, 1.0, 0.2);
	end
	BlinkHealthTextTargetText:SetText(format("%d",perH));
	BlinkHealthTextTargetText:SetAlpha(BHT_TextAlphaValue);
end

-------------------------------------------------------------------------------

function BlinkPowerTextTarget_OnLoad()
	this:RegisterEvent("UNIT_MANA");
	this:RegisterEvent("UNIT_RAGE");
	this:RegisterEvent("UNIT_FOCUS");
	this:RegisterEvent("UNIT_ENERGY");
	this:RegisterEvent("UNIT_HAPPINESS");
	this:RegisterEvent("UNIT_MAXMANA");
	this:RegisterEvent("UNIT_MAXRAGE");
	this:RegisterEvent("UNIT_MAXFOCUS");
	this:RegisterEvent("UNIT_MAXENERGY");
	this:RegisterEvent("UNIT_MAXHAPPINESS");
	this:RegisterEvent("UNIT_DISPLAYPOWER");
end

function BlinkPowerTextTarget_OnEvent(event)
	if( arg1 == "target" )then
		BHT_DisplayTargetPowerText();
	end
end

function BHT_DisplayTargetPowerText()
	local min, maxValue = TargetFrameManaBar:GetMinMaxValues();
	--local info = BHT_ManaBarColor[UnitPowerType(arg1)];

	local pvalue;
	if ((min == 0) and (maxValue == 0)) then
		pvalue= "";
	else
		currValue = TargetFrameManaBar:GetValue();
		if( UnitClass("target") == "도적" and maxValue > 100 )then
			pvalue = currValue .. "/" .. maxValue;
		else
			pvalue = currValue;
		end
	end
	if( UnitClass("target") == "드루이드" ) then
		if( UnitPowerType("target") == 1 ) then
			BlinkPowerTextTargetText:SetTextColor(1.0, 0.2, 0.2);
		elseif( UnitPowerType("target") == 3 ) then
			BlinkPowerTextTargetText:SetTextColor(1.0, 1.0, 0.2);
		else
			BlinkPowerTextTargetText:SetTextColor(0.0, 0.5, 1.0);
		end
	elseif( UnitClass("target") == "전사" ) then
		if( UnitIsPlayer("target") ) then
			BlinkPowerTextTargetText:SetTextColor(1.0, 0.2, 0.2);
		else
			BlinkPowerTextTargetText:SetTextColor(1.0, 0.6, 0.2);
		end
	elseif( UnitClass("target") == "도적" ) then
		BlinkPowerTextTargetText:SetTextColor(1.0, 1.0, 0.2);
	else
		BlinkPowerTextTargetText:SetTextColor(0.0, 0.5, 1.0);
	end
	BlinkPowerTextTargetText:SetText(pvalue);
	BlinkPowerTextTargetText:SetAlpha(BHT_PowerTextAlphaValue);
end

-------------------------------------------------------------------------------
